Python common error and solution

1. OSError: [Errno 22] Invalid argument.......

Open the file during file operation: with open ( "D: \ Job \ a.txt", "r") as fp: given as follows OSError: [Errno 22] Invalid argument: 'file path'

The reason: in python \ is the escape character

Solution: D: /Job/a.txt, that is not the direct use of forward slash backslash

2. self.host_info = "socket %s:%d" % (self.host, self.port) TypeError: %d format: a number is required

When connecting to the database to read the contents of the above error report

The reason: When the port number is read out a string

The solution: use what type int conversion, such as port = int (port)

 

Guess you like

Origin blog.csdn.net/chang_jinling/article/details/82854330