Well I knew that this works fine, even if I feel a bit guilty to do this, and better is: foo = 'bar' if some_condition else 'baz' Anyway for me the suprise is that something that is defined *later* at the module scope is found in a function which is defined *earlier*.