Swapping through a texture sequence?

Heya! Im still new to python and coding in general so im not sure if im doing this correctly.

I have a texture sequence (tex_1.jpg, tex_2.jpg, tex_3.jpg … tex_50.jpg) that i want to swap/cycle through.
I have it set up like this because eventually i want to have a task that lets the user hold down a button to swap/cycle though a sequence of textures that are being applied/replaced on a specific model.

this is what i came up with:

sphere = loader.loadModel("models/sphere.obj")
tex = loader.loadTexture("seq/frame_1.jpg")

frame_count = {'frame' : 1}

def updateTex(task):
    current_frame = frame_count.get('frame')  
    current_path = '"seq/frame_'+str(current_frame)+'.jpg"'
    tex = loader.loadTexture(current_path)
    frame_count['frame'] += 1    
    return task.again

taskMgr.doMethodLater(1,updateTex, 'frame update')

This gives me the following error
OSError: Could not load texture: “seq/frame_1.jpg”

this error comes from within the task loop, not the initial texture loader outside the loop.

when i change

current_path = ‘"seq/frame_’+str(current_frame)+’.jpg"’


current_path = “seq/frame_40.jpg”

then it loads the texture. but not when i add the +str() variable

you have extra quotation marks in your current_path which are not needed.

Simply change the line

current_path = '"seq/frame_'+str(current_frame)+'.jpg"'
                ^                                    ^


current_path = 'seq/frame_'+str(current_frame)+'.jpg'

and it should work

you may also use pythons f-string format which sometimes makes things like this a lot more readable. In this example, you could write it like

current_path = f'seq/frame_{current_frame}.jpg'

ah yes, that seems to work. thanks so much!