in the one case i have first, i want the variable to help the module decide which code to define the function with. the is not the actual code, just a fun example.
i think i have found a solution: set an environment variable.
i have done this definition of a function under conditional logic before to define functions differently based which version of python is running. this allowed me to work with the unicode type in python2 and the bytes type in python3. i call this split definition.
if yesdoit: def doit(): print('yes') return 'yes' else: def what(): returnthe code above is the typical uselessness you might see in school classes. it's just to show the concept's codability.
i think i have found a solution: set an environment variable.
i have done this definition of a function under conditional logic before to define functions differently based which version of python is running. this allowed me to work with the unicode type in python2 and the bytes type in python3. i call this split definition.
if str == bytes: def prthing(x): if isinstance(x,(str,unicode)): print x return elif isinstance(x,bytearray): print str(x) return else: print repr(x) return else: def prthing(x): if isinstance(x,str): return print(x) elif isinstance(x,(bytes,bytearray)): return print(''.join([chr(c) for c in x])) else: return print(repr(x))but i do have different kinds of needs for split definitions. now i have come to where it is a setting by the code doing the importing.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.