0

hii..m stuck in an issue...and need a help

I have Try.c file having contents

ValidateFunction()
{
......
......
print
}
....

I want to print data between the braces {....}. Also i do not want to read the contents of file line by line because file is of very big size.How can I get this in Python?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by pyTony
0

You would have to read each record ("lines" is a word processing term and many types of files do not have lines) until you reach the first "{". Then store or print the records until the next "}". Then switch off an indicator. Note that you might want to count the number of "{"s and the number of "}"s to allow for multiple levels, and when they are equal set the indicator to False. To stop the file read would be something like this pseudo-code:

reading = True
while reading:
   fp.readline()
   if "}" is found or end_of_file:
       reading = False

Edited by woooee: n/a

0

Also the count of { can be used with itertools.groupby to divide the file in parts. Be careful about what you call very big size file. At least the file size should be in hundreds of megabytes to call it huge these days.

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.