[Python-Dev] elementtree in stdlib
Nick Coghlan
ncoghlan at gmail.com
Fri Apr 7 15:26:42 CEST 2006
Georg Brandl wrote:
> Greg Ewing wrote:
>> Trent Mick wrote:
>>
>>> try:
>>> import xml.etree.ElementTree as ET # in python >=2.5
>>> except ImportError:
>> > ... etc ad nauseam
>>
>> For situations like this I've thought it might
>> be handy to be able to say
>>
>> import xml.etree.ElementTree or cElementTree or \
>> elementtree.ElementTree or lxml.etree as ET
>
> Suppose I wanted to implement that, what would be the best strategy
> to follow:
> - change handling of IMPORT_NAME and IMPORT_FROM in ceval.c
> - emit different bytecodes in compile.c
> - directly create TryExcept AST nodes in ast.c
Definitely option 3, since you only have to modify the parser and the AST
compiler.
To change it in compile.c, you have to first modify the parser, the AST
definition and the AST compiler in order to get the info to the bytecode compiler.
To change it in ceval.c, you have to first modify the parser, the AST
definition, the AST compiler and the bytecode compiler in order to get the
info to the eval loop.
Given that import statements aren't supposed to be in time critical code, go
for the easy option :)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list