So pflücken Sie ein Attribut in ein ObjektPython

Python-Programme
Anonymous
 So pflücken Sie ein Attribut in ein Objekt

Post by Anonymous »

Die Frage ist, wie ein Attribut einer Instanz innerhalb einer mit Anweisung angezeigt wird. Ich habe es mit dem folgenden Beispiel versucht, das nicht funktioniert. Es druckt wie im Kommentar. < /P>

Code: Select all

from mock import patch, PropertyMock

class Foo(object):
f = {'a': 1}

new_foo = Foo()

with patch.object(new_foo, 'f', new_callable=PropertyMock) as mock:
mock.return_value = {'b': 2}
print new_foo.f
# 

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post