2,190 Posted Topics
Re: Everyone should also print what was entered. [code]conbi = ['a1','b1','c3','c4','f7'] left_unmatched = 5 wrongtimes = 0 right = 0 guess = input('Shoot: ').split(' ') ## guess is already a list because of the split() print "guess entered =", guess guess = list (guess) for ctr in range(len(guess)): print " checking … | |
Re: You would run an existing python program file from DOS. The file would be created using a text editor, just like any other text file. You can not use IDLE, which comes with Python, since is requires a GUI. Some [url=http://www.freenetpages.co.uk/hp/alan.gauld/tutstart.htm]useful info[/url]. [quote]if somebody have some simple example[/quote] See [url=http://wiki.python.org/moin/SimplePrograms]this … | |
From a thread on another forum, I wondered how difficult it would be to create a Tic-Tac-Toe game that could not be beaten. Since it is easiest if the computer goes first and chooses the center square, this code implements that portion. The logic is fairly simple; occupy the center … | |
Re: [QUOTE=;][/QUOTE] A hint: [code]ctr=0 while ctr < len(s): print ctr, s[ctr] ctr += 1 [/code] | |
Re: [QUOTE=;][/QUOTE] The simple method is to split on the space and then on the colon. I will leave it up to you to organize the output. [code]test_list=["name:bob grade:a dob:1980","dob:1976 name:kate grade:c"] for substr_1 in test_list: print "-"*30 first_split =substr_1.split() for substr_2 in first_split: print substr_2.split(":") [/code] | |
Re: [QUOTE=Lorilei;1216983]went to the Stanford site and this looks interesting. Does anyone know if it'll work on a Mac running Win XP in Parallels?[/QUOTE] You are running XP on a Mac? In any case, if XP is running the folding@home XP version should work. Post your results in case there is … | |
Re: Pass the dictionary to all of the functions, as that is what you are operating on. Something like [code]def add_student(student_dict): ## the while() loop is only necessary for the Yes/No input add_student="x" while add_student not in ["Y", "N"]: add_student = input('Add Student[s]? Y/N: ') add_student = add_student.upper() if add_student == … | |
Re: [QUOTE=;][/QUOTE] [quote]because the window doesn't go to the front[/quote]You possibly want to provide a takefocus=True parameter, but I have no idea what widget you mean by "window". Without code your questions make no sense. Both SMTP and webbrowser work on my Slackware box. | |
Re: [QUOTE=;][/QUOTE] Dictionary keys have to be unique, so if you try to add a key that is already in the dictionary, it will not add a new key but write over the existing key, so add some code to test if the key already exists in the dictionary and print … | |
Re: [QUOTE=;][/QUOTE] See "List operations" [url=http://www.freenetpages.co.uk/hp/alan.gauld/tutdata.htm]here.[/url] | |
Re: [QUOTE=;][/QUOTE] And you might want to use a tuple for the key, ("man1", "car"), ("man1", "wallet"), etc. as a dictionary of dictionaries gets messy fast. | |
Re: [QUOTE=;][/QUOTE] [quote]everything works fine except secondWindow doesn't show up[/quote]You hide it. [code] def do_something(x, y) : # Code return True self.mainWindow.hide() self.secondWindow.show() isdone = do_something(x, y) ## isdone is always True so secondWindow is always hidden if isdone : self.secondWindow.hide()[/code]And Tony is correct. Your indentation is terrible. If you want … | |
Re: [QUOTE=;][/QUOTE] Pyguy62 is correct about the button call back. To send arguments to a function from a Tkinter callback you use partial. [code]from functools import partial for item in options : Button(self.wdw, text= item, command= parital(self.escolha, item=item)).pack()[/code][quote]My problem is that when I launch the second window with the options my … | |
Re: [QUOTE=;]self.vbox1 = wx.Sizer(wx.VERTICAL) [/QUOTE] [code] self.hbox1 = wx.Sizer(wx.HORIZONTAL)[/code]You possibly want [code]self.hbox1 = wx.BoxSizer() self.hbox1.Add(self.yt_username, flag = wx.EXPAND | wx.RIGHT, border = 8) self.vbox1 = wx.Sizer(wx.VERTICAL) # and the above becomes self.vbox1 = wx.BoxSizer(wx.VERTICAL) [/code]See [url=http://www.daniweb.com/forums/post623598-3.html]this example[/url] in the "Starting wxPython (GUI code)" thread. | |
Re: [QUOTE=;][/QUOTE] You can also use divmod. [code]whole, remain = divmod(11, 3) print whole, remain [/code] | |
Re: [QUOTE=;][/QUOTE] A way that is perhaps easier to understand, but slightly more processor intensive, is to store the first record, add up all of the columns from all of the records, and then print the values for the columns > 6 in the first record. And I don't understand what … | |
Re: [QUOTE=;][/QUOTE] [quote]cos i tried testing 21 and 49, and they were tested as prime. thanks![/quote]What does this mean as "It is" or "It is not a prime number" will print y-1 times for each number tested, or until "not prime" is found. Add a print statement under the for() loop … | |
Re: [QUOTE=;][/QUOTE] [quote]I have code for the chart but I just don't know how to insert the data into it.[/quote]ASCII "data" is just integers from 0-255 | |
Re: [QUOTE=;][/QUOTE] Check out the difference between [url=http://docs.python.org/library/copy.html]copy and deepcopy as well[/url]. You probably want deepcopy (not a copy, and not a reference pointer to the list) since b is a list of tuples [code]a=[[(34,5),(34,6)],[(35,5),(35,6)]] b=[(36,5),(36,6)] a.append(copy.deepcopy(b))[/code] ![]() | |
Re: Submit a sample file so we can see specifically what you are trying to run. And what operating system is your computer running. It may be the file and not python. | |
Re: [QUOTE=;][/QUOTE] If you want to eliminate certain common words like "the and "and", etc. use a list. [code] omit_words = ["the", "a", "and", "but", "i"] for w in sorted_words[0:30]: if w not in omit_words: [/code] | |
Re: [QUOTE=;][/QUOTE] The Tkinter keyword is "image" not "self.image"; see the example [url=http://effbot.org/tkinterbook/label.htm]here[/url]. Also, a label is usually in a frame or some other container. Finally, you can not mix grid() and pack() so choose one or the other. [code]gmail=PhotoImage(file='gmail.gif') self.lab=Label(image=gmail) self.lab.photo=gmail self.lab.pack() [/code] | |
Re: [QUOTE=;][/QUOTE] You can also use eval(). [code]x=eval("9.15E+02") print x, type(x) ## --> 915.0 float[/code] | |
Re: [QUOTE]After navigating to dialog2 if i press close button in Dialog2, Dialog2 is closed but Dialog1 is displayed.[/QUOTE]You should be able to close everything, otherwise you have to close dialog1 and close dialog2 within the same function. [CODE]## to close everything self.connect(self.pushButton, QtCore.SIGNAL('clicked()'), self.button_clicked) def button_clicked(self): print "close the window" … | |
Re: [QUOTE=;][/QUOTE] Or, to state Snippsat's post another way, add another print statement. [code]for l in word: total=total+ord(l)-64 print l, ord(l)-64, total [/code] | |
Re: [QUOTE=;][/QUOTE] You would bind <TAB> to a function that would set the focus to the next button. The program would then know which button the <RETURN> should be bound to. See the examples at this [url=http://www.ferg.org/thinking_in_tkinter/all_programs.html]page[/url]. The program becomes more complicated if you also want to include a button click … | |
Re: [QUOTE=;][/QUOTE] [quote]I want to see how many elements are within each group of coordinates from file2[/quote]Does this mean you want to count them or print/copy them? You only have to store the first file in a container, and check each record from the second file against it. The following uses … | |
Re: [QUOTE=;][/QUOTE] [quote]However, for just the input(), I need to check to make sure it's not a number and to check to make sure it isn't blank[/quote]To make sure it isn't blank, check that len(variable.strip()) > 0 To make sure that it is not a number, you can use not variable.isdigit(), … | |
Re: Nice. I would never have thought of using GMail. | |
Re: [QUOTE=;][/QUOTE] Which SQL are you using? If it's SQLite, it does not support this feature. | |
Re: [QUOTE=;][/QUOTE] Use instance variables (self.) instead of global variables. Also, you can clean the program up by combining all of the number buttons into one for() loop and pass the number to a common function. [code]import wx from functools import partial class jake(wx.Frame): def __init__(self,parent,id): self.foo="" self.outp=0 wx.Frame.__init__(self,parent,id,'Virtual Bank', size=(500,550)) … | |
Re: [QUOTE=;][/QUOTE] AFAIK the Tkinter text widget is the only widget that will do sub/super-scripts. You would have to use a gif of the text or some other nasty work around to do it. | |
Re: [QUOTE=;][/QUOTE] There is no way to make heads or tails of this code for those of us who don't know what you are trying to do. Some general suggestions [code]1. Break this code into functions and test each function 2. instead of surface = "*SURFACE" in lines.strip() and then if … | |
Re: [QUOTE=;][/QUOTE] Computers use numbers not strings. To check for a certain user I would use os.getuid(); root=0 and all other users=some other number. You can print the value for the halton user to find that user's number. I think the hack to get the name is something like pwd.getpwuid(os.getuid())[0] Also, … | |
Re: [QUOTE=;][/QUOTE] [quote]and then i have to write down the programm to get dictionary of people that know each other depending on the pictures they were on together[/quote]The index would be the photo, pointing to a list or set of all people in the photo. [quote]now i would have to edit … | |
Re: [QUOTE=;][/QUOTE] How are you designating the cards, numbers 1-52, or value and suit (10Heart)?. You can use one of the following depending on how the cards are kept:[code]# two related lists cards = [2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace] cards_name=['2', '3', '4', '5', … | |
Re: [QUOTE=;][/QUOTE] I would suggest that you print "ab" prior to the search. Since it is not passed to the class, the class has no idea what it is. [code]if __name__=='__main__': ab={'josh':'me'} AB=AddressBook(ab) ## AB=class instance, ab=dict class Interface(Frame): def __init__(self, master, AB_instance): self.AB_instance=AB_instance if query==self.AB_instance.book: Interface(root, AB) # ##--------- or … | |
Re: [QUOTE=;][/QUOTE] Using a for() loop which may be easier to understand: [code]input_str = "2BBI,3HHR" unique_list = [] for ltr in input_str: if ltr not in unique_list: unique_list.append(ltr) print unique_list ## 2BI,3HR [/code] | |
Re: [QUOTE=;][/QUOTE] A numpy array is accessed by row and column. Add some print statements to find out what the data looks like. Also, a numpy array is overkill. Read the records one by one and store/calculate the values. Start with some sample data that is small, say 10 records, so … | |
Re: [QUOTE=;][/QUOTE] As I see it, the function UUT_Info() does not know about __name__, wx, or InfoUUT() as they are all declared/defined somewhere else and not passed to the function, but without a complete error message there is no way to tell which name is undefined. You would use something like … | |
Re: [QUOTE=;][/QUOTE] It appears that this forum has a reputation for free code as I don't see this much on other forums. But then again, if you are the OP of the "calculating the avg and std" post, you know that you can just keep asking questions until someone provides a … | |
Re: [QUOTE=;][/QUOTE] It has nothing to do with class instances, but with the self.destroy which shuts down wx. If you want to destroy/close one object only, then you must first create the object and then close/destroy it only. There is a "Starting wxPython" at the top of the threads that has … | |
Re: [QUOTE=;][/QUOTE] "self" is just a reference to the class, so that the class knows that the function or variable is in it's name space, so you have to include it when calling a function of the class from/within the class, otherwise the compiler will default to looking outside of the … ![]() | |
Re: [QUOTE=;][/QUOTE] I like to use a function as it is simple and the logic obvious [code]def value_func(): value = -1 if true: print 'hello world' # Some unexpected value is set so I would like to leave here # but break statement is for loop and not for if if … | |
Re: [QUOTE=;][/QUOTE] You can replace [code]if ' ' in sentence: words = sentence.split() encrypted_words = [] else: # #etc. with words = sentence.split() for word in words: [/code]If there isn't a space, then "words" will just contain one entry, and the for loop will exit after the first loop. Also [code] … | |
Re: [QUOTE=;][/QUOTE] You have 2 ?s and one variable. Also, you should use a dictionary as it is more secure. [code]#update if meshblock_06=='21' g.execute('UPDATE meshblock_1107 SET etv_1107==:update_1 WHERE meshblock_06==:select_1', {'update_1':pv[0:2], 'select_1':'21'}) [/code] | |
Re: [QUOTE=;][/QUOTE] See the [URL=http://www.daniweb.com/software-development/cpp/threads/78223]Read This Before Posting[/url] thread, especially the last paragraph. For tutorials, the Python wiki has links [url]http://wiki.python.org/moin/[/url] This link addresses asking for help with your homework (the "books" problem has been posted many times) [url]http://www.daniweb.com/forums/post3625.html#post3625[/url] | |
![]() | Re: [QUOTE=;][/QUOTE] In the first example, both the function and the button object are assigned to the same variable name, so "d1" can refer to either one (you may or may not be calling the function). Second. the function could set a Tkinker StringVar, used as a textvariable of the button, … |
Re: [QUOTE=;][/QUOTE] You'll have to post the entire error message and state what version of Python you are running for us to help there. However, the statement while product_price <=0 or product_price=="": first assumes product_price is an integer, "<=0", and second assumes it is a string,product_price=="". You have to choose one … ![]() | |
Re: [QUOTE=;][/QUOTE] Since each point appears to be a tuple, you can use [code]print(len(points)) for point in points: print(point) for each_point in point: print(" ", each_point) # etc. [/code] |
The End.