May-01-2017, 05:24 PM
Hi,
I am defining an
My only issue - PyCharm does not recognize the structure of the generated object. Is there some way to force auto-completion for that kind of objects?
I am defining an
Enum
-style object as a wrapper for string constants1 2 3 4 5 6 7 8 9 |
import time, re, collections def make_enum( * enum_args, * * enum_kwargs): _tokenizer = lambda s: re.sub( '\W+' , '_' , s) enum_kwargs = {k.upper(): v for k, v in enum_kwargs.items()} enum_kwargs.update([(_tokenizer(s).upper(), s) for s in enum_args]) return collections.namedtuple( '_C_{:x}' . format ( hash (time.time())), enum_kwargs.keys())( * * enum_kwargs) C = make_enum( 'true' , 'false' , sentence = 'This is long' ) |
My only issue - PyCharm does not recognize the structure of the generated object. Is there some way to force auto-completion for that kind of objects?
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.