繁体   English   中英

如何使用Python打开“〜/ .bash_profile”

[英]How can I use Python to open “~/.bash_profile”

我想使用Python编辑~/.bash_profile ,但是当我运行这些代码时:

f = open('~/.bash_profile', 'rb')

它告诉我:

IOError: [Errno 2] No such file or directory: '~/.bash_profile'

我以为是因为~/.bash_profile是系统保护文件。 是否有使用Python打开此文件的方法?

通常~由外壳扩展,而不是由系统调用扩展。 在Python中,使用os.path.expanduser()扩展以~开头的路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM