将r与包含希腊字母的字符串arg串联

问题描述 投票:0回答:1

正如下面的示例所示,我想将r与包含希腊字母的字符串参数连接起来,以避免unicode错误

book = xlrd.open_workbook(r'C:\a_directory_with_greek_letters_inside.xlxs')

但是在此代码中,该函数未按我期望的那样连接r和字符串:

url='C:\a_directory_with_greek_letters_inside.xlxs'

def fnc(arg):
   book = xlrd.open_workbook(r+arg))
   return book

fnc(url)

我该如何解决?

python python-3.x xlrd
1个回答
0
投票
不确定您要避免的Unicode错误,但是您可以这样做:

rf'{arg}'

赞:

url='C:\a_directory_with_greek_letters_inside.xlxs' def fnc(arg): book = xlrd.open_workbook(rf'{arg}') return book fnc(url)

© www.soinside.com 2019 - 2024. All rights reserved.