macropy

Adding Macros to Python

我与影子孤独终老i 提交于 2019-12-20 16:47:11
问题 I would like to invoke the following code in-situ wherever I refer to MY_MACRO in my code below. # MY_MACRO frameinfo = getframeinfo(currentframe()) msg = 'We are on file ' + frameinfo.filename + ' and line ' + str(frameinfo.lineno) # Assumes access to namespace and the variables in which `MY_MACRO` is called. current_state = locals().items() Here is some code that would use MY_MACRO : def some_function: MY_MACRO def some_other_function: some_function() MY_MACRO class some_class: def some

Can literals in Python be overridden?

烂漫一生 提交于 2019-12-18 04:40:13
问题 Couldn't find a way to phrase the title better, feel free to correct. I'm pretty new to Python, currently experimenting with the language.. I've noticed that all built-ins types cannot be extended with other members.. I'd like for example to add an each method to the list type, but that would be impossible. I realize that it's designed that way for efficiency reasons, and that most of the built-ins types are implemented in C. Well, one why I found to override this behavior is be defining a

Can literals in Python be overridden?

ぐ巨炮叔叔 提交于 2019-11-29 06:16:09
Couldn't find a way to phrase the title better, feel free to correct. I'm pretty new to Python, currently experimenting with the language.. I've noticed that all built-ins types cannot be extended with other members.. I'd like for example to add an each method to the list type, but that would be impossible. I realize that it's designed that way for efficiency reasons, and that most of the built-ins types are implemented in C. Well, one why I found to override this behavior is be defining a new class, which extends list but otherwise does nothing. Then I can assign the variable list to that new