Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
145 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
  • 93
1 vote
2 answers
87 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,881
3 votes
2 answers
70 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,630
1 vote
1 answer
62 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
0 votes
4 answers
146 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
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
2 votes
1 answer
816 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
  • 43
1 vote
5 answers
184 views

I want to create an f-string that combines two strings, prepending a '.' character to the second if it is not empty. reference = "file" modifier = "read" print(f"unknown ...
creative-resort's user avatar
0 votes
1 answer
199 views

I'm confused as to why a local pylint check ignores the following error, but an apparently identical pylint check as part of a GitHub Actions workflow raises a syntax error. I have a small Python test ...
semuadmin's user avatar
0 votes
2 answers
102 views

I would like to set the formatting of a large integer in an fstring programmatically. Specifically, I have an integer that can span several orders of magnitude and I'd like to print it using the ...
Ziofil's user avatar
  • 2,105
1 vote
1 answer
302 views

I noticed, that with Python 3.12 and a numpy.float64 when I simply do a x = numpy.sqrt(3) # type is <class 'numpy.float64'> now print(f"{x = }") # this is printed >>>x = np....
emefff's user avatar
  • 11
0 votes
3 answers
85 views

I have a string templ with variable part that I have to convert with local variables. Variable part of string have a dictionary cur_cols_dct from which I want to get a single value. Key of a ...
Valiot's user avatar
  • 1
-5 votes
1 answer
3k views

The following code message = ( f'Lembrete de que existe uma reserva para amanhã de *{dayAfter}* {dayAfterCellphone} para a carrinha que estás a usar.' ) is giving me ...
Duarte Almeida's user avatar
-1 votes
3 answers
97 views

In C programming language dynamic field width and precision is specified before the argument. printf("%.*s", 2, "ABCDEF") Yet when str.format was introduced in Python3.0 in 2008 ...
KamilCuk's user avatar
  • 146k
-1 votes
1 answer
51 views

I've tried to figure this out on my own, but I'm coming to a dead end. I'm trying to return a string from a function that I created that references amounts derived from a pandas dataframe that was ...
MJP's user avatar
  • 99
2 votes
2 answers
4k views

With Python 3.12 I can do the following without error: a = "abc" s = f"{a.replace("b", "x")}" Note the nested " characters. With Python 3.6 the same will ...
pktl2k's user avatar
  • 660
-1 votes
1 answer
125 views

Trying to format SPARQL queries in python using f-strings in order to build different queries from a template, but i'm getting KeyError when i try to format a multiline string: query = f'''SELECT ?age ...
m.rp's user avatar
  • 748
-2 votes
1 answer
187 views

The server I'm posting ym data to doesn't seem to support format call so I get the folowing error. Use f-string instead of 'format' call for the functions below. def write_xlsx_response(self, queryset)...
user2875230's user avatar
-1 votes
1 answer
45 views

a = 'guindo , barwos, zasport' a guindo , barwos, zasport But when I write print(f'find is {a.find('a')}') I get error SyntaxError: f-string: unmatched '(' Why? Can someone please write right ...
Ruslan Efanov's user avatar
0 votes
1 answer
105 views

I was messing around a bit with empty ndarrays and uncovered some unexpected behavior. Minimal working example: import numpy as np print(f"{np.empty(0)} :: {type(np.empty(0))}") print(f&...
realityChemist's user avatar
0 votes
1 answer
96 views

I am working on converting some Python 2.7 code to reflect a more Python 3.10 method and came across this scenario. A string variable is holding the formatting and then later on variables are added to ...
mecook112's user avatar
0 votes
2 answers
76 views

I'm making these report files and am trying to append a blank line in between each cycle of my loop, just to help with readability. Usually, I can just open the file and f.write('\n') to do this - for ...
Liam's user avatar
  • 11
0 votes
1 answer
37 views

I have a python program that creates an output file. That all works correctly. However, I'd now like to save the python output file with a "_username" appended to the filename. I have ...
thepen's user avatar
  • 1
1 vote
1 answer
107 views

I am pulling data from Datastream for a project. I have a list of 40 countries for which I want their bond issuance information. The query is as follows: All1 = rd.discovery.search( view = rd....
GoodFish's user avatar
-1 votes
3 answers
253 views

I'd like to program an alternate print() function, that automatically turns the inputted string into a formatted one, with correct formatting for variables. So why doesn't this work? Test = 'Hello!' ...
Emse's user avatar
  • 3

1
2 3 4 5
14