print() a list
Mark Tolonen
metolone+gmane at gmail.com
Sat Sep 5 02:38:15 EDT 2009
More information about the Python-list mailing list
Sat Sep 5 02:38:15 EDT 2009
- Previous message (by thread): print() a list
- Next message (by thread): print() a list
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"DarkBlue" <pict100 at gmail.com> wrote in message news:b9c0c4ac-5f8f-4133-b928-9e55ab4b22a0 at x5g2000prf.googlegroups.com... >I am trying to get used to the new print() syntax prior to installing > python 3.1: > > test=[["VG", "Virgin Islands, British"],["VI", "Virgin Islands, U.S."], > ["WF", "Wallis and Futuna"],["EH", "Western Sahara"],["YE", "Yemen"], > ["ZM", "Zambia"],["ZW", "Zimbabwe"],] > > #old print > > for z in test: > if z[0].startswith('W'): > print z[0] , z[1] > > print > > > # new print() > # now a list would have to be printed like this to be equal to old > print ? > > for z in test: > if z[0].startswith('W'): > print('%s %s') % (z[0] , z[1]) > > print > > # this output prints the brackets etc. too, not what we want > > for z in test: > if z[0].startswith('W'): > print(z[0] , z[1]) > > print > > > > on python 2.6 I get following output: > > WF Wallis and Futuna > > WF Wallis and Futuna > > ('WF', 'Wallis and Futuna') > > > Before actually installing python 3.1 my question is if the py2to3 > converter also considers this situation ? You need the following statement to use print() in Python 2.6: from __future__ import print_function test = [ ["VG", "Virgin Islands, British"], ["VI", "Virgin Islands, U.S."], ["WF", "Wallis and Futuna"], ["EH", "Western Sahara"], ["YE", "Yemen"], ["ZM", "Zambia"], ["ZW", "Zimbabwe"]] for z in test: if z[0].startswith('Z'): print(z[0],z[1]) print() ----result---- ZM Zambia ZW Zimbabwe -Mark
- Previous message (by thread): print() a list
- Next message (by thread): print() a list
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list