Re: e-mail address change (was Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept)

2005-02-09 Thread Danny Yoo
On Thu, 10 Feb 2005, Ismael Garrido wrote: > Danny Yoo wrote: > > >### > > > >def f(a,L=[]): > >if L==[5]: > >print 'L==[5] caught' > >print L > >print 'resetting L...' > >L=[] > >L.append(a) > >return L > >### > > > Now I'm dizzy... I can't understand

Re: [Tutor] Hex to Str - still an open issue

2005-02-09 Thread Johan Geldenhuys
I am not so clued up on the 'base 2' and 'base 8' stuff. Care to explain that a little? Johan On Tue, 2005-02-08 at 12:12, Pierre Barbier de Reuille wrote: MMmmhh ... no ! The number you wrote is equivalent to '010' and any number beginning by '0' and not followed by "x" will be considered

Re: e-mail address change (was Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept)

2005-02-09 Thread Max Noel
On Feb 10, 2005, at 03:07, Ismael Garrido wrote: Danny Yoo wrote: ### def f(a,L=[]): if L==[5]: print 'L==[5] caught' print L print 'resetting L...' L=[] L.append(a) return L ### Now I'm dizzy... I can't understand why there are two "L"! L is a local variable of

Re: e-mail address change (was Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept)

2005-02-09 Thread Ismael Garrido
Danny Yoo wrote: ### def f(a,L=[]): if L==[5]: print 'L==[5] caught' print L print 'resetting L...' L=[] L.append(a) return L ### Now I'm dizzy... I can't understand why there are two "L"! L is a local variable of the function, right? (I can't imagine it bein

Re: [Tutor] executing SAS and passing parameters

2005-02-09 Thread Terry Carroll
I'd echo what Alan said. It sounds more like you're having trouble finding out what the command line to SAS should look like, rather than invoking it with Python. (I'm going to quote some of your message out-of-order to better facilitate my approach to this. I will, I trust, not misrepresent

Re: [Tutor] help with refactoring needed -- which approach is more Pythonic?

2005-02-09 Thread Brian van den Broek
Danny Yoo said unto the world upon 2005-02-09 19:06: If we want to be fancy, we can also take advantage of Python's generator support to avoid constructing an explicit list: Hi Brian, Oh good grief. *grin* That last snippet won't work; I had forgotten about appending lines into current_node_conte

Re: [Tutor] help with refactoring needed -- which approach is more Pythonic?

2005-02-09 Thread Danny Yoo
> If we want to be fancy, we can also take advantage of Python's generator > support to avoid constructing an explicit list: > > ### > def partition_node_content(self, body_contents): > """Returns an iterator whose contents are a bunch of >node_content lists.""" > c

Re: [Tutor] help with refactoring needed -- which approach is more Pythonic?

2005-02-09 Thread Danny Yoo
On Wed, 9 Feb 2005, Brian van den Broek wrote: > Hi all, > > I have data files with a format that can be scheamatized as: > > File Header Contents > . . . > File Header End Tag > Node Header Contents > . . . > Node Header End Tag > Node Contents > . . . > Node End Tag > [Repeat Node elements unt

[Tutor] Re: python's default argument value handling in functions - weird syntax? problem grappling with the concept

2005-02-09 Thread Jeffrey Lim
On Wed, 09 Feb 2005 23:50:49 +0100, Abel Daniel <[EMAIL PROTECTED]> wrote: > > quoted lines are from Jeffrey Lim > [... I have rearranged the order of the quotes ...] > thanks, Abel! Especially for the part on the 'C' concept of variables, vs that of Python's (and the links, as well). appreciat

Re: [Tutor] python's default argument value handling in functions -weird syntax? problem grappling with the concept

2005-02-09 Thread Jeffrey Lim
On Wed, 9 Feb 2005 22:38:20 -, Alan Gauld <[EMAIL PROTECTED]> wrote: > > > > My questions: > > > > [snip] > > [snip] > > HTH, yes it did! I've already gotten it - but your explanation was just simply beautiful (it really is). Thanks for the note about "not in think in terms of C" as well - I'

[Tutor] Re: python's default argument value handling in functions - weird syntax? problem grappling with the concept

2005-02-09 Thread Abel Daniel
quoted lines are from Jeffrey Lim [... I have rearranged the order of the quotes ...] > How is 'L == None' even possible all the time, given that for > def f(a, L=[]): > L.append(a) > return L > , L isn't even [] except for the first call to 'f'? This is the important point. You see, its

Re: e-mail address change (was Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept)

2005-02-09 Thread Jeffrey Lim
On Wed, 9 Feb 2005 14:05:23 -0800 (PST), Danny Yoo <[EMAIL PROTECTED]> wrote: > > [snip] > > Does this make sense so far? YES!!! Most perfectly!!! Thanks for your detailed step-by-step analysis man - it was very helpful, and much appreciated... > > Looking back at the program, I think that you

Re: [Tutor] python's default argument value handling in functions -weird syntax? problem grappling with the concept

2005-02-09 Thread Alan Gauld
> > My questions: > - is the '==' operation a 'list' comparison - rather than a pointer > comparison? (my experiments seem to indicate that it is a 'list' > comparison) Forget pointers and all you ever knew of them from C. Trying to think of Python in terms of Pointers is ultimately an excercise i

Re: [Tutor] python's default argument value handling in functions -weird syntax? problem grappling with the concept

2005-02-09 Thread Alan Gauld
> This leads me to at first conclude several things: > > 1. 'L' in this case (or by extension, all function arguments for which > a default is given in the function definition) is "static" Pretty close, yes. Especially if the parameter is mutable. > language definition). This is my conclusion, se

Re: [Tutor] executing SAS and passing parameters

2005-02-09 Thread Alan Gauld
> os.execl('C:\Program Files\SAS Institute\SAS\V8\SAS.exe') You might find that os.system() is all you need here, but if execl works don't worry too much. > However, the program in question is c:\work\run_ratios.sas, with 2 > parameters: incov, and outcov. This program was initially invoked from

Re: e-mail address change (was Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept)

2005-02-09 Thread Jeffrey Lim
On Wed, 09 Feb 2005 14:51:42 -0700, Bob Gailer <[EMAIL PROTECTED]> wrote: > At 02:22 PM 2/9/2005, Jeffrey Lim wrote: > >and have the Common Courtesy to stop hijacking or rewriting other > >people's thread titles unnecessarily pls. (Like when was this thread > >ever about the change of email address

Re: [Tutor] print out lines that start with a word

2005-02-09 Thread Alan Gauld
> I'm trying to get only the lines that start with > "This" for a text file. > > Here's what I wrote: > > >>> import re > >>> f = open('c:/lines.txt').readlines() > >>> for line in f: > match = re.search('^This',f) > if line == match: > print match try if line.startwith('This'): its easi

[Tutor] help with refactoring needed -- which approach is more Pythonic?

2005-02-09 Thread Brian van den Broek
Hi all, I have data files with a format that can be scheamatized as: File Header Contents . . . File Header End Tag Node Header Contents . . . Node Header End Tag Node Contents . . . Node End Tag [Repeat Node elements until end of file] I'm refactoring the heck out of a file conversion utility I wr

Re: e-mail address change (was Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept)

2005-02-09 Thread Danny Yoo
On Thu, 10 Feb 2005, Jeffrey Lim wrote: > > > > > >Example 1 > > > >>> def f(a,L=[]): > > >... if L==[5]: > > >... print 'L==[5] caught' > > >... print L > > >... print 'resetting L...' > > >... L=[] > > >... L.append(a) > > >... return L > > >... Hi Jeffery,

Re: [Tutor] help

2005-02-09 Thread Alan Gauld
> PhoneNumber and such, I cannot get it to put them in > as a string? I can't help in general but I did notice... > PhoneNumber = input("what is the phone number for the > person you are adding? ") You shouldn't store phone numbers as numbers. People often include spaces or hyphens or parenthes

Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept

2005-02-09 Thread Jeffrey Lim
On Wed, 9 Feb 2005 13:12:22 -0800, Mike Bell <[EMAIL PROTECTED]> wrote: > The function's local variable L is not static, but "default argument > value" is, which is what the documentation means when it says that it > will evaluate these only once. When the default value is a list (in > your code,

Re: e-mail address change (was Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept)

2005-02-09 Thread Bob Gailer
At 02:22 PM 2/9/2005, Jeffrey Lim wrote: and have the Common Courtesy to stop hijacking or rewriting other people's thread titles unnecessarily pls. (Like when was this thread ever about the change of email address change on your part???) I have no idea how this happened. My computer started acting

Re: e-mail address change (was Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept)

2005-02-09 Thread Jeffrey Lim
and have the Common Courtesy to stop hijacking or rewriting other people's thread titles unnecessarily pls. (Like when was this thread ever about the change of email address change on your part???) -jf ___ Tutor maillist - Tutor@python.org http://mail.

Re: e-mail address change (was Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept)

2005-02-09 Thread Jeffrey Lim
On Wed, 09 Feb 2005 14:12:30 -0700, Bob Gailer <[EMAIL PROTECTED]> wrote: > At 01:14 PM 2/9/2005, Jeffrey Lim wrote: > > > >Example 1 > > >>> def f(a,L=[]): > >... if L==[5]: > >... print 'L==[5] caught' > >... print L > >... print 'resetting L...' > >... L=[] > >...

Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept

2005-02-09 Thread Mike Bell
The function's local variable L is not static, but "default argument value" is, which is what the documentation means when it says that it will evaluate these only once. When the default value is a list (in your code, not "the empty list" but a list which happens to be empty when the default argum

e-mail address change (was Re: [Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept)

2005-02-09 Thread Bob Gailer
At 01:14 PM 2/9/2005, Jeffrey Lim wrote: hey folks, i'm a relative newbie to python itself, and I am currently learning by making my way through the tutorial found within the docs of 2.4 (http://www.python.org/doc/2.4/tut/tut.html). I am currently having a problem dealing with the concept of the "d

[Tutor] python's default argument value handling in functions - weird syntax? problem grappling with the concept

2005-02-09 Thread Jeffrey Lim
hey folks, i'm a relative newbie to python itself, and I am currently learning by making my way through the tutorial found within the docs of 2.4 (http://www.python.org/doc/2.4/tut/tut.html). I am currently having a problem dealing with the concept of the "default argument value" in python functio

Re: [Tutor] help

2005-02-09 Thread Bob Gailer
At 09:35 PM 2/8/2005, james middendorff wrote: I want to use mysqldb to add people into a database, but when I ask for the certain fields like Name, PhoneNumber and such, I cannot get it to put them in as a string? You can increase your chances of getting help by telling us what happens when you e

[Tutor] executing SAS and passing parameters

2005-02-09 Thread Williams, Thomas
Here is the code I am using to invoke SAS: import os import sys shell = os.environ.get('COMSPEC') if shell is None: shell = os.environ.get('SHELL') if shell is None: shell = 'an unknown command processor' print 'Running under', shell os.exe

[Tutor] Re: print out lines that start with a word

2005-02-09 Thread Wolfram Kraus
Liam Clarke wrote: print [w for w in j.split() if w[0] == '*' and w[-1] == '*'] Wouldn't that only work if it was bug *car* jeff? I can imagine bug*car*jeff would throw it. Cheers, Liam Clarke x = 'bug*car*jeff*foo*bar' [x.split('*')[a] for a in range(1,len(x.split('*')), 2)] When you mix * and

Re: [Tutor] Re: print out lines that start with a word

2005-02-09 Thread Liam Clarke
print [w for w in j.split() if w[0] == '*' and w[-1] == '*'] Wouldn't that only work if it was bug *car* jeff? I can imagine bug*car*jeff would throw it. Cheers, Liam Clarke -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic

[Tutor] Re: print out lines that start with a word

2005-02-09 Thread Wolfram Kraus
Damn! C&P-bug here to! Is this a virus? ;-) print [w for w in j.split() if words[0] == '*' and words[-1] == '*'] Should be: print [w for w in j.split() if w[0] == '*' and w[-1] == '*'] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman

[Tutor] Re: print out lines that start with a word

2005-02-09 Thread Wolfram Kraus
Liam Clarke wrote: x= ["Dude", 'How is it going man', ' '] print x ['Dude', 'How is it going man', ' '] j=[] for item in x: ... if re.search('\S+',item): ... j.append(item) print j ['Dude', 'How is it going man'] What about: x= ["Dude", 'How is it going man', ' ']

Re: [Tutor] Re: print out lines that start with a word

2005-02-09 Thread Liam Clarke
>>> x= ["Dude", 'How is it going man', ' '] >>> print x ['Dude', 'How is it going man', ' '] >>> j=[] >>> for item in x: ... if re.search('\S+',item): ... j.append(item) >>> print j ['Dude', 'How is it going man'] Now, I first did that in a Perl script, but it easily come

Re: [Tutor] Re: print out lines that start with a word

2005-02-09 Thread Pierre Barbier de Reuille
Wolfram Kraus a écrit : Liam Clarke wrote: regexes are common across a lot of languages, even Java has them. Though the pain that would be I daren't not imagine. So the syntax is familiar, whereas string methods may not be. But IMHO string methods are (more) explicit and readable, the name tells

[Tutor] Re: print out lines that start with a word

2005-02-09 Thread Wolfram Kraus
Liam Clarke wrote: regexes are common across a lot of languages, even Java has them. Though the pain that would be I daren't not imagine. So the syntax is familiar, whereas string methods may not be. But IMHO string methods are (more) explicit and readable, the name tells you what the method is

Re: [Tutor] Re: print out lines that start with a word

2005-02-09 Thread Liam Clarke
regexes are common across a lot of languages, even Java has them. Though the pain that would be I daren't not imagine. So the syntax is familiar, whereas string methods may not be. On Wed, 09 Feb 2005 09:00:52 +0100, Wolfram Kraus <[EMAIL PROTECTED]> wrote: > Ron Nixon wrote: > > Can anyone tell

[Tutor] Re: print out lines that start with a word

2005-02-09 Thread Wolfram Kraus
Ron Nixon wrote: Can anyone tell me what I've done wrong in this script. I'm trying to get only the lines that start with "This" for a text file. Here's what I wrote: import re f = open('c:/lines.txt').readlines() for line in f: match = re.search('^This',f) if line == match: