On Jan 9, 12:57 pm, "Jerry Hill" wrote:
> On Fri, Jan 9, 2009 at 3:39 PM, Benjamin Kaplan
>
> > This looks like a CSV file to me. If that is the case, it is easier to use
> > the built-in csv module than to try to write your own parser.
>
> It should be as easy as this:
>
> import csv
>
> testfile
On Fri, Jan 9, 2009 at 3:39 PM, Benjamin Kaplan
> This looks like a CSV file to me. If that is the case, it is easier to use
> the built-in csv module than to try to write your own parser.
It should be as easy as this:
import csv
testfile = open('testfile.csv', 'w')
testdata = """100-01001-001,"
On Fri, 09 Jan 2009 12:39:22 -0800, Leland wrote:
> It seems work this way, but is there more elegant way to do this?
Yes, the `csv` module in the standard library.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, Jan 9, 2009 at 3:26 PM, Leland wrote:
> Hi,
>
> I have some formatted strings that I'd like to split and get the
> meaningful data, here is the example of the string format. The big
> difference of these two line are the second double quote set at the
> second line
> 100-01001-001,"Diode,
Hi,
I have some formatted strings that I'd like to split and get the
meaningful data, here is the example of the string format. The big
difference of these two line are the second double quote set at the
second line
100-01001-001,"Diode,Small Signal,SOT-23",1,D46,
100-01004-001,"Diode,High Voltage
Hi,
I have some formatted strings that I'd like to split and get the
meaningful data, here is the example of the string format. The big
difference of these two line are the second double quote set at the
second line
100-01001-001,"Diode,Small Signal,SOT-23",1,D46,
100-01004-001,"Diode,High Voltage
Hi,
I have some formatted strings that I'd like to split and get the
meaningful data, here is the example of the string format. The big
difference of these two line are the second double quote set at the
second line
100-01001-001,"Diode,Small Signal,SOT-23",1,D46,
100-01004-001,"Diode,High Voltage
Peter Otten schrieb:
Kurt Mueller wrote:
How to (super)split a string (literal) containing " and/or ' and/or
\.
example:
' a " b b " c\ c '.supersplit(' ')
->
['a', ' b b ', 'c c']
import shlex
shlex.split(' a " b b " c\ c ')
['a', ' b b ', 'c c']
Thanks Peter
Thanks Paul
Kurt Mueller wrote:
> How to (super)split a string (literal) containing " and/or ' and/or
> \.
>
> example:
>
> ' a " b b " c\ c '.supersplit(' ')
> ->
> ['a', ' b b ', 'c c']
>
>
> Thanks and Grüessli
>>> import shlex
>>> shlex.split(' a " b b " c\ c ')
['a', ' b b ', 'c c']
On Jun 24, 3:56 am, Kurt Mueller <[EMAIL PROTECTED]> wrote:
> How to (super)split a string (literal) containing " and/or ' and/or \.
>
> example:
>
> ' a " b b " c\ c '.supersplit(' ')
> ->
> ['a', ' b b ', 'c c']
>
> Thanks and Grüessli
> --
> Kurt Müller:
> [EMAIL PROTECTED]
Or did you m
On Jun 24, 3:56 am, Kurt Mueller <[EMAIL PROTECTED]> wrote:
> How to (super)split a string (literal) containing " and/or ' and/or \.
>
> example:
>
> ' a " b b " c\ c '.supersplit(' ')
> ->
> ['a', ' b b ', 'c c']
>
> Thanks and Grüessli
> --
> Kurt Müller:
> [EMAIL PROTECTED]
>>> re.split
How to (super)split a string (literal) containing " and/or ' and/or \.
example:
' a " b b " c\ c '.supersplit(' ')
->
['a', ' b b ', 'c c']
Thanks and Grüessli
--
Kurt Müller:
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
Sorry for breaking threading by replying to a reply, but I don't seem to
have the original post.
On Wed, 2008-03-12 at 15:29 -0500, Michael Wieher wrote:
> Hey all,
>
> I have these annoying textilfes that are delimited by the ASCII char
> for << (only its a single character) and >> (again a sin
> import re
> splitter_re = re.compile(chr(174) + '|' + chr(175))
> for line in file(FILENAME):
> parts = splitter_re.split(line)
> do_something(parts)
>
> and then go find a large blunt object with which to bludgeon the
> creator of the file... :)
p>> creator= CreatorOfTheFile(
> I have these annoying textilfes that are delimited by the ASCII char for <<
> (only its a single character) and >> (again a single character)
>
> Their codes are 174 and 175, respectively.
>
> My datafiles are in the moronic form
>
> X<>Z
>
> I need to split on those freaking characters. Any
On Wed, 2008-03-12 at 15:29 -0500, Michael Wieher wrote:
> Hey all,
>
> I have these annoying textilfes that are delimited by the ASCII char
> for << (only its a single character) and >> (again a single character)
>
> Their codes are 174 and 175, respectively.
>
> My datafiles are in the moronic
Hey all,
I have these annoying textilfes that are delimited by the ASCII char for <<
(only its a single character) and >> (again a single character)
Their codes are 174 and 175, respectively.
My datafiles are in the moronic form
X<>Z
I need to split on those freaking characters. Any tips on h
Steve Holden wrote:
> robert wrote:
> [...]
>> but its also wrong regarding partial last lines.
>>
>> re.split obviously doesn't understand \A \Z ^ $ and also \b etc. empty
>> matches.
>>
> [...]
> Or perhaps you don't understand re?
>
> It's a tricky thing to start playing with. Look up re.MULTI
robert wrote:
[...]
> but its also wrong regarding partial last lines.
>
> re.split obviously doesn't understand \A \Z ^ $ and also \b etc.
> empty matches.
>
[...]
Or perhaps you don't understand re?
It's a tricky thing to start playing with. Look up re.MULTILINE ans
re.DOTALL.
regards
Ste
Jeffrey Froman wrote:
> robert wrote:
>
>> thanks. Yet this does not work "naturally" consistent in my line
>> processing algorithm - the further buffering. Compare e.g.
>> ss.split('\n') ..
>>
> 'owi\nweoifj\nfheu\n'.split('\n')
>> ['owi', 'weoifj', 'fheu', '']
> 'owi\nweoifj\nfheu\nxx'.
Tim Chase wrote:
this didn't work elegantly as expected:
>>> ss
'owi\nweoifj\nfheu\n'
>>> re.split(r'(?m)$',ss)
['owi\nweoifj\nfheu\n']
>>> Do you have a need to use a regexp?
>> I'd like the general case - split without consumption.
>
> I'm not sure there's a one-p
robert wrote:
> thanks. Yet this does not work "naturally" consistent in my line
> processing algorithm - the further buffering. Compare e.g.
> ss.split('\n') ..
>
> >>> 'owi\nweoifj\nfheu\n'.split('\n')
> ['owi', 'weoifj', 'fheu', '']
> >>> 'owi\nweoifj\nfheu\nxx'.split('\n')
> ['owi', 'weoifj'
>>> this didn't work elegantly as expected:
>>>
>>> >>> ss
>>> 'owi\nweoifj\nfheu\n'
>>> >>> re.split(r'(?m)$',ss)
>>> ['owi\nweoifj\nfheu\n']
>> Do you have a need to use a regexp?
>
> I'd like the general case - split without consumption.
I'm not sure there's a one-pass regex solution to the
Tim Chase wrote:
>> this didn't work elegantly as expected:
>>
>> >>> ss
>> 'owi\nweoifj\nfheu\n'
>> >>> re.split(r'(?m)$',ss)
>> ['owi\nweoifj\nfheu\n']
>
> Do you have a need to use a regexp?
I'd like the general case - split without consumption.
>
ss.splitlines(True)
> ['owi\n', 'weoi
> this didn't work elegantly as expected:
>
> >>> ss
> 'owi\nweoifj\nfheu\n'
> >>> re.split(r'(?m)$',ss)
> ['owi\nweoifj\nfheu\n']
Do you have a need to use a regexp?
>>> ss.splitlines(True)
['owi\n', 'weoifj\n', 'fheu\n']
-tkc
--
http://mail.python.org/mailman/listinfo/python-list
this didn't work elegantly as expected:
>>> ss
'owi\nweoifj\nfheu\n'
>>> re.split(r'\A',ss)
['owi\nweoifj\nfheu\n']
>>> re.split(r'\Z',ss)
['owi\nweoifj\nfheu\n']
>>> re.split(r'$',ss)
['owi\nweoifj\nfheu\n']
>>> re.split(r'(?s)$',ss)
['owi\nweoifj\nfheu\n']
>>> re.split(r'(?m)(?s)$',ss)
['o
Michele Petrazzo wrote:
> Just a question about that "different algorithm", because it force the
> developer to do other work for make the "split" result more "logically
> compatible":
>
> S = "" # this can become from an external source like config parser
>
> for s n S.split():
> do the wor
Peter Otten wrote:
> The documentation for Python 2.4 has a better explanation.
>
<-cut->
> Quoted after http://docs.python.org/lib/string-methods.html#l2h-202.
>
> Peter
Thanks, I haven't see it.
Just a question about that "different algorithm", because it force the
developer to do other work
Michele Petrazzo wrote:
> I don't understand why split (string split) doesn't work with the same
> method if I can't pass values or if I pass a whitespace value:
>
> >>> "".split()
> []
> >>> "".split(" ")
> [
Michele Petrazzo wrote:
> Hello ng,
> I don't understand why split (string split) doesn't work with the same
> method if I can't pass values or if I pass a whitespace value:
>
>>>> "".split()
> []
>>>> "".split("
Hello ng,
I don't understand why split (string split) doesn't work with the same
method if I can't pass values or if I pass a whitespace value:
>>> "".split()
[]
>>> "".split(" ")
['']
But into the doc I see:
""
31 matches
Mail list logo