Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
dictionary/hash and '1' versus 1
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Steven D'Aprano, post: 3206041"] # How to fix this broken function without modifying the source? def foo(arg): """Returns a string instead of a number.""" return "1" # oops I meant 1 _foo = foo # save a reference to original broken function foo = lambda *args, **kwargs: int(_foo(*args, **kwargs)) # and patch it And now you can use foo(arg) confident that it will always return an int like you expect. Modifications of this technique should be obvious. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
dictionary/hash and '1' versus 1
Top