Home > Mobile >  python 2.7.5 why does this require an integer
python 2.7.5 why does this require an integer

Time:03-10

where why does this statement require an integer

with open('file, 'r', 'ignore'):

output

Traceback (most recent call last):
  File "PYdown.py", line 9, in <module>
    with open(links, 'r', 'ignore') as links:
TypeError: an integer is required

I've tried to find documentation to tell me why an integer is required but I couldn't find why open() needs an integer

CodePudding user response:

Based on the documentation

open(name[, mode[, buffering]])

1st variable filename 2nd open mode 3rd buffer type

"The optional buffering argument specifies the file’s desired buffer size: 0 means unbuffered, 1 means line buffered, any other positive value means use a buffer of (approximately) that size (in bytes). A negative buffering means to use the system default, which is usually line buffered for tty devices and fully buffered for other files. If omitted, the system default is used. 2"

These are the buffer values.

Seems like you are checking python 3 documentation based on the syntax you show.

Hope this is helpful.

CodePudding user response:

The third argument is buffering, which is an integer.

You can use the ignore string in the errors argument in Python 3

You can use it then as follows:

with open('file, 'r', errors='ignore'):

Check differences in the documentation for open in Python 2 and 3:

  • Related