Skip to content
Advertisement

Python Telegram Bot – Calling variable in URL?

am having difficulty calling a variable as part of the url in a message I intend to send via the Python Telegram bot. Due to the nature of my code, the ‘webpage’ variable varies and the url has to be called as a variable. Placing the `url’ variable in curly brackets did not work and some searching online has been in vain. Appreciate any pointers.

JavaScript

Advertisement

Answer

Try this:

JavaScript

The f before the " causes the {url} to be parsed, otherwise it is handled as a simple string and {} are not getting replaced.

You can read more details about “Formatted String Literals” or simple “f-strings”, e.g. here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement