Python Forum
filing in Python 3.7 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: filing in Python 3.7 (/thread-21950.html)



filing in Python 3.7 - ArryMan - Oct-22-2019

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.


RE: filing in Python 3.7 - buran - Oct-22-2019

is the whole file one line (it looks like)? can you post part of the file content in output tags


RE: filing in Python 3.7 - ArryMan - Oct-22-2019

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"'] >>>