11 ms·
I only want print as statement again
by dvl 12y ago
I only want print as statement again
- thuuuomas 12y agoI thought `repr backticks` were convenient, but alas "there is only one way to do it".
- dorfsmay 12y agoSeriously? The first thing I do when writing python 2 is import the print_function!
- the_mitsuhiko 12y agoOut of curiosity: why?
- darkseas 12y agoI use map(print, list_of_tuples) quite a bit, but that possibly an artifact of my print-based debugging. I can only do this with print as a function rather than a statement, and the single line makes it easy to drop in or comment out as needed.
- njharman 12y agoPrint '\n'.join(str(x) for x in list_of_tuples) Not as nice, but doable.
- the_mitsuhiko 12y agomap(print, list_of_tuples) does not work on Python 3 unless you wrap it in list(). In any case it's a anti-idiom because it creates a useless list. Please don't do that.
- darkseas 12y agoAh, I can see now that `map` will return a list of Nones, and also that Py3 `map` returns a lazy iterator. Thanks. Seeing how my transition to Py3 got hung up on sending bytes in and out of ZeroMQ sockets, I might stop that now. Back to the for loop or join the strings as suggested below.
- mborch 12y ago>>> from pprint import pprint; pprint(list_of_tuples)
- dorfsmay 12y agoI can never remember the python 2 quirky, inconsistent syntax, I always have to look it up. PRINT TO A FILE, OR STDERR print >> sys.stderr, "blah" What are those '>' signs here? Why two? What happens if I use one only? Compare this to (py3k): print("blablah", file=sys.stderr) PRINT WITHOUT NEW LINE sys.stdout.write('blah') I can't use print to print? compare to: print("blah", end="") DISABLE FLIUSH In python 2 there are 2 or 3 different ways to do that, all more complicated than each other. Compared to: print("blah", flush=True) Finally, it's a function, you can do everything you do with a function, use map, return a print from another function, include it in generator expressions etc...
- dragonwriter 12y ago> PRINT WITHOUT NEW LINE sys.stdout.write('blah') I can't use print to print? You can. Compare the output from: print "foo" print "bar" With that from: print "foo", print "bar"
- dvl 12y agoNot at all, I can live without it, was only less thing to type when debugging.