PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 30, 2022

[FIXED] How to fix EOF Error when reading a file using with open()

 October 30, 2022     eof, python-3.x     No comments   

Issue

I am making a program to read something from a group of files, but I get an EOF error.

def readMem(memId):

    with open(memId, "r") as rf:
        memVal = memId.read()

I get the error at the with open(), (error persists even without the last line) but I cannot find out why. In my knowledge, there is no issue, I have even used this EXACT code in a different file.


Solution

You should call the read method of the file object rf instead:

def readMem(memId):
    with open(memId, "r") as rf:
        memVal = rf.read()


Answered By - blhsing
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing