Skip to content
Advertisement

I keep getting a read issue [Errno 22] Invalid argument

I have tried putting the (r"F:Server ... "r") it says:

file.write(float(u) + 'n')
TypeError: unsupported operand type(s) for +: 'float' and 'str'.

When I don’t put the r were it is it will double \ on me saying:

read issue [Errno 22] Invalid argument: 'F:\Server\Frames\Server_Stats_GUIx08yteS-F_FS_Input.toff'.

Here is my code

JavaScript

Advertisement

Answer

You have two separate errors here.

1: Filename with Escape Characters

This error:

read issue [Errno 22] Invalid argument: ‘F:ServerFramesServer_Stats_GUIx08yteS-F_FS_Input.toff’.

…is in the open() function.

Your filename has an escape character in it. ‘b’ is being evaluated to ‘x08’ (backspace). The file is not found, which throws an error.

a) To ignore escape characters, you can either double the backslash:

JavaScript

or b) use r (rawstring) as a prefix to the string:

JavaScript

You’ve used the second way, which fixed that issue.

2: TypeError on write()

The next error:

file.write(float(u) + ‘n’) TypeError: unsupported operand type(s) for +: ‘float’ and ‘str’.

is in the write() function.

You’re treating a float as a string. You need to a) convert it to a string before trying to append the newline:

JavaScript

or b) use string formatting:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement