Re: Elementary string-parsing

2008-02-05 Thread Steve Holden
Dennis Lee Bieber wrote: > On Tue, 05 Feb 2008 04:03:04 GMT, Odysseus > <[EMAIL PROTECTED]> declaimed the following in > comp.lang.python: > >> Sorry, translation problem: I am acquainted with Python's "for" -- if >> far from fluent with it, so to speak -- but the PS operator that's most >> simi

Re: Elementary string-parsing

2008-02-05 Thread Steve Holden
Marc 'BlackJack' Rintsch wrote: > On Tue, 05 Feb 2008 06:19:12 +, Odysseus wrote: > >> In article <[EMAIL PROTECTED]>, >> Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> >>> Another issue is testing. If you rely on global names it's harder to test >>> individual functions. [...] >>> >

Re: Elementary string-parsing

2008-02-05 Thread Marc 'BlackJack' Rintsch
On Tue, 05 Feb 2008 06:19:12 +, Odysseus wrote: > In article <[EMAIL PROTECTED]>, > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > >> Another issue is testing. If you rely on global names it's harder to test >> individual functions. [...] >> >> In programs without such global names

Re: Elementary string-parsing

2008-02-04 Thread Odysseus
In article <[EMAIL PROTECTED]>, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > The term "global" usually means "module global" in Python. Because they're like the objects obtained from "import"? > [T]he functions depend on some magic data coming from "nowhere" and > it's much harder t

Re: Elementary string-parsing

2008-02-04 Thread Odysseus
In article <[EMAIL PROTECTED]>, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Mon, 04 Feb 2008 09:43:04 GMT, Odysseus > <[EMAIL PROTECTED]> declaimed the following in > comp.lang.python: > > > > > Thanks, that will be very useful. I was casting about for a replacement > > for PostScript's

Re: Elementary string-parsing

2008-02-04 Thread Marc 'BlackJack' Rintsch
On Mon, 04 Feb 2008 09:43:04 +, Odysseus wrote: > In article <[EMAIL PROTECTED]>, > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > >> def extract_data(names, na, cells): >> found = dict() > > The problem with initializing the 'super-dictionary' within this > function is that I w

Re: Elementary string-parsing

2008-02-04 Thread Marc 'BlackJack' Rintsch
On Mon, 04 Feb 2008 12:25:24 +, Odysseus wrote: > I'm not clear on what makes an object global, other than appearing as an > operand of a "global" statement, which I don't use anywhere. But "na" is > assigned its value in the program body, not within any function: does > that make it global

Re: Elementary string-parsing

2008-02-04 Thread Odysseus
In article <[EMAIL PROTECTED]>, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > Rather complicated description... A sample of the real/actual input > /file/ would be useful. Sorry, I didn't want to go on too long about the background, but I guess more context would have helped. The data

Re: Elementary string-parsing

2008-02-04 Thread John Machin
On Feb 4, 8:43 pm, Odysseus <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > found = dict() > BTW what's the difference between the above and "found = {}"? {} takes 4 fewer keystrokes, doesn't have the overhead of a functio

Re: Elementary string-parsing

2008-02-04 Thread Paul Hankin
On Feb 4, 3:21 am, Odysseus <[EMAIL PROTECTED]> wrote: > The next one is much messier. A couple of the strings represent times, > which I think will be most useful in 'native' form, but the input is in > the format "DD Mth HH:MM:SS UTC". time.strptime will do this! You can find the documenta

Re: Elementary string-parsing

2008-02-04 Thread Odysseus
In article <[EMAIL PROTECTED]>, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > Here and in later code you use a ``while`` loop although it is known at > loop start how many times the loop body will be executed. That's a job > for a ``for`` loop. If possible not over an integer that is

Re: Elementary string-parsing

2008-02-04 Thread Marc 'BlackJack' Rintsch
On Mon, 04 Feb 2008 03:21:18 +, Odysseus wrote: > def extract_data(): > i = 0 > while i < len(names): > name = names[i][6:] # strip off "Name: " > found[name] = {'epoch1': cells[10 * i + na], >'epoch2': cells[10 * i + na + 1], >

Elementary string-parsing

2008-02-03 Thread Odysseus
I'm writing my first 'real' program, i.e. that has a purpose aside from serving as a learning exercise. I'm posting to solicit comments about my efforts at translating strings from an external source into useful data, regarding efficiency and 'pythonicity' both. My only significant programming