【发布时间】:2016-06-03 10:13:45
【问题描述】:
我现在遇到以下问题。 (我用谷歌搜索但没有找到解决方案)
问题是我想将文件复制到文件夹名称中带有变量的文件夹中。变量是时间戳。我怎样才能做到这一点?
这是我的代码:
datetime_ordner = time.strftime("__%d_%m_%y-%H-%M")
dir = mkdir('test' + str(datetime_ordner))
data_xls = pd.read_excel('test.xls')
data_xls.to_csv('test_daten' + str(datetime) + '.csv')
shutil.copy2('test_daten.csv', '/',dir(),'test' + str(datetime) + '.csv')
我试过了,但它不会工作。如果这可能是一个愚蠢的问题,我很抱歉,但我自己无法弄清楚。
【问题讨论】:
-
您应始终包含实际的完整错误消息,以便我们更轻松地为您提供帮助。
-
shutil.copy2('test_daten.csv', '/',dir(),'test' + str(datetime) + '.csv') TypeError: 'NoneType' object is not callable 那就是我得到的错误!
-
这告诉你你试图在一个不提供它的对象上执行调用运算符
()。那一行有三个候选人。作为提示,请检查 mkdir 函数的返回值是什么。 -
使用 dir 作为变量名 dir 是 python 的内置函数。 docs.python.org/2/library/functions.html#dir
标签: python file operating-system