turn text lines into a list

F. Petitjean littlejohn.75 at news.free.fr
Mon Jun 27 12:56:34 EDT 2005


[En-tête "Followup-To:" positionné à comp.lang.python.]
Le Mon, 27 Jun 2005 14:27:28 -0000, Grant Edwards a écrit :
> On 2005-06-27, Xah Lee <xah at xahlee.org> wrote:
>> i have a large number of lines i want to turn into a list.
>> In perl, i can do
>>
>> @corenames=qw(
>> rb_basic_islamic
>> sq1_pentagonTile
>> sq_arc501Tile
>> sq_arc503Tile
>> );
>>
>> use Data::Dumper;
>> print Dumper(\@corenames);
>>
>> ----------
>> is there some shortcut to turn lines into list in Python?
>
> corenames = [ "rb_basic_islamic",
>               "sq1_pentagonTile",
>               "sq_arc501Tile",
>               "sq_arc503Tile"]
>
Another way : (less typing of quotes)

all_names = """
rb_basic_islamic
sq1_pentagonTile
sq_arc501Tile
sq_arc503Tile
"""

corenames = all_names.split()

Regards.




More information about the Python-list mailing list