[Tutor] Question related to Tkinker
Hello All, I am putting up a simple game .. the game is about manipulation. If the gets through level one ... I have to change the word with another... Am I going to destroy level window and build level 2 or is there a way to just adjust the word (I used labels) Regards, Janus -- *Satajanus Nig. Ltd * ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question related to Tkinker
Excerpts from Emeka's message of Sun Jul 24 02:56:02 -0400 2011: Hello All, I am putting up a simple game .. the game is about manipulation. If the gets through level one ... I have to change the word with another... Am I going to destroy level window and build level 2 or is there a way to just adjust the word (I used labels) When working with tkinter, http://effbot.org/tkinterbook/ will likely be your best friend. Specifically, you're going to want your_label1.config(text=New word!) your_label2.config(text=Another!) -- Corey Richardson Those who deny freedom to others, deserve it not for themselves -- Abraham Lincoln signature.asc Description: PGP signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Don't understand this class/constructor call syntax
dave wrote: Thank you for the two explanations. I think I have a good idea of what is going on now with the arguments and keyword arguments. My only remaining question is the pad_for_usrp argument. The default value is True so I thought it was a boolean and couldn't have anything to do with the selftransmit_path that was passed to it. However, I can probably puzzle that out by looking at how it's used in the code. I don't know why a transmit_path instance is being passed as a pad_* flag, but you may not be aware that in Python, any object can be used as if it were a boolean, not just True and False. Generally, the rule is: something is considered true-valued; nothing is considered false-valued. So, among the built-ins, we have nothings such as: 0 0.0 '' # empty string [] # empty list {} # empty dict () # empty tuple set([]) # empty set None are all considered to be false in a boolean context. And we have somethings, such as: 42 0.125 'x' [None, 42, '*'] {0: None} object() etc. all considered to be true in a boolean context. (Note that among strings, only the empty string counts as nothing. The strings 'nothing', 'empty', 'false', 'not a thing', 'nada', 'not a brass farthing', dry as a dingo's donger etc. are non-empty strings and therefore count as true-values.) True and False are merely the canonical flags. In general, functions and methods are expected to be liberal in what they accept (any object can be used as if it were a boolean) and conservative in what they return (if returning a flag, you should return True/False, or 1/0 if you need to support *really* ancient versions of Python). -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question related to Tkinker
for i,cha in enumerate(wordi): label = Label(root, image=photoimage, text = cha) label.grid(row=1, column=i, columnspan=1, rowspan=1,sticky=W+E+N+S, padx=0, pady=1) label1 = Label(root, image=IMAGE) I used grid ... Though I used labels, I was dealing only on character level. So for word like JAVA . I will have a row with four cells and each filled with the individual character so that I could manipulate them individually. Now, if I late have ORACLE in level 2.. I would want to use to write it in the same row as above however with six cells. I will check the link you posted On Sun, Jul 24, 2011 at 8:00 AM, Corey Richardson kb1...@aim.com wrote: Excerpts from Emeka's message of Sun Jul 24 02:56:02 -0400 2011: Hello All, I am putting up a simple game .. the game is about manipulation. If the gets through level one ... I have to change the word with another... Am I going to destroy level window and build level 2 or is there a way to just adjust the word (I used labels) When working with tkinter, http://effbot.org/tkinterbook/ will likely be your best friend. Specifically, you're going to want your_label1.config(text=New word!) your_label2.config(text=Another!) -- Corey Richardson Those who deny freedom to others, deserve it not for themselves -- Abraham Lincoln ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- *Satajanus Nig. Ltd * ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question related to Tkinker
Emeka wrote: for i,cha in enumerate(wordi): label = Label(root, image=photoimage, text = cha) label.grid(row=1, column=i, columnspan=1, rowspan=1,sticky=W+E+N+S, padx=0, pady=1) label1 = Label(root, image=IMAGE) I used grid ... Though I used labels, I was dealing only on character level. So for word like JAVA . I will have a row with four cells and each filled with the individual character so that I could manipulate them individually. Now, if I late have ORACLE in level 2.. I would want to use to write it in the same row as above however with six cells. Keep the labels in a list and ensure that there are enough labels (the list is long enough) before you configure them to show the characters. Use the grid_forget() method to hide extra labels if the current word is shorter than a previous one. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Don't understand this class/constructor call syntax
On Sun, Jul 24, 2011 at 2:07 AM, Steven D'Aprano st...@pearwood.infowrote: (Note that among strings, only the empty string counts as nothing. The strings 'nothing', 'empty', 'false', 'not a thing', 'nada', 'not a brass farthing', dry as a dingo's donger etc. are non-empty strings and therefore count as true-values.) Though just for completeness sake, you could do something like: def mytest(string): if string.lower() in (nothing, empty, false, not a thing, nada, not a brass farthing, dry as a dingo's donger): return False else: return True if you were really interested in using values such as those. Personally, just for kicks and giggles, when I write personal programs and I ask for Y/N input, I'm fairly liberal - so instead of N you could input N, No, nyet, no way, no thanks... you get the picture. My 1 cent and pocket lint, -Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Basic program question
Hello- I am running Python v 3.1.1. As an exercise, I wrote a simple coin flipper program, where the computer flips a coin 100 times and then prints out the number of heads and tails. My program crashes immediately if I run it normally through the command line, but if I go to Run- Run Module, it seems to work just fine. I can't seem to figure out why. I've pasted the relevant code below- any help will be greatly appreciated. Thanks! import random print(\tWelcome to the 'Coin Flipper' program!) counter = 0 heads = 0 tails = 0 while counter 100: the_number = random.randint(1, 2) if the_number == 1: heads += 1 else: tails += 1 counter += 1 print(\nI flipped the coint 100 times.) print(It came up heads, heads, times and tails, tails, times.) print(\n\nPress the enter key to exit.) _ -Alex ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Basic program question
On Sun, Jul 24, 2011 at 3:59 PM, Alexander Quest alexxqu...@gmail.comwrote: My program crashes immediately if I run it normally through the command line, Is there a traceback associated? Those usually help a lot -Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Running Python in script vs. Idle
Python version 2.6.6 I wrote this in Idle and ran it in Idle and it worked fine. class ExClass: eyes = brown age = 99 height = '5\'11' def thisMethod(self): return 'This method works.' This is me running it in Idle. ExClass *class __main__.ExClass at 0xb5aec2fc* x = ExClass() x.eyes *'brown'* x.age *99* x.height *5'11* x.thisMethod() *'This method works.'* Then I try to run it from a script in Gnome-terminal and it does not run. I do not get output. I have to add print. to get any output like this: #!/usr/bin/python class ExClass: eyes = brown age = 99 height = '5\'11' def thisMethod(self): return 'This method works.' x = ExClass() x.eyes x.age x.height x.thisMethod() *print* x.thisMethod() What is the difference? This is what was confusing me before. Brandon ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Basic program question
Alexander Quest wrote: Hello- I am running Python v 3.1.1. As an exercise, I wrote a simple coin flipper program, where the computer flips a coin 100 times and then prints out the number of heads and tails. My program crashes immediately if I run it normally through the command line, but if I go to Run- Run Module, it seems to work just fine. I can't seem to figure out why. I've pasted the relevant code below- any help will be greatly appreciated. Thanks! What do you mean, crashes? Do you get a segmentation error? A Python traceback? Computer hangs and you have to restart to recover? Something else? What do you mean, run it normally through the command line? What operating system are you using? What command are you using on the command line? Since I love guessing games, I'm going to take a wild stab in the dark that you're using Linux, and you're done something like this: [steve@sylar ~]$ echo print('spam') spam.py # make a Python script [steve@sylar ~]$ cat spam.py print('spam') [steve@sylar ~]$ chmod u+x spam.py # make it executable [steve@sylar ~]$ ./spam.py ./spam.py: line 1: syntax error near unexpected token `'spam'' ./spam.py: line 1: `print('spam')' That's because you're trying to run it as a shell script. You need to add a hash-bang line to the file, or run it with Python: [steve@sylar ~]$ python3 spam.py spam If that's not what you are doing, then we'll need more information to solve the problem. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running Python in script vs. Idle
brandon w wrote: I wrote this in Idle and ran it in Idle and it worked fine. [...] Then I try to run it from a script in Gnome-terminal and it does not run. I do not get output. I have to add print. to get any output like this: [...] What is the difference? This is what was confusing me before. As a convenience, the Python interactive interpreter prints the output of any line you give it. So a line like this: x = 1+2 doesn't print anything, because the result is stored as x. But a line like this: 1+2 prints 3. This is *purely* a convenience feature, and it is only activated in the *interactive* interpreter. When running as a script, you need to explicitly call print to have things printed. IDLE emulates that behaviour. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running Python in script vs. Idle
On 24-Jul-11 16:21, brandon w wrote: Then I try to run it from a script in Gnome-terminal and it does not run. I do not get output. I have to add print. to get any output like this: When you type a Python expression at the interactive prompt in IDLE or the python command-line interpreter, it will take the extra step of printing the value of that expression for you. That's not otherwise how Python works. Normally you have to use a print command (or print() function in Python 3.x) to actually see the output. -- Steve Willoughby / st...@alchemy.com A ship in harbor is safe, but that is not what ships are built for. PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running Python in script vs. Idle
brandon w wrote: Thank you. I understand that this ( x = 1+2 ) assigns a variable to x and will not print in Idle, but how would I get the 'class' that I created to run from the script like it does in Idle? Will I have to put print before everything I have to print? Yes. If you want something printed, you have to print it. In your script, you have: # definition of ExClass not shown x = ExClass() x.eyes x.age x.height x.thisMethod() print x.thisMethod() This creates an instance of ExClass, calls it x. Then it retrieves the eyes, age and height from x, but does nothing with the results except immediately discard them. Then it calls thisMethod, and discards the result. Lastly, it calls thisMethod again and prints the result. That is the only thing that the script will output. I recommend you do this instead: # definition of ExClass not shown x = ExClass() print x.eyes, x.age, x.height print x.thisMethod() -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Running Python in script vs. Idle
On 07/24/2011 07:59 PM, Steven D'Aprano wrote: brandon w wrote: Thank you. I understand that this ( x = 1+2 ) assigns a variable to x and will not print in Idle, but how would I get the 'class' that I created to run from the script like it does in Idle? Will I have to put print before everything I have to print? Yes. If you want something printed, you have to print it. In your script, you have: # definition of ExClass not shown x = ExClass() x.eyes x.age x.height x.thisMethod() print x.thisMethod() This creates an instance of ExClass, calls it x. Then it retrieves the eyes, age and height from x, but does nothing with the results except immediately discard them. Then it calls thisMethod, and discards the result. Lastly, it calls thisMethod again and prints the result. That is the only thing that the script will output. I recommend you do this instead: # definition of ExClass not shown x = ExClass() print x.eyes, x.age, x.height print x.thisMethod() Thanks. I understand now. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Don't understand this class/constructor call syntax
dave wrote: I was dimly aware of the functioning of booleans, but I see now that it doesn't specify an actual boolean type. Still, the code confuses me. Is the usage of pad_for_usrp consistent with it being treated as a boolean? Why would the entire self reference be transmitted then? Parameter passing in Python is fast -- the object (which may be large) is not copied unless you explicitly make a copy. So it is no faster to pass a big, complex object than a lightweight object like True or False. (Implementation note: in CPython, the main Python implementation which you almost certainly are using, objects live in the heap and are passed around as pointers.) The code you show isn't very illuminating as far as pad_for_usrp goes. All that happens is that it gets stored as an attribute, then later gets passed on again to another function or class: class ieee802_15_4_mod_pkts(gr.hier_block2): ... self.pad_for_usrp = pad_for_usrp def send_pkt(self, seqNr, addressInfo, payload='', eof=False): ... pkt = make_ieee802_15_4_packet(FCF, seqNr, addressInfo, payload, self.pad_for_usrp) So it's *consistent* with being used as a bool, or anything else for that matter! I expect that make_ieee802_15_4_packet may be the thing that actually does something useful with pad_for_usrp. Another thing to look for is the transmit_path class itself. If it has a __len__, __bool__ or __nonzero__ method, then it has customized the way it appears as a boolean. If it has none of those methods, then it will always be considered true-valued, and I can't imagine why it is being used as pad_for_usrp instead of just passing True. But without looking at the rest of the code, I can't really tell for sure. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Don't understand this class/constructor call syntax
I was dimly aware of the functioning of booleans, but I see now that it doesn't specify an actual boolean type. Still, the code confuses me. Is the usage of pad_for_usrp consistent with it being treated as a boolean? Why would the entire self reference be transmitted then? Example code again: class transmit_path(gr.top_block) [...] self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self._spb, msgq_limit=2) The class from the ieee802_15_4_pkt module: class ieee802_15_4_mod_pkts(gr.hier_block2): IEEE 802.15.4 modulator that is a GNU Radio source. Send packets by calling send_pkt def __init__(self, pad_for_usrp=True, *args, **kwargs): Hierarchical block for the 802_15_4 O-QPSK modulation. Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples See 802_15_4_mod for remaining parameters try: self.msgq_limit = kwargs.pop('msgq_limit') except KeyError: pass gr.hier_block2.__init__(self, ieee802_15_4_mod_pkts, gr.io_signature(0, 0, 0), # Input gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output self.pad_for_usrp = pad_for_usrp # accepts messages from the outside world self.pkt_input = gr.message_source(gr.sizeof_char, self.msgq_limit) self.ieee802_15_4_mod = ieee802_15_4.ieee802_15_4_mod(self, *args, **kwargs) self.connect(self.pkt_input, self.ieee802_15_4_mod, self) def send_pkt(self, seqNr, addressInfo, payload='', eof=False): Send the payload. @param seqNr: sequence number of packet @type seqNr: byte @param addressInfo: address information for packet @type addressInfo: string @param payload: data to send @type payload: string if eof: msg = gr.message(1) # tell self.pkt_input we're not sending any more packets else: FCF = make_FCF() pkt = make_ieee802_15_4_packet(FCF, seqNr, addressInfo, payload, self.pad_for_usrp) #print pkt =, packet_utils.string_to_hex_list(pkt), len(pkt) msg = gr.message_from_string(pkt) #ERROR OCCURS HERE (a few functions in while inserting onto the msg queue) self.pkt_input.msgq().insert_tail(msg) --- End of Forwarded Message --- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] List problem
class Node: def __init__(self,initdata): self.data = initdata self.next = None def getData(self): return self.data def getNext(self): return self.next def setdata(self,newData): self.data = newData def setNext(self,newnext): self.next = newnext class UnorderedList: def __init__(self): self.head = None def isEmpty(self): return self.head == None ## Adds next item on to the head def add(self,item): temp = Node(item) temp.setNext(self.head) self.head = temp def length(self): current = self.head count = 0 while current !=None: count = count + 1 current = current.getNext() return count def search(self,item): current = self.head found = False while current != None and not found: if current.getData()== item: found =True else: current = current.getNext() return found def remove(self,item): '''Removes item from the List''' current = self.head previous = None found = False while not found: if current.getData() == item: found = True else: previous = current current = current.getNext() if previous == None: self.head = current.getNext() else: previous.setNext(current.getNext()) def getIndex(self,item): current = self.head index = 0 found = False while current != None and not found: if current.getData()== item: found = True else: current = current.getNext() index = index + 1 return index def append(self,item): '''Adds an item to the end of the List''' current = self.head previous = None while current.getNext() != None: previous = current current = current.getNext() if current.getNext() == None: previous = previous.setNext(current) current = current.setNext(item) myList = UnorderedList() myList.add(31) myList.add(77) myList.add(17) myList.add(93) myList.add(26) myList.add(54) print(myList.length()) myList.append(24) print(myList.length()) myList.search(24) Output Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] Type help, copyright, credits or license for more information. [evaluate unorderedList.py] 6 builtins.AttributeError: 'int' object has no attribute 'getNext' What do I need to do the append method to fix it? -- Dave Merrick merrick...@gmail.com Ph 03 3423 121 Cell 027 3089 169 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List problem
I have no desire to wade through all that code. Please post the entire traceback. On 7/24/2011 10:19 PM, David Merrick wrote: class Node: def __init__(self,initdata): self.data = initdata self.next = None def getData(self): return self.data def getNext(self): return self.next def setdata(self,newData): self.data = newData def setNext(self,newnext): self.next = newnext class UnorderedList: def __init__(self): self.head = None def isEmpty(self): return self.head == None ## Adds next item on to the head def add(self,item): temp = Node(item) temp.setNext(self.head) self.head = temp def length(self): current = self.head count = 0 while current !=None: count = count + 1 current = current.getNext() return count def search(self,item): current = self.head found = False while current != None and not found: if current.getData()== item: found =True else: current = current.getNext() return found def remove(self,item): '''Removes item from the List''' current = self.head previous = None found = False while not found: if current.getData() == item: found = True else: previous = current current = current.getNext() if previous == None: self.head = current.getNext() else: previous.setNext(current.getNext()) def getIndex(self,item): current = self.head index = 0 found = False while current != None and not found: if current.getData()== item: found = True else: current = current.getNext() index = index + 1 return index def append(self,item): '''Adds an item to the end of the List''' current = self.head previous = None while current.getNext() != None: previous = current current = current.getNext() if current.getNext() == None: previous = previous.setNext(current) current = current.setNext(item) myList = UnorderedList() myList.add(31) myList.add(77) myList.add(17) myList.add(93) myList.add(26) myList.add(54) print(myList.length()) myList.append(24) print(myList.length()) myList.search(24) Output Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] Type help, copyright, credits or license for more information. [evaluate unorderedList.py] 6 builtins.AttributeError: 'int' object has no attribute 'getNext' What do I need to do the append method to fix it? -- Dave Merrick merrick...@gmail.com mailto:merrick...@gmail.com Ph 03 3423 121 Cell 027 3089 169 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor