Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20508

Re: Reading sub-string from a file

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
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; 'help!!': 0.09; 'subject:string': 0.09; 'substring': 0.09; 'verbatim': 0.09; 'am,': 0.12; 'def': 0.13; 'debugging': 0.13; 'subject:file': 0.13; '16,': 0.15; 'void': 0.15; "'r')": 0.16; '-1:': 0.16; '.py': 0.16; '4321': 0.16; 'char,': 0.16; 'except:': 0.16; 'filename,': 0.16; 'int);': 0.16; 'skip:\xc2 30': 0.16; 'skip:\xc2 40': 0.16; 'undesirable': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'int': 0.18; 'written': 0.19; 'cheers,': 0.20; 'suggest': 0.20; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; '(or': 0.22; 'feb': 0.22; 'received:209.85.212.46': 0.23; 'received:mail- vw0-f46.google.com': 0.23; 'int,': 0.23; 'defined': 0.24; 'ignore': 0.24; 'extract': 0.24; 'cc:2**0': 0.26; 'code': 0.26; 'all,': 0.27; 'function': 0.27; 'variable': 0.28; '-----': 0.28; 'posted': 0.29; 'message-id:@mail.gmail.com': 0.29; "skip:' 10": 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'chris': 0.30; '(e.g.': 0.31; '---': 0.31; 'remaining': 0.32; 'thu,': 0.32; 'actual': 0.32; '----': 0.32; "isn't": 0.33; 'received:209.85.212': 0.33; 'instead': 0.33; 'skip:# 10': 0.34; 'try:': 0.34; 'post': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'skip:" 10': 0.37; 'using': 0.37; 'received:209.85': 0.38; 'several': 0.38; 'subject:from': 0.39; 'received:209': 0.39; 'greatly': 0.40; 'being': 0.40; 'your': 0.61; 'you.': 0.62; 'below': 0.62; 'here': 0.64; 'wish': 0.68; '8bit%:100': 0.69; 'skip:\xc2 10': 0.74; 'assisting': 0.77; 'code;': 0.84; 'sender:addr:chris': 0.84; 'onwards': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=0KgdVCFdz9oXsW9+cIFEGI99WhR7jLHU2OgN82AhasE=; b=Bo6QQBTHZ6fjo7g3ZPWuJ5t9cRoqX3UC/JMB7ZmkHZYygetV7cbpPO7BO+t5xEZo8Z 9n/poKbxfhhHnzy2qI1PEEdbYL1AwLga3NdhRvusWQTbB4fgnboIfvb8rnmCBSKAceuM /apwiypvPjrMbWHm/jBuejfFmdKdylhsg+cro=
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <CAJ1erZ1izVQVHQj3tt4y5HoumQv0bM9qDp40fMehKzYewnfUVQ@mail.gmail.com>
References <CAJ1erZ1izVQVHQj3tt4y5HoumQv0bM9qDp40fMehKzYewnfUVQ@mail.gmail.com>
Date Thu, 16 Feb 2012 02:24:49 -0800
X-Google-Sender-Auth xgNH6wh-karUU8QjqcPWMFij-rg
Subject Re: Reading sub-string from a file
From Chris Rebert <clp2@rebertia.com>
To Smiley 4321 <ssmile03@gmail.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Gm-Message-State ALoCoQnsWLWdXGyBQj2JCwPjKAesO8KRkRrWay8YHkRval5JXBn5e8NBcnKHB5Ivyy7z1nbRPwLt
Cc python-list@python.org
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.5882.1329387892.27778.python-list@python.org> (permalink)
Lines 67
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1329387892 news.xs4all.nl 6897 [2001:888:2000:d::a6]:36867
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20508

Show key headers only | View raw


On Thu, Feb 16, 2012 at 1:52 AM, Smiley 4321 <ssmile03@gmail.com> wrote:
> All,
>
> I am a python newbie.
>
> 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.
>
> Plz help!!

Several oddities in the code you posted (e.g. you defined foo() but
instead call set_foo(); the `handle` variable comes out of nowhere)
suggest that it isn't your actual code; this greatly hinders us in
assisting you. Please post your /actual/ code verbatim (or as much of
it as you can with as few modifications as you can).
Also, avoid using "plz" in the future; it's gotten a reputation for
being associated with undesirable folk.

Cheers,
Chris

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Reading sub-string from a file Chris Rebert <clp2@rebertia.com> - 2012-02-16 02:24 -0800

csiph-web