[英]Accesing UNIX variable path in Python
I want to access a file present in a certain location in UNIX box. 我想访问UNIX框中某个位置的文件。 Usually I use
通常我用
Path 路径
$HOME/my/path/filename
I am pusuing the following python code 我正在推出以下python代码
#!/usr/bin/python
import time
mytime= time.strftime("%Y%m%d", localtime)
file = $HOME/my/path/Text.$mytime*
I am getting the following error 我收到以下错误
file = $HOME/my/path/Text.$mytime*
^
SyntaxError: invalid syntax
PS: Filename is of the format PS:文件名是格式
Text.YYYYMMDDhhmmss
Text.YYYYMMDDhhmmss
Python Version 2.6 Python版本2.6
import os
os.environ["HOME"]
os.environ["mytime"]
os.environ will provide access to your environmental variables os.environ将提供对环境变量的访问
file = "%s/my/path/Text%s*"%(os.environ["HOME"], os.environ["mytime"])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.