| Entrambe le parti precedenti la revisioneRevisione precedenteProssima revisione | Revisione precedente |
| python:porting_python_2_to_pyton_3 [2020/01/22 17:39] – WIP apressato | python:porting_python_2_to_pyton_3 [2020/01/22 18:01] (versione attuale) – WIP apressato |
|---|
| ====== Porting da Python 2 a Python 3 ====== | ====== Porting da Python 2 a Python 3 ====== |
| |
| <WRAP center round important 60%> | |
| ***WIP***: Quello seguente è un articolo in divenire | |
| </WRAP> | |
| |
| |
| * L'ultima alternativa è il flag ''**--future-unicode**'' che importa gli ''unicode_literals'' dal modulo **<nowiki>__future__</nowiki>** usando il fixer contenuto in ''libmodernize.fixes.fix_unicode_future''.\\ Ciò richiede Python 2.6 e versioni successive e richiederà di contrassegnare le bytestring con b '' e le stringhe native in str('') o qualcosa di simile che sopravviva alla trasformazione. | * L'ultima alternativa è il flag ''**--future-unicode**'' che importa gli ''unicode_literals'' dal modulo **<nowiki>__future__</nowiki>** usando il fixer contenuto in ''libmodernize.fixes.fix_unicode_future''.\\ Ciò richiede Python 2.6 e versioni successive e richiederà di contrassegnare le bytestring con b '' e le stringhe native in str('') o qualcosa di simile che sopravviva alla trasformazione. |
| |
| | ==== Preparazione ==== |
| | Dal prompt dei comandi lanciare |
| | <code bash> |
| | pip --install modernize |
| | </code> |
| | Al termine dell'installazione avrete a disposizione l'eseguibile **python-modernize** |
| |
| | ==== Batch di conversione ==== |
| | <code batch> |
| | set mydatetime=%date:~-4%%date:~-7,2%%date:~-10,2%_%time:~0,2%%time:~3,2%%time:~6,2% |
| | set logpath=.\Logs |
| | set logfile=%logpath%\Migrate_%Application%_2to3_%mydatetime%.log |
| | set RepoPath=path\to\your \web2py\applications |
| | set Application=Your_Folder_App_Name |
| |
| | IF NOT EXIST %logpath% ( |
| | MKDIR %logpath% |
| | ) |
| | |
| | (FOR /f "delims=" %%a IN ('DIR %RepoPath%\%Application%\*.pyc /b /s') do (del %%a)) |
| | (FOR /f "delims=" %%a IN ('DIR %RepoPath%\%Application%\*.py /b /s') do (python-modernize -w %%a >> %LogFile%)) |
| | (FOR /f "delims=" %%a IN ('DIR %RepoPath%\%Application%\*.bak /b /s') do (del %%a)) |
| | </code> |
| |
| |
| - [[https://www.geeksforgeeks.org/important-differences-between-python-2-x-and-python-3-x-with-examples/]] | - [[https://www.geeksforgeeks.org/important-differences-between-python-2-x-and-python-3-x-with-examples/]] |
| - [[https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html]] | - [[https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html]] |
| | - [[https://python-modernize.readthedocs.io/en/latest/]] |
| |
| |