I am a little tired of having to input first chcp 936
before using python with command line. (more details: my python version is 2.7
, and os is Windows 8
and I am starting command line under the File menu of my project folder. )
936
represents coding for Simplified Chinese GBK
; Python 2.7 seems to be unaware of code page 65001
(meaning utf-8
) which is the default setting for my command line, and thus causes error whenever it runs a program.
So I wonder if it is possible to configure the cmd setting so that it uses code page 936
as the default setting.
Create a shortcut pointing to cmd /k "chcp 936"
EDITED - With the same idea, but to integrate into shell, save as .reg
file and run
Windows Registry Editor Version 5.00
;--------------------------------------------
; Create handler for right click on directory
;--------------------------------------------
[-HKEY_CLASSES_ROOT\Directory\shell\cmdPython]
[HKEY_CLASSES_ROOT\Directory\shell\cmdPython]
@="Open python command window here"
[HKEY_CLASSES_ROOT\Directory\shell\cmdPython\command]
@="cmd /k pushd \"%L\" & chcp 936"
;-------------------------------------------------------
; Create handler for right click on directory background
;-------------------------------------------------------
[-HKEY_CLASSES_ROOT\Directory\Background\shell\cmdPython]
[HKEY_CLASSES_ROOT\Directory\Background\shell\cmdPython]
@="Open python command window here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\cmdPython\command]
@="cmd /k pushd \"%L\" & chcp 936"
;----------------------------------------
; Create handler for right click on drive
;----------------------------------------
[-HKEY_CLASSES_ROOT\Drive\shell\cmdPython]
[HKEY_CLASSES_ROOT\Drive\shell\cmdPython]
@="Open python command window here"
[HKEY_CLASSES_ROOT\Drive\shell\cmdPython\command]
@="cmd /k pushd \"%L\" & chcp 936"
Create a batch file called c.bat
and put it on the path: You can type c and press enter.
Additionally you can put the python command inside the batch file to accept parameters, if that fits in with your tasks.
@echo off
chcp 936
Alternately there is an autoexec.nt
in the system32
folder which launches with cmd
and you can add commands there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With