Hacker News new | ask | show | jobs
by dorfsmay 4399 days ago
I 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...

1 comments

> 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"