Skip to main content

All Questions

1 vote
1 answer
311 views

How to identify a dynamic input checkbox element through xpath using Selenium

Hello I need some help i'm using python last version with selenium. I can't reach an element input checkbox. Here is the input : <div class="info info13"> <input type="...
Aymeric's user avatar
  • 125
3 votes
3 answers
2k views

How to include a dict comprehension in an f-string?

Is there any way to use dict comprehension inside a fstring? THe case is the following: a = ['a', 'b', 'c', 'd'] list_comprehension = [v for v in a] my_f_string = f"dict comprehension {v:None for ...
GGChe's user avatar
  • 312
6 votes
2 answers
6k views

Is there an equivalent of an f-string in Google Sheets?

I am making a portfolio tracker in Google Sheets and wanted to know if there is a way to link the "TICKER" column with the code in the "PRICE" column that is used to pull JSON data ...
cryptoversion's user avatar
5 votes
2 answers
2k views

How can named expressions be interpreted in f-strings?

I am trying to use named expressions inside a f-string: print(f"{(a:=5 + 6) = }") Returns: (a:=5 + 6) = 11 But I am hoping for something like this: a = 11 Is that possible, by combining the walrus ...
Gustav Rasmussen's user avatar
3 votes
1 answer
480 views

What is the name of the internal function that "executes" an f-string?

I've read How do I convert a string into an f-string? and How to postpone/defer the evaluation of f-strings? and have seen many (working) solutions with exec to postpone the execution of an f-string, ...
Basj's user avatar
  • 46.6k
15 votes
3 answers
9k views

How to evaluate a variable as an f-string?

I would like to have a mechanism which evaluates an f-string where the contents to be evaluated are provided inside a variable. For example, x=7 s='{x+x}' fstr_eval(s) For the usage case I have in ...
Ben Mares's user avatar
  • 2,207
89 votes
6 answers
135k views

How can I use f-string with a variable, not with a string literal?

I want to use f-string with my string variable, not with string defined with a string literal, "...". Here is my code: name=["deep","mahesh","nirbhay"] ...
Deep Ghodasara's user avatar
9 votes
2 answers
8k views

Choose the number of decimal points in string interpolation

Is there a way to use a variable to decide the number of decimal points in literal string interpolation? for example if I have something like f'{some_float:.3f}' is there a way to replace the 3 with ...
Dan's user avatar
  • 45.8k
62 votes
3 answers
34k views

How do I convert a string into an f-string?

I was reading this blog post on Python's new f-strings and they seem really neat. However, I want to be able to load an f-string from a string or file. I can't seem to find any string method or other ...
piRSquared's user avatar
  • 295k
101 votes
6 answers
47k views

Is there a formatted byte string literal in Python 3.6+?

I'm looking for a formatted byte string literal. Specifically, something equivalent to name = "Hello" bytes(f"Some format string {name}") Possibly something like fb"Some format string {name}". Does ...
Enrico Borba's user avatar
  • 2,137
6 votes
1 answer
2k views

Why is this usage of python F-string interpolation wrapping with quotes?

Code in question: a = 'test' # 1) print(f'{a}') # test # 2) print(f'{ {a} }') # {'test'} # 3) print(f'{{ {a} }}') # {test} My question is, why does case two print those quotes? I didn't find ...
Connor Clark's user avatar
45 votes
5 answers
32k views

Transform string to f-string

How do I transform a classic string to an f-string? variable = 42 user_input = "The answer is {variable}" print(user_input) Output: The answer is {variable} f_user_input = # Here the ...
François M.'s user avatar
  • 4,278
110 votes
6 answers
80k views

f-strings vs str.format()

I'm using the .format() a lot in my Python 3.5 projects, but I'm afraid that it will be deprecated during the next Python versions because of f-strings, the new kind of string literal. >>> ...
nivhanin's user avatar
  • 1,928
214 votes
16 answers
68k views

How to postpone/defer the evaluation of f-strings?

I am using template strings to generate some files and I love the conciseness of the new f-strings for this purpose, for reducing my previous template code from something like this: template_a = "...
JDAnders's user avatar
  • 6,001