I am having a text file contaning the following:
"int Function1 (int arg1, "0|1", char * arg2);
int Function2 (int arg1, " ", char * prt1);
..."
I need to open this file, split the each word and store it as global variable. I did this in Perl but now I need it in Python. I am new to Python. Give some idea to acheive this in Python.
kes_ee 0 Newbie Poster
Recommended Answers
Jump to PostIf by each "word", you mean strictly at every space, then you could read the file line by line, and perform this on every line:
fh = open('filename', 'r') for line in fh.readlines(): # use 'xreadlines()' if the file is large and you just want an iterator …
Jump to PostUse something like this:
s = "Function1 (text1) (text2) (text3) [text4]" print s.count('(') print s.count(')') print s.count('[') print s.count(']')
All 5 Replies
shadwickman 159 Posting Pro in Training
kes_ee 0 Newbie Poster
shadwickman 159 Posting Pro in Training
kes_ee 0 Newbie Poster
Lardmeister 461 Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.