Skip to content
Advertisement

Tag: f-string

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