`
zealotds
  • 浏览: 119783 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

My Python Tips 1: chdir, load module

阅读更多
python, chdir, sys.path, working directory, load module

# Directory relative -----------------

# current working directory
os.getcwd()
# getcwd UNICODE version 
os.getcwu()
# path separator, : for UINX and ; for Win
os.pathsep
# change your current working directory, useful in Interactive mode
os.chdir(path)
# alternative of chdir, invoke a OS shell command directly
os.system(command)


# To load your module ----------------

# module search path list
# append your moudule path to import
sys.path
sys.path.append(path)

# import your module
# remember that your module name should better not same to
# some built-in module, otherwise it python will load the built-in
# modules instead of yours
# to check available built-in module: (Interactive mode)
# help('modules')
import <module_name>

# call this global to reload your module
reload(module_name)


Set a environment variable to avoid setting the search path every time:
export PYTHONPATH=$PYTHONPATH:<you-lib-path>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics