one-element tuples
Marko Rauhamaa
marko at pacujo.net
Mon Apr 11 08:12:26 EDT 2016
BartC <bc at freeuk.com>:
> Of course this doesn't help you parsing typical input which uses
> commas as separators, not terminators!
That's a red herring. You mustn't parse with eval(). You shouldn't event
think of parsing non-Python data with eval(). Why should Python's syntax
resemble a CSV file?
Try compiling the data file with a C compiler or bash.
The real answer is to do:
"a,b,c".split(",")
==> ['a', 'b', 'c']
Now, tuples would be trivial:
tuple("a,b,c".split(","))
==> ('a', 'b', 'c')
but a tuple is probably not what you'd want here since the number of
data elements in the OP's question is not constant.
Marko
More information about the Python-list
mailing list