本帖最后由 yu2n 于 2017-6-17 15:53 编辑
我這裡 Python 3.5.2 默認安裝位置在:- python -c "import sys; print(sys.executable);"
- C:\Users\Yu2n\AppData\Local\Programs\Python\Python35-32\python.exe
复制代码 所以,重複造個輪子:- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :: Python2to3.bat
- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- @echo off & cls
-
- :::::::::::::::::::::::::::
- :: Check if the system has python installed
- :::::::::::::::::::::::::::
- set "pyver="
- for /f "tokens=1,* delims= " %%a in ('python --version') do (set "pyver=%%~b")
- if not defined pyver (
- echo Please install python 3 version ^!
- goto completed
- )
-
- :::::::::::::::::::::::::::
- :: Check the python version of the system installation
- :::::::::::::::::::::::::::
- echo python version^: %pyver%
- set "pyver=%pyver:.=%"
- set /a "pyver=%pyver:~0,2%"
- if %pyver% lss 30 (
- echo Please use python 3 version ^!
- goto completed
- )
-
- :::::::::::::::::::::::::::
- :: Get the python installation path
- :::::::::::::::::::::::::::
- for /f "delims=" %%a in ('python -c "import sys; print(sys.executable);"') do (set "pydir=%%~dpa")
- echo python directory^: %pydir%
-
- :::::::::::::::::::::::::::
- :my_loop :: Change the python version 2.x to 3.x
- :::::::::::::::::::::::::::
- if "%~1"=="" (
- echo ========================================================================
- echo Done!
- goto completed
- )
- call :bak "%~1"
- echo python 2to3.py -w %1
- echo ========================================================================
- python "%pydir%\Tools\scripts\2to3.py" -w %1
- shift
- goto my_loop
-
- :::::::::::::::::::::::::::
- :bak :: backup file
- :::::::::::::::::::::::::::
- if not defined n set /a n=0
- set /a n+=1
- if exist "%~dp1%~n1 (%n%)%~x1.bak" (
- goto :bak
- ) else (
- echo backup^: "%~1" "%~dp1%~n1 (%n%)%~x1.bak"
- copy "%~1" "%~dp1%~n1 (%n%)%~x1.bak"
- goto :eof
- )
-
- :::::::::::::::::::::::::::
- :completed
- :::::::::::::::::::::::::::
- PAUSE
复制代码 結果如下:- python version: 352
- python directory: C:\Users\Yu2n\AppData\Local\Programs\Python\Python35-32\
- backup: "C:\Users\Yu2n\Desktop\0.py" "C:\Users\Yu2n\Desktop\0 (10).py.bak"
- 1 file(s) copied.
- python 2to3.py -w C:\Users\Yu2n\Desktop\0.py
- ========================================================================
- RefactoringTool: Skipping optional fixer: buffer
- RefactoringTool: Skipping optional fixer: idioms
- RefactoringTool: Skipping optional fixer: set_literal
- RefactoringTool: Skipping optional fixer: ws_comma
- RefactoringTool: No changes to C:\Users\Yu2n\Desktop\0.py
- RefactoringTool: Files that need to be modified:
- RefactoringTool: C:\Users\Yu2n\Desktop\0.py
- ========================================================================
- Done!
- Press any key to continue . . .
复制代码
|