I have this piece of code i’m using for a telegram bot:
r = requests.post("https://api.telegram.org/botMY_BOT_ID/sendPhoto?chat_id=MY_CHAT_ID",files=stuff)
print(r.status_code)
print(r.content)
Theres any way to change the "files=stuff" to "data=stuff" depending on the type of "stuff"(bytes or string), without writing another requests line ?
2
Answers
Use a
dict
display that evaluates an expression to generate the correct keyword.where
kind_of_stuff
is a function that returns'file'
or'data'
as appropriate based on the type ofstuff
.Maybe something like this?