Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- filename = 'test.txt'
- delimiter = '"'
- # opening file for read
- with open(filename) as fileobject:
- # read once, forget about memory insufficiency for sake of I\O
- filedata = fileobject.read()
- quote_positions = [] # tuples of quote indices
- QUOTESTART = None # explicit init
- for index, letter in enumerate(filedata):
- if letter == delimiter:
- if QUOTESTART:
- QUOTEEND = index
- quote_positions.append((QUOTESTART, QUOTEEND))
- QUOTESTART = None
- else:
- QUOTESTART = index + 1 # we dont need delimiter itself
- for position in quote_positions:
- START = position[0]
- END = position[1]
- quote = filedata[START:END]
- print(quote)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement