А затем мне нужно было добавить его в другой сценарий, в котором также была проблема с недопустимыми символами. Но это не сработало, ошибка с недопустимым символом все еще возникает, кажется, эта строка «dfC = dfC.applymap(remove_illegal_chars)», добавленная в другую функцию, не работала должным образом... есть какие-нибудь предложения?
Код: Выделить всё
#Here below is original code that works directly:
def remove_illegal_chars(s):
if isinstance(s, str):
return re.sub(r'[\x00-\x1F\x7F-\x9F]', '', s)
return s
df = df.applymap(remove_illegal_chars)
Код: Выделить всё
def remove_illegal_chars(s):
if isinstance(s, str):
return re.sub(r'[\x00-\x1F\x7F-\x9F]', '', s)
return s
def get_txt(instrFilePath):
try:
#
sys.path.insert(1, in_ModulePyFileFolderPath)
import A_Functions
df = A_Functions.add_to_main_DataFrame(instrFilePath)
df = df.applymap(remove_illegal_chars)
# ....lots other code skipped here as they work fine.....
except Exception as errorMessage:
returnError='Error Occurred while Parsing Receipt. Exception: '+str(errorMessage)
return returnError
Подробнее здесь: https://stackoverflow.com/questions/786 ... r-function