我想就我的代码寻求帮助,因为它给了我一个我看不到的错误。通常情况下,IDLE会突出显示错误,但这一次,它根本没有给我任何东西,所以我对我的问题位置感到困惑。
也只是一个单挑,我对python很新,并且刚刚在2天前尝试过,所以如果有人能帮助这个菜鸟(我)这个问题,我会感激不尽。
import time as t
from os import path
##dest is the string
def createFile(dest):
'''
The script creates a text at the passed in location, names file based on date
'''
date = t.localtime(t.time())
##name=month/day/year
name = '%d_%d_%d.txt'%(date[1],date[2],(date[0]%100))
##if file does not exist
if not(path,isfile(dest+name)):
f = open(dest + name, 'w')
f.write('\n'*30)
f.close()
if __name__=='__main__':
destination = 'C:\\Python34\\My Projects in Python\\'
createFile(destination)
input("done!")
答案 0 :(得分:0)
您的代码中存在几个问题:
path.isfile
而不是path,isfile
此处的工作代码:
import time as t
from os import path
##dest is the string
def createFile(dest):
'''
The script creates a text at the passed in location, names file based on date
'''
date = t.localtime(t.time())
##name=month/day/year
name = '%d_%d_%d.txt'%(date[1],date[2],(date[0]%100))
##if file does not exist
if not(path.isfile(dest+name)):
f = open(dest + name, 'w')
f.write('\n'*30)
f.close()
if __name__=='__main__':
destination = 'C:\Python34\My Projects in Python\'
createFile(destination)
input("done!")