Python Forum

Full Version: filing in Python 3.7
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have an eternal file in this format: "4b32j","aq8","71yt346" only much longer. I want to load each item one at a time for processing. I can't find how to do this, so I tried to load the whole file and split it up. But it loads as a complete string anyway. I used the code below:

path = '/Users/davidellis/Documents/Python 3 Files/docCodes_File.txt'
test = open(path, 'r')
play = [test.read()]
test.close()
print (play)
This just gives me [' "4b32j","aq8","71yt346" ']. If I load it as a string, it still comes in as strings within a string.
Can you suggest how I could open the file and load just one item at a time sequentially, please? I've searched Python help, but could only find material on loading specific lengths or lines, not items.
is the whole file one line (it looks like)? can you post part of the file content in output tags
For simplicity and to keep the file size down, I just created this text file and saved it as Test_File:

"This", "file", "was", "created", "to", "practice", "file", "operations", "in", "Python"

Here's the result of running the code as already posted:

Output:
>>> ===== RESTART: /Users/davidellis/Documents/Python 3 Files/scratchPad.py ===== ['"This", "file", "was", "created", "to", "practice", "file", "operations", "in", "Python"'] >>>