Speaking of list-comprehension?

2005-06-30 Thread Chinook
I'm probably just getting languages mixed up, but I thought in my Python readings over the last couple months that I had noticed an either/or expression (as opposed to a bitwise or, or truth test). Being a curious sort, I tried several variations of how a list comprehension *might* be construc

Re: Escaping commas within parens in CSV parsing?

2005-06-30 Thread Devan L
Try this. re.findall(r'(.+? \(.+?\))(?:,|$)',yourtexthere) -- http://mail.python.org/mailman/listinfo/python-list

Re: Escaping commas within parens in CSV parsing?

2005-06-30 Thread Devan L
Oops, the above code doesn't quite work. Use this one instead. re.findall(r'(.+? (?:\(.+?\))?)(?:,|$)',yourtexthere) -- http://mail.python.org/mailman/listinfo/python-list

Re: Escaping commas within parens in CSV parsing?

2005-06-30 Thread Paul McGuire
Well, this doesn't have the terseness of an re solution, but it shouldn't be hard to follow. -- Paul #~ This is a very crude first pass. It does not handle nested #~ ()'s, nor ()'s inside quotes. But if your data does not #~ stray too far from the example, this will probably do the job. #~ Down

Re: How to run commands in command line from a script

2005-06-30 Thread Ivan Shevanski
Alright well I'm quite a noob and when I run a simple command to change the current directory, nothing happens. I made a little test script to show it: import os cwd = os.getcwd() print cwd os.system('cd = C:\Program Files') print cwd then the result: C:\Python24\Python Scripts C:\Python24\

Re: How to run commands in command line from a script

2005-06-30 Thread Robert Kern
Ivan Shevanski wrote: > Alright well I'm quite a noob and when I run a simple command to change > the current directory, nothing happens. I made a little test script to > show it: > > import os > cwd = os.getcwd() > print cwd > os.system('cd = C:\Program Files') > print cwd > > then the result

Re: OOP help needed incorporating existing modules in class

2005-06-30 Thread Peter Hansen
Koncept wrote: > I want to incorporate the datetime and other modules into my class. I > am new to Python and would really appreciate some help doing this. > > class FooBar: >def getDate(self): > return > > ^^^ how do I do something like this? Um have you read the tutorial yet? I

Re: How to run commands in command line from a script

2005-06-30 Thread Peter Hansen
Ivan Shevanski wrote: > Alright well I'm quite a noob and when I run a simple command to change > the current directory, nothing happens. I made a little test script to > show it: > > > import os > cwd = os.getcwd() > print cwd > os.system('cd = C:\Program Files') > print cwd There are at lea

Re: How to run commands in command line from a script

2005-06-30 Thread Peter Hansen
Peter Hansen wrote: > Ivan Shevanski wrote: >> Alright well I'm quite a noob and when I run a simple command to >> change the current directory, nothing happens. I made a little test >> script to show it: > > Generally, the only way to use an application (i.e. a program like the > Python inter

Re: Lost in a sea of documentation...can you point me in the right direction?

2005-06-30 Thread Andrew Durdin
On 30 Jun 2005 14:38:17 -0700, MooMaster <[EMAIL PROTECTED]> wrote: > So I started reading about os, threads, > and the path for the special folders in the archives and in the Python > docs and I'm kind of lost because there aren't many concrete examples > in the documentation. Can anyone point me

Re: aligning text with space-normalized text

2005-06-30 Thread Steven Bethard
John Machin wrote: > Steven Bethard wrote: > >> John Machin wrote: >> >>> For example, text = 'foo bar', chunks = ['foobar'] >> >> This doesn't match the (admittedly vague) spec > > That is *exactly* my point -- it is not valid input, and you are not > reporting all cases of invalid input; you h

Splitting string into dictionary

2005-06-30 Thread David Pratt
I have string text with language text records that looks like this: 'en' | 'the brown cow' | 'fr' | 'la vache brun' Two or more language records can exist in each string (example above shows 2 - but could contain more) The second vertical line character in the example above is the record break

Re: Splitting string into dictionary

2005-06-30 Thread Robert Kern
David Pratt wrote: > I have string text with language text records that looks like this: > > 'en' | 'the brown cow' | 'fr' | 'la vache brun' > > Two or more language records can exist in each string (example above > shows 2 - but could contain more) > The second vertical line character in the ex

Re: Speaking of list-comprehension?

2005-06-30 Thread George Sakkis
"Chinook" wrote: > I'm probably just getting languages mixed up, but I thought in my Python > readings over the last couple months that I had noticed an either/or > expression (as opposed to a bitwise or, or truth test). Being a curious > sort, I tried several variations of how a list comprehensi

Re: Speaking of list-comprehension?

2005-06-30 Thread Steven Bethard
Chinook wrote: > >>> ta = [5, 15, 12, 10, 9] > >>> for i in range(len(ta)): > ... if ta[i] >= 10: > ... ta[i] -= 10 > ... else: > ... ta[i] += 10 > ... > >>> ta > [15, 5, 2, 0, 19] One possibility: py> [(tai + 10, tai - 10)[tai >= 10] for tai in ta] [15, 5, 2, 0, 19] But see: htt

Re: Splitting string into dictionary

2005-06-30 Thread Robert Kern
David Pratt wrote: > I have string text with language text records that looks like this: > > 'en' | 'the brown cow' | 'fr' | 'la vache brun' > > Two or more language records can exist in each string (example above > shows 2 - but could contain more) > The second vertical line character in the ex

Re: Speaking of list-comprehension?

2005-06-30 Thread Terry Hancock
On Thursday 30 June 2005 10:13 pm, Chinook wrote: > >>> ta = [5, 15, 12, 10, 9] > >>> for i in range(len(ta)): > ... if ta[i] >= 10: > ... ta[i] -= 10 > ... else: > ... ta[i] += 10 It's not exactly the same in that it doesn't change values in place, but this is similar if you are onl

Re: Escaping commas within parens in CSV parsing?

2005-06-30 Thread gene tani
Why don't you use a different delimiter when you're writing the CSV? -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting string into dictionary

2005-06-30 Thread Devan L
One line solution. dict(re.findall(r"'(.+?)' \| '(.+?)'(?:\s\||$)",yourtexthere)) -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting string into dictionary

2005-06-30 Thread George Sakkis
"Robert Kern" wrote: > Ignore the last message. > > translations = [x.strip(" '") for x in line.split('|')] > d = dict(zip(translations[::2], translations[1::2])) Or in case you're working with a lot and/or huge records, the second line can be more efficiently written as: from itertools import i

Re: Splitting string into dictionary

2005-06-30 Thread David Pratt
Wow Robert that is incredible python magic! I am trying to figure out what this is doing since my attempts were regex and some long string splitting and collection. Ok. So it is a list comprehension and then collection. What is zip doing in the second line? Regards David On Friday, July 1,

Re: Splitting string into dictionary

2005-06-30 Thread David Pratt
Pretty amazing Devan! Great regex! Thank you. Regards, David On Friday, July 1, 2005, at 02:29 AM, Devan L wrote: > One line solution. > dict(re.findall(r"'(.+?)' \| '(.+?)'(?:\s\||$)",yourtexthere)) > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mai

Re: Splitting string into dictionary

2005-06-30 Thread George Sakkis
"David Pratt" wrote: > Wow Robert that is incredible python magic! I am trying to figure out > what this is doing since my attempts were regex and some long string > splitting and collection. > > Ok. So it is a list comprehension and then collection. What is zip > doing in the second line? > > R

Re: Speaking of list-comprehension?

2005-06-30 Thread George Sakkis
"Terry Hancock" wrote: > Chinook wrote: > > >>> ta = [5, 15, 12, 10, 9] > > >>> for i in range(len(ta)): > > ... if ta[i] >= 10: > > ... ta[i] -= 10 > > ... else: > > ... ta[i] += 10 > > It's not exactly the same in that it doesn't change values in > place, but this is similar if you

Re: Splitting string into dictionary

2005-06-30 Thread David Pratt
Thanks George! You guys are great! I am always learning. Python is awesome!! On Friday, July 1, 2005, at 02:33 AM, George Sakkis wrote: > "Robert Kern" wrote: > >> Ignore the last message. >> >> translations = [x.strip(" '") for x in line.split('|')] >> d = dict(zip(translations[::2], transla

Re: Splitting string into dictionary

2005-06-30 Thread George Sakkis
"David Pratt" > Thanks George! You guys are great! I am always learning. Python is > awesome!! Yeap, that was the reaction of many/most of us when we stumbled upon python. Welcome aboard ! George -- http://mail.python.org/mailman/listinfo/python-list

I am a Java Programmer

2005-06-30 Thread mjmrifai
I am a java programmer and I want to learn Python Please help me. -- http://mail.python.org/mailman/listinfo/python-list

Re: I am a Java Programmer

2005-06-30 Thread George Sakkis
"[EMAIL PROTECTED]" wrote: > I am a java programmer and I want to learn Python Please help me. Google Is Your Friend: http://www.razorvine.net/python/PythonForJavaProgrammers http://www.ferg.org/projects/python_java_side-by-side.html George -- http://mail.python.org/mailman/listinfo/python-li

<    1   2   3