Reading sub-string from a file
Smiley 4321
ssmile03 at gmail.com
Thu Feb 16 04:52:52 EST 2012
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!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120216/a26b3d68/attachment.html>
More information about the Python-list
mailing list