Skip to content
Advertisement

Extract parameters from variable length python f-string

Using Python 3.6

I have an f-string in main that looks like

JavaScript

used in the following function call send_mail(title, message, to, from)

I am not allowed to change the function call.

The question is, inside send_email can I extract the folder, and host variables from the f-string?

I would normally try something like:

JavaScript

but folder and host are both going to be variable length.

Advertisement

Answer

you can do a combination of split and slice like this :

JavaScript

output :

JavaScript

I also work with spaces and with ” on ” in the folder name if you do an other trick :

JavaScript

output :

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