2023-05-18 12:44:12 +01:00
|
|
|
# 2to3
|
|
|
|
|
|
|
|
> Geautomatiseerde conversie van Python 2 naar 3-code.
|
2024-10-20 18:01:17 +02:00
|
|
|
> Deze module is sinds 3.11 verouderd en is sinds 3.13 verwijderd.
|
|
|
|
> Ter referentie: <https://github.com/python/cpython/blob/8d42e2d915c3096e7e7ac1c649751d1da567bb7c3/doc/whatsnew/3.13.rst?plain=188>.
|
|
|
|
> Meer informatie: <https://manned.org/2to3>.
|
2023-05-18 12:44:12 +01:00
|
|
|
|
|
|
|
- Geef de wijzigingen weer die zouden worden uitgevoerd zonder ze uit te voeren (simulatie):
|
|
|
|
|
|
|
|
`2to3 {{pad/naar/bestand.py}}`
|
|
|
|
|
|
|
|
- Converteer een Python 2-bestand naar Python 3:
|
|
|
|
|
|
|
|
`2to3 --write {{pad/naar/bestand.py}}`
|
|
|
|
|
|
|
|
- Converteer specifieke Python 2-taalfuncties naar Python 3:
|
|
|
|
|
2024-05-04 09:32:33 +02:00
|
|
|
`2to3 --write {{pad/naar/bestand.py}} --fix {{raw_input}} --fix {{print}}`
|
2023-05-18 12:44:12 +01:00
|
|
|
|
|
|
|
- Converteer alle Python 2-taalfuncties behalve de gespecificeerde naar Python 3:
|
|
|
|
|
2024-05-04 09:32:33 +02:00
|
|
|
`2to3 --write {{pad/naar/bestand.py}} --nofix {{has_key}} --nofix {{isinstance}}`
|
2023-05-18 12:44:12 +01:00
|
|
|
|
|
|
|
- Geef een lijst weer met alle beschikbare taalfuncties die kunnen worden geconverteerd van Python 2 naar Python 3:
|
|
|
|
|
|
|
|
`2to3 --list-fixes`
|
|
|
|
|
2023-10-19 14:43:39 +02:00
|
|
|
- Converteer alle Python 2-bestanden in een map naar Python 3:
|
2023-05-18 12:44:12 +01:00
|
|
|
|
2024-05-04 09:32:33 +02:00
|
|
|
`2to3 --output-dir {{pad/naar/python3_map}} --write-unchanged-files --nobackups {{pad/naar/python2_map}}`
|
2023-05-18 12:44:12 +01:00
|
|
|
|
|
|
|
- Voer 2to3 uit met meerdere threads:
|
|
|
|
|
2024-05-04 09:32:33 +02:00
|
|
|
`2to3 --processes {{4}} --output-dir {{pad/naar/python3_map}} --write --nobackups --no-diff {{pad/naar/python2_map}}`
|