Python 使用变量作为目录的名称

Python 使用变量作为目录的名称,python,Python,我试图用python编写一个脚本,创建一个名为“current timestamp”的文件夹,但并不真正了解执行此操作的语法。到目前为止,我有: timestamp = int(time.time()) #fetches timestamp if not os.path.exists([timestamp]): #creates new folder titled the current timestamp os.makedirs([timestamp]) os.chdir([times

我试图用python编写一个脚本,创建一个名为“current timestamp”的文件夹,但并不真正了解执行此操作的语法。到目前为止,我有:

timestamp = int(time.time()) #fetches timestamp
if not os.path.exists([timestamp]): #creates new folder titled the current timestamp
    os.makedirs([timestamp])
os.chdir([timestamp]) #navigates to new folder
当我运行这个时,我会遇到错误


另外,我是初学者,请不要咬人。

时间戳需要转换为
str
ing。然后,
str
ing需要作为参数传递给
os
函数:

timestamp = str(int(time.time())) #fetches timestamp
if not os.path.exists(timestamp): #creates new folder titled the current timestamp
    os.makedirs(timestamp)
os.chdir(timestamp) #navigates to new folder

时间戳需要转换为
str
ing。然后,
str
ing需要作为参数传递给
os
函数:

timestamp = str(int(time.time())) #fetches timestamp
if not os.path.exists(timestamp): #creates new folder titled the current timestamp
    os.makedirs(timestamp)
os.chdir(timestamp) #navigates to new folder

问题是什么?你有什么错误吗?有什么问题吗?你有什么错误吗?谢谢!这对我帮助很大!非常感谢。这对我帮助很大!