简体   繁体   中英

How can I use .format() with list in python?

import excel2img
import os 

filelist = [
'1R 1R 1R',
'24 54 994',
'9d 13 885',
]

file_name = "C:/Users/3315/Desktop/fdifndfd.xlsx"
img_name ='C:/Users/3315/Desktop/Weekly/company/{}.png' .format(filelist[1])
excel2img.export_img(file_name, img_name, "", "'{}'!A1:HO29") .format(filelist[1])



i want to use list element in format function to use this code as repeatable with for i in filelist: . but it keeps fail to use list data although print(filelist[1]) is possible.

I look through many papers but it doesn't deal with list in format function.Can anyone give me the solution?

here's error message Exception: Failed locating range '{}':A1:HO29

You're formatting the output of your export _img function, not the string you put into it.

That can't work. It's also fundamentally different than what you do in the lines above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM