I am in the process of converting my python code from 2.7 to 3 using 2to3. It seems to convert as expected, except that my code always starts with the line #!/usr/bin/python
which I expected to change to #!/usr/bin/python3
but it doesn't. Have I missed something? Is there a way to get that to happen?
Asked
Active
Viewed 208 times
1

Mick Sulley
- 99
- 2
- 11
-
4I think 2to3 is not supposed to do that. It transforms Python code and sees this line as a comment. – mkrieger1 Feb 10 '19 at 20:04
-
1Here is a list of things it does: https://docs.python.org/3/library/2to3.html What you want is not mentioned there. – mkrieger1 Feb 10 '19 at 20:06
1 Answers
2
#!/usr/bin/python
is not a python
version-dependent statement, or even python
at all. It essentially instructs a shell to execute the script (file) using the python
executable (program) located at /usr/bin
.
The intent behind 2to3
it get you along the path of converting your code to python 3, frequently doing all the work for you. It doesn't address issues outside the python
code.
It's entirely possible for /usr/bin/python
to be python
3. The #! line exists let a shell execute a script using what's typically a systems default python
.

Chris Larson
- 1,684
- 1
- 11
- 19