Notepad/enter/Coding Tips (Classical)/Terminal Tips/2. CLI Tools/Languages/Python/Convert Python 2 to 3.md

19 lines
401 B
Markdown
Raw Permalink Normal View History

Use the script [2to3](https://docs.python.org/3/library/2to3.html) to upgrade python 2 code to python 3:
This can be done via the command line:
```python
2to3 example.py
```
To write to the file directly:
```python
2to3 -w example.py
```
To translate an entire project from one directory tree to another use:
```python
2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode
```