我尝试在子目录中创建一个随机名称的文件,但是我遇到了这个错误:
URL/<bound method webSiteCompanies.nameGenerator of
<__main__.webSiteCompanies instance at 0x7fc30dbccd88>>
我的代码看起来像那样:
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
import os
import string
import random
class webSiteCompanies():
def __init__(self):
self.path = "URL"
self.stringSize = 42
def nameGenerator(self):
chars = string.ascii_uppercase + string.digits
return str(''.join(random.choice(chars) for _ in range(self.stringSize)))
def createFile(self):
realPath = self.path + "/" + str(self.nameGenerator)
try:
os.mkdir(self.path)
except Exception:
pass
print realPath
os.mknod(realPath+".txt")
# Main
if __name__=='__main__':
bob = webSiteCompanies()
bob.createFile()
我的文件已创建,但名称为错误...
我如何解决我的问题?