Re: [Tutor] primes - sieve of odds

2005-03-23 Thread C Smith
Now it would be fine to have an *equally fast* infinite prime number generator. Has anybody any suggestions? [cut] What follows is an attempt based on the previous tutor-evolved sieve that extends the range in which to find the next prime by a factor of 2 over the last known prime. A similar alg

Re: [Tutor] Passing data from html to py

2005-03-23 Thread Kent Johnson
Vicki Stanfield wrote: I have one last question on this particular script. I am using the following line to print out the post data: for key in form: print "%s: %s" % (key, form[key].value) The difficulty is that sometimes you have a single value and sometimes you have a list. If yo

[Tutor] xmlrpc server

2005-03-23 Thread Luis N
Hi, I've been exploring xmlrpc implementations, and am somewhat confused as to what I should use. I've spent the most time poking at Twisted, which took me a while to figure out the basics of, and have spent a moment or two exploring py-xmlrpc as well as SimpleXMLRPCServer in the standard library.

Re: [Tutor] I need some guidance

2005-03-23 Thread Jacob S.
My two bits... Use the python interpreter a lot! Run through the examples in the tutorial, see the output piece by piece, then make small variations and see the output. For example, when the tutorial passes one variable to a function, change the variable and see the output. Then see if you can

Re: [Tutor] Passing data from html to py

2005-03-23 Thread Vicki Stanfield
I have one last question on this particular script. I am using the following line to print out the post data: for key in form: print "%s: %s" % (key, form[key].value) It works fine except for when the key is to a list object made by the following select statement: Mother

[Tutor] Passing data from html to py

2005-03-23 Thread Vicki Stanfield
I am trying to understand how to pass data back and forth from a form to a python script. I mostly have it working now, but I am unsure about how to find out which variables are being passed from the html. I can see them in the form.list, but I need to iterate over them and print a label for each.

Re: [Tutor] I need some guidance

2005-03-23 Thread Liam Clarke
On Thu, 24 Mar 2005 00:30:22 +, John Carmona <[EMAIL PROTECTED]> wrote: > Hi to everyone first, this is my first posting and I hope that I won't make > a mess. > > I am 100% newbie (and when I mean newbie it is with a big N). > > I decided to have a go at programming and after reading differe

Re: [Tutor] Passing data from html to py

2005-03-23 Thread Vicki Stanfield
> > Hi Vicki --- > > Two things: > > Firstly, a there is a difference between /n and \n :-) > > Secondly, remember that all whitespace (including newlines) in HTML is > collapsed > down to a single space. > > The newlines will be there, but your web browser is just ignoring them. A > quick > fix i

Re: [Tutor] I need some guidance

2005-03-23 Thread jfouhy
Quoting John Carmona <[EMAIL PROTECTED]>: > Second question: As i am not, unfortunately, involved professionaly in > the field of programming is there a specific technique to learn other than > just read everything I put my hand on? Reading is fine, but you really need to be writing code to cemen

Re: [Tutor] I need some guidance

2005-03-23 Thread R. Alan Monroe
> My first question is do i need to really understand everything first time I > come across or does it get easier if you kind of move along and get back to > it later? My personal experience is that anything makes more sense when you come back to it later, so yes :^) > Third question: Does anyb

RE: [Tutor] I need some guidance

2005-03-23 Thread Kooser, Ara S
Title: RE: [Tutor] I need some guidance Welcome. And we all start as newbies (eerrr Level 1 programmers armed with a +1 Python and d4 hit points) "My first question is do i need to really understand everything first time I come across or does it get easier if you kind of move along and get b

Re: [Tutor] Passing data from html to py

2005-03-23 Thread jfouhy
Quoting Vicki Stanfield <[EMAIL PROTECTED]>: > > for key in form: > > print '%s: %s' % (key, form[key].value) > Thanks John, > That is exactly what I was looking for. I would like to add a newline > after each line. I tried adding a \n after the second %s, but that > doesn't seem to work. But wait

[Tutor] I need some guidance

2005-03-23 Thread John Carmona
Hi to everyone first, this is my first posting and I hope that I won't make a mess. I am 100% newbie (and when I mean newbie it is with a big N). I decided to have a go at programming and after reading different articles I decided to have a go at Python (first because it is free, secondly becaus

Re: [Tutor] Passing data from html to py

2005-03-23 Thread jfouhy
Quoting Vicki Stanfield <[EMAIL PROTECTED]>: > I need something more like this: > > First Name: Vicki > Last Name: Stanfield > etc. Instead of just printing form, try this: for key in form: print '%s: %s' % (key, form[key].value) Basically, a FieldStorage object is organised as a dicti

Re: [Tutor] Dictionary blues...

2005-03-23 Thread Igor Riabtchuk
I just solved it :) thank you all for chastising me :) particularly Alan Gauld - you save me again :) I reckon I will have to put a credit for you in the code :) Igor - Original Message - From: "Igor Riabtchuk" <[EMAIL PROTECTED]> To: Sent: Wednesday, March 23, 2005 11:51 PM Subject: R

Re: [Tutor] Dictionary blues...

2005-03-23 Thread Igor Riabtchuk
My deepest and most sincere apologies - cooking dinner for the family and posting questions do not mix, I keep making mistakes in the code I type. Once again my apologies - here's the code as it is in my source: import sys, os, unicodedata from Tkinter import * class CRED(Frame): def __init__

Re: [Tutor] Dictionary blues...

2005-03-23 Thread Alan Gauld
Igor, > I posted the wrong code before. The code is: Is this the actual code you have written? If so it is so far from being working code that it suggests you need to back up a little and work at the basics of Python before trying to tackle Tkinter and GUIs. I'll assume this really is your co

Re: [Tutor] primes - sieve of odds

2005-03-23 Thread C Smith
On Wednesday, Mar 23, 2005, at 04:00 America/Chicago, [EMAIL PROTECTED] wrote: Now it would be fine to have an *equally fast* infinite prime number generator. Has anybody any suggestions? I think when you add the condition of it being an infinite generator, you are changing the rules and can't e

Re: [Tutor] problems with dictionary

2005-03-23 Thread Max Noel
On Mar 23, 2005, at 21:55, Bill Mill wrote: In line 3 of the Conv function, you write "str="The name is" + str . However, str has yet to be defined, from what I can tell. Thus, Python should throw a NameError. Unforutnately, you haven't included the exception that Python gives you with this email,

Re: [Tutor] problems with dictionary

2005-03-23 Thread Alan Gauld
> D={a:"tom", b:"dick", c:"harry"} You don't have quotes around the keys. > > text.bind('', self.Conv) > > def Conv(self,event): The fact that you have 'self' as a first parameter to COnv and as a second argument to bind suggests this is all part of a class definition? Is D part off the same c

Re: [Tutor] Dictionary blues...

2005-03-23 Thread Danny Yoo
On Wed, 23 Mar 2005, Igor Riabtchuk wrote: > I posted the wrong code before. The code is: > > from Tkinter import * > > D={a:"tom", b:"dick", c:"harry"} > > text.bind('', self.Conv) > > def Conv(self,event): > if D.has_key(event.keysym): > str=D[event.keysym] > self.text.insert(END

[Tutor] Dictionary blues...

2005-03-23 Thread Igor Riabtchuk
I posted the wrong code before. The code is:   from Tkinter import *   D={a:"tom", b:"dick", c:"harry"}   text.bind('', self.Conv)   def Conv(self,event):    if D.has_key(event.keysym):  str=D[event.keysym]    self.text.insert(END,str)    return 'break'   The error message says wrong

Re: [Tutor] problems with dictionary

2005-03-23 Thread Bill Mill
On Wed, 23 Mar 2005 20:49:11 -, Igor Riabtchuk <[EMAIL PROTECTED]> wrote: > > Hi, > was wondering whether you can help? > > Say I got a dictionary of keys:values : > > And what I want to do is depending on what key (a,b,c) the person presses, I > want to output the value (tom, dic, h

Re: [Tutor] List comprehensions

2005-03-23 Thread Liam Clarke
Geez, that's pretty bad. I've got to stop playing with code when I'm tired. Thanks all. On Wed, 23 Mar 2005 20:24:32 -, Alan Gauld <[EMAIL PROTECTED]> wrote: > > Is there a way to apply multiple actions within one list > comprehension? > > Write a function? > > def foo(i): ># do stuf

[Tutor] problems with dictionary

2005-03-23 Thread Igor Riabtchuk
Hi, was wondering whether you can help?   Say I got a dictionary of keys:values :   And what I want to do is depending on what key (a,b,c) the person presses, I want to output the value (tom, dic, harry).   So I program like this:   import Tkinter   D={a:"tom", b:"dick", c:"harry"}   text.

Re: [Tutor] List comprehensions

2005-03-23 Thread Alan Gauld
> Is there a way to apply multiple actions within one list comprehension? Write a function? def foo(i): # do stuff to i return i [foo(i) for i in alist] Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tut

Re: [Tutor] blocking user access

2005-03-23 Thread John Fouhy
Diana Hawksworth wrote: Hi! I need help on blocking user access to a message box - for example, the program could provide an answer to an input. At the moment, the user has access to - and can type into - that "answer" space. How do I prevent that from happening please? Are you using Tkinter?

Re: [Tutor] List comprehensions

2005-03-23 Thread John Fouhy
Ryan Davis wrote: I think map is a little cleaner is some cases. Not sure if its more Pythonic, I'm still trying to figure out exactly what that means. map is (probably) going to be removed in Python3000 :-( So it's probably better to not get into the habit of using it. -- John. __

Re: [Tutor] .readlines() condensing multiple lines

2005-03-23 Thread Kent Johnson
Mike Hall wrote: On Mar 23, 2005, at 3:17 AM, Kent Johnson wrote: Anyway, Mike, it seems clear that your file has line endings in it which are not consistent with the default for your OS. If reading with universal newlines doesn't solve the problem, please let us know what OS you are running und

Re: [Tutor] .readlines() condensing multiple lines

2005-03-23 Thread Mike Hall
On Mar 23, 2005, at 3:17 AM, Kent Johnson wrote: Anyway, Mike, it seems clear that your file has line endings in it which are not consistent with the default for your OS. If reading with universal newlines doesn't solve the problem, please let us know what OS you are running under and give more

Re: [Tutor] .readlines() condensing multiple lines

2005-03-23 Thread Mike Hall
On Mar 23, 2005, at 12:53 AM, Alan Gauld wrote: Typically what happens is you view the file in an application that autrowraps long lines so it looks like multiple lines on screen but in fact it is one long line in the file. In that case Python will only see the single long line. I'm using subEthaEd

Re: [Tutor] Getting error that calendar is underfined when importing calendar module

2005-03-23 Thread Vicki Stanfield
> The cgi is importing itself when you 'import calendar'. Try renaming your > calendar.py to something > else like calendar-cgi.py > > Kent Thanks. I was almost there, having noticed that dir(calendar) was different when run from the script than in an interactive session. Vicki P.S. Now to parse

Re: [Tutor] .readlines() condensing multiple lines

2005-03-23 Thread Mike Hall
Liam, "rU" worked like a charm. My previous syntax where the lines were condensing was: fOpen = file(f, "r") fRead = fTmp.readlines() In this instance the size of fRead would not correspond to my line numbers. With fOpen = file(f, "rU") it now does. Thanks :) On Mar 22, 2005, at 7:15 PM, Lia

Re: [Tutor] Getting error that calendar is underfined when importing calendar module

2005-03-23 Thread Kent Johnson
The cgi is importing itself when you 'import calendar'. Try renaming your calendar.py to something else like calendar-cgi.py Kent Vicki Stanfield wrote: Hi all. I am using Python 2.4 on a Slackware Linux box and am having a problem importing the calendar module into a program that I am writing. T

[Tutor] Getting error that calendar is underfined when importing calendar module

2005-03-23 Thread Vicki Stanfield
Hi all. I am using Python 2.4 on a Slackware Linux box and am having a problem importing the calendar module into a program that I am writing. The code is simple and looks like this: import cgitb, os, sys cgitb.enable() sys.strerr = sys.stdout import cgi import time import calendar print "Conten

Re: [Tutor] List comprehensions

2005-03-23 Thread Kent Johnson
Liam Clarke wrote: Is there any guides to this (possibly obtuse) tool? http://docs.python.org/tut/node7.html#SECTION00714 http://www.amk.ca/python/2.0/index.html#SECTION00060 Kent ___ Tutor maillist - Tutor@python.org htt

Re: [Tutor] List comprehensions

2005-03-23 Thread Sean Perry
Liam Clarke wrote: Is there any guides to this (possibly obtuse) tool? Think of it this way. A list comprehension generates a new list. So, you should think about list comps whenever you have old_list -> new_list style behavior. There are two advantages to list comps over map: 1) a list comp can

RE: [Tutor] List comprehensions

2005-03-23 Thread Ryan Davis
I'm not sure if you can or want to do this solely one list comprehension. You could make a helper function and use map: ### def helper(i): i.pop(3) return map(int, i) a = map(helper, x) ### Description of map: http://docs.python.org/lib/built-in-funcs.html I think map is a little clea

Re: [Tutor] List comprehensions

2005-03-23 Thread Kent Johnson
Liam Clarke wrote: Hi, Is there a way to apply multiple actions within one list comprehension? i.e. instead of a = [] for i in x: i.pop(3) g = [ int(item) for item in i] a.append(g) You can nest list comps. Except for the pop, the above can be written a = [ [ int(item) for item in

Re: [Tutor] blocking user access

2005-03-23 Thread Kent Johnson
Diana Hawksworth wrote: Hi! I need help on blocking user access to a message box - for example, the program could provide an answer to an input. At the moment, the user has access to - and can type into - that "answer" space. How do I prevent that from happening please? It sounds like you want

Re: [Tutor] Livewires Help

2005-03-23 Thread Kent Johnson
Alan Gauld wrote: The official tutor only covers core Python, not even Tkinter. But I believe there is a separate LiveWires tutor somewhere, although I've never used LiveWires personally. In fact, although I've seen it mentioned here several times I confess I don't even know what LiveWires is! I

Re: [Tutor] .readlines() condensing multiple lines

2005-03-23 Thread Kent Johnson
Liam Clarke wrote: Oh right, From his email, I got the impression he was getting a list like - [[abc\rdef\rghi\r]] We really need a clarification of what is in the original file and what results he is getting. My impression is that it is mixed line endings so the result of readlines is multiple s

[Tutor] List comprehensions

2005-03-23 Thread Liam Clarke
Hi, Is there a way to apply multiple actions within one list comprehension? i.e. instead of a = [] for i in x: i.pop(3) g = [ int(item) for item in i] a.append(g) Is there any guides to this (possibly obtuse) tool? Regards, Liam Clarke PS I can see how nested list comprehensio

Re: [Tutor] blocking user access

2005-03-23 Thread Liam Clarke
Hi Diana, Welcome. Are you using IDLE? Could you provide a copy of your code? Regards, Liam Clarke Still a newbie, but not as much. :) On Wed, 23 Mar 2005 20:59:02 +1100, Diana Hawksworth <[EMAIL PROTECTED]> wrote: > > Hi! I need help on blocking user access to a message box - for exam

[Tutor] blocking user access

2005-03-23 Thread Diana Hawksworth
Hi!  I need help on blocking user access to a message box - for example, the program could provide an answer to an input.  At the moment, the user has access to - and can type into - that "answer" space. How do I prevent that from happening please?   Diana - a very newbie! ___

[Tutor] Livewires

2005-03-23 Thread David Holland
If you have any questions on Livewires (do you mean the Scripture Union pygame wrapper ?). We will try to help.Send instant messages to your online friends http://uk.messenger.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailma

Re: [Tutor] What does Python gain by having immutable types?

2005-03-23 Thread Alan Gauld
> After showing him to change it to this > s1 = s1.replace("is a", "is a short") > He then asked > Why is it that the sort operation modfies the original list variable? > > l1=[3,44,1,22] > l1.sort() > l1 > [1, 3, 22, 44] > > I don't know, but I think it has something to do with strings being > im

Re: [Tutor] primes - sieve of odds

2005-03-23 Thread Gregor Lingl
C Smith schrieb: Hi Gregor, I had done the same thing. I also noted that assigning (or inserting) an element into a list is faster than creating a new list: l.insert(0,2) is faster than l = [2]+l. ### def sieve (maximum): if maximum < 2: return [] limit = int(maximum**0.5) nums

Re: [Tutor] .readlines() condensing multiple lines

2005-03-23 Thread Alan Gauld
> Unless I'm mistaken .readlines() is supposed to return a list, where > each index is a line from the file that was handed to it. Well I'm > finding that it's putting more than one line of my file into a single > list entry, and separating them with \r. \r is the carriage return marker which is

Re: [Tutor] Livewires Help

2005-03-23 Thread Alan Gauld
The official tutor only covers core Python, not even Tkinter. But I believe there is a separate LiveWires tutor somewhere, although I've never used LiveWires personally. In fact, although I've seen it mentioned here several times I confess I don't even know what LiveWires is! I probably should