我正在尝试用Python编写一个excel公式,以便我可以执行一个excel API。
问题是我正在尝试用引号写一些东西,所以使用\但我得到了\'而不是我想要的'。我的代码如下。
j = [1, 2, 3, 4, 5]
h = []
for hh in j:
h.append(str(('=IFERROR(FDS(B')+('%d')%hh+(',"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C')+('%d')%hh+('&",,,')+('\'CURRENCY=LOCAL\'')+('")')))
raw_data2 = {'EPS EST': h}
问题围绕术语('\'CURRENCY=LOCAL\'')
。我希望它显示为'CURRENCY=LOCAL'
,但目前正在打印\'CURRENCY=LOCAL\'
。
答案 0 :(得分:2)
引导和跟踪\
只是在unicode对象中转义为u
的表示,它对数据没有任何影响 - 如下所示
j = [1, 2, 3, 4, 5]
h = []
for hh in j:
h.append(str(('=IFERROR(FDS(B')+('%d')%hh+(',"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C')+('%d')%hh+('&",,,')+("'CURRENCY=LOCAL'"+('")'))))
print h#See '\' is present
for t in h: #but here '\' is absent
print t
输出 -
['=IFERROR(FDS(B1,"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C1&",,,\'CURRENCY=LOCAL\'")', '=IFERROR(FDS(B2,"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C2&",,,\'CURRENCY=LOCAL\'")', '=IFERROR(FDS(B3,"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C3&",,,\'CURRENCY=LOCAL\'")', '=IFERROR(FDS(B4,"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C4&",,,\'CURRENCY=LOCAL\'")', '=IFERROR(FDS(B5,"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C5&",,,\'CURRENCY=LOCAL\'")']
=IFERROR(FDS(B1,"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C1&",,,'CURRENCY=LOCAL'")
=IFERROR(FDS(B2,"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C2&",,,'CURRENCY=LOCAL'")
=IFERROR(FDS(B3,"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C3&",,,'CURRENCY=LOCAL'")
=IFERROR(FDS(B4,"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C4&",,,'CURRENCY=LOCAL'")
=IFERROR(FDS(B5,"FE_ESTIMATE(EPS,MEAN,ANNUAL_ROLL,+1,"&C5&",,,'CURRENCY=LOCAL'")