Python Forum

Full Version: concatenat - shutil
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import shutil
t1 = 'bjjj'
t2 = 4455
t3 = '.txt'
t6 = print(t1+str(t2)+t3)
shutil.copy('bjjj.txt', 't6')
shutil.copy('bjjj.txt', 'bjjj4455.txt')

NOTE NOTE
I have a job file called bjjj.txt. When the program ended, I wanted it to be copied to the same name concatenated with a variable. I made immense attempts to no avail. If you put fixed bjjj4455.txt it works perfectly. But I want to increase the number 4455 +1 ...
Thank you
Is this what your are looking for?

prefix = 'bjjj'
version_number = 4455
version_number += 1
sufix = '.txt'
new_file_name = f'{prefix}{version_number}{sufix}'
shutil.copy('bjjj.txt', new_file_name)
or condensed:

new_file_name = f'bjjj{version_number}.txt'
Smile Smile Smile Smile Smile Smile Smile Heart
thank you. what should I do to complete this request of mine. Worked perfectly. thanks again
(Feb-10-2021, 11:21 PM)BashBedlam Wrote: [ -> ]Is this what your are looking for?

prefix = 'bjjj'
version_number = 4455
version_number += 1
sufix = '.txt'
new_file_name = f'{prefix}{version_number}{sufix}'
shutil.copy('bjjj.txt', new_file_name)
or condensed:

new_file_name = f'bjjj{version_number}.txt'
NOTE NOITE
100% sorted out Dance LOL

I have a problem to finalize the program for the post subject "goto". there is a line in the "for _ in range (1)" cycle that says
"print (f '{k} EXISTS')" must go back to for _, as this number that exists should not be announced. please, can you help me?! In the hands of a good programmer, it should be easy. Do you have access to my GOTO order?