pipsik
pipsik

Reputation: 219

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?

Upvotes: 0

Views: 46

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121256

fname is None, not a string:

>>> 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.

Upvotes: 5

Related Questions