Message252386
ast.Attribute node actually means "the atribute of something", ie. the node includes this "something" as subnode.
> How can I get the position of 'bar' in 'foo.bar'?
I don't know a good way for this, because bar is not an AST node for Python. If Python AST nodes included the information about where a node ends in source, I would take the ending col of node.value (foo in your example), and added 2.
In my own program (http://thonny.cs.ut.ee, it's a Python IDE for beginners) I'm using a really contrived algorithm for determining the end positions of nodes. See function mark_text_ranges here: https://bitbucket.org/plas/thonny/src/b8860704c99d47760ffacfaa335d2f8772721ba4/thonny/ast_utils.py?at=master&fileviewer=file-view-default
I'm not happy with my solution, but I don't know any other ways. |
|
Date |
User |
Action |
Args |
2015-10-06 10:56:59 | Aivar.Annamaa | set | recipients:
+ Aivar.Annamaa, brett.cannon, georg.brandl, ncoghlan, benjamin.peterson, flox, Mark.Shannon, scummos, python-dev, rnovacek |
2015-10-06 10:56:58 | Aivar.Annamaa | set | messageid: <1444129018.99.0.0687907360799.issue21295@psf.upfronthosting.co.za> |
2015-10-06 10:56:58 | Aivar.Annamaa | link | issue21295 messages |
2015-10-06 10:56:58 | Aivar.Annamaa | create | |
|