[Tutor] Notes on sorting

2007-07-29 Thread Kent Johnson
At my local Python user group meeting I have a regular spot on the agenda called Kent's Korner where I present not-quite-beginner material. This month was on sorting; my notes are here: http://personalpages.tds.net/~kent37/kk/7.html You can see past notes at http://personalpages.tds.net/~ken

Re: [Tutor] attribute error - quick addition

2007-07-29 Thread Alan Gauld
"Sara Johnson" <[EMAIL PROTECTED]> wrote > Sorry...I forgot a few more lines at the end of the code. Starts > with "outfile2write..." > I also added outfile2.sort() OK, at leasrt we see where the error occcurs. The problem emains that you are trying to sort a file which doesn't have a sort me

Re: [Tutor] attribute error

2007-07-29 Thread Alan Gauld
"Sara Johnson" <[EMAIL PROTECTED]> wrote > I always thought with floats you needed a 0.0. > I do have some percentages that are less than 1% but more than 0.0. If you already have a float value then you can compare it to an int and save the typing. zero means the same in a float comparison as

Re: [Tutor] attribute error

2007-07-29 Thread Alan Gauld
"Sara Johnson" <[EMAIL PROTECTED]> wrote Is this the correct traceback? Output okay except it will not sort alphabetically. Traceback (most recent call last): File "./mymods.py", line 83, in ? outfile2.sort() AttributeError: 'file' object has no attribute 'sort' *

Re: [Tutor] what is the * operator called in this context?

2007-07-29 Thread Kent Johnson
bill nieuwendorp wrote: > when ever I need to use the struct module > I always store my values in a list or a dict, then > I do something like the code below > > import struct > list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > length =len(list) > struct.pack(">%di"%(length), *[i for i in list]) You don't

Re: [Tutor] what is the * operator called in this context?

2007-07-29 Thread bill nieuwendorp
of course I take one more look through the docs after I send the origonal message and stumble upon it right away. http://www.python.org/doc/2.5/tut/node6.html#SECTION00674 On 7/29/07, bill nieuwendorp <[EMAIL PROTECTED]> wrote: > > when ever I need to use the struct module > I alw

[Tutor] what is the * operator called in this context?

2007-07-29 Thread bill nieuwendorp
when ever I need to use the struct module I always store my values in a list or a dict, then I do something like the code below import struct list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] length =len(list) struct.pack(">%di"%(length), *[i for i in list]) now I can not remember where I came up with that,

[Tutor] data structures and algorithms with object-oriented design patterns in python

2007-07-29 Thread bhaaluu
Greetings, While searching for information about Python Data Structures I came across this site and thought it might be interesting for others on the list as well: http://www.brpreiss.com/books/opus7/ Data Structures and Algorithms with Object-Oriented Design Patterns in Python. Bruno Preiss. Co

Re: [Tutor] attribute error - quick addition

2007-07-29 Thread Sara Johnson
Sorry...I forgot a few more lines at the end of the code. Starts with "outfile2write..." I also added outfile2.sort() Is this the correct traceback? Output okay except it will not sort alphabetically. Traceback (most recent call last): File "./mymods.py", line 83, in

Re: [Tutor] attribute error

2007-07-29 Thread Sara Johnson
Is this the correct traceback? Output okay except it will not sort alphabetically. Traceback (most recent call last): File "./mymods.py", line 83, in ? outfile2.sort() AttributeError: 'file' object has no attribute 'sort' * Here's the code. I did not wr

Re: [Tutor] build a really simple "json" api from a db

2007-07-29 Thread Picio
The beginning idea was to build a json API myself. Since I need only to generate json from a db, maybe Django is too much. I'm a Django beginner. I don't know Turbogears. I've not found anything like: "how to build a json api". Maybe MySqldb+simplejson is the enough? Or Is It more simple to learn h

Re: [Tutor] Livewires questions

2007-07-29 Thread Tonu Mikk
Luke Paireepinart wrote: >> >> >> Sure, sure. I'm glad it at least ran. I don't have livewires >> installed so I wasn't able to test any of the code I wrote. >> >> Thanks again for your help. If you have suggestions on the 't' key, >> please share them. This seems to be the one issue p

Re: [Tutor] attribute error

2007-07-29 Thread Sara Johnson
- Original Message From: Alan Gauld [EMAIL PROTECTED] >> for key in skeys: >> fracmiss=1.*numberMissing(z[key].values())/nsites #note decimal >> multiplication, 1.* >This is a mess. Why have that long comment when all that's needed >is to add the zero?! (and some spaces to make

Re: [Tutor] don't repeat yourself; question about code optimization CORRECTION

2007-07-29 Thread Bob Gailer
[EMAIL PROTECTED] wrote: > > > On 7/23/07, *Bob Gailer* <[EMAIL PROTECTED] > > wrote: > > A correction to the code at the end. The test of > self.total_num_of_items > should precede the pop(0) > > > > Bob, I spent today studying what you've been telling me and

Re: [Tutor] don't repeat yourself; question about code optimization

2007-07-29 Thread ALAN GAULD
> assert create_table(5, 3) == [(0, 1, 2), (3, 4)] > AssertionError > > I know that my method of calculating the number of rows is faulty, > but I'm not sure how to correct it. num_rows = (num_items/row_size) + (num_items%row_size) This uses integer division then adds the remainder, so f

Re: [Tutor] don't repeat yourself; question about code optimization CORRECTION

2007-07-29 Thread Eric Brunson
[EMAIL PROTECTED] wrote: > > > On 7/23/07, *Bob Gailer* <[EMAIL PROTECTED] > > wrote: > > A correction to the code at the end. The test of > self.total_num_of_items > should precede the pop(0) > > > > Bob, I spent today studying what you've been telling me and

Re: [Tutor] don't repeat yourself; question about code optimization

2007-07-29 Thread tpc247
On 7/23/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > > The prime directive of coding is make it readable! > The DRY principle is just that a principle. If repeating makes for > more maintainable or readable code then repeat yourself. > > Remember 80% of the cost of software is in maintenance not in

Re: [Tutor] don't repeat yourself; question about code optimization CORRECTION

2007-07-29 Thread tpc247
On 7/23/07, Bob Gailer <[EMAIL PROTECTED]> wrote: > > A correction to the code at the end. The test of self.total_num_of_items > should precede the pop(0) Bob, I spent today studying what you've been telling me and I put the finishing touches to make your code pass my battery of tests. It still

Re: [Tutor] attribute error

2007-07-29 Thread Alan Gauld
"Sara Johnson" <[EMAIL PROTECTED]> wrote > However, is there an indentation error here? Not that I can see. Is there an error? If so can you send the traceback? Its very hard to answer questions without any context. > I may just be too frustrated to see it. > > for key in skeys: > fracm