Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53674
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <vincent.vandevyvre@swing.be> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'importing': 0.05; 'interpreter': 0.05; 'url:launchpad': 0.05; 'column': 0.07; 'nested': 0.07; 'subject:code': 0.07; 'subject:file': 0.07; '"if': 0.09; 'python': 0.11; 'def': 0.12; "%s'": 0.16; 'from:addr:swing.be': 0.16; 'from:addr:vincent.vandevyvre': 0.16; 'from:name:vincent vande vyvre': 0.16; 'message-id:@swing.be': 0.16; 'oqapy': 0.16; 'paqager': 0.16; 'received:mobistar.be': 0.16; 'stringio': 0.16; 'subject:comment': 0.16; 'tokenize': 0.16; 'tokens:': 0.16; 'url:oqapy': 0.16; 'url:paqager': 0.16; 'url:qarte': 0.16; 'v.v.': 0.16; '\xe9crit': 0.16; 'subject: ?': 0.16; 'module': 0.19; 'import': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'script': 0.25; '(for': 0.26; 'header:In-Reply- To:1': 0.27; 'comment': 0.34; 'false': 0.36; 'possible': 0.36; 'auto': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:- 60': 0.39; 'how': 0.40; 'email addr:gmail.com': 0.63; 'subject:source': 0.84; 'yourself,': 0.95 |
| Date | Thu, 05 Sep 2013 07:33:18 +0200 |
| From | Vincent Vande Vyvre <vincent.vandevyvre@swing.be> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130803 Thunderbird/17.0.8 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: how to detect comment in source code file ? |
| References | <1fbab13d-bb98-465e-affe-f2fddeec8138@googlegroups.com> |
| In-Reply-To | <1fbab13d-bb98-465e-affe-f2fddeec8138@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.77.1378359658.5461.python-list@python.org> (permalink) |
| Lines | 30 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1378359658 news.xs4all.nl 15865 [2001:888:2000:d::a6]:35742 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:53674 |
Show key headers only | View raw
Le 04/09/2013 08:05, vnkumbhani@gmail.com a écrit :
> how works python interpreter for finding comment ?
> if possible find nested comment ?
If you need to find it yourself, you can use the module tokenize.
ex.:
---------------------------------------------------------------
import tokenize
from StringIO import StringIO
script = "# importing comment\nfrom foo import baz"\
"if baz.vers < 2:\n AUTO = False # Retrocompatibility"
def find_comment():
print script
cmt = tokenize.COMMENT
tokens = tokenize.generate_tokens(StringIO(script).readline)
for typ, _, begin, _, _ in tokens:
if typ == cmt:
print 'Find comment line %s at column %s' % begin
find_comment()
---------------------------------------------------------------
(for Python 3 import StringIO from io)
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
how to detect comment in source code file ? vnkumbhani@gmail.com - 2013-09-03 23:05 -0700
Re: how to detect comment in source code file ? Ben Finney <ben+python@benfinney.id.au> - 2013-09-04 17:02 +1000
Re: how to detect comment in source code file ? Paul Rudin <paul@rudin.co.uk> - 2013-09-04 08:18 +0100
Re: how to detect comment in source code file ? Steven D'Aprano <steve@pearwood.info> - 2013-09-05 01:56 +0000
Re: how to detect comment in source code file ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-09-04 23:40 -0400
Re: how to detect comment in source code file ? Piet van Oostrum <piet@vanoostrum.org> - 2013-09-05 08:11 -0400
Re: how to detect comment in source code file ? Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-09-05 07:33 +0200
csiph-web