Hi guys i need help with one thing in Python...
I've got something like

number=001 
example = "picture%d" % number 
print example ---> But it prints picture1 not picture 001....

and i need it as integer not as string because i want to use

--->

number=number + 2 for example...

Thank You guys, sorry for my English, and I hope that you understood

Recommended Answers

Read this http://www.daniweb.com/code/snippet232375.html and use

assert 0 <= number < 1000
example = "picture{num:0>3d}".format(num=number)
Jump to Post

Gribouillis want to stop counter wrap arround to stop program destroying files. Rename = move in Linux systems. Good thinking.

Jump to Post

All 7 Replies

assert type(number) == int

But if you want to increment number. Number is already int type.

Gribouillis want to stop counter wrap arround to stop program destroying files. Rename = move in Linux systems. Good thinking.

commented: Thanks for your support ! +5

I've solved it, Thank You very much guys :)

Gribouillis want to stop counter wrap arround to stop program destroying files. Rename = move in Linux systems. Good thinking.

I read a good rule: assert the most obvious hypotheses about your data :)

Maybe the reason rwas not like I said as formatting normally expands if number does not fit. Still it is easy to optimize out assert statements because they make your dear program slower. Premature optimization is not without reason sin in Python world.

Maybe the reason rwas not like I said as formatting normally expands if number does not fit. Still it is easy to optimize out assert statements because they make your dear program slower. Premature optimization is not without reason sin in Python world.

My idea is that if the OP wanted larger numbers, he would have written picture0001, so there was an implicit assumption which deserved to be checked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.