Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16557
| Date | 2011-12-02 17:01 +0000 |
|---|---|
| From | Andrea Crotti <andrea.crotti.0@gmail.com> |
| Subject | Re: python 2.5 and ast |
| References | (4 earlier) <4ed4c2ce$0$29988$c3e8da3$5496439d@news.astraweb.com> <4ED4E35E.6090405@gmail.com> <mailman.3166.1322676221.27778.python-list@python.org> <4bbaa89c-55d2-40d1-91fb-cb00c3f2239a@s4g2000yqk.googlegroups.com> <4ED902CA.7090404@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3231.1322845312.27778.python-list@python.org> (permalink) |
And on a related topic, how can I actually detect other types of
imports, for example
__import__
Doing a dump I get this:
In [113]: ast.dump(ast.parse('__import__("module")'))
Out[113]: "Module(body=[Expr(value=Call(func=Name(id='__import__',
ctx=Load()), args=[Str(s='module')], keywords=[], starargs=None,
kwargs=None))])"
So the visitor should be quite smart, and the string passed can't be
always be done.
I think the easiest way is just to use regexp and look for them warning
the user that there might be other
stupid imports, the harder way is to try to detect it and if the string
passed is actually known at compile-time
use it, otherwise warn the user.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: python 2.5 and ast Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-29 09:51 +0000
Re: python 2.5 and ast Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-29 11:32 +0000
Re: python 2.5 and ast Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-29 13:51 +0000
Re: python 2.5 and ast Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-11-30 18:03 +0000
Re: python 2.5 and ast DevPlayer <devplayer@gmail.com> - 2011-12-02 07:18 -0800
Re: python 2.5 and ast Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-12-02 16:54 +0000
Re: python 2.5 and ast Andrea Crotti <andrea.crotti.0@gmail.com> - 2011-12-02 17:01 +0000
csiph-web