相关疑难解决方法(0)

在Python中,"<>"是什么意思?

我正在尝试在Python 3.3中使用一个旧库(可追溯到2003年!).当我导入它时,Python会抛出一个错误,因为<>源文件中有迹象,例如:

if (cnum < 1000 and nnum <> 1000 and ntext[-1] <> "s":
    ...
Run Code Online (Sandbox Code Playgroud)

我想这是一个现在被遗弃的语言标志.

究竟是什么意思,我应该用哪个(更近期的)标志替换它?

python syntax operators python-2.x

53
推荐指数
4
解决办法
4万
查看次数

isinstance和Mocking

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)

python unit-testing mocking

22
推荐指数
3
解决办法
1万
查看次数

标签 统计

python ×2

mocking ×1

operators ×1

python-2.x ×1

syntax ×1

unit-testing ×1