Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20509
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'lines.': 0.05; 'names.': 0.07; 'python': 0.08; 'filename': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'snippets': 0.09; 'subject:string': 0.09; 'substring': 0.09; 'def': 0.13; 'debugging': 0.13; 'subject:file': 0.13; 'void': 0.15; "'r')": 0.16; '-1:': 0.16; '.py': 0.16; '4321': 0.16; 'char,': 0.16; 'except:': 0.16; 'filename,': 0.16; 'hint:': 0.16; 'int);': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.18; 'int': 0.18; 'written': 0.19; 'posting': 0.20; 'suggest': 0.20; 'from:addr:web.de': 0.23; 'int,': 0.23; 'that!': 0.23; 'ignore': 0.24; 'extract': 0.24; 'fix': 0.25; 'code.': 0.26; 'code': 0.26; 'function': 0.27; '-----': 0.28; "skip:' 10": 0.29; 'problem': 0.29; 'print': 0.29; 'iterating': 0.30; '---': 0.31; 'remaining': 0.32; 'actual': 0.32; '----': 0.32; 'there': 0.33; 'instead': 0.33; 'file': 0.34; 'header:X-Complaints-To:1': 0.34; 'skip:# 10': 0.34; 'be,': 0.34; 'try:': 0.34; 'to:addr:python-list': 0.35; 'received:org': 0.36; 'skip:" 10': 0.37; 'using': 0.37; 'could': 0.38; 'characters': 0.39; 'that.': 0.39; 'subject:from': 0.39; 'change': 0.40; 'might': 0.40; 'to:addr:python.org': 0.40; 'your': 0.61; 'below': 0.62; 'here.': 0.64; 'here': 0.64; 'wish': 0.68; 'onwards': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Reading sub-string from a file |
| Date | Thu, 16 Feb 2012 11:25:49 +0100 |
| Organization | None |
| References | <CAJ1erZ1izVQVHQj3tt4y5HoumQv0bM9qDp40fMehKzYewnfUVQ@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p5084b8ad.dip.t-dialin.net |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5883.1329387966.27778.python-list@python.org> (permalink) |
| Lines | 66 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1329387966 news.xs4all.nl 6948 [2001:888:2000:d::a6]:38389 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:20509 |
Show key headers only | View raw
Smiley 4321 wrote:
> I am a python newbie.
Welcome!
> Let's say I have a filename (test.conf) as below -
>
> ----
> int Apple(int, int);
> void Jump_OnUnload(float, int);
> int Jockey_Apple_cat_1KK(float, int, char, int);
> int Jockey_Apple_cat_look(int, float, int, int);
> int Jockey_Apple_cat_test_ki21es(int, int, int, int);
> int Jockey_Apple_cat_tarLK12OU(void, int, int, int);
> ---
>
> Here substring "Jockey_Apple_cat" is common from 3rd line onwards as a
> function name. I wish to extract ONLY that function name which has
> 'Jockey_Apple_cat' as a substring and ignore remaining function names.
>
> The program .py written is -
>
> -----
> ---
> #!/usr/bin/python
>
> def foo(filename):
> try:
> one = open(filename, 'r')
> except:
> print filename, 'cannot be open.'
>
> AllLines = one.readline()
>
> for eachLine in AllLines:
> start = eachLine.find('Jockey_Apple_cat')
> if start != -1:
> finish = eachLine.find ('(')
> print eachLine[start:finish]
>
> handle.close()
>
> set_foo("test.conf")
> -----
>
> I did perform debugging using pdb, it only reads all the lines.
There are errors in the above that suggest that you retyped your actual
code. Don't do that! Always use cut and paste for code snippets you are
posting here.
As to what the problem in your actual code might be, here's a hint:
You could be iterating over the characters of the first line of the file
instead of the lines. Change
> AllLines = one.readline()
>
> for eachLine in AllLines:
to
for eachLine in one:
to fix that.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Reading sub-string from a file Peter Otten <__peter__@web.de> - 2012-02-16 11:25 +0100
csiph-web