我在Visual 2015中使用Python (实际上是IronPython)来创建一个WPF应用程序。我导入了os,但无法访问它的方法。
我就是这样做的:
import os
class Utils(object):
def fcn(self, arg):
if os.path.exists(arg):
print 'Exists!.'
else:
print 'Doesn't exist... :/'
raise在按下GUI中的一个按钮后,我从视图模型文件调用这个类
class ViewModel(ViewModelBase):
def __init__(self):
ViewModelBase.__init__(self)
self.RunCommand = Command(self.RunMethod)
self.utils = Utils()
def RunMethod(self):
self.utils.fcn("C:\path")如果我在"if os.path.exists(arg)“之后设置了断点,程序就会冻结,如果我在(或在该行上)之前设置它,它就会正常停止。
有什么想法吗?
谢谢。
发布于 2015-10-21 19:49:50
子模块需要显式导入:
import os.path # not just import os在标准的Python实现中,import os可能会由于实现os.path的奇怪方式而独立工作,但是如果您想使用os.path,那么它仍然应该是import os.path。
https://stackoverflow.com/questions/33267780
复制相似问题