Skip to content
Advertisement

Tag: python-2.7

Redefining python built-in function

I’m working on a python program and the author has written a function that looks like this This seems to work, even though str is a built in function and shouldn’t be used as a variable. What is actually happening here? My guess is str will no longer be usable as a function, but only in the scope of the

Using return value inside another function

I have these two functions: and When I run my script, it says that user_channel_number is not defined globally. How can I use user_channel_number inside the delete_events function? Answer Functions can not share their local variables. You can return the value from the first and pass it to the second: Or save value on the object:

subclassing dict; dict.update returns incorrrect value – python bug?

I needed to make a class that extended dict and ran into an interesting problem illustrated by the dumb example in the image below. Why is d.update() ignoring the class’s __getitem__? EDIT: This is in python2.7 which does not appear to contain collections.UserDict Thinking UserDict.UserDict is the equivalent I tried this, and it gets closer, but still behaves interestingly. Answer

Advertisement