python更改启动/默认目录 [英] python change starting up/default directory
问题描述
每当我启动shell,它总是给我的目录为:
... /文件名/ Python /
但是我想将其更改为:
... /文件名/ python程序/
如何在不更改导入调制内容的情况下执行?
我怕这样做是错误的,所以我不能再导入了,但是很麻烦:
import os
os.chdir(... / file name / python program /)
每次打开shell后。
感谢您的帮助!
结帐: http://docs.python.org/using/cmdline.html#envvar-PYTHONSTARTUP
这是一个可以设置为文件的环境变量。这是在启动shell之前执行的,只有在使用交互式shell的情况下才适用。
您可以使用此命令在shell的起始位置指定路径作为当前目录。
import os
os.chdir('/ pathto')
del os
写入一个文件,并用env变量指向。
如果这只是你正在运行的一个文件,那么你应该更改脚本中的目录
os .chdir('/ pathto')
I am new to python. Every time I start the shell, it always gives me directory as:
".../file name/Python/"
But I want to change it to:
".../file name/python program/"
How do I do it without changing the import modulate stuff? I am afraid to make it wrong so that I can't import anymore, but it is so annoy to put:
import os
os.chdir(".../file name/python program/")
every time after I open the shell. Thanks for help!
Checkout: http://docs.python.org/using/cmdline.html#envvar-PYTHONSTARTUP
This is an environment variable that can be set to a file. This is executed prior to start up of shell and only applies if you are using interactive shell.
You can use this to specify a path as current directory at start of your shell.
import os
os.chdir('/pathto')
del os
Write to a file and point to it with env variable.
If this is just specific to a file that you are running, then you should be changing the directory inside the script
os.chdir('/pathto')
这篇关于python更改启动/默认目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!