Forum Archive

Python String Question

DavinE

Hello,

I Have a question about Python String formating.
This is my String:

csvFile__ProjectID = 83498246
rexelCSV = '%sr.csv' % (csvFile__ProjectID) 

Is it possible to do like this:

file Exempel:
83498246r1.csv
83498246r10.csv
83498246r17.csv

csvFile__ProjectID = 83498246
rexelCSV = '%sr?.csv' % (csvFile__ProjectID) 

The ? is for any Key

I hope you understand what I want 😂

ccc
csvFile__ProjectID = 83498246
for i in range(20):
    print(f"{csvFile__ProjectID}r{i}.csv")
DavinE

@ccc
Okay, I thought there was a nicer solution like placeholders or something.

but thank you for your fixed answer 👍

ccc

The alternatives with relative speed are at https://www.scivision.dev/python-f-string-speed

JonB

@DavinE

csvFile__ProjectID = 83498246
for i in range(20):
    print(f"{csvFile__ProjectID}r{i:02}.csv")

So you don't hate yourself later, when you have wwritten folders and folders of files that won't sort properly.

DavinE

@JonB
Thank you 👍

krishay.baxte

THANKS FOR SHARING THE PROBLEM I HAD THE SAME Nox Vidmate VLC