Skip to content
Advertisement

Tag: f-string

Get variables from function input and text after

So id like to make varibles from my function input So basically, the if statement should check if the varible is True or not. And i want to use the function input + ”-outcome” to check. Here is an example, to make you understand my problem better! I’ve tried to find a solution but don’t find it anywhere Thanks! Answer

Is it possible to use whitespace in format specifier

If I have following print statements: I will get a nice border around my “Hello World” but with dots: If I use a ‘ ‘ instead of the . in the second to fourth print statement, I will get a ValueError: Invalid format specifier. How can replace the dot with whitespace or any other ascii symbol? Answer Isn’t it enough

Execute f-string in function

I have a and want to replace all tokens starting with with a new token I wrote a function: If I execute the lines separately it works. But the function itself doesn’t work. I’d expect How can I “exec” f-string in a function? Answer You are overcomplicating this. Simply reassign x: But it’s probably easier to rewrite the function similar

Python variable file path and string prefixes

Using tkinter to select output folder for processed files. Would like to use file_output and x as variables for my file path, My attempt: This does not work in my program. The output I need is I am reading the docs https://docs.python.org/3/reference/lexical_analysis.html#grammar-token-stringprefix Still don’t understand how to escape or a workaround, Help would be much appreciated. Answer you can easily

How do I format a date and also pad it with spaces?

Formatting appears to work differently if the object you’re formatting is a date. returns i.e. it has the padding. If I now do this: then the response is Which is obviously not what I want. I’ve tried various other combinations where I put in the date format as well, but all it does is draw the date out and then

Why does `'{x[1:3]}’.format(x=”asd”)` cause a TypeError?

Consider this: What could be the cause for this behavior? Answer An experiment based on your comment, checking what value the object’s __getitem__ method actually receives: Output (Try it online!): So while the 4 gets converted to an int, the 4:6 isn’t converted to slice(4, 6, None) as in usual slicing. Instead, it remains simply the string ‘4:6’. And that’s

Advertisement