On 27 Jun 2005 16:56:34 GMT, "F. Petitjean" <[EMAIL PROTECTED]> wrote:
>[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 <[EMAIL PROTECTED]> 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([EMAIL PROTECTED]); >>> >>> ---------- >>> 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() Of course, the lines better not have embedded spaces or they'll be split into several lines. For lines per se, probably I'd do corenames = """\ rb_basic_islamic sq1_pentagonTile sq_arc501Tile sq_arc503Tile """.splitlines() Note the \ to avoid a blank leading line. >>> """\ ... solid ... embedded space ... leading ... trailing ... both ... """.splitlines() ['solid', 'embedded space', ' leading', 'trailing ', ' both '] Regards, Bengt Richter
-- http://mail.python.org/mailman/listinfo/python-list