Reading sub-string from a file

Smiley 4321 ssmile03 at
Thu Feb 16 04:52:52 EST 2012


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 -


def foo(filename):
                one = open(filename, 'r')
                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]



I did perform debugging using pdb, it only reads all the lines.

Plz help!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list