导入后无法使用 os 函数
Cannot use os functions after having imported it
我正在使用 Python(实际上是 IronPython)和 Visual Studio 2015 制作 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
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)" 之后设置断点,程序会冻结,如果我在之前(或在那一行)设置断点,它会正常停止。
有什么想法吗?
谢谢。
子模块需要显式导入:
import os.path # not just import os
在标准的 Python 实现中,由于 os.path
的实现方式很奇怪,import os
可能会自行运行,但它应该仍然是 import os.path
如果你想使用 os.path
.
我正在使用 Python(实际上是 IronPython)和 Visual Studio 2015 制作 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
中按下按钮后,我从视图模型文件中调用此 classclass 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)" 之后设置断点,程序会冻结,如果我在之前(或在那一行)设置断点,它会正常停止。
有什么想法吗?
谢谢。
子模块需要显式导入:
import os.path # not just import os
在标准的 Python 实现中,由于 os.path
的实现方式很奇怪,import os
可能会自行运行,但它应该仍然是 import os.path
如果你想使用 os.path
.