Python's qw

Fernando Perez fperez528 at yahoo.com
Fri May 16 16:23:25 EDT 2003


A Puzzled User wrote:

> 
> Erik Max Francis wrote:
>> 
>> I've seen similar things used [e.g., 'sunflower tulip jasmine'.split()],
>> so it's not uncommon.  I prefer the old fashioned way, myself.
> 
> 
> Erik, thanks for your post.  The old fashion way, you mean
> just using
>    a = ['sunflower', 'tulip', 'jasmine']
> ?
> 
> It is because I probably have a list of about 80
> items, and it is more editing work to add and
> maintain the list.

In those cases, a simple split works (I use it a lot).  A typical example:

sources = """
binary_decomp.f90 binexpandx.f90 bitsequence.f90 constructwv.f90
display_matrix.f90 findkeypos.f90 findlevel.f90 findnodx.f90 gauleg.f90
gauleg2.f90 gauleg3.f90 ihpsort.f90 invf2cn.f90 invf2cu.f90 keysequence2d.f90
level_of_nsi.f90 matmult.f90 plegnv.f90 plegvec.f90 r2norm.f90 xykeys.f90

mwadap_tools.pyf""".split()


Note that by default, split() works on whitespace, so it handles automatically
_both_ spaces, newlines and empty lines correctly.

cheers,

f




More information about the Python-list mailing list