Функция удаления недопустимых символов не работает в другой функции.Python

Программы на Python
Anonymous
Функция удаления недопустимых символов не работает в другой функции.

Сообщение Anonymous »

Я добавил приведенный ниже код в сценарий, и он отлично работает, удаляя недопустимые символы.
А затем мне нужно было добавить его в другой сценарий, в котором также была проблема с недопустимыми символами. Но это не сработало, ошибка с недопустимым символом все еще возникает, кажется, эта строка «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)

#Here below is after being added into another script and didn't work, I think df = df.applymap(remove_illegal_chars) is not working

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```

Remove illeagal character function to be working inside another function, but I can't instal xlsxwriter


Подробнее здесь: https://stackoverflow.com/questions/786 ... r-function

Вернуться в «Python»