Article From:https://segmentfault.com/q/1010000012150237
Question:

Directly use src_read=pd.read_csv (src_dir+ “” +src_file_nm “) OSError: Initializing from file failed


But it’s OK with open
f=open(src_dir+”\”+src_file_nm)
src_read=pd.read_csv(f,dtype=”str”)

Why is this?

Answer 0:

Because the first parameter of read_csv is:

filepath_or_buffer : str, pathlib.Path, py._path.local.LocalPath or any object with a read() method (such as a file handle or StringIO)

So you can accept the IO object after open, and the open function is Chinese name, so there will be no open error.

Leave a Reply

Your email address will not be published. Required fields are marked *