Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

using curly braces in filepaths

Trying to create animation effect by for looping images on a specific file path and found that:
THIS WORKS:

img=pygame.image.load(f'/img/{self.char_type}/walk/0.png') 

note 0.png but this DOES NOT:

img=pygame.image.load(f'/img/{self.char_type}/walk/{i}.png')

where i is from the simple FOR loop.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

All FAQ posts read so far suggest swapping / for , using f and r, using // or \ and even importing pathlib but all these seem to fail – so anyone got a sure fire method please?

>Solution :

Make a string first and pass it to the loader.

for i in range(11):
    srt = f'/img/{self.char_type}/walk/{i}.png'
    img=pygame.image.load(srt)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading