我正在尝试在Python 3.3中使用一个旧库(可追溯到2003年!).当我导入它时,Python会抛出一个错误,因为<>源文件中有迹象,例如:
if (cnum < 1000 and nnum <> 1000 and ntext[-1] <> "s":
...
Run Code Online (Sandbox Code Playgroud)
我想这是一个现在被遗弃的语言标志.
究竟是什么意思,我应该用哪个(更近期的)标志替换它?
class HelloWorld(object):
def say_it(self):
return 'Hello I am Hello World'
def i_call_hello_world(hw_obj):
print 'here... check type: %s' %type(HelloWorld)
if isinstance(hw_obj, HelloWorld):
print hw_obj.say_it()
from mock import patch, MagicMock
import unittest
class TestInstance(unittest.TestCase):
@patch('__main__.HelloWorld', spec=HelloWorld)
def test_mock(self,MK):
print type(MK)
MK.say_it.return_value = 'I am fake'
v = i_call_hello_world(MK)
print v
if __name__ == '__main__':
c = HelloWorld()
i_call_hello_world(c)
print isinstance(c, HelloWorld)
unittest.main()
Run Code Online (Sandbox Code Playgroud)
这是追溯
here... check type: <type 'type'>
Hello I am Hello World
True
<class 'mock.MagicMock'>
here... check type: <class 'mock.MagicMock'>
E …Run Code Online (Sandbox Code Playgroud)