Re: [Tutor] Trying to enter text from a file to a Dictionary

2006-01-27 Thread Ben Markwell
> I understand f.next(), but [gloss.setdefault(l,f.next()) for l in f]> is beyond me at this point. [expr for l in f] is a "list comprehension". expr is an _expression_ thatmay involve l.result = [expr for l in f] # is equivalent to:result = []for l in f:result.append(expr) "list comprehension"

Re: [Tutor] Trying to enter text from a file to a Dictionary

2006-01-27 Thread Bob Gailer
Ben Markwell wrote: > > > On 1/27/06, *Bob Gailer* <[EMAIL PROTECTED] > > wrote: > > Bob Gailer wrote: > > Alan Gauld wrote: > > > >> Hi Ben, > >> > >> > >> > >>> I want to enter the words and definitions from the text file > into the

Re: [Tutor] Trying to enter text from a file to a Dictionary

2006-01-27 Thread Ben Markwell
On 1/27/06, Bob Gailer <[EMAIL PROTECTED]> wrote: Bob Gailer wrote:> Alan Gauld wrote:>>> Hi Ben,> I want to enter the words and definitions from the  text file into the>>> dict.>>> The way the text file is set up is that one  line is the word and the >>> next line is the definition.>>>

Re: [Tutor] Fwd: Trying to enter text from a file to a Dictionary

2006-01-27 Thread Ben Markwell
Hi Ben,Yes, that's the point: Python doesn't know when to stop.  *grin* The way we've rewritten the loop:while True:...is an "infinite" loop that doesn't stop unless something in the loop'sbody does something extraordinary, like "breaking" out of the loop. Python is much dumber than we

Re: [Tutor] Dictionaries

2006-01-27 Thread Alan Gauld
> their equivalent for keys and values. I notice Ken suggests iteritems(), > while Alan suggests items() only. I'm old fashioned and rarely use new language features until I really have to. Kent uses the more modern idioms. I think iteritems is the preferred usage nowadays, but its longer to type

Re: [Tutor] Fwd: Trying to enter text from a file to a Dictionary

2006-01-27 Thread Danny Yoo
> Here's one way we can avoid the problem: > > while True: > word = f.readline() > defn = f.readline() > if not word or not defn: >break > ... > > Does this make sense? > > It does mostly...I don't see why you need the: > > if not word or not defn:

[Tutor] Fwd: Trying to enter text from a file to a Dictionary

2006-01-27 Thread Ben Markwell
Hello Danny Thanks for replying to my post. >   I tried :>>   for line in f:Thanks for your reply to my post. >   gloss[line] = f.readline()> This should have worked, but there's one problem.  Whenever we're doingsomething like:for line in f:...there can be some interference bet

Re: [Tutor] Trying to enter text from a file to a Dictionary

2006-01-27 Thread Alan Gauld
>> for line in f: >> if isDefinition: >>gloss[currentKey] = line >>currentKey = None >>isDefinition = False >> else: >>currentKey = line >>isDefinition = True >> > Or you can use next(): > > for line in f: >gloss[line] = f.next() Ah! Indeed y

Re: [Tutor] Trying to enter text from a file to a Dictionary

2006-01-27 Thread Bob Gailer
Bob Gailer wrote: > Alan Gauld wrote: > >> Hi Ben, >> >> >> >>> I want to enter the words and definitions from the text file into the >>> dict. >>> The way the text file is set up is that one line is the word and the >>> next line is the definition. >>> >>> >> >> >

Re: [Tutor] Dictionaries

2006-01-27 Thread Kent Johnson
Victor Bouffier wrote: > Hi Alan and Ken, > > I think know the difference between using items() vs. iteritems() and > their equivalent for keys and values. I notice Ken suggests iteritems(), > while Alan suggests items() only. > > Does one approach have an advantage over the other? > Should we us

Re: [Tutor] the chicken and the egg

2006-01-27 Thread Kent Johnson
Christopher Spears wrote: > Thanks to all of the tutors on this mailing list! I'm > finally making some headway! I originally decided to > tackle my problem one operator at a time: > > class MyList: > def __init__(self, aList=None): > if aList is None: >

Re: [Tutor] Dictionaries

2006-01-27 Thread Alan Gauld
> ... print '%*s --> %*s' % (maxKey, name, maxValue, pairs[name]) > > thanks for pointing out the '*' syntax. Ignorant as I am I have > had to write things like > > print '%%%ss --> %%%ss' % (maxKey, maxValue) % (name, pairs[name]) I didn't even try that, I've always done it on two lines fmt

Re: [Tutor] Trying to enter text from a file to a Dictionary

2006-01-27 Thread Bob Gailer
Alan Gauld wrote: > Hi Ben, > > >> I want to enter the words and definitions from the text file into the >> dict. >> The way the text file is set up is that one line is the word and the >> next line is the definition. >> > > >> I tried using a for loop like this >> >> f = open('glos

Re: [Tutor] Dictionaries

2006-01-27 Thread Victor Bouffier
Hi Alan and Ken, I think know the difference between using items() vs. iteritems() and their equivalent for keys and values. I notice Ken suggests iteritems(), while Alan suggests items() only. Does one approach have an advantage over the other? Should we use only one of them favorably? Thanks.

[Tutor] the chicken and the egg

2006-01-27 Thread Christopher Spears
Thanks to all of the tutors on this mailing list! I'm finally making some headway! I originally decided to tackle my problem one operator at a time: class MyList: def __init__(self, aList=None): if aList is None: self.mylist = [] el

Re: [Tutor] designing a class

2006-01-27 Thread Kent Johnson
Christopher Spears wrote: >>class MyList: >> def __init__(self, aList=None): >> if aList is None: >> self._list = [] >> else: >> self._list = aList[:] >> > > > This code certainly looks like it will do the trick. > I'm just not sure what the _ in front of list (i.e. > _list

Re: [Tutor] designing a class

2006-01-27 Thread Christopher Spears
> class MyList: >def __init__(self, aList=None): > if aList is None: >self._list = [] > else: >self._list = aList[:] > This code certainly looks like it will do the trick. I'm just not sure what the _ in front of list (i.e. _list) denotes. "I'm the last person t

[Tutor] templates

2006-01-27 Thread Mike Hansen
For some of the web programming I've done in Python, I've used htmltmpl. I had some experience with it in Perl, and found a Python version. http://htmltmpl.sourceforge.net/ I like that there's nearly a complete separation between the presentation and the code. This is great when one person is d

Re: [Tutor] socket and lost data

2006-01-27 Thread Alan Gauld
I'm a wee bit confused. > def envoyer(conn, mysize): > print mysize,' KB sent This doesn't seem to be true from the code. > data = '1'*1024 > data_end = data[:-5]+'#' > data = data*(mysize-1) So data is mysize-1 KB, but you printed mysize KB? > begining = time.time() >

Re: [Tutor] Dictionaries

2006-01-27 Thread Kent Johnson
Jon Moore wrote: > Hi > > Is there anyway to print informtation from dictionaries better than this?: > > >>> pairs = {"Jon Moore": "Tony Moore", > "Simon Nightingale": "John Nightingale", > "David Willett": "Bernard Willet", > "John Jackson": "Stuart Jackson", >

Re: [Tutor] Dictionaries

2006-01-27 Thread Michael Janssen
On 1/26/06, John Fouhy <[EMAIL PROTECTED]> wrote: > >>> for name in pairs: > ... print '%*s --> %*s' % (maxKey, name, maxValue, pairs[name]) thanks for pointing out the '*' syntax. Ignorant as I am I have had to write things like print '%%%ss --> %%%ss' % (maxKey, maxValue) % (name, pairs[na

Re: [Tutor] why can't I find a function that gives me the sign of an integer?

2006-01-27 Thread Rinzwind
On 1/27/06, Wolfram Kraus <[EMAIL PROTECTED]> wrote: > Rinzwind wrote: > > In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > > I searched on the web for a bit but sgn and sign give me way too many > > discussions about Decimals. python.org with > > numbe

Re: [Tutor] [newbie alert] why can't I find a function that gives me the sign of an integer?

2006-01-27 Thread Wolfram Kraus
Rinzwind wrote: > In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > I searched on the web for a bit but sgn and sign give me way too many > discussions about Decimals. python.org with > numbers/digits doesn't tell about a function. > > Maybe Python us

Re: [Tutor] [newbie alert] why can't I find a function that gives me the sign of an integer?

2006-01-27 Thread Wolfram Kraus
Rinzwind wrote: > In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > I searched on the web for a bit but sgn and sign give me way too many > discussions about Decimals. python.org with > numbers/digits doesn't tell about a function. > > Maybe Python us

Re: [Tutor] socket and lost data

2006-01-27 Thread Kent Johnson
le dahut wrote: > Hi, > I try to send some data across a network (between 400KB and 10MB) like > this : > def envoyer(conn, mysize): > print mysize,' KB sent' > data = '1'*1024 > data_end = data[:-5]+'#' > data = data*(mysize-1) > begining = time.time() > conn.sen

Re: [Tutor] why can't I find a function that givesme the sign of aninteger?

2006-01-27 Thread Kent Johnson
Alan Gauld wrote: > Orri, > > >>Eh you mean to say that in next Python versions someone could decide >>to change cmp(x,0) to another meaning? I bet my countryman (I'm from >>Holland too ;-) ) will veto that! Or else I'll pay him a visit :D > > > Its not another meaning, its the current meaning.

[Tutor] socket and lost data

2006-01-27 Thread le dahut
Hi, I try to send some data across a network (between 400KB and 10MB) like this : def envoyer(conn, mysize): print mysize,' KB sent' data = '1'*1024 data_end = data[:-5]+'#' data = data*(mysize-1) begining = time.time() conn.send(data) conn.send(data_end)

Re: [Tutor] why can't I find a function that givesme the sign of aninteger?

2006-01-27 Thread Rinzwind
On 1/27/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > Orri, > > > Eh you mean to say that in next Python versions someone could decide > > to change cmp(x,0) to another meaning? I bet my countryman (I'm from > > Holland too ;-) ) will veto that! Or else I'll pay him a visit :D > > Its not another mea

Re: [Tutor] why can't I find a function that givesme the sign of aninteger?

2006-01-27 Thread Alan Gauld
Orri, > Eh you mean to say that in next Python versions someone could decide > to change cmp(x,0) to another meaning? I bet my countryman (I'm from > Holland too ;-) ) will veto that! Or else I'll pay him a visit :D Its not another meaning, its the current meaning. Kent is just pointing out that

Re: [Tutor] Trying to enter text from a file to a Dictionary

2006-01-27 Thread Alan Gauld
Hi Ben, > I want to enter the words and definitions from the text file into the > dict. > The way the text file is set up is that one line is the word and the > next line is the definition. > I tried using a for loop like this > > f = open('glossary.txt','r') > gloss = {} > > for line in f

Re: [Tutor] Controling my loops and redundant code?!?

2006-01-27 Thread Jon Moore
PaulThe book is called 'Python Programming for the absolute beginner'. It is written by Michael Dawson and published by Premier Press.I have to say that as someone that has no experience in programming what so ever, I am hooked! I need to learn Python for a job I am starting next month and to say I

Re: [Tutor] First steps with Tkinter

2006-01-27 Thread Etrade Griffiths
Catherine I'm a Python newbie too but have done some programming with C++ Builder so have a little knowledge of GUIs etc Best regards Alun At 22:41 26/01/2006, catherine curley wrote: Alan   As a matter of interest, did you have much knowledge of Python before you tried TKinter?  I'm only a pyth

Re: [Tutor] AttributeError - ChatServer

2006-01-27 Thread Alan Gauld
> AttributeError: ChatServer instance has no attribute 'decriptors' Read the error carefully - a typo maybe? Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Is this overkill?

2006-01-27 Thread Alan Gauld
Catherine > I've spend some time going throught the many available turorials, but find > it hard to get good exercises to try out what you learn. Most tutorials do have a few suggested exercises but the best way is to take the examples they give and modify them to see what happens. The reason for

Re: [Tutor] designing a class

2006-01-27 Thread Alan Gauld
> Write a class called Mylist that shadows ("wraps") a > Python list: it should overload most list operators > ... > When I read this, I feel like a deer caught in the > headlights. Where should I begin? How do I go about > designing a new class? Well, to quote an old joke, I wouldn't start from