This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Aivar.Annamaa
Recipients Aivar.Annamaa, Mark.Shannon, benjamin.peterson, brett.cannon, flox, georg.brandl, ncoghlan, python-dev, rnovacek, scummos
Date 2015-10-06.10:56:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1444129018.99.0.0687907360799.issue21295@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-10-06 10:56:59Aivar.Annamaasetrecipients: + Aivar.Annamaa, brett.cannon, georg.brandl, ncoghlan, benjamin.peterson, flox, Mark.Shannon, scummos, python-dev, rnovacek
2015-10-06 10:56:58Aivar.Annamaasetmessageid: <1444129018.99.0.0687907360799.issue21295@psf.upfronthosting.co.za>
2015-10-06 10:56:58Aivar.Annamaalinkissue21295 messages
2015-10-06 10:56:58Aivar.Annamaacreate