简体   繁体   中英

How to make a path from variables

 content = os.path.abspath("content")
for i in os.listdir(os.path.abspath("content")):
    path = str(i)
    bot.upload_photo(content "/" path, caption ="Technical Scripter Event 2019") 

SO, I need to make something like this.The program makes the files from the folder variables and I need to connect the path to it.

This line contains a syntax error:

bot.upload_photo(content "/" path, caption ="Technical Scripter Event 2019")

In order to concatenate content and path, you should use os.path.join :

bot.upload_photo(os.path.join(content,path), caption ="Technical Scripter Event 2019")

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