it 's possible to put a variable into the path in python/linux
for example :
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image'counter'.jpeg', 'rb'))
I have syntax error when i do that.
it 's possible to put a variable into the path in python/linux
for example :
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image'counter'.jpeg', 'rb'))
I have syntax error when i do that.
You could use an f-string if you’re working in python 3.6+
This is the most efficient method.
counter = 0
filepath = f"/home/user/image{counter}.jpeg"
image = ClImage(file_obj=open(filepath, 'rb'))
Otherwise the second best would be using the .format() function:
counter = 0
filepath = "/home/user/image{0}.jpeg".format(counter)
image = ClImage(file_obj=open(filepath, 'rb'))
You need string concatenation.
>>>counter = 0;
>>>image = ClImage(file_obj=open('/home/user/image' + str(counter) + '.jpeg', 'rb'))