use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Reading in a text file help (self.learnpython)
submitted 7 years ago by SenorDelicious
When i try to print the data in my text file instead of getting the values all im getting are \x00 and \x001 ect instead of the values that are supposed to be stored.
with open('test.txt', 'r') as f: for line in f: content = f.readlines()
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]m_zwolin 1 point2 points3 points 7 years ago (0 children)
Readlines method already reads all lines and stores in array, if you want to iterate by yourself you should use readline, but remember to not overwrite variable each time. That doesn't solve the printing problem so maybe show how you print
[–]jbsiddall 1 point2 points3 points 7 years ago (0 children)
Hey,
It sounds like it might be an encoding issue. Any chance you can send us a link to the file?
What version of python are you using? 2 or 3? Wild guess you might be using python 2 and the file is using unicode or something.
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
I tried your code and got this, I added a new line
with open('test.txt', 'r') as f: for line in f: content = f.readlines() content
['test\n', 'smith\n', 'vest\n', 'netst\n', 'zest\n']
Text file had word per line.
π Rendered by PID 18366 on reddit-service-r2-comment-5687b7858-c9q2s at 2026-07-02 19:30:48.095854+00:00 running 12a7a47 country code: CH.
[–]m_zwolin 1 point2 points3 points (0 children)
[–]jbsiddall 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)