lllllIllIlllI 178 Veteran Poster

There is no goto keyword in java that will take you to a certain line. According to wikipedia the goto keyword is reserved in java but not actually used.

So, goto is not a choice.. changing the code should be though. i'll leave that to someone a little more equipped when it comes to java though :P

lllllIllIlllI 178 Veteran Poster

Oh i definitely agree. Classes are the way to go, i was just suggesting an alternative in case you were not comfortable with classes :)

lllllIllIlllI 178 Veteran Poster

How about you have something that means that if your functions are going to be something along the lines of room1, room2, room3, room4 and such.

So what you could do was return the room number you wanted to go to. eg. 1,2,3,4,5 then you can use the eval statement to make a string of the function such as:

RoomInt = 3
eval("room"+str(RoomInt)+'()')

So that will first give you a string of 'room3()' and then evaluate it which will then call the function. That way you can have soo many functions.

hope that helps

lllllIllIlllI 178 Veteran Poster

Here is what i would do. I would have something that is the Main function, that calls room1 to start off with... Then IF room1 wants to call room2 it returns a special value that means i know the Main function has to call room2.

def room1():
    #is you need to call room two then:
    if something:
        #return the number 2
        return 2

def room2():
    print "ROOM 2"

def Main():
    var = room1()
    if var == 2:
        room2()

So by having return values you can make it a lot easier to see what is going on as there is only one place to look (the Main function) as well as you don't get stuck in some massive recursive loop.

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

If you have to make your own sort algorithm i would look at the wikipedia pages for sorts such as the bubble sort. It is a very simple sort and the pseudo-code can be very easily translated into python.
http://en.wikipedia.org/wiki/Bubble_sort

From wikipedia pseudo code

procedure bubbleSort( A : list of sortable items ) defined as:
  do
    swapped := false
    for each i in 0 to length(A) - 2 inclusive do:
      if A[i] > A[i+1] then
        swap( A[i], A[i+1] )
        swapped := true
      end if
    end for
  while swapped
end procedure

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

just an FYI as to what split is for (i am assuming you are new to python) is that is automatically splits up a string into its separate words. Such as

'Hello i am Paul'.split()
#Would give the result of a list:
['Hello','i','am','Paul']

The argument you can give it is what so split by in case you don't want to split by spaces. For your case it appears that you have a colon distinguishing your keyword from your value. Therefore the previous poster is correct in saying that x.split(':') should be perfect for you as it will split the string instead of by the spaces but by the colon.

Hope that helps

lllllIllIlllI 178 Veteran Poster

Here is a quick program to get all the current ones. But it really doesn't matter if you overwrite them for the most part anyway. The chance of you doing that is also very small

import wx

for f in dir(wx):
    if f.startswith("ID_"):
        print f, eval('wx.'+f)

This will print the name of the ID with the corresponding value. They are all four digit though, so you could get around your problem by having 1,2,3,5,6 or 7 digit numbers.

Hope that helps! :D

lllllIllIlllI 178 Veteran Poster

If you knew that the array is only two deep (2D array) then you could do it:

for listIndex, subList in enumerate(myList):
    try:
        ind = subList.index('sheep')
        break
    except ValueError:
        print "Not in list number",listIndex
print "It is in list number",listIndex
print "and index number",ind,"of that list"

What that does is it goes through all the lists inside your larger list, looks for the string and if it finds the string it breaks from the loop and gives the two values, one is the list that it is in inside the larger list (from 0) and the other is the index of the string in that sublist.

hope that helps :)

lllllIllIlllI 178 Veteran Poster

<CannedResponseforhomework>
So, what have you done?
Remember here at daniweb we aren't here just to do your homework:
http://www.daniweb.com/forums/announcement114-2.html

When you have shown effort, we will show some too.
</CannedResponseforhomework>

lllllIllIlllI 178 Veteran Poster

It isn't the third line that is having the issues. It is line 37. If you look there, there is an if yet no indentation after it. Though i assume all you need to do is backspace that if a couple of times to get it on the correct level.

Like this:

def getEnergyAndMana(magicExp, energyExp, maxYourMana, bonus, energyLevel, bonus1):
    magicLevel = 0
    if magicExp >= 0:
        magicLevel = 0
        maxYourMana = 50 + bonus
    if magicExp >= 550:
        magicLevel = 1
        maxYourMana = 100 + bonus
    if magicMax >= 1150:
        magicLevel = 2
        maxYourMana = 150 + bonus
    if magicExp >= 1750:
        magicLevel = 3
        maxYourMana = 200 + bonus
    if magicExp >= 2350:
        magicLevel = 4
        maxYourMana = 250 + bonus
    if magicExp >= 3050:
        magicLevel = 5
        maxYourMana = 300 + bonus
    if magicExp >= 3750:
        magicLevel = 6
        maxYourMana = 350 + bonus
    if magicExp >= 4650:
        magicLevel = 7
        maxYourMana = 400 + bonus
    if magicExp >= 5050:
        magicLevel = 8
        maxYourMana = 450 + bonus
    if magicExp >= 5750:
        magicLevel = 9
        maxYourMana = 500 + bonus
    if magicExp >= 6350:
        magicLevel = 10
        maxYourMana = 550 + bonus

    if energyExp >= 0:
        energyLevel = 0
        maxYourEnergy = 50 + bonus1
    if energyExp >= 550:
        energyLevel = 1
        maxYourEnergy = 100 + bonus1
    if energyExp >= 1150:
        energyLevel = 2
        maxYourEnergy = 150 + bonus1
    if energyExp >= 1750:
        energyLevel = 3
        maxYourEnergy = 200 + bonus1
    if energyExp >= 2350:
        energyLevel = 4
        maxYourEnergy = 250 + bonus1
    if energyExp >= 3050:
        energyLevel = 5
        maxYourEnergy = 300 + bonus1
    if energyExp >= 3750:
        energyLevel = 6
        maxYourEnergy = 350 + bonus1
    if energyExp >= 4650:
        energyLevel = 7
        maxYourEnergy = 400 + bonus1
    if energyExp >= 5050:
        energyLevel = 8
        maxYourEnergy = 450 + bonus1
    if energyExp >= 5750:
        energyLevel = 9
        maxYourEnergy = 500 + bonus1
    if energyExp >= 6350:
        energyLevel = 10
        maxYourEnergy = 550 + bonus1
    yourEnergy = maxYourEnergy
    yourMana = maxYourMana
    return maxYourEnergy, maxYourMana, yourMana, yourEnergy

Also, your code was mixing tabs and spaces.. thats a dangerous thing to do. Try just using spaces for the best results.

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

If i remember correctly wxPython is not looking to port to python 3.x any time soon. So if you are interested in using that then i would reccomend that you don't change.

Personally i have not moved, i have tried it out but i never really found a reason to stick with it in the end so i have stayed with python 2.6 and i will until there is a major reason to change and at the moment there really isnt.

vegaseat commented: good point +10
lllllIllIlllI 178 Veteran Poster

Well i would start by re-downloading the file. Something may have gone wrong that caused the download to stop halfway through.

So try that, if you haven't already :)

lllllIllIlllI 178 Veteran Poster

Well i can help with your first problem.
I had trouble with this for a bit, but looking at the wxPython Demo's code i noticed that instead of just appending it, they first add a "StringItem" and get the return value of that (which is the index of the string item) and then just add values/colours to that.

#!/usr/bin/python

import wx
import sys

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, (550, 350))

        self.List = wx.ListCtrl(self, wx.ID_ANY, style = wx.LC_REPORT)

        self.List.InsertColumn(0,"Title")
        self.List.InsertColumn(1,"Artist")
        self.List.InsertColumn(2,"Album")

        index =  self.List.InsertStringItem(sys.maxint,"We didn't start the fire")
        self.List.SetStringItem(index, 1, "Billy Joel")
        self.List.SetStringItem(index, 2, "Unknown")
        self.List.SetItemBackgroundColour(index,"light blue")
                                            
        index =  self.List.InsertStringItem(sys.maxint,"Take it easy")
        self.List.SetStringItem(index, 1, 'Eagles')
        self.List.SetStringItem(index, 2, 'The complete greatest hits')
        self.List.SetItemBackgroundColour(index,"green")
       

       

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'wxCAKE')
        frame.Centre()
        frame.Show(True)
        return True
    
app = MyApp(0)
app.MainLoop()

This shows how it is done. You should be able to see the vast difference from the last one, even though it looks like a lot more code, with a smart 'for' loop you should be able to get it a bit cleaner

hope that helps :)

lllllIllIlllI 178 Veteran Poster

I have a feeling that you could use a listctrl in a better way. If you use the style wx.LC_REPORT i think it is, you can have a look just like you want in just one widget.

Ill just give you an example.

#!/usr/bin/python

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, (550, 350))

        self.List = wx.ListCtrl(self, wx.ID_ANY, style = wx.LC_REPORT)

        self.List.InsertColumn(0,"Title")
        self.List.InsertColumn(1,"Artist")
        self.List.InsertColumn(2,"Album")

        self.List.Append(("We didn't start the fire", "Billy Joel", "Unknown"))
        self.List.Append(("Take it easy",'Eagles','The complete greatest hits'))

        sizer = wx.BoxSizer()

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'wxCAKE')
        frame.Centre()
        frame.Show(True)
        return True
    
app = MyApp(0)
app.MainLoop()

Hope that helps :) its amazing how much the widget changes just because of changing one style isnt it?

HAve a look at the wx api if you want to know more about the wx.ListCtrl and what you can do with it.
http://www.wxpython.org/docs/api/wx.ListCtrl-class.html

Cheers :)

lllllIllIlllI 178 Veteran Poster

This shows that your data inside the incoming_data list is of type long. You can just 'add' (+) strings and longs together. You can do one of two things.
You can do something like this using the comma

>>>print "Hello this uses a comma to add an int to the end",15
Hello this uses a comma to add an int to the end 15

Or you can use the str() method to change the int/long to a string and the add it together using the + sign.

>>> print "This uses the str method: "+str(15)
This uses the str method:15

I would reccomend either changing your code to

sql_cmd = \
        "INSERT INTO customer_synch " + \
        "VALUES ( " + \
        "'A', " , \
        incoming_data[0] , "," , \
        incoming_data[1] , "," , \
        incoming_data[2] , "," , 
        #you get the point by now

or

sql_cmd = \
        "INSERT INTO customer_synch " + \
        "VALUES ( " + \
        "'A', " + \
       str( incoming_data[0]) + "," + \
       str (incoming_data[1]) + "," + \
        str(incoming_data[2]) + "," + \

I hope that helps you out :)

BTW: one thousand posts!!!! YAY :)

Gribouillis commented: congrats for the 1000 posts +3
lllllIllIlllI 178 Veteran Poster

Perhaps just put it in the same directory as your executable. That could help, i have never really used icons on my programs so i'm not super sure, but when i use files in my executables such as .txt and .jpg i need to make sure that they are either bundled into the program (a bit of work) or in the same directory as the exe.


Hope that helps :)

ooh 999 posts, cant wait for the next one

lllllIllIlllI 178 Veteran Poster

Yeah, i got that. Its easily fixed by taking out the manifest. I didn't have this problem with windows XP but i am getting it with 7.
So i would use gui2exe like suggested above and just make sure that XP manifest file is unticket down the bottom

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

You could just use the Show(False) function on all of the children of the panel.

lllllIllIlllI 178 Veteran Poster

Glad i could help :)

lllllIllIlllI 178 Veteran Poster

Also, its good practice to not have functions that are using names that are already taken. Such as print, int, str, list bool and so on. So it's probably best if you change your list() function to another name. :)

lllllIllIlllI 178 Veteran Poster

This page explains it very clearly
http://www.network-theory.co.uk/docs/pytut/Packages.html

One thing i noticed quickly though, you are not meant to have

my_package/
	__init.py__
	sub_pack/
		__init.py__
		test.py

in your actual code for __init__.py Its just meant to be the way you organise the filesystem. From the first __init__.py you should be able to go something like

import subpack.test.py

and that should come back error free :)

hope that helps

lllllIllIlllI 178 Veteran Poster

Yeah i agree with vegaseat, we need to see the code for MyFrame, thats where the problem most likely is.

Also just to make sure, are you actually getting any errors? Or is it just not updating?

lllllIllIlllI 178 Veteran Poster

No. http://www.daniweb.com/forums/announcement114-2.html

Tell us your problem you are having ("its not working" doesn't count) and we can help you with your problems. We aren't going to go and find the bugs as well as try and fix them.

lllllIllIlllI 178 Veteran Poster

You need what are called 'command line arguments'. Dive into python has a great section explaining command line arguments. But in essence you could do something like this:

import sys
if sys.argv:
    print "The first command line argument i recieved was:",sys.argv[0]

Then we would run our code like this:

python filename.py ThisIsTheArgument

And the result would print the following out

The first command line argument i recieved was: ThisIsTheArgument

So i'm sure you can see that instead of writing 'ThisIsTheArgument' that you could put a path to a file there instead and then do things to it in your program. Anyway, have a look at the link above, it'll help you out :)

lllllIllIlllI 178 Veteran Poster

Yup, having used both languages i generally find python even easier than java to do that.

#Just have a class we can instantiate
class Instance(object):
    x = 1
    def __init__(self, number):
        self.number = number

instances = []
for f in range(10):
    instances.append(Instance(f))

for f in instances:
    print(f.number)

The main difference is that you do not need to use the 'new' operator and also you do not need to say how long the array is going to be so you can just use the append argument which means that the instance will be appended to the list.

Hope that helps

lllllIllIlllI 178 Veteran Poster

Here is a snippet from the code that controls the demo

self._mgr.AddPane(self.CreateSizeReportCtrl(), aui.AuiPaneInfo().
                          Name("test2").Caption("Client Size Reporter").
                          Bottom().Position(1).CloseButton(True).MaximizeButton(True).
                          MinimizeButton(True))

So it appears that rather than using styles that they have functions to make them have max, min and close buttons

lllllIllIlllI 178 Veteran Poster

I think so. That can almost always be changed by changing the styles when making the widget.

lllllIllIlllI 178 Veteran Poster

Thing is, if there isnt one you really aren't interested in then create your own if you're passionate about something. :) hopefully then people will jump on the bandwagon and help you out.

lllllIllIlllI 178 Veteran Poster

Personally i dont think its a good idea to just piggyback on an open source project just because you want to stretch your skills. Instead think of something that you really think would be fun to do, or interesting and complex and then go for that, that way you don't start losing interest after the first day or two of programming.

Here is a stack overflow thread on the same subject which could be useful :)
http://stackoverflow.com/questions/117561/what-are-good-open-source-projects-in-python-for-which-i-can-be-a-contributor

lllllIllIlllI 178 Veteran Poster

If you do multiple songs then to play them you would need the path to every song so therefore my method would work fine, you would just use my method for every song that you needed to find out the info.

lllllIllIlllI 178 Veteran Poster

If you can get the whole string (which you can with os.walk) then you can do this no worries :)

>>> s = "/home/foo/Music/The Eagles/Hell Freezes Over/<songname>"
>>> list_s = s.split('/')
>>> list_s
['', 'home', 'foo', 'Music', 'The Eagles', 'Hell Freezes Over', '<songname>']
>>> print list_s[-2]
Hell Freezes Over
>>> print list_s[-3]
The Eagles
>>>

See how this works? We split up the path of the song, then if we know how it is structured then we can extract the song album and artist. :)

Have a fiddle, see if you can incorporate that into your own program :)

EDIT: Thats an awesome album by the way

lllllIllIlllI 178 Veteran Poster

How would I have a python program running constantly?

If you are running windows you can just put your program in the 'startup' folder in your start menu and it will be started every time the computer turns on.

Though, if somehow the program quits, be that because of an error or some other means it will not be restarted.

lllllIllIlllI 178 Veteran Poster

When looking at the wx.Aui example i can see examples of 'frames' with maximise, minimise and close buttons. Sounds a lot like what you need?

Im just looking at the wxPython Docs and Demos :)

Stefano Mtangoo commented: Yah! you are right - that is the widget! +4
lllllIllIlllI 178 Veteran Poster

You could try Eric IDE, i never got around to installing it, but it always looked promising
http://eric-ide.python-projects.org/

lllllIllIlllI 178 Veteran Poster

I never ever go to the main page, i start my visit at forum 26 every time. Its what i have as my bookmark. Then if My Favourite Forum shows that there are posts to be read in other forums i will go to them.

At the moment i am reducing my activity because i can't be bothered going and checking out all the forums in case there has been a post, thats why the golden folders next to the forums on My Favourite Forums were so good.

I agree with everyone else, most of the people i see have less than 5 posts, and i dont think they even CARE about the features of the site. But this is quite annoying, if you care so much about what gets the top spot on the side bar, why dont you put it one or two down?

Personally i have never used anything else apart from My Favourite Forums on the side bar, and im very sorry to see it go.
I wish perhaps that three hour discussion had included some of us.

lllllIllIlllI 178 Veteran Poster

snippsat, you should post that as a tutorial :)

lllllIllIlllI 178 Veteran Poster

mmmm, i would use decorators as well... i was just thinking if you didnt want to have to type that arbitraryFunction() that you probably wouldn't want to type @arbitraryDecorator That being said, decorators can be very useful and powerful especially when it comes to classes, so if you haven't used them before i would think its probably a good idea to have a go, even if it just is to lean about them. :)

lllllIllIlllI 178 Veteran Poster

Yes, you can, although its not that pretty, here is something that i think shows how something like that can be done.

class Example(object):
    #This is what we use to call every function
    def functionCaller(self, functionName):
        #This is the function that needs to 
        #be called every time
        self.FunctionThatGetsCalledFirst()
        #Now we call the function that was supplied
        exec("self."+functionName+"()")

    def FunctionThatGetsCalledFirst(self):
	print "First"
	
    def Test(self):
        print "Hello"

        
e =Example()
#Try and call the function Test()
e.functionCaller("Test")
"""
First
Hello
""""

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

I tried wing IDE personally, i got the personal version. Though i do not use it any more, it actually wasn't nearly as good as it looked like it would be.
Now i just use Netbeans with a python plugin, it works a charm :)

lllllIllIlllI 178 Veteran Poster

Isnt it possible that you could just have two large buttons side to side? When you click them you can set the label (if you are using wxPython) via wx.Button.SetLabel("Label Here") Then you can bind it to an event so every time the user click a button it updates the label on the button.

I cant see the exact image you want, im at school.. so its blocked. But if you're not using wxPython and using Tkinter, then im sorry, i cant help with that :P

lllllIllIlllI 178 Veteran Poster

Why dont you just have it that it reads the first line of project1 and that can have a simple string telling you what version it is. Then if there is a newer one replace

Have this as the first line:

"12"

f = open('proj1.py')
lineOne = int(f.readlines()[0].strip('"'))
newVersion = 13
if newVersion > lineOne:
    #update

Hope that helps

lllllIllIlllI 178 Veteran Poster

Please post the code that you have written, or a specific problem that you have. We are *not* here to do your homework

lllllIllIlllI 178 Veteran Poster

Here is another page you also might enjoy
http://docs.python.org/library/email-examples.html

lllllIllIlllI 178 Veteran Poster

Im going sailing on my boat, i used to live on it for a number of years sailing up and down Queensland and NSW. So we are going back out on that these holidays... and i have a massive programming job to be done, so not all holiday for me :P

lllllIllIlllI 178 Veteran Poster

We can fix that with one character, a lowly comma :)
If you put the comma after the print statement it should work

for x in range(1, len(depend)):
   #comma after the whole statement
    print "%05s" % ('I#'+str(x)),

hope that helps

EDIT: Also you need to have the percentage sign after the quotation marks to make the string formatting work properly, i put that in the code already though

lllllIllIlllI 178 Veteran Poster

I think this is what you need:

import os
os.startfile('filename.py')

Hope that helps :)

lllllIllIlllI 178 Veteran Poster

I see myself in there!!! ;)

I know! Im there too, i feel quite privileged :)

lllllIllIlllI 178 Veteran Poster

Yeah i must admit i have noticed that number always seems to look a little low recently

lllllIllIlllI 178 Veteran Poster

Cause in line 4 of the program you reset the input to 0!? :P Delete line 4

lllllIllIlllI 178 Veteran Poster

Okay, so look at your sentence just here:

ask the user for the current population and displays the population after 1/2 years unitil it reaches 1 million at a rate of 8% per year. for example

That tells you exactly what you need to do, first: Ask the user for the current population
This is done with just an input statement

#designed for python 3.x but will work with 2.x
population = int(input("Enter the population"))

So now to the while loop, a while loop needs a condition on which it stops.. We have that here:Until it reaches 1 million

while population < 1000000:
    #do stuff

So not to give everything away, try having a go at that and see what you get, try and make it work! :)