Re: [Tutor] Dictionaries

2006-01-26 Thread Alan Gauld
> Is there anyway to print informtation from dictionaries better than this?: For formatted printing look at the print format operator '%' You can specify field sizes, justification etc thus : >>> pairs = {"Jon Moore": "Tony Moore", "Simon Nightingale": "John Nightingale", "Da

Re: [Tutor] Dictionaries

2006-01-26 Thread Jon Moore
KentThanks! I have not come accross string formatting yet, but I can see how the for statement works.How would I modify this to just print either the values or keys?Jon On 26/01/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Jon Moore wrote:> Hi>> Is there anyway to print informtation from dictionarie

[Tutor] Adding items to dictionaries

2006-01-26 Thread Jon Moore
Hi,I have the following dictionary:pairs = {"Jon Moore": ["Tony Moore", "Stanley Moore"], "Simon Nightingale": ["John Nightingale", "Alan Nightingale"], "David Willett": ["Bernard Willet", "Robert Willet"], "John Jackson": ["John Jackson", "Peter Jackson"], "James S

Re: [Tutor] Dictionaries

2006-01-26 Thread Kent Johnson
Jon Moore wrote: > Kent > > Thanks! I have not come accross string formatting yet, but I can see how > the for statement works. > > How would I modify this to just print either the values or keys? Use for key in pairs.iterkeys(): or for value in pairs.itervalues(): and change the print st

Re: [Tutor] mod_python and other web frameworks

2006-01-26 Thread wkranec
There seems to be a discussion about this sort of thing every other week or so, and I'm always surprised that no one mentions Cheetah Templates (www.cheetahtemplate.org). It's useful for both web and non-Web applications, and has a straightforward syntax that pretty much *is* Python. For web prog

Re: [Tutor] Adding items to dictionaries

2006-01-26 Thread Kent Johnson
Jon Moore wrote: > Hi, > > I have the following dictionary: > > pairs = {"Jon Moore": ["Tony Moore", "Stanley Moore"], > "Simon Nightingale": ["John Nightingale", "Alan Nightingale"], > "David Willett": ["Bernard Willet", "Robert Willet"], > "John Jackson": ["John Jacks

[Tutor] smarter way of looping

2006-01-26 Thread Elderely Geek
Hi, I`m a python newbie and could use some help.   I often do a loop over arbitrary number of sequences. I do it like this:   for elem1 in seq1:     for elem2 in seq2:     do whatever seq1,seq2   this isn`t nice I think. Is there some way I can say myiterator=geniousfunction(seq1,seq2,seq3)   a

Re: [Tutor] Dictionaries

2006-01-26 Thread Alan Gauld
for father,son in pairs.items: > ... print "%20s\t%20s" % (father,son) Oops! Should have been for father,son in pairs.items(): Sorry, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Dictionaries

2006-01-26 Thread Alan Gauld
> How would I modify this to just print either the values or keys? Just ask for the values or the keys! for value in pairs.values() print value for key in pairs.keys() print key for key,value in pairs.items() print key print value Dictionaries are extremely powerful data cont

Re: [Tutor] smarter way of looping

2006-01-26 Thread Kent Johnson
Elderely Geek wrote: > Hi, > I`m a python newbie and could use some help. > > I often do a loop over arbitrary number of sequences. I do it like this: > > for elem1 in seq1: > for elem2 in seq2: > do whatever seq1,seq2 > > this isn`t nice I think. Is there some way I can say > my

Re: [Tutor] mod_python and other web frameworks

2006-01-26 Thread Christian Wyglendowski
Some others have already mentioned TurboGears, but since it sounds like you want more control perhaps, I would recommend going with CherryPy (http://www.cherrypy.org). You basically write python code and then expose it to the web (or intranet or whatever). # simple example import cherrypy import

Re: [Tutor] Adding items to dictionaries

2006-01-26 Thread Jon Moore
KentThanks again. I have a question (see below).On 26/01/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Jon Moore wrote:> Hi,>> I have the following dictionary:>> pairs = {"Jon Moore": ["Tony Moore", "Stanley Moore"], >  "Simon Nightingale": ["John Nightingale", "Alan Nightingale"],>  

Re: [Tutor] mod_python and other web frameworks

2006-01-26 Thread Intercodes
 Christian,You are certainly right. I couldn't get anything apart from "Hello world" coding in mod_python. The mod_python manual is also bit vague, not for beginners. I wonder why there aren't any good tutorials on mod_python. I am having a look at quixote as a developer in this list suggested. I w

Re: [Tutor] Adding items to dictionaries

2006-01-26 Thread Alan Gauld
> pairs[son][0] = father > KeyError: 'Steven Bates' > Where am I going wrong? A KeyError means you are trying to access an object that does not exist in the dictionary. And this is true, you haven't added anything for Steven Bates yet, but you are trying to access his parents list. You need

Re: [Tutor] smarter way of looping

2006-01-26 Thread Alan Gauld
> I often do a loop over arbitrary number of sequences. I do it like this: > >for elem1 in seq1: >for elem2 in seq2: >do whatever seq1,seq2 > > this isn`t nice I think. Actually its pretty common and not that ugly. But... > myiterator=geniousfunction(seq1,seq2,seq3) > > and then myite

Re: [Tutor] smarter way of looping

2006-01-26 Thread Elderly Geek
On 1/26/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > I often do a loop over arbitrary number of sequences. I do it like this: > > > >for elem1 in seq1: > >for elem2 in seq2: > >do whatever seq1,seq2 > > this isn`t nice I think. > > Actually its pretty common and not that ugly. > But...

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

2006-01-26 Thread Bob Gailer
At 08:44 AM 1/25/2006, Jon Moore wrote: Hi, I have written the program below as an exercise from a book I am working my way through. Objective from book:Write a character creator program for a role-playing-game. The player should be given a pool of 30 points to spend on four attributes: strength,

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

2006-01-26 Thread Paul Kraus
What book are you working through? That is a pretty interesting exercise. Paul On Thursday 26 January 2006 12:52 pm, Bob Gailer wrote: > At 08:44 AM 1/25/2006, Jon Moore wrote: > > Hi, > > I have written the program below as an exercise from a book I am working my > way through. > > Objective from

[Tutor] First steps with Tkinter

2006-01-26 Thread etrade . griffiths
Hi! Just started trying to get to grips with Python and Tkinter. Have Frederick Lundh's tutorial and am on program hello2.py which looks like this # File: hello2.py from Tkinter import * class App: def __init__(self, master): frame = Frame(master) frame.pack() s

Re: [Tutor] First steps with Tkinter

2006-01-26 Thread Michael Lange
On Thu, 26 Jan 2006 18:20:48 + [EMAIL PROTECTED] wrote: > > root.mainloop() > > I am running from inside Pythonwin 2.4 IDE under XP Pro and every time I run > hello2.py it freezes when I press "QUIT". The only way to kill it is through > Alt-Ctrl-Del but this crashes Pythonwin. Any work

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

2006-01-26 Thread Bob Gailer
At 08:44 AM 1/25/2006, Jon Moore wrote: > Hi, > > I have written the program below as an exercise from a book I am > working my way through. > > Objective from book: > Write a character creator program for a role-playing-game. The player > should be given a pool of 30 points to spend on four attr

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

2006-01-26 Thread Orri Ganel
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 uses a different name for it s

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

2006-01-26 Thread Rinzwind
Thank you!*opens manual again*WimOn 1/26/06, Orri Ganel <[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

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

2006-01-26 Thread Rinzwind
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 uses a different name for it so I am not looking for t

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

2006-01-26 Thread Orri Ganel
No problem.  As for the main use of  cmp(), btw, afaik, it's used to define custom sorting, as in the following: >>> import random >>> temp = [] >>> for i in range(10):     temp.append((random.randint(0,100),random.randint(0,100),random.randint(0,100)))     >>> temp [(16, 70, 87), (57, 80, 3

[Tutor] list.__init__()

2006-01-26 Thread Christopher Spears
What purpose does list.__init__() play in the piece of code below? class Mylist(list): def __init__(self, value = []): list.__init__([]) self.concat(value) def concat(self, value): for x in value: if not x in s

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

2006-01-26 Thread Kent Johnson
Orri Ganel wrote: > Rinzwind wrote: > >> In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > Well, the cmp() function does this if you compare the number to 0: > > >>> cmp(-34,0) > -1 > >>> cmp(0,0) > 0 > >>> cmp(23,0) One caution: this behaviour doesn't seem to be requi

Re: [Tutor] list.__init__()

2006-01-26 Thread Kent Johnson
Christopher Spears wrote: > What purpose does list.__init__() play in the piece of > code below? It's an incorrect call to the base class __init__() function. This does base class initialization on the current list. The correct call is list.__init__(self) By the way this list seems to be doin

[Tutor] designing a class

2006-01-26 Thread Christopher Spears
Here is an exercise out of Learning Python: Write a class called Mylist that shadows ("wraps") a Python list: it should overload most list operators and operations including +, indexing, iteration, slicing, and list methods such as append and sort. See the Python reference manual for a list of po

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

2006-01-26 Thread Alan Gauld
>> In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > Well, the cmp() function does this if you compare the number to 0: Neat trick Orri, I'd never have thought of that one :-) Alan G. ___ Tutor maillist - Tutor@python.org http:

Re: [Tutor] Is this overkill?

2006-01-26 Thread catherine curley
Bradly   I'm new to python also.  Have you come across any good exercises that a beginner try.   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.   Catherine  On 1/21/06, Bradly McConnell <[EMAIL PROTECTED]> wrote: G

Re: [Tutor] First steps with Tkinter

2006-01-26 Thread catherine curley
Alan   As a matter of interest, did you have much knowledge of Python before you tried TKinter?  I'm only a python beginner at present.   Catherine  On 1/26/06, [EMAIL PROTECTED] <[EMAIL PROTECTED] > wrote: Hi!Just started trying to get to grips with Python and Tkinter.  Have FrederickLundh's tutor

Re: [Tutor] designing a class

2006-01-26 Thread Terry Carroll
On Thu, 26 Jan 2006, Christopher Spears wrote: > Here is an exercise out of Learning Python: Which edition? If I recall, the second edition covers through a release of Python (2.2?) that permits direct subclassing of lists; while the earlier one came out prior to Python 2.2, and would expect you

[Tutor] AttributeError - ChatServer

2006-01-26 Thread Bob Hinkle
While following a tutorial on how to create a simple chat server I stumbled upon this problem: AttributeError: ChatServer instance has no attribute 'decriptors' here is my code: #... import socket import select class

Re: [Tutor] AttributeError - ChatServer

2006-01-26 Thread John Fouhy
On 27/01/06, Bob Hinkle <[EMAIL PROTECTED]> wrote: > While following a tutorial on how to create a simple chat server I stumbled > upon this problem: > AttributeError: ChatServer instance has no attribute 'decriptors' Hi Bob, Attributes are things like methods or variables that are "attached" to

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

2006-01-26 Thread Ben Markwell
Being new to programming, I made a text file that contains terms with their definitions that I have come across in my studying. As an exercise, I thought  I would make a glossary using a dictionary so I can look up words, add new words, view all entries, etc.  I want to enter the words and def

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

2006-01-26 Thread Danny Yoo
> I tried : > > for line in f: > gloss[line] = f.readline() > This should have worked, but there's one problem. Whenever we're doing something like: for line in f: ... there can be some interference between the iteration and any readline() in the body of the loop. For eff

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

2006-01-26 Thread Rinzwind
> On 1/26/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > >> In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > > Well, the cmp() function does this if you compare the number to 0: > > Neat trick Orri, I'd never have thought of that one :-) > > Alan G. Glad I could help :=) On

Re: [Tutor] designing a class

2006-01-26 Thread Runsun Pan
On 1/26/06, Christopher Spears <[EMAIL PROTECTED]> wrote: > headlights. Where should I begin? How do I go about > designing a new class? Some starter 101: First, recognize that a class is a compound type that is not only a type but binds other variables and methods with it. #-

Re: [Tutor] designing a class

2006-01-26 Thread Runsun Pan
# initialization of class If you want to be able to give initial values to the class when it is instantialized, you do it in the __init__ function that Terry mentioned: class People(object): def __init__(self, firstname='Chris', lastname='Spears'):