converting from perl: variable sized unpack
Roy Smith
roy at panix.com
Fri Jul 13 22:11:25 EDT 2001
What's the best way to translate this perl snippet into python:
($f1, $f2, $f3, $f4, $f5, $f6) = split ('\s+', $line);
The obvious translation would be:
[f1, f2, f3, f4, f5, f6] = string.split (line)
but the problem is that line may have fewer than 6 fields on it. Perl
handles this smoothly by leaving the "extra" variables undefined, whereas
python raises a ValueError exception. What I'd like to do is have the
extra field variables left as null strings.
More information about the Python-list
mailing list