1
的錯誤是這樣的:無法寫入[錯誤22]無效MOD或文件名
mini: mkrule www.google.com therule
Traceback (most recent call last):
File "C:/Users/t11/Dropbox/2.0/cmd2.0.py", line 88, in <module>
MiniDownloader().cmdloop()
File "C:\Python27\lib\cmd.py", line 142, in cmdloop
stop = self.onecmd(line)
File "C:\Python27\lib\cmd.py", line 221, in onecmd
return func(arg)
File "C:/Users/t11/Dropbox/2.0/cmd2.0.py", line 75, in do_mkrule
functions2.write(self.RulesDir+site, xpath)
File "C:\Users\t11\Dropbox\2.0\functions2.py", line 12, in write
with open(path_file, mod) as FileObject:
IOError: [Errno 22] invalid mode ('w') or filename: 'C:\\Users\\t11\\Dropbox\\2.0\\Rules\\https://www.google.com'
Process finished with exit code 1
我使用CMD模塊 ,這是功能:
def write(path_file, data, mod="w", writeover=False):
""" gets file path + name and contents
check if the name is taken and if not write it (return's True if successful and False if not) """
if os.path.exists(path_file) and writeover is not True:
return False
else:
with open(path_file, mod) as FileObject:
FileObject.write(data)
FileObject.flush()
return True
我打電話這裏的功能:
def do_mkrule(self, s):
s = s.split()
if len(s) != 2:
self.help_mkrule()
return
site = s[0]
xpath = s[1]
site = functions2.url_check(site)
if xpath == "del":
os.remove(self.RulesDir+site)
print "file "+site+" removed"
else:
if site != False:
functions2.write(self.RulesDir+site, xpath)
print "rule for "+site+" created"
該函數的意圖是獲取文件路徑,名稱和內容,檢查名稱是採取,如果不寫。
它應該返回True,如果成功則返回False,否則返回False。