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。