简体   繁体   English

打开文件时出错。 蟒蛇

[英]Error in opening of file. Python

I trying to open file and met some problem: 我试图打开文件,遇到了一些问题:

TypeError: coercing to Unicode: need string or buffer, NoneType found

Here is the code example: 这是代码示例:

a = open(fname, "rb").read(255)

Whats wrong with the code? 代码有什么问题?

fname is None , not a string: fnameNone ,不是字符串:

>>> open(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: coercing to Unicode: need string or buffer, NoneType found

You'll have to fix how you set fname or explicitly guard against it being None . 您必须修复设置fname或者明确地防止它为None

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM