使用变量创建目录问题
我无法使用定义的变量创建目录,我得到一个 WindowsError: [Error 183] Cannot create a file when that file hasladen:
我尝试了这样的操作:
import os, ConfigParser
import Tkinter as tk
root = Tk()
exp_no = ""
config = ConfigParser.ConfigParser()
config.read("config.ini")
resultado = config.get("General", "lugar_exp")
en1 = tk.Entry(root, width = 30, background = 'white', textvariable = exp_no)
en1.pack()
os.mkdir(resultado+'/'+en1.get())
i can't make a directory using defined variables, i get an , WindowsError: [Error 183] Cannot create a file when that file already exists:
i tried something like this:
import os, ConfigParser
import Tkinter as tk
root = Tk()
exp_no = ""
config = ConfigParser.ConfigParser()
config.read("config.ini")
resultado = config.get("General", "lugar_exp")
en1 = tk.Entry(root, width = 30, background = 'white', textvariable = exp_no)
en1.pack()
os.mkdir(resultado+'/'+en1.get())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信它
正在运行,
因为
en1.get()
可能是空的,或者路径的连接是错误的,这只会导致resultado
。您能否验证
en1.get()
包含某些内容?您可以使用 os.path.join 吗?I believe that
is running as
because
en1.get()
might be empty or concatanation of paths is wrong which results in justresultado
.Could you verify that
en1.get()
contains something? And could you useos.path.join
?听起来 Windows 正在引发错误,因为该目录已经存在。
您可能想通过检查是否存在来增加更多的安全性。另外
os.makedirs
更好一点因为它将创建路径上所有丢失的目录:It sounds like Windows is raising an error because the directory already exists.
You may want to add a bit more safety by checking for existence. Also
os.makedirs
is a bit nicer in that it will create all missing directories on the path: