All Questions
414 questions
0
votes
0
answers
50
views
string format a Decimal instance using an underscore as a thousands separator?
I can easily do this for floats using an f-string like this:
x = float(123456789.123456)
print(f"{x:_f}")
prints 123_456_789.123456 exactly as expected.
But if try the same technique for a ...
0
votes
0
answers
16
views
I can't align the contents of some dataframe columns displayed in a text widget
Here's a code snnippet that illustrates the problem.
# Agregar el encabezado del reporte
header_text = "REPORTE DE REGISTRO VITCA TECHNOLOGY"
text_widget.insert(tk.END,...
0
votes
0
answers
12
views
Replace placeholder in python format method with a string variable? [duplicate]
I am trying to uniquify a string example _foo{f}_bar{b} with f ranging from 0 to F_MAX and b ranging from 0 to B_MAX. However, I'm not able to replace f with variable that holds it in the format ...
1
vote
5
answers
153
views
F-string format for conditionally prefixing a value
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 ...
-1
votes
1
answer
48
views
How to include variables in a multiple line string in Python? [duplicate]
For example, I have the following:
first_count = 5000
query = '''
{
students(first: first_count) {
id
firstName
college {
id
name
location
...
0
votes
1
answer
444
views
ValueError: Space not allowed in string format specifier
I was modernizing some old % formatted string via regex substitution to change:
# Old:
'Map: % 20s' % name
# to New:
'Map: {: 20s}'.format(name)
and was surprised to get this error:
...
1
vote
1
answer
64
views
Parsing string to dictionary
I'm working on a communications project with a radio that transmits a formatted string message, similar to:
message_string = 'Transmission\n variables \n 0.01 First variable\n 0.02 Second variable\n ...
2
votes
1
answer
298
views
Python: Insert escape character (single '\') into a string to escape markdown text rendering later
I'm hoping I'm overlooking something simple here. I have a function that sends some debug messages to Discord in code blocks (```). Since it can quote past messages, previous code blocks can interrupt ...
1
vote
0
answers
87
views
how to format column in currency in python
locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')
filtered_data['Receita Total'] = filtered_data['Receita Total'].apply(lambda x: locale.currency(x, grouping=True))
filtered_data['Margem Final'] = ...
-1
votes
1
answer
38
views
Python search for the errors in the JSON
Premise: those dictionaries are strings. Those are JSON with a bad format. I search for the errors inside those JSON and print them.
example 1:
input
{
"ced": {
"CED_PH2&...
1
vote
2
answers
278
views
converting string to datetime without success in python
so I am reading the datetime from a file (but it is reading it as a string) and then converting it to a datetime format using this simple code
last_update_str = flast.readlines()[-1].strip()
...
0
votes
1
answer
48
views
String format doesn’t show int number 1
I have this method that receives seconds (as an integer) and returns a string with the years, days, hours, minutes and seconds.
When any of the values (years, days, hours, minutes or seconds) = 1 it's ...
-2
votes
1
answer
212
views
Format string with substrings
I need to format a string with substrings of a variable. If I do:
sample="1234567890XXXX"
f"{sample[:5]}/{sample[5:10]}/{sample}/config"
It works fine:
'12345/67890/1234567890XXXX/...
0
votes
1
answer
25
views
getting specified format input from Entry widget in python
I want to convert a string in specified format (start-stop-dataNumber) to a array.
datanumber is a number of data in that range from start to stop.
for example:
input="1-10:5"
output=[1,3,5,...
10
votes
2
answers
9k
views
Is there a way to interpolate variables into a python string WITHOUT using the print function?
Every example I have seen of Python string variable interpolation uses the print function.
For example:
num = 6
# str.format method
print("number is {}".format(num))
# % placeholders
print(...