Re: [Tutor] Handling 'None' (null) values when processing sqlite cursor results

2010-07-14 Thread Andre Engels
On Wed, Jul 14, 2010 at 6:31 AM, Monte Milanuk memila...@gmail.com wrote: Hello all, I'm struggling a bit trying to find the right way to deal with null values in my sqlite database when querying it and processing the results in python. If my cursor.fetchall() results return the following:

Re: [Tutor] Help

2010-07-14 Thread Andre Engels
On Tue, Jul 13, 2010 at 12:34 PM, Nitin Pawar nitinpawar...@gmail.com wrote: Adding to what Andre said, another way of optimizing the problem would be storing the prime number in the range you want to check an array and see if the given number is divisible by any of those prime number As I

[Tutor] I don't understand this code

2010-07-14 Thread ZUXOXUS
Hi, I am a true beginner in programming, and im learning with inventwithpython.com. There's something I dont understand, and i would really appreciate any help. In chapter 9, the one about the Hangman game, I don't get the block of code in line 61 59. words = 'ant baboon badger bat bear' 60.

Re: [Tutor] I don't understand this code

2010-07-14 Thread Stefan Behnel
ZUXOXUS, 13.07.2010 16:43: Hi, I am a true beginner in programming, and im learning with inventwithpython.com. There's something I dont understand, and i would really appreciate any help. In chapter 9, the one about the Hangman game, I don't get the block of code in line 61 59. words = 'ant

Re: [Tutor] I don't understand this code

2010-07-14 Thread Nitin Pawar
I tried replying with inline the questions read below within your mail On Tue, Jul 13, 2010 at 8:13 PM, ZUXOXUS zuxo...@gmail.com wrote: Hi, I am a true beginner in programming, and im learning with inventwithpython.com. There's something I dont understand, and i would really appreciate

Re: [Tutor] I don't understand this code

2010-07-14 Thread Peter Otten
ZUXOXUS wrote: Hi, I am a true beginner in programming, and im learning with inventwithpython.com. There's something I dont understand, and i would really appreciate any help. In chapter 9, the one about the Hangman game, I don't get the block of code in line 61 59. words = 'ant

Re: [Tutor] I don't understand this code

2010-07-14 Thread Michael M Mason
The thing is, the passed list of strings is called words, not wordList, so I see it shouldn't work. On the other hand, the variable wordList is defined nowhere! wordList is just a name that the function (getRandomWord) uses to refer to whatever values get passed to it. Remember that you don't

Re: [Tutor] I don't understand this code

2010-07-14 Thread Serdar Tumgoren
The rest of the list does a great job explaining the situation, which bears out in the code itself. If you look farther down in the code sample in Chapter 9, you'll see the function called twice. http://inventwithpython.com/chapter9/ snipped print('H A N G M A N') missedLetters = ''

Re: [Tutor] Response to responses about list of lists: a metaexercise in mailinglist recursion

2010-07-14 Thread Alan Gauld
Steven D'Aprano st...@pearwood.info wrote If you're starting a new discussion, or raising a new question, make a fresh, blank email, put a descriptive title in the subject line, and put tutor@python.org as the To address. If you're replying to an existing message, using reply is fine, but

[Tutor] GUI Creation Aide

2010-07-14 Thread Corey Richardson
Hey tutors! I'm creating a GUI for a program. Really simple. I don't mind coding it out, but I was looking into things like Glade and the like. Do you recommend those over just coding it out by hand, or should I try Glade (or similiar) out? Also, I don't really have a preference for which

Re: [Tutor] I don't understand this code

2010-07-14 Thread Alan Gauld
ZUXOXUS zuxo...@gmail.com wrote 59. words = 'ant baboon badger bat bear' 1. def getRandomWord(wordList): 3. wordIndex = random.randint(0, len(wordList) - 1) 4. return wordList[wordIndex] The thing is, the passed list of strings is called words, not wordList, so I see it

Re: [Tutor] Handling 'None' (null) values when processing sqlite cursorresults

2010-07-14 Thread Alan Gauld
Monte Milanuk memila...@gmail.com wrote (104, None, u'Sylvester', None, u'Evans', None, u'527-9210 Proin Av.', u'Liberal', u'VT', u'24742', u'1-135-197-1139', u'vehicula.pellentes...@idmollis.edu', u'2010-07-13 22:52:50', u'2010-07-13 22:52:50') At first I was having fits as str.join() was

Re: [Tutor] GUI Creation Aide

2010-07-14 Thread Alex Hall
On 7/14/10, Corey Richardson kb1...@aim.com wrote: Hey tutors! I'm creating a GUI for a program. Really simple. I don't mind coding it out, but I was looking into things like Glade and the like. Do you recommend those over just coding it out by hand, or should I try Glade (or similiar) out?

Re: [Tutor] GUI Creation Aide

2010-07-14 Thread Alan Gauld
Corey Richardson kb1...@aim.com wrote Hey tutors! I'm creating a GUI for a program. Really simple. I don't mind coding it out, but I was looking into things like Glade and the like. Do you recommend those over just coding it out by hand, or should I try Glade (or similiar) out? Also, I don't

Re: [Tutor] GUI Creation Aide

2010-07-14 Thread Wayne Werner
On Wed, Jul 14, 2010 at 7:18 AM, Corey Richardson kb1...@aim.com wrote: Hey tutors! I'm creating a GUI for a program. Really simple. I don't mind coding it out, but I was looking into things like Glade and the like. Do you recommend those over just coding it out by hand, or should I try Glade

Re: [Tutor] Handling 'None' (null) values when processing sqlite cursorresults

2010-07-14 Thread Christian Witts
On 14/07/2010 14:32, Alan Gauld wrote: Monte Milanuk memila...@gmail.com wrote (104, None, u'Sylvester', None, u'Evans', None, u'527-9210 Proin Av.', u'Liberal', u'VT', u'24742', u'1-135-197-1139', u'vehicula.pellentes...@idmollis.edu', u'2010-07-13 22:52:50', u'2010-07-13 22:52:50') At

Re: [Tutor] Response to responses about list of lists: a meta exercise in mailinglist recursion

2010-07-14 Thread Siren Saren
Steven D'Aprano, Your response was profoundly helpful to me.  If that sounds grandiose, I mean it nonetheless.  You not only answered all of my specific questions and taught me general methods I will use and reuse, you also gave me some hope.  It's a lonely process teaching myself to program

Re: [Tutor] Path?

2010-07-14 Thread Adam Bark
On 14 July 2010 02:53, Jim Byrnes jf_byr...@comcast.net wrote: Adam Bark wrote: snipped some old stuff If I use the terminal to start the program it has no problem using the file. There are multiple files in multiple directories so I was looking for a way to just double click them and

Re: [Tutor] Response to responses about list of lists: a meta exercise in mailinglist recursion

2010-07-14 Thread Steven D'Aprano
On Wed, 14 Jul 2010 11:53:38 pm Siren Saren wrote: Steven D'Aprano, Your response was profoundly helpful to me. [...] Thank you for the kind words, and cheers! I wish you good fortunate and a lot of fun in your endeavour. I thought something in the culture of programming was particularly

[Tutor] Global name not found, though clearly in use

2010-07-14 Thread Corey Richardson
Hey tutors. Two separate submissions one day, guess I'm getting busy ;) Anyway, I'm re-writing my hangman program to make use of my new-found understanding of OOP, and using a GUI this time around. I decided on coding with Tkinter, to get my feet wet with GUI stuff. Here is the traceback:

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Nitin Pawar
From the logs looks like the variable is not initiated when it was used. If I read it correct, you said it down ... that means below the line where the error came? and if they belong to same function then this error is valid Thanks, Nitin On Wed, Jul 14, 2010 at 7:48 PM, Corey Richardson

[Tutor] Help execution time calculation:

2010-07-14 Thread Vineeth Rakesh
Hello all, I want to calculate the execution time of a program. Say I have a function like below: def RepAdd(i): j = 0 while(ji): j += 1 return j now I want to calculate the execution time of the function RepAdd when say 10 is passed as an argument. I did come across the module

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Steven D'Aprano
On Thu, 15 Jul 2010 12:18:58 am Corey Richardson wrote: Hey tutors. Two separate submissions one day, guess I'm getting busy ;) Anyway, I'm re-writing my hangman program to make use of my new-found understanding of OOP, and using a GUI this time around. I decided on coding with Tkinter, to

Re: [Tutor] Help execution time calculation:

2010-07-14 Thread Steven D'Aprano
On Thu, 15 Jul 2010 01:11:58 am Vineeth Rakesh wrote: Hello all, I want to calculate the execution time of a program. Say I have a function like below: def RepAdd(i): j = 0 while(ji): j += 1 return j now I want to calculate the execution time of the function RepAdd when say

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Corey Richardson
I was under the impression that when you define a function, it doesn't try to evaluate anything yet. If I had called the function before I defined the variable, I would understand, but I haven't. The entirety of my (incomplete and buggy) code is now available here:

[Tutor] Searching a text file's contents and comparing them to a list

2010-07-14 Thread Eric Hamiter
Hi all, New programmer here. This is what I want to do: 1. Open an existing text file named grocery_list.txt, which has one item per line, like so: butter juice bread asparagus magazines ice cream 2. ...and search for these items in a pre-defined list. But I can't seem to get this working.

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Emile van Sebille
On 7/14/2010 8:31 AM Corey Richardson said... I was under the impression that when you define a function, it doesn't try to evaluate anything yet. If I had called the function before I defined the variable, I would understand, but I haven't. The difference is in understanding what's executed

Re: [Tutor] Searching a text file's contents and comparing them to a list

2010-07-14 Thread Emile van Sebille
On 7/14/2010 8:46 AM Eric Hamiter said... Hi all, New programmer here. This is what I want to do: 1. Open an existing text file named grocery_list.txt, which has one item per line, like so: butter juice bread asparagus magazines ice cream 2. ...and search for these items in a pre-defined

Re: [Tutor] Searching a text file's contents and comparing them to a list

2010-07-14 Thread Eric Hamiter
Fantastic! I have this, which now works. Is there a better place to put string.strip? aisle_one = [chips, bread, pretzels, magazines] grocery_list = open(grocery_list.txt, r) for line in grocery_list.readlines(): if line.strip() in aisle_one: print success! i found %s % line else:

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Corey Richardson
Hmm..If I add a few debugging lines like that into my code, I get this: Starting program In class Hangman done defs in class eWordEntryBox defined Exception in Tkinter callback Traceback (most recent call last): File "C:\Python31\lib\tkinter\__init__.py", line 1399, in __call__

Re: [Tutor] Path?

2010-07-14 Thread Jim Byrnes
Adam Bark wrote: On 14 July 2010 02:53, Jim Byrnesjf_byr...@comcast.net wrote: Adam Bark wrote: snipped some old stuff If I use the terminal to start the program it has no problem using the file. There are multiple files in multiple directories so I was looking for a way to just double

Re: [Tutor] Searching a text file's contents and comparing them to a list

2010-07-14 Thread Emile van Sebille
On 7/14/2010 9:22 AM Eric Hamiter said... Fantastic! I have this, which now works. Is there a better place to put string.strip? I might make the changes below, but there's nothing wrong with the way you've got it. aisle_one = [chips, bread, pretzels, magazines] grocery_list =

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Dave Angel
Corey Richardson wrote: The entirety of my (incomplete and buggy) code is now available here: http://pastebin.com/QTNmKYC6 .. Hmm..If I add a few debugging lines like that into my code, I get this: Starting program In class Hangman done defs in class eWordEntryBox defined Exception in

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Alan Gauld
Corey Richardson kb1...@aim.com wrote defined the variable, I would understand, but I haven't. The entirety of my (incomplete and buggy) code is now available here: http://pastebin.com/QTNmKYC6 There are quite a few errors here, one is that many of your class's methods don't have self as

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Emile van Sebille
On 7/14/2010 9:33 AM Corey Richardson said... Hmm..If I add a few debugging lines like that into my code, I get this: The point was that statements in a class at class level (ie, not in defs) are executed sequentially and expect referenced variables to exist (ie, defined somewhere 'above'

Re: [Tutor] Searching a text file's contents and comparing them toa list

2010-07-14 Thread Alan Gauld
Eric Hamiter ehami...@gmail.com wrote Fantastic! I have this, which now works. Is there a better place to put string.strip? Its largely a matter of taste and how you intend using the value. aisle_one = [chips, bread, pretzels, magazines] grocery_list = open(grocery_list.txt, r) for line

Re: [Tutor] Handling 'None' (null) values when processing sqlite cursorresults

2010-07-14 Thread Alan Gauld
Christian Witts cwi...@compuscan.co.za wrote You need a display function that can strip out the nulls as needed. A simple list comprehension or generator expression would work in this case: print ' '.join(str(field) for field in data if field is not 'None') The problem with that is if

Re: [Tutor] Searching a text file's contents and comparing them toa list

2010-07-14 Thread Eric Hamiter
On Wed, Jul 14, 2010 at 12:26 PM, Alan Gauld alan.ga...@btinternet.comwrote: If you never need a stripped version of line again, or if you are planning on writing it out to another file then this is fine. If you are going to use it again its probably better to strip() and asign to itelf:

Re: [Tutor] Path?

2010-07-14 Thread Adam Bark
On 14 July 2010 17:41, Jim Byrnes jf_byr...@comcast.net wrote: Adam Bark wrote: On 14 July 2010 02:53, Jim Byrnesjf_byr...@comcast.net wrote: Adam Bark wrote: snipped some old stuff If I use the terminal to start the program it has no problem using the file. There are multiple

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Serdar Tumgoren
Hmm..If I add a few debugging lines like that into my code, I get this: The point was that statements in a class at class level (ie, not in defs) are executed sequentially and expect referenced variables to exist (ie, defined somewhere 'above' the current statement) -- there is no forward

[Tutor] str format conversion help

2010-07-14 Thread eMyListsDDg
'\x00\x11\xb2\x00@,O\xa4' the above str is being returned from one key/value pair in a dictionary. it is the addr of a network device. i want to store the addr's in their 8byte mac format like this, [00 11 b2 00 40 2C 4F A4] the combinations of format strings using the print statement

Re: [Tutor] str format conversion help

2010-07-14 Thread Steve Willoughby
On 14-Jul-10 11:35, eMyListsDDg wrote: '\x00\x11\xb2\x00@,O\xa4' the above str is being returned from one key/value pair in a dictionary. it is the addr of a network device. i want to store the addr's in their 8byte mac format like this, [00 11 b2 00 40 2C 4F A4] the combinations of

Re: [Tutor] Searching a text file's contents and comparing them toa list

2010-07-14 Thread Eric Hamiter
Follow-up question: My code is now this: aisle_one = [chips, bread, pretzels, magazines] aisle_two = [juice, ice cream] aisle_three = [asparagus] def find_groceries(): grocery_list = open(grocery_list.txt, r) for line in grocery_list.readlines(): line = line.strip() if

Re: [Tutor] Searching a text file's contents and comparing them toa list

2010-07-14 Thread Luke Paireepinart
You already know how to store multiple vars -- use lists! Just create a blank one before your loop and append() to it. Also you might think of a generic way to do this without relying on separate variables for each aisle, what if your store has 30 aisles? Hint: lists can contain any python

Re: [Tutor] str format conversion help

2010-07-14 Thread Alan Gauld
eMyListsDDg emylists...@gmail.com wrote First please start new threads wirth a new email, do not reply to a previous post - it confuses threaded readers. (and sometimes human readers too!) '\x00\x11\xb2\x00@,O\xa4' the above str is being returned from one key/value pair in a dictionary.

Re: [Tutor] Searching a text file's contents and comparing them toalist

2010-07-14 Thread Alan Gauld
Eric Hamiter ehami...@gmail.com wrote aisle_one = [chips, bread, pretzels, magazines] aisle_two = [juice, ice cream] aisle_three = [asparagus] def find_groceries(): grocery_list = open(grocery_list.txt, r) for line in grocery_list.readlines(): See previous about removing the redundant

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Emile van Sebille
On 7/14/2010 11:11 AM Serdar Tumgoren said... But I was wondering (for my own edification), can anyone point to the portion of the docs that clearly spells out the order of execution (top to bottom, classes vs. functions, etc.). I found this in the tutorial in the modules section: ( see

Re: [Tutor] Searching a text file's contents and comparing them toalist

2010-07-14 Thread Eric Hamiter
Thanks for the pointers! This is now working, albeit probably ugly and clunky: aisle_one = [chips, bread, pretzels, magazines] aisle_two = [juice, ice cream] aisle_three = [asparagus] def find_groceries(): with open(grocery_list.txt) as grocery_list: first_trip = [Located on aisle

Re: [Tutor] Searching a text file's contents and comparing them to alist

2010-07-14 Thread davidheiserca
There are probably return characters at the end of each line from the grocery_list. Try using the String method line.strip(). Or grocery_list.read().splitlines() - Original Message - From: Eric Hamiter ehami...@gmail.com To: tutor@python.org Sent: Wednesday, July 14, 2010 8:46

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Serdar Tumgoren
I also found this interesting (but possibly not to newbies :) : http://www.shinetech.com/attachments/108_python-language-internals.pdf Very helpful, especially that last resource. Thank you! Serdar ___ Tutor maillist - Tutor@python.org To

Re: [Tutor] Searching a text file's contents and comparing them toalist

2010-07-14 Thread christopher . henk
Eric Hamiter wrote on 07/14/2010 04:57:57 PM: Thanks for the pointers! This is now working, albeit probably ugly and clunky: aisle_one = [chips, bread, pretzels, magazines] aisle_two = [juice, ice cream] aisle_three = [asparagus] def find_groceries(): with open(grocery_list.txt)

Re: [Tutor] Searching a text file's contents and comparing them toalist

2010-07-14 Thread Nick Raptis
On 07/14/2010 11:57 PM, Eric Hamiter wrote: Last question (for today, at least): Right now, the output is less than aesthetically pleasing: (['Located on aisle 1: ', 'bread', 'magazines'], ['Located on aisle 2: ', 'juice', 'ice cream'], ['Located on aisle 3: ', 'asparagus'], ['Not found in the

Re: [Tutor] Searching a text file's contents and comparing them toalist

2010-07-14 Thread bob gailer
[snip] Since you look up the items in the grocery list it seems to me a dictionary relating each item to its aisle would be best. inventory = {chips : 1, bread : 1, pretzels : 1, magazines : 1, juice : 2, ice cream : 2, asparagus : 3} MAX_AISLE = 3 aisles = [[] for i

Re: [Tutor] str format conversion help

2010-07-14 Thread eMyListsDDg
Steve, glad you pointed that out. struct.unpack or something...i'll look into that module. thx On 14-Jul-10 11:35, eMyListsDDg wrote: '\x00\x11\xb2\x00@,O\xa4' the above str is being returned from one key/value pair in a dictionary. it is the addr of a network device. i want to

Re: [Tutor] str format conversion help

2010-07-14 Thread eMyListsDDg
Hello Alan, First please start new threads wirth a new email, do not reply to thought i did, my apologies. eMyListsDDg emylists...@gmail.com wrote First please start new threads wirth a new email, do not reply to a previous post - it confuses threaded readers. (and sometimes human

Re: [Tutor] Handling 'None' (null) values when processing sqlite cursorresults

2010-07-14 Thread Monte Milanuk
On 7/14/10 5:32 AM, Alan Gauld wrote: The key principle is do not try to store your data in a display format. Never was my intention. I just hadn't anticipated needing to write my own function to handle something as (I would think) common as a NULL value in a database field. I had been

Re: [Tutor] Handling 'None' (null) values when processing sqlite cursorresults

2010-07-14 Thread Christian Witts
On 14/07/2010 19:34, Alan Gauld wrote: Christian Witts cwi...@compuscan.co.za wrote You need a display function that can strip out the nulls as needed. A simple list comprehension or generator expression would work in this case: print ' '.join(str(field) for field in data if field is not