All Questions
50 questions
2
votes
3
answers
2k
views
How can I make certain text bold in Python string formatting?
I have a snippet where I generate a string that includes an original number (original_number) and its corresponding Roman numeral (roman_number). I want to format this string so that the original ...
-1
votes
1
answer
298
views
How to Format Lists of Strings and Dictionaries for Email Body in Python
I'm working on a Python script where I need to format three different types of lists into a string that will be used as the body of an email. The lists are as follows:
A list of strings:
a = ['1.1.1.1'...
0
votes
1
answer
457
views
In Python, is there a max length float to string formatting parameter?
I have a program that prints matrices in the console which means I want the spacing for each matrix entry to be the same, regardless of how big the number is, positive or negative. I want numbers that ...
0
votes
1
answer
582
views
Format a string using dictionary unpacking (Python 3.9) [duplicate]
mystr = '{1} {0}'
mydict = {'0': '5', '1': 'ZIDANE'}
result = mystr.format(**mydict)
Which raises:
IndexError: Replacement index 1 out of range for positional args tuple
I can do the following:
...
1
vote
2
answers
190
views
Problem with formatting my f string output in Python
I am trying to get the output of my code formatted in the following way:
Expected:
1 aggc tgtc aatg
13 ctag gcat agaa
25 gtcg tgct gtag
37 agat agtc tgat
49 agtc gc
However, I always get the ...
-1
votes
2
answers
419
views
How to format strings with tuples of values like using %(name)s
I've always seen formatting strings by placing tuples of values in between the modulo symbol and s character like using %(levelno)s:%(message)s from the Python logging module in a string for the fmt ...
0
votes
1
answer
64
views
How do I string format variables that require additional formatting
I am doing a project where I have to print a pay summary for someone based off of information like their hours worked and their pay rate, etc. In the print summary, the spacing is very specific to ...
1
vote
2
answers
735
views
Is it possible to write nested format strings?
I want to write something like
format_specifier = "{some_dict[some_key]}"
to later use it together with .format():
result = format_specifier.format(some_dict={"one": "eins&...
0
votes
2
answers
69
views
Python: pull out elements of given array in certain order
I have an array of arrays with names, addresses, cities, states, and postal codes. Is there a way I can collectively use the elements and display the information in the format of Name, Address, City, ...
0
votes
1
answer
247
views
formatting with optional "replacement fields" in python
there is such a code:
text = "{first}, {second}, {etc}"
print(text.format(first="1", etc="34.."))
when it is executed, I (expectedly) get a KeyError.
my question is ...
3
votes
3
answers
9k
views
How to fill string with n character to make it a certain length in Python
I'm having a tough time finding the exact wording for my question since I'm new to formatting strings.
Let's say I have two variables:
customer = 'John Doe'
balance = 39.99
I want to print a line ...
3
votes
2
answers
73
views
String formatting in Python for today standards [duplicate]
i'm learning python from a book that i bought in 2017 and from a online course at the same time.
The book says that i should format the string like this example;
print("Guess number %d of %d" % (...
1
vote
1
answer
768
views
How to combine files of similar file names together in python?
Imagine I have a folder with the following items :
default.xml df_ak01.1001.jpg df_ak01.1002.jpg df_ak01.1003.jpg
df_ak01.1005.jpg df_ak01.1006.jpg
(Here we can see that df_ak01.1004.jpg ...
0
votes
3
answers
351
views
Remove items from a tuple in string format [duplicate]
Here is my string
a = '(20.0, 8.0, 8.0, 37.0)'
and i want only first three items in this format
str = 20.0x8.0x8.0
and store the last item in a list.
leftover = [37.0]
Earlier I had only three ...
0
votes
1
answer
1k
views
Python logging string not being formatter
I'm trying to use python logging creating one logger per class.
The essential problem is that my output if not being formatted at all, it justs prints out the format string.
This is the script I'm ...