Re: [Tutor] "local variable 'l1' referenced before assignment"

2008-06-28 Thread Douglas Drumond
> > But if you don't have l1 defined yet, you can't add to l2 > It's like: > def a2(): > l1 = foo + l2 > > UnboundLocalError: local variable 'foo' referenced before assignment > > It's because l1 (and foo at above example) is a local variable. > a1's l1 is different from a2's l1. > > > Sorr

[Tutor] addressbook program

2008-06-28 Thread Danny Laya
Hi I am making an addressBook program now, and you know some problem, the program doesn't work. This is the code : # Loading the addressbook filename = "addbook.dat" def readBook(book)     import os     if os.path.exists(filename):     store = open(filename,'r')     for line in store:         na

Re: [Tutor] "local variable 'l1' referenced before assignment"

2008-06-28 Thread Dick Moores
At 12:44 AM 6/28/2008, Dick Moores wrote: At 12:11 AM 6/28/2008, Douglas Drumond wrote: But if you don't have l1 defined yet, you can't add to l2 It's like: def a2():     l1 = foo + l2 UnboundLocalError: local variable 'foo' referenced before assignment It's because l1 (and foo at abo

Re: [Tutor] "local variable 'l1' referenced before assignment"

2008-06-28 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote I'm puzzled by the below error msg. If I change the line in a2() from l1 = [1,2,3]*100 This is not in a2() this is in the global namespace outside of a2. a2() consists of a single assignment statement. And assignment inside a function creates a local

Re: [Tutor] addressbook program

2008-06-28 Thread Alan Gauld
"Danny Laya" <[EMAIL PROTECTED]> wrote Hi I am making an addressBook program now, and you know some problem, the program doesn't work. Always describe the error and, if possible, send the error text. Python error messages may seem cryptic to a beginner but they are actually very informative on

[Tutor] Is "var = None" in Python equivalent to "Set var = Nothing" in VB?

2008-06-28 Thread Kelie
Hello, Suppose var holds a reference to an objeect, my question is in the subject. Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] "local variable 'l1' referenced before assignment"

2008-06-28 Thread wesley chun
> Sorry to be dense, but how, in what way, is a1's l1 different from a2's > l1"? Both are [1,2,3]*100 . dick, alan and everyone else are correct, but let me just put it as simply as this: - in a1(), you're accessing l1 as a global variable - in a2(), you're making l1 a local variable but tryin

Re: [Tutor] "local variable 'l1' referenced before assignment"

2008-06-28 Thread Dick Moores
At 01:05 AM 6/28/2008, Alan Gauld wrote: "Dick Moores" <[EMAIL PROTECTED]> wrote I'm puzzled by the below error msg. If I change the line in a2() from l1 = [1,2,3]*100 This is not in a2() this is in the global namespace outside of a2. a2() consists of a single assignment statement. And ass

[Tutor] need help with a regular expression

2008-06-28 Thread Kelie
Hello, I'm trying to write a regular expression to filter strings that meet the following criteria: 1. Starts with 0-3 underscores; 2. Followed by one letter; 3. Then followed by 0 or more letters or digits or hyphens('-'), 4. Ends with one letter or digit; and 5. There should not be more than o

Re: [Tutor] "local variable 'l1' referenced before assignment"

2008-06-28 Thread Martin Walsh
Douglas Drumond wrote: > > In a2() you do l1 += l2, ie, l1 = l1 + l2 A subtle clarification is warranted I think. l1 += l2 is not the same as l1 = l1 + l2, when l1 and l2 are lists. l1 += l2 is an augmented assignment statement, and as such will perform the operation in place if possible, IIUC. C

Re: [Tutor] Is "var = None" in Python equivalent to "Set var = Nothing"in VB?

2008-06-28 Thread Alan Gauld
"Kelie" <[EMAIL PROTECTED]> wrote Suppose var holds a reference to an objeect, my question is in the subject. Pretty much so, yes. There may be very subtle differences due to how Python and VB treat variables but the basic intent is the same Alan G ___

Re: [Tutor] "local variable 'l1' referenced before assignment"

2008-06-28 Thread Dick Moores
At 02:22 AM 6/28/2008, Martin Walsh wrote: Douglas Drumond wrote: > > In a2() you do l1 += l2, ie, l1 = l1 + l2 A subtle clarification is warranted I think. l1 += l2 is not the same as l1 = l1 + l2, when l1 and l2 are lists. And wow, can the times for each differ from each other! See, for exa

[Tutor] addressbook program

2008-06-28 Thread Danny Laya
Hi I am making an addressBook program now, and you know ... another error message , the program doesn't work. This is the code : # Loading the addressbook filename = "addbook.dat" def readBook(book)     import os     if os.path.exists(filename):     store = open(filename,'r')     for line i

Re: [Tutor] "local variable 'l1' referenced before assignment"

2008-06-28 Thread Dick Moores
At 01:52 AM 6/28/2008, wesley chun wrote: > Sorry to be dense, but how, in what way, is a1's l1 different from a2's > l1"? Both are [1,2,3]*100 . dick, alan and everyone else are correct, but let me just put it as simply as this: - in a1(), you're accessing l1 as a global variable - in a2(),

Re: [Tutor] need help with a regular expression

2008-06-28 Thread Dick Moores
On Sat, Jun 28, 2008 at 2:15 AM, Kelie <[EMAIL PROTECTED]> wrote: > Hello, > > I'm trying to write a regular expression to filter strings that meet the > following criteria: > > 1. Starts with 0-3 underscores; > 2. Followed by one letter; > 3. Then followed by 0 or more letters or digits or hyphens

Re: [Tutor] addressbook program

2008-06-28 Thread bhaaluu
Hello Danny, Part of learning to program a computer is learning how to solve problems. I copy/pasted this code directly from the email, and tried to run it, as is. Error messages in Python are very informative. See below. On Sat, Jun 28, 2008 at 3:31 AM, Danny Laya <[EMAIL PROTECTED]> wrote: > Hi

Re: [Tutor] need help with a regular expression

2008-06-28 Thread Lie Ryan
Filter it. Use two re, one the one you've made, the other the double hyphen filter: pat2 = re.compile('.*?\-\-.*?') If the string matches this re, then the string is rejected, if it DOES NOT match (i.e. pat2.match('blah') returns None, i.e. if not pat2.match('blah')), then it is accepted. btw: Y

[Tutor] How to print numbers in scientific notation form?

2008-06-28 Thread Dick Moores
%.4g comes close to what I want, but no cigar. In the examples below, the first 2 are not scientific notation form. >>> print "%.4g" % 5.09879870978 5.099 >>> print "%.4g" % .0009874345 0.0009874 >>> print "%.4g" % .09878 9.878e-006 >>> print "%.4g" % 187686876876238746 1.877e+017 How can I

Re: [Tutor] need help with a regular expression

2008-06-28 Thread Andre Engels
On Sat, Jun 28, 2008 at 11:15 AM, Kelie <[EMAIL PROTECTED]> wrote: > Hello, > > I'm trying to write a regular expression to filter strings that meet the > following criteria: > > 1. Starts with 0-3 underscores; > 2. Followed by one letter; > 3. Then followed by 0 or more letters or digits or hyphen

Re: [Tutor] How to print numbers in scientific notation form?

2008-06-28 Thread Cédric Lucantis
Le Saturday 28 June 2008 14:55:04 Dick Moores, vous avez écrit : > %.4g comes close to what I want, but no cigar. In the examples below, > the first 2 are not scientific notation form. > > >>> print "%.4g" % 5.09879870978 > > 5.099 > > >>> print "%.4g" % .0009874345 > > 0.0009874 > > >>> print "

Re: [Tutor] need help with a regular expression

2008-06-28 Thread Lie Ryan
>> Hello, >> >> I'm trying to write a regular expression to filter strings that meet > the >> following criteria: >> >> 1. Starts with 0-3 underscores; >> 2. Followed by one letter; >> 3. Then followed by 0 or more letters or digits or hyphens('-'), >> 4. Ends with one letter or digit;

Re: [Tutor] How to print numbers in scientific notation form?

2008-06-28 Thread Dick Moores
At 06:17 AM 6/28/2008, Cédric Lucantis wrote: '%e' % 1.0 '1.00e+00' and to set the number of significant digits (it seems to only set the number of digits after the comma, so you have to subtract 1 from it) : >>> '%.3e' % 1.0 '1.000e+00' Perfect! Thanks. Dick

Re: [Tutor] addressbook program

2008-06-28 Thread Kent Johnson
On Sat, Jun 28, 2008 at 6:30 AM, Danny Laya <[EMAIL PROTECTED]> wrote: > > Hi I am making an addressBook program now, and you know ... another > error message , the program doesn't work. This is the code : > > # Loading the addressbook > filename = "addbook.dat"

Re: [Tutor] How to print numbers in scientific notation form?

2008-06-28 Thread Alan Gauld
"Dick Moores" <[EMAIL PROTECTED]> wrote >>> print "%.4g" % 5.09879870978 5.099 >>> print "%.4g" % .09878 9.878e-006 How can I print all numbers in scientific notation form, and designate the number of significant digits? use %e instead of %g Alan G ___

Re: [Tutor] need help with a regular expression

2008-06-28 Thread Andre Engels
On Sat, Jun 28, 2008 at 3:21 PM, Lie Ryan <[EMAIL PROTECTED]> wrote: > > I think > > > > _{0,3}[A-Z](\-?[A-Z0-9])+ > > > > will do what you are looking for. > > That, doesn't allow single hyphen, which his requirement allowed as long > as it (the hypehn) is not as the first or last character.

Re: [Tutor] need help with a regular expression

2008-06-28 Thread Lie Ryan
On Sat, 2008-06-28 at 17:39 +0200, Andre Engels wrote: > On Sat, Jun 28, 2008 at 3:21 PM, Lie Ryan <[EMAIL PROTECTED]> wrote: > > > > I think > > > > > > _{0,3}[A-Z](\-?[A-Z0-9])+ > > > > > > will do what you are looking for. > > > > That, doesn't allow single hyphen, which his requirement al

Re: [Tutor] need help with a regular expression

2008-06-28 Thread Mark Tolonen
"Kelie" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Hello, I'm trying to write a regular expression to filter strings that meet the following criteria: 1. Starts with 0-3 underscores; 2. Followed by one letter; 3. Then followed by 0 or more letters or digits or hyphens('-'), 4

Re: [Tutor] "local variable 'l1' referenced before assignment"

2008-06-28 Thread wesley chun
> BTW I see that your book has what seems to be a thorough discussion of > namespaces and variable scopes in chapter 12. ah, that section (12.3) you're referring to is mostly about namespaces as it's in the Modules chapter. the real bit about variable scope that you're seeking is actually in the

Re: [Tutor] Using Python in Windows

2008-06-28 Thread wesley chun
> IDLE 1.2.2 > >>> from gasp import * > > Traceback (most recent call last): > File "", line 1, in >from gasp import * > ImportError: No module named gasp as brian mentioned, gasp doesn't come with Python. in fact, this very thread came up just last month, and here was one of my repli

Re: [Tutor] addressbook program

2008-06-28 Thread Alan Gauld
"FT" <[EMAIL PROTECTED]> wrote #Copying the Address Book With New Name! def copy_Book (book): save = 1 file_name2 = text_Input(" Enter Name Of File To Save Address Book:") if file_name2 == "": print "No File Saved!" save = 0 if save == 1: try: s

Re: [Tutor] Using Python in Windows

2008-06-28 Thread Ben
Hmm. The instruction on adding something gaspthe library seems to be catered towards Linux. I've done a Google search and glanced at the Tutorial, the Windows FAQ ( http://www.python.org/doc/faq/windows/), ect. I don't see it in the global mod

[Tutor] Create file and input text

2008-06-28 Thread David
Hi, I am very new to python and it is my first attempt at programing except for some basic bash scripts. I came up with this; #!/usr/bin/python import os filename = raw_input('Enter the filename: ') fobj = open(filename, 'w') yourname = raw_input('What is your name: ') fobj.write(yourname) fobj.

Re: [Tutor] addressbook program

2008-06-28 Thread FT
Hi Alan, You said: > #DO TEXT INPUT WITH ENTRY ON NEXT LINE! > def text_Input(prompt): > print prompt > return (raw_input(">> ")) Just use: raw_input(prompt + "\n>> " ) Yes, that is OK if you are sighted, for the screen reader program does not say the message in the prompt unless t

Re: [Tutor] need help with a regular expression

2008-06-28 Thread Kelie
Dick Moores gmail.com> writes: > I'm not sure of your 5th condition. Do you mean, "A hyphen should not > be immediately followed by a hyphen"? Could you give examples of what > you will permit, and will not permit? Dick, your are correct. A hyphen should not be immediately followed by a hyphen.

Re: [Tutor] need help with a regular expression

2008-06-28 Thread Kelie
Mark Tolonen gmail.com> writes: > re.compile(r'^_{0,3}[A-Z](?:[A-Z0-9]|-(?!-))*[A-Z0-9]$') # if rule 4 is an > additional letter or digit > re.compile(r'^_{0,3}[A-Z](?:[A-Z0-9]|-(?!-))*(? single-letter strings are allowed > Mark, single-letter strings are allowed and your regular expression w

[Tutor] need help; save web data

2008-06-28 Thread Michael Miesner
Hi all- I am trying to save the output of a web search to a local file, using python. Im really new to this, but I want to be able to write a program that uses google scholar, but takes search results and saves them to a local file. I am perfectly fine with playing around wtih this until I get it,

[Tutor] arrays in python

2008-06-28 Thread Kirk Z Bailey
Just wondering, if I can find a way to do a 2 dimensional array in python. 1 dimension would be a list it would seem; for 2, I could use a list of lists? Strange how I can't think of ever needing one since I discovered snake charming, but so many languages do foo dimensional arrays, it would s

Re: [Tutor] Using Python in Windows

2008-06-28 Thread wesley chun
> Hmm. The instruction on adding something gasp the library seems to be > catered towards Linux. hmmm, you are correct, and apparently, this is a popular question to the maintainers (note these links are circular): https://answers.launchpad.net/gasp-code/+question/36144 https://answers.launchpad.

Re: [Tutor] Create file and input text

2008-06-28 Thread wesley chun
> Hi, I am very new to python and [...] came up with this; > #!/usr/bin/python > > import os > filename = raw_input('Enter the filename: ') > fobj = open(filename, 'w') > yourname = raw_input('What is your name: ') > fobj.write(yourname) > fobj.close() > > It seems to work Ok, I w

Re: [Tutor] Create file and input text

2008-06-28 Thread Danny Yoo
>> #!/usr/bin/python > > > > import os > > filename = raw_input('Enter the filename: ') > > fobj = open(filename, 'w') > > yourname = raw_input('What is your name: ') > > fobj.write(yourname) > > fobj.close() > > > > It seems to work Ok, I was shocked! Is it OK? Hi David, The fir

Re: [Tutor] Create file and input text

2008-06-28 Thread wesley chun
> The first line, the import of the 'os' module, is superfluous: it's > not being used. oops, good catch danny... i didn't even see that. > Python won't let you break any laws of gravity. But there are a lot > of good people here on Tutor who will be happy to be of assistance > when the pro

Re: [Tutor] arrays in python

2008-06-28 Thread Mark Tolonen
"Kirk Z Bailey" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Just wondering, if I can find a way to do a 2 dimensional array in python. 1 dimension would be a list it would seem; for 2, I could use a list of lists? Strange how I can't think of ever needing one since I discover