On 14/07/2010 19:34, Alan Gauld wrote:
"Christian Witts" 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
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 wo
Hello Alan,
> First please start new threads wirth a new email, do not reply to
thought i did, my apologies.
> "eMyListsDDg" 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!)
>
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
[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
aisle
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 d
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 o
>
>
>>
> 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
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"
To:
Sent: Wednesday, July 14, 2010 8:46 AM
Subject: [Tutor] Sea
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 = ["L
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 http:
"Eric Hamiter" 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 redundan
"eMyListsDDg" 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. it is the addr of a
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 objec
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.stri
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
'\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 h
> 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 for
On 14 July 2010 17:41, Jim Byrnes wrote:
> Adam Bark wrote:
>
>> On 14 July 2010 02:53, Jim Byrnes wrote:
>>
>> Adam Bark wrote:
>>>
>>>
>>>
>>>
>>> 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 wa
On Wed, Jul 14, 2010 at 12:26 PM, Alan Gauld wrote:
>
> 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:
>
> line = line.strip()
"Christian Witts" 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 you're relying on a se
"Eric Hamiter" 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 in gr
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' the
"Corey Richardson" 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 their first pa
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 Tki
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 = open
Adam Bark wrote:
On 14 July 2010 02:53, Jim Byrnes wrote:
Adam Bark wrote:
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 have them run. If it turns
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__
ret
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" % l
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 li
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 a
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. R
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:
http://pastebin.com/QTNmKYC6
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(j j += 1
> return j
>
> now I want to calculate the execution time of the function RepAdd
> w
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,
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(j___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listi
>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 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 get my feet wet with GUI stuff.
Here is the traceback:
Tra
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
On 14 July 2010 02:53, Jim Byrnes wrote:
> Adam Bark wrote:
>
>
>
>
> 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 have them run. I
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 in
On 14/07/2010 14:32, Alan Gauld wrote:
"Monte Milanuk" 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
On Wed, Jul 14, 2010 at 7:18 AM, Corey Richardson 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
> simili
"Corey Richardson" 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 really have
On 7/14/10, Corey Richardson 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
"Monte Milanuk" 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 giving me a 'None
"ZUXOXUS" 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 shouldn't work.
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 toolk
"Steven D'Aprano" 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
just
trim the quote
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 = ''
correct
> 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 t
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. wo
I tried replying with inline the questions
read below within your mail
On Tue, Jul 13, 2010 at 8:13 PM, 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.
>
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
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.
On Tue, Jul 13, 2010 at 12:34 PM, Nitin Pawar 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 wrote, my code was not
On Wed, Jul 14, 2010 at 6:31 AM, Monte Milanuk 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:
>
> (104, None,
57 matches
Mail list logo