2,190 Posted Topics
Re: The second return statement in inputPlayerLetter() never executes because the function exits when the first return is called. It should be return Player, Computer And you then have to catch the return when you call the function. See "the return Statement" at this link for a tutorial http://www.tutorialspoint.com/python/python_functions.htm and https://www.safaribooksonline.com/library/view/python-cookbook-3rd/9781449357337/ch07s04.html | |
Re: > don't work this: bg_fon2 = PhotoImage(file='2.GIF') We have no idea what that means. Is it displaying upside down, or cropped, bad colors, etc. | |
Re: using main() is a waste as it is the same thing as putting it under `if __name__` etc. Instructors use it to teach students about functions, and always use the same name so as not to confuse them. For "real programmers" each function has a specific function (makes sense) and … | |
Re: > second it does not give me messages for when a one is rolled or 2 is rolled Do you mean one or two dice are rolled, or the dice rolled total one or two > nor does it go on to the next players turn like its suppose too … | |
Re: [quote]if door == 1 and b1.clicked(pt): AttributeError: 'NoneType' object has no attribute 'clicked'[/quote]I am not that familiar with the GUI named "graphics", but obviously b1==None which means it has no method clicked, or any other method. Examples of creating buttons exist here on Daniweb as well as on the web. … | |
Re: Print the variable, url, in the funtion to see if your title is correct or not. | |
Re: You can use he same variable for the number of spaces to print, see below. If you want to print a total of 40 stars, I can't tell from your code and you didn't explain empty_spaces=0 one_side=7 # stars stars_side=0 incr=1 stars_printed=0 while stars_printed < 40: print "%s*" % (" … | |
Re: To emphasize what Tony said: [CODE] actorNode = findNode(graph,actorName) if actorNode == None: actorNode = mkNode(actorName) print "created", actorNode graph.append(actorNode) print "graph", graph [/CODE]You want to test each function individually before going on to the next function, or you have 56 lines of code to debug and no idea what … | |
There aren't that many, and of course this is more for entertainment. I will start it out 1. You didn't post a complete, working example to a homework problem that can be copied, pasted, and handed in. | |
Re: You would have to use multiprocessing for the timer since the program is doing two things, 1. getting the answer 2. moving on/killing the question's process after 30 seconds whether the question has or has not been answered. Multiprocessing takes a little fiddling to get the input in a thread … | |
Re: You create a new list on every pass through the for() loop, so everything except for the final value in the range was garbage collected. Move the ID=[] somewhere outside of the for loop(s) so it contains all values. for channels_id in range(4127, 4548, 70): ID = [] # re-created … | |
Re: I would use a Manager dictionary which would contain 1. a counter or other method that can be easily compared to the original to show that there is a change 2. the configuration See the Managing Shared State heading on Doug Hellmann's site [Click Here](http://pymotw.com/2/multiprocessing/communication.html) This simple example shows that … | |
Re: You have an infinite loop because all of the returns call main() again. BTW main is a bad name for a function because it is not descriptive. Some instructors use it in their beginning courses so as to not confuse the students with functions that have different names. In your … | |
Re: You can pass an optional start location to .find() but that means iterating over the entire list several times. Another way word="APPLE" guess="P" hint=["-" for ctr in range(len(word))] print "initial =", hint for index in range(len(word)): if word[index]==guess: hint[index]=guess print "".join(hint) | |
Re: What, no one has mentioned writing a sloppy, undocumented program because it is a one-time quick and dirty use. Murphy's law says you will still be using that program 10 years from now and it will be much, much longer. ![]() | |
Re: I would suggest that first you print "i" as it is probably not what you think it is. See [Click Here](http://www.ibm.com/developerworks/library/os-python6/index.html) "for loop and a string" Second, you want to test for limits after the shift. You did not post any code to shift by "b". To eliminate spaces, periods, … | |
Re: Start here with your post [Click Here](http://www.daniweb.com/forums/post3625.html#post3625 ) | |
Re: Conundrum = Trying to fiqure out what Pneumonoultramicroscopicsilicovolcanoconiosis means | |
Re: 1. your indentation is not correct (and can not be corrected because you did not say what you are trying to do). 2. you do not import math 3. math does not contain a square_root function. Try help(math) to get a list of built-in functions for math 4. project_to_distance does … | |
Re: grid() returns None so self.label1 equals None in the code you posted. There are two ways to update a label, illustrated below. There is way too much code here for me to traverse so the following is independent of any code you posted. class UpdateLabel(): def __init__(self): self.master = tk.Tk() … | |
Re: You will have to continuously check the status of the processes, or the value of some variable/dictionary/object to know when it changes. You can use is_alive() to check the status of a process in multiprocessing. You could also use a manager.dict() set to True for each processes' key, and have … | |
Re: > I've tried a 'for i in range(53):'loop but > that doesn't work for this Why not? It seems like the proper way to do this. Note that you salt the variables with the first 2 numbers, so the loop would run 2 less than the number of the total … | |
Re: You would use a list of lists. One sub-list for each row, so if the data is 1, 3, 2, 7, 5 and you are drawing the third row, you would place an "X" in the element at offsets 1,3, and 4 since those 3 all require a third row. … | |
Re: puntaje = str(int(A + B + C + D + E + F + G + H + I + J + K + L)) If "B", or any variable is less than 3, then the if statement is not satisfied and B (or any variable) is never declared. Some … | |
Re: The docs are always a good place to start [Click Here](https://docs.python.org/2/library/datetime.html) Strftime is part of the datetime.date class, not datetime.datetime. | |
Re: PySerial finds the port by he offset so the first port would be offset 0, since it is at the beginning. Port #5 would offset the first 4 ports from the beginning so would be ser = serial.Serial(4, 9600) Take a look at the intro docs [Click Here](http://pyserial.sourceforge.net/shortintro.html) and try … | |
Re: I don't see anything in your code that is adding an extension.You might want to use the [FileDialog](http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/tkFileDialog.html) module to get the file name. Also note that you have duplicate PhotoImage statements in the program. | |
Re: If you print "digit" you will see that it goes from right to left so for input that is an even number in length, the code is bass ackwards. Also a=a/10 only executes under the else. Use a for loop instead of a while loop with your logic or something … | |
Re: There are several ways to do this. I prefer a while loop ## Not divisible by 3 mylist = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] newlist = [] sublist=[] ctr = 0 while ctr < len(mylist): sublist.append(mylist[ctr]) ctr += 1 if not ctr % 3: … | |
Re: What does it do differently than what you expect? A simple example with an explanation of what you want will get faster and better results Note that encode_files is declared twice and there are indentation errors in the code. | |
Re: I would suggest that you first write it out on paper with 2 or 3 actual examples of what you want and then see how the program differs from the actual examples. For example, balance and remaining balance never change, why? How would you keep track of remaining balance when … | |
Re: > using a list, return a 'counterlist' containing all the strings in the original list plus the number of times the string appears in the list You want a list of lists. While the list in your post can work CounterList = ["hello", 1, "hi", 2] a list of list … | |
Re: Cross posted so may have already been answered. Check first so you don't waste your time. http://qt-project.org/forums/viewthread/46750 http://bytes.com/topic/python/answers/958375-how-check-signal-emit-finished-python | |
Re: > this is where my problem is,,,i cant use this fuction to read from the text file and display the corresponding results in the text widget I don't understand what you mean. Insert is the correct way to insert text into a Text widget. Edit: Ah, you don't call the … | |
Re: Please post the entire error message as we have no idea where it may be coming from. The call to encode_files, may be the problem but that code is not included so we can't tell.. | |
Re: It is a good idea to strip() a record first, unless you are really really sure of the format. Lambda is a bad habit IMHO. Guido wanted to omit lambda (and map, reduce, & filter) from Python3 because [list comprehension](http://carlgroner.me/Python/2011/11/09/An-Introduction-to-List-Comprehensions-in-Python.html) is faster and the code is easier to understand. So … | |
Re: while not (done): will loop until done==True To get done==True in the code you posted, you have have to enter "s" on your only input line, i.e. choose=input("\nChoose a class please : f=Fighter, m=Magic User ") You can also use a [return statement](http://www.tutorialspoint.com/python/python_functions.htm) to exit the funtion containing the while … | |
Re: This code from Vegaseat tells you which key is pressed. You can use a similar function that tests for cetain keys and responds accordingly. I think the general binding is widget.bind("<1>", call_back) (for the number 1). try: import Tkinter as tk ## Python 2.x except ImportError: import tkinter as tk … | |
![]() | Re: [This example](http://matplotlib.org/examples/api/fahrenheit_celsius_scales.html) from the pyplot examples page, plots two scales, and there are probably more. |
![]() | Re: "Aligning" depends also on the font used. If you are displaying the result in the console, then the console must use a fixed witdth font. If you want to experiment, save the result to a file, open the file with any text/word processor and change the font from proportional to … |
Re: We don't know which one of at least 3 or 4 possible statements is causing the error because you did not include the error message. As a shot in the dark I would suggest that you print row or cur or both somewhere around this for() statement cur.execute('SELECT channel FROM … | |
Re: Sweet. Much nicer than termios solutions. | |
Re: builtins.UnicodeDecodeError: 'utf-8' Don't know much about unicode but it may be that the OS is not set up for utf8, so include this at the top of the file to let the interpreter know to use utf8, or whatever,instead of the encoding set by the OS when you try to … | |
Re: You want to use a class. The variable will be visible and accessible as long as the class exists.[code]from Tkinter import * class Demo: def __init__(self, top): self.name="" frame_e = Frame(top) frame_e.pack() self.t_name = StringVar() text = Entry(frame_e, textvariable=self.t_name, bg="white") text.pack() text.focus_force() nameButton = Button(frame_e, text="Accept", command=self.Naming) nameButton.pack(side=BOTTOM, anchor=S) def … | |
Re: You have to use the get() method of the StringVar. See the second, or get() example at [Click Here](http://effbot.org/tkinterbook/optionmenu.htm) i.e convert from a Tkinter variable to a Python variable | |
Re: I only know multiprocessing. The example below starts an infinite loop in a process and uses the terminate method to end the thread, which could also be tied to the backspace key, so perhaps you can adapt the program. You should consider experimenting with a simple example to get the … | |
Re: And problem solving skills only work when the problem is defined. A well defined problem is 50% solved or more IMHO. | |
Re: You would use partial. I don't have Qt installed so can't test, but this should work. Note that if it is self.thrown error, you don't have to pass it to the function as "self" variables can be accessed anywhere within the class. from PyQt4.QtCore import pyqtSignal, pyqtSlot from PyQt4.QtGui import … | |
Re: It is possible that the GUI or whatever that setLabel uses, does not update the screen until the for loop finishes. We don't have enough info to help much further than that as the code is incomplete. Also, please post what you have done to debug this code. If you … |
The End.