Reputation: 71
I am trying to write an excel formula in Python so I can execute an excel API.
The issue is that I am trying to write something in quotations so using \ but I am getting \' instead of what I want '. My code is below.
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}
The issue is around the term ('\'CURRENCY=LOCAL\'')
. I want it to appear 'CURRENCY=LOCAL'
but currently it is printing \'CURRENCY=LOCAL\'
.
Upvotes: 2
Views: 171
Reputation: 5292
Leading and traling \
is just a representation for escaping just like u
in unicode object it has not any effect on data- try as below
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
Output-
['=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'")
Upvotes: 2