Python Error: 'invalid literal for int() with base 10: '\ufeff94352'' - How to Fix
This error message indicates that the code is trying to convert a string into an integer using the int() function, but the string contains non-numeric characters that cannot be converted into an integer. The '\ufeff' character at the beginning of the string is a byte order mark that can cause issues when trying to convert the string to an integer.
To fix this error, you can remove the byte order mark from the string and then convert it to an integer:
s = '\ufeff94352'
s = s.strip('\ufeff') # remove byte order mark
n = int(s) # convert to integer
Alternatively, if the string may contain non-numeric characters other than the byte order mark, you can use error handling to handle the conversion:
s = '\ufeff94352'
try:
n = int(s)
except ValueError:
print('Invalid input')
原文地址: https://www.cveoy.top/t/topic/omLF 著作权归作者所有。请勿转载和采集!