-1

I like python 2's print "TEXT" which does not use without parenthesis, compared to print("TEXT") in python 3.

Can I keep the python 2 print around to use by binding it to something like pr?

I understand has been discussed in this thread, but this wasn't mentioned as one of the solutions: Python 3 print without parenthesis

(By the way, the issue for me is typing and escaping the brackets. The keys ( and ) harder to press than a space bar. Also, because my IDE puts them in automatically, I then need to move my cursor out of it.)

EDIT: This is neither a duplicate of the question as indicated NOR am I asking how to use python-3.x's print without parenthesis. Instead, I'm specifically asking if I can bind a python 2 function (presumably after importing it). If the answer is no, that is new information.

  • 1
    Easiest solution: Use python 2 :) – cs95 Jul 04 '17 at 21:12
  • 1
    On a more serious note, short of changing python's [grammar specification](https://docs.python.org/3/reference/grammar.html) you absolutely cannot remove those brackets. The language has been built to recognise and parse functions this way, there's just no way around it. – cs95 Jul 04 '17 at 21:15
  • 1
    In python 2 `print` is a keyword that triggers a statement. It's not a value that you can assign to something. – Alex Hall Jul 04 '17 at 21:15
  • The easiest way to avoid typing brackets is probably to configure a snippet in your IDE. For example you could type `pr`, then press Tab, and have it autocompleted to `print()`. – Aran-Fey Jul 04 '17 at 21:15
  • the question you're linking to is a good candidate to close as duplicate... I'm tempted. – Jean-François Fabre Jul 04 '17 at 21:24
  • It wasn't mentioned as a solution because no solution exists. You simply can't use `print` as a statement if the language doesn't support it. – Dimitris Fasarakis Hilliard Jul 04 '17 at 21:29
  • 1
    @JimFasarakisHilliard you just killed my joy :) – Jean-François Fabre Jul 04 '17 at 21:30
  • @Jean-FrançoisFabre If you enjoy wielding the hammer, I'll ping next time :-D – Dimitris Fasarakis Hilliard Jul 04 '17 at 21:32
  • The `print()` function is more useful than the `print` statement, allowing for `sep`, `end` and `file` parameters. I would try to look passed its slight increase in verbosity for the sake of its virtues – juanpa.arrivillaga Jul 04 '17 at 21:38
  • 1
    @JimFasarakisHilliard don't worry, I'm fine: https://stackoverflow.com/questions/44921948/change-name-of-dictionary-or-list-in-a-loop :) – Jean-François Fabre Jul 05 '17 at 09:18
  • This is neither a duplicate of the question as indicated NOR am I asking how to use python-3.x's print without parenthesis. Instead, I'm specifically asking if I can bind python 2's "print" function (presumably after importing it) to another one, i.e. "pr". If the answer is no, that is new information. This has not been been answered. Instead, my question has been flagged as duplicate and multiple answers have been given to another question that wasn't asked. – Courtney Kristensen Jul 05 '17 at 23:34
  • First of all, python 2's `print` is not a function, it's a statement. And secondly, you can't "import" python 2 functions into python 3. – Aran-Fey Jul 05 '17 at 23:50

1 Answers1

0

In order to achieve what you want you need to define your own keyword, but you can't do this as you can't define or redefine language keywords without rewriting a compiler/interpreter/etc.

pythad
  • 4,241
  • 2
  • 19
  • 41
  • As as in the question, I'm specifically asking if I can bind python-2.7's "print" function (presumably after importing it) to another one, i.e. "pr". – Courtney Kristensen Jul 05 '17 at 23:35