Python-Turning a string into and integer while keeping leading zeros -


i trying convert string, such 'ab0001', integer appears '001'

i trying:

x='ab0001' z=int(x[2:len(x)]) 

though output is:

1 

i need integer used in:

format_string=r'/home/me/desktop/file/ab'+r'%05s'+r'.txt' % z 

thank time , please let me know how acquire following outcome:

format_string=r'/home/me/desktop/file/ab0001.txt' 

you cannot have leading zeros @ in python3 , in python 2 signify octal numbers. if going pass string keep string.

if want pad 0's can zfill:

print(x[2:].zfill(5)) 

i don't see why slice @ thought when seem want exact same output original string.

 format_string=r'/home/me/desktop/file/{}.txt'.format(x) 

will give want.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -