Jun-17-2019, 06:37 AM
(This post was last modified: Jun-17-2019, 08:17 AM by Gribouillis.)
Skaperen Wrote:but nearly all of them involve a number of variables in the local context, such as emulating a terminal screen.Again, the normal pythonic solution is to use instance variables and not variables in the local context. For example
class CookingPot: pass def my_func(lines): pot = CookingPot() for line in lines: for c in line: if c == 'a': pot.spam = 'foo' elif c == 'b': pot.spam = 'bar' elif c == 'c': bacon(pot) def bacon(pot): pot.spam = 'qux'Also remember that the mapping returned by locals() is not writable.