Aivar Annamaa added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21295>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to