Skip to content Skip to sidebar Skip to footer

Facing Issue While Providing Dynamic Name To File In Python Through A Function

the line : with open('new%s.txt' % intg ,'a') as g : is giving error in below code. Every time I call the function 'Repeat', it should create file with name new1.txt, new2.txt and

Solution 1:

you can concatenate integer and strings doing so:

withopen('new' + str(intg) + '.txt','a') as g:

or doing so:

withopen('new{0}.txt'.format(intg),'a') as g:

Post a Comment for "Facing Issue While Providing Dynamic Name To File In Python Through A Function"