[Tutor] using re to build dictionary

2009-02-24 Thread Norman Khine
Hello, From my previous post on create dictionary from csv, i have broken the problem further and wanted the lists feedback if it could be done better: >>> s = 'Association of British Travel Agents (ABTA) No. 56542\nAir Travel Organisation Licence (ATOL)\nAppointed Agents of IATA (IATA)\nInce

Re: [Tutor] Simple CGI script and Apache configuration

2009-02-24 Thread wormwood_3
I wasn't sure if that was needed, so I took it out, sorry about that. I put ScriptAlias /cgi-bin/ "/var/www/samuelhuckins.com/cgi-bin/" in place, reloaded, and it works! I think the problem throughout was that I was mixing up what was necessary between CGI and mod_python. If you'd like a ran

Re: [Tutor] using re to build dictionary

2009-02-24 Thread spir
Le Tue, 24 Feb 2009 12:48:51 +0100, Norman Khine s'exprima ainsi: > Hello, > From my previous post on create dictionary from csv, i have broken the > problem further and wanted the lists feedback if it could be done better: > > >>> s = 'Association of British Travel Agents (ABTA) No. 56542\nA

Re: [Tutor] using re to build dictionary

2009-02-24 Thread Kent Johnson
On Tue, Feb 24, 2009 at 6:48 AM, Norman Khine wrote: > Hello, > From my previous post on create dictionary from csv, i have broken the > problem further and wanted the lists feedback if it could be done better: > s = 'Association of British Travel Agents (ABTA) No. 56542\nAir Travel Orga

Re: [Tutor] using re to build dictionary

2009-02-24 Thread Norman Khine
Thank you all, this is great. Kent Johnson wrote: On Tue, Feb 24, 2009 at 6:48 AM, Norman Khine wrote: Hello, From my previous post on create dictionary from csv, i have broken the problem further and wanted the lists feedback if it could be done better: s = 'Association of British Travel Ag

[Tutor] String to list conversion

2009-02-24 Thread Taylan Karaman
Hello, I am a beginner. And I am trying to get a user input converted to a list. print 'Enter your first name :' firstname = raw_input() So if the user input is firstname = 'foo'--->should become> firstlist['f','o','o'] thanks in advance ___

Re: [Tutor] String to list conversion

2009-02-24 Thread عماد نوفل
On Tue, Feb 24, 2009 at 10:16 AM, Taylan Karaman wrote: > Hello, > > I am a beginner. And I am trying to get a user input converted to a list. > > print 'Enter your first name :' > firstname = raw_input() > > So if the user input is > > firstname = 'foo'--->should become> > fir

Re: [Tutor] String to list conversion

2009-02-24 Thread Kent Johnson
On Tue, Feb 24, 2009 at 10:16 AM, Taylan Karaman wrote: > Hello, > > I am a beginner. And I am trying to get a user input converted to a list. > > print 'Enter your first name :' > firstname = raw_input() > > So if the user input is > > firstname = 'foo'    --->should become> > fir

Re: [Tutor] Simple CGI script and Apache configuration

2009-02-24 Thread Martin Walsh
wormwood_3 wrote: > I wasn't sure if that was needed, so I took it out, sorry about that. I put > > ScriptAlias /cgi-bin/ "/var/www/samuelhuckins.com/cgi-bin/" > > in place, reloaded, and it works! I think the problem throughout was > that I was mixing up what was necessary between CGI and mod_p

Re: [Tutor] String to list conversion

2009-02-24 Thread Robert Berman
Or, you could do: In [1]: print list(raw_input('name please...')) name please...John ['J', 'o', 'h', 'n'] Robert Berman Kent Johnson wrote: On Tue, Feb 24, 2009 at 10:16 AM, Taylan Karaman wrote: Hello, I am a beginner. And I am trying to get a user input converted to a lis

[Tutor] Accessing callers context from callee method

2009-02-24 Thread mobiledreamers
when i call a method foo from another method func. can i access func context variables or locals() from foo so def func(): i=10 foo() in foo, can i access func's local variables on in this case i Thanks a lot -- Bidegg worlds best auction site http://bidegg.com ___

[Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread nathan virgil
I'm experimenting with OOP using the Critter Caretaker script from Python Programming for the Absolute Beginner as my basis. I've noticed that a dictionary/function combo is a great way to handle menus, and so I've adapted the menu to read as: selection = raw_input("Choice: ") choices = {"0":quit

Re: [Tutor] Accessing callers context from callee method

2009-02-24 Thread spir
Le Tue, 24 Feb 2009 10:53:29 -0800, mobiledream...@gmail.com s'exprima ainsi: > when i call a method foo from another method func. can i access func context > variables or locals() from foo > so > def func(): > i=10 > foo() > > in foo, can i access func's local variables on in this case i > T

Re: [Tutor] Passing parameters in dictionary values?

2009-02-24 Thread Justin Ezequiel
From: nathan virgil > selection = raw_input("Choice: ") > choices = {"0":quit, "1":crit.talk, "2":crit.eat, "3":crit.play} > choice = choices[selection] > choice() > > ...so that I can call methods from a dictionary > the problem I'm running into with this is that > I can't pass any perimeters thr

Re: [Tutor] Accessing callers context from callee method

2009-02-24 Thread Chris Rebert
On Tue, Feb 24, 2009 at 10:53 AM, wrote: > when i call a method foo from another method func. can i access func context > variables or locals() from foo > so > def func(): >   i=10 >   foo() > > in foo, can i access func's local variables on in this case i You can, but it's an evil hack that I w

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread spir
Le Tue, 24 Feb 2009 14:03:09 -0500, nathan virgil s'exprima ainsi: > I'm experimenting with OOP using the Critter Caretaker script from Python > Programming for the Absolute Beginner as my basis. I've noticed that a > dictionary/function combo is a great way to handle menus, and so I've > adapted

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread Kent Johnson
On Tue, Feb 24, 2009 at 2:03 PM, nathan virgil wrote: > I'm experimenting with OOP using the Critter Caretaker script from Python > Programming for the Absolute Beginner as my basis. I've noticed that a > dictionary/function combo is a great way to handle menus, and so I've > adapted the menu to r

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread Kent Johnson
On Tue, Feb 24, 2009 at 2:35 PM, spir wrote: > Le Tue, 24 Feb 2009 14:03:09 -0500, > nathan virgil s'exprima ainsi: >> so that I can call methods from a dictionary, instead of having an >> excruciatingly long if structure. Unfortunately, the problem I'm running >> into with this is that I can't

Re: [Tutor] Accessing callers context from callee method

2009-02-24 Thread wesley chun
> when i call a method foo from another method func. can i access func context > variables or locals() from foo > so > def func(): >   i=10 >   foo() > > in foo, can i access func's local variables A. python has statically-nested scoping, so you can do it as long as you: 1. define foo() as an in

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread nathan virgil
I'm not familiar with lambdas yet, and I don't think this book will introduce me to them; they aren't listed in the index, anyway. Adding a bunch of single-line functions would work, but I'm not sure how much better that is then the if structure. I think it's what I'm going to go with, anyway. At

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread Kent Johnson
On Tue, Feb 24, 2009 at 5:13 PM, nathan virgil wrote: > I'm not familiar with lambdas yet, and I don't think this book will > introduce me to them; they aren't listed in the index, anyway. Here are two brief introductions: http://docs.python.org/tutorial/controlflow.html#lambda-forms http://www.i

Re: [Tutor] Accessing callers context from callee method

2009-02-24 Thread Alan Gauld
wrote when i call a method foo from another method func. can i access func context variables or locals() from foo Yes and there are several ways to do it, but nearly always this is a bad idea. It will make foo almost totally unusable in any other context since it will rely on the calling fu

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread Andre Engels
On Tue, Feb 24, 2009 at 8:03 PM, nathan virgil wrote: > I'm experimenting with OOP using the Critter Caretaker script from Python > Programming for the Absolute Beginner as my basis. I've noticed that a > dictionary/function combo is a great way to handle menus, and so I've > adapted the menu to r

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread Andre Engels
On Wed, Feb 25, 2009 at 12:47 AM, Andre Engels wrote: > - Show quoted text - > On Tue, Feb 24, 2009 at 8:03 PM, nathan virgil wrote: >> I'm experimenting with OOP using the Critter Caretaker script from Python >> Programming for the Absolute Beginner as my basis. I've noticed that a >> dictionary

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread Alan Gauld
"nathan virgil" wrote in selection = raw_input("Choice: ") choices = {"0":quit, "1":crit.talk, "2":crit.eat, "3":crit.play} choice = choices[selection] choice() so that I can call methods from a dictionary, instead of having an excruciatingly long if structure. Unfortunately, the problem I'm

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread Alan Gauld
"nathan virgil" wrote I'm not familiar with lambdas yet, and I don't think this book will introduce me to them; they aren't listed in the index, anyway. lambda is just a fancy mathematical name for a simple concept - its a block of code, like the body of a function. In Python its even simp

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread nathan virgil
On Tue, Feb 24, 2009 at 6:50 PM, Alan Gauld wrote: > > > Or you can build the param value into the dictionary: > > selection = raw_input("Choice: ") > choices = { > "0":(quit, None), > "1":(crit.talk, "Hi there"), > "2":(crit.eat, "Nuts"), > "3": (crit.play, "Soccer") > "4": (crit.play, "Baseball"

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread nathan virgil
Erm, it's still not working... Whenever I try to use the talk method (which reports the mood, and doesn't take parameters), it says I gave it too many parameters. Maybe it might help if I posted the code in it's entirety # Critter Caretaker # A virtual pet to care for class Critter(object):

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread Emile van Sebille
nathan virgil wrote: Erm, it's still not working... if selection in choices: choice = choices[selection] choice[0](choice[1]) s/bchoice[0]() main() ("\n\nPress the enter key to exit.") hth, Emile

Re: [Tutor] calling user defined function

2009-02-24 Thread Lie Ryan
On Sun, 22 Feb 2009 22:21:22 +0100, roberto wrote: > hello > i have a question which i didn't solved yet: i can define a function > using the text editor provided by IDLE 3.0; then i'd like to call this > function from the python prompt > > but when i try to do it, python warns me that function d

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread Lie Ryan
On Tue, 24 Feb 2009 18:26:29 -0500, Kent Johnson wrote: > On Tue, Feb 24, 2009 at 5:13 PM, nathan virgil > wrote: >> I'm not familiar with lambdas yet, and I don't think this book will >> introduce me to them; they aren't listed in the index, anyway. Nobody remembers partial? from functools imp

Re: [Tutor] String to list conversion

2009-02-24 Thread Lie Ryan
> name like "foo" to be changed Nitpick: "foo" is a string, not a name... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Formatting

2009-02-24 Thread prasad rao
hi. s = 'Association of British Travel Agents (ABTA) No.56542\nAir Travel Organisation Licence (ATOL)\nAppointed Agents ofIATA (IATA)\nIncentive Travel & Meet. Association (ITMA)' licenses = re.split("\n+", s) licenseRe = re.compile(r'\(([A-Z]+)\)( No. (\d+))?') >>> for license in licenses:

Re: [Tutor] Formatting

2009-02-24 Thread Senthil Kumaran
On Wed, Feb 25, 2009 at 10:37 AM, prasad rao wrote: > > licenseRe = re.compile(r'\(([A-Z]+)\)( No. (\d+))?') Change that to: licenseRe = re.compile(r'\(([A-Z]+)\)\s*(No.\d+)?') It now works. Thanks, Senthil ___ Tutor maillist - Tutor@python.org ht

Re: [Tutor] Accessing callers context from callee method

2009-02-24 Thread A.T.Hofkamp
mobiledream...@gmail.com wrote: when i call a method foo from another method func. can i access func context variables or locals() from foo so def func(): i=10 foo() in foo, can i access func's local variables on in this case i As others have already pointed out, this is a really bad idea.