Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
47 views

What is the correct way to define set/dictionary comprehension in f-strings, so that flake8 does not complain? Currently I get the following errors: echo 'f"{ {k for k in []} }"' | flake8 - ...
dgeorgiev's user avatar
  • 941
0 votes
1 answer
224 views

I'm currently following this Python course course from Harvard. At the point in the video, the instructor shows that the following code should raise a SyntaxError because of the conflicting double ...
Matteo's user avatar
  • 71
3 votes
2 answers
208 views

I wrote a subclass of Decimal to represent an amount of money. I wrote a custom __str__ to display the currency along with a sign format. My method works when calling str() but in a f-string somehow ...
Antoine Gallix's user avatar
1 vote
2 answers
93 views

Working: #!/usr/bin/python3 import re path = "/a/b/c/e72cc82c-e83a-431c-9f63-c8d80eec9307" if re.match(r"/a/b/c/[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$&...
Qiang Xu's user avatar
  • 4,921
2 votes
1 answer
111 views

When using a backslash followed by three integers, Python interprets them as an octal value: # A backslash followed by three integers will result in an octal value: txt = "\110\145\154\154\157&...
K4zo's user avatar
  • 33
3 votes
2 answers
81 views

This script: import numpy as np a = np.array([2, 3, 1, 9], dtype='i4') print(a) print(f'{a=}') produces: [2 3 1 9] a=array([2, 3, 1, 9], dtype=int32) Is there a way to get just a=[2 3 1 9] from {a=}...
Paul Jurczak's user avatar
  • 8,708
2 votes
1 answer
187 views

import numpy as np number = np.float32(0.12345678) assert str(number) == "0.12345678" assert f"{number}" == "0.12345678359270096" Why is this different when converting ...
Noushadali's user avatar
1 vote
1 answer
70 views

My question is very simple, but I can't find how to do it in the Snakemake documentation. Let's say I have a very long string to expand, like : rule all: input: expand("sim_files/test_nGen{ngen}...
Kiffikiffe's user avatar
3 votes
3 answers
167 views

I need to format a command line where some parameters come from simple variables, and others are the result of a longer expression. Python f-strings work well for the variables, and I'm using a printf-...
patraulea's user avatar
  • 1,014
0 votes
4 answers
212 views

I am trying to manipulate a file name to remove an underscore. final_name = '{0}{1}{2}_{4}_new'.format(*filename.split('_')) The filename is something like - 2024_10_10_091530_xyz_new.txt and the ...
BSachin's user avatar
  • 21
0 votes
2 answers
438 views

for a class I'm trying to write a python program. One of the lines tries to use an f string to report the value of a key ('cost') inside of a dictionary ('espresso') that is inside another dictionary ...
user3573647's user avatar
14 votes
4 answers
2k views

I'm learning how Python f-strings handle formatting and came across this syntax: a = 5.123 b = 2.456 width = 10 result = f"The result is {(a + b):<{width}.2f}end" print(result) This ...
S_D's user avatar
  • 182
0 votes
3 answers
252 views

print can nicely unpack a tuple removing brackets and commas, e.g. a = (0, -1, 1) print(*a) produces 0 -1 1. Trying the same with f-strings fails: print(f'{*a}') The closest f-string option I found ...
Paul Jurczak's user avatar
  • 8,708
1 vote
1 answer
1k views

I'm trying to format a datetime object in Python using either the strftime method or an f-string. I would like to include the time zone offset from UTC with a colon between the hour and minute. ...
E_Cross's user avatar
  • 33
0 votes
2 answers
514 views

I'm working with Python 3.12 and recently added mypy type-checking to my project. I've encountered an odd issue where mypy throws a syntax error for certain f-strings in my code, specifically those ...
Cornelius Roemer's user avatar

15 30 50 per page
1
2 3 4 5
46