Home > Net >  Creating a Tuple made of variable strings
Creating a Tuple made of variable strings

Time:06-03

The following code works:

image_files=['imgpy1.png','imgpy2.png']
clip = moviepy.video.io.ImageSequenceClip.ImageSequenceClip(image_files, fps=20)

But I have 200 filenames 'imgpy1.png', 'imgpy2.png' and so on. How do I create an object called image_files, that contain these file names. I tried to create an array of strings:

flist=[]
flist=list(map(str,flist))
flist.append['imagepy1.png']
flist.append['imagepy2.png']

but that does not work. I get the error message

Traceback (most recent call last):
  File "C:\Users\vince\image.py", line 53, in <module>
    flist.append['imagepy1.png']
TypeError: 'builtin_function_or_method' object is not subscriptable

I am new to Python and can't figure out how to get an array or Tuple of strings. I've tried for 2-3 hours to non avail, at least 40 different ways including stuff I read online that don't work on my laptop. In the end, I am only interested in passing an argument to the video function that (1) does not crash the Python interpreter and (2) can be digested by the video function. So far, I am stuck with (1). But in the end I'm looking at solving (2). I don't care if it's an array, a list, a Tuple or anything else, as long as it works.

CodePudding user response:

I think append function is not correct.

flist.append('imagepy1.png')   # not brackets
flist.append('imagepy2.png')

CodePudding user response:

flist = []
for i in range(200):
    flist.append(f"imagepy{i   1}.png") #you use square brackets not round ones
print(flist)

this gets you

['imagepy1.png', 'imagepy2.png', 'imagepy3.png', 'imagepy4.png', 'imagepy5.png', 'imagepy6.png', 'imagepy7.png', 'imagepy8.png', 'imagepy9.png', 'imagepy10.png', 'imagepy11.png', 'imagepy12.png', 'imagepy13.png', 'imagepy14.png', 'imagepy15.png', 'imagepy16.png', 'imagepy17.png', 'imagepy18.png', 'imagepy19.png', 'imagepy20.png', 'imagepy21.png', 'imagepy22.png', 'imagepy23.png', 'imagepy24.png', 'imagepy25.png', 'imagepy26.png', 'imagepy27.png', 'imagepy28.png', 'imagepy29.png', 'imagepy30.png', 'imagepy31.png', 'imagepy32.png', 'imagepy33.png', 'imagepy34.png', 'imagepy35.png', 'imagepy36.png', 'imagepy37.png', 'imagepy38.png', 'imagepy39.png', 'imagepy40.png', 'imagepy41.png', 'imagepy42.png', 'imagepy43.png', 'imagepy44.png', 'imagepy45.png', 'imagepy46.png', 'imagepy47.png', 'imagepy48.png', 'imagepy49.png', 'imagepy50.png', 'imagepy51.png', 'imagepy52.png', 'imagepy53.png', 'imagepy54.png', 'imagepy55.png', 'imagepy56.png', 'imagepy57.png', 'imagepy58.png', 'imagepy59.png', 'imagepy60.png', 'imagepy61.png', 'imagepy62.png', 'imagepy63.png', 'imagepy64.png', 'imagepy65.png', 'imagepy66.png', 'imagepy67.png', 'imagepy68.png', 'imagepy69.png', 'imagepy70.png', 'imagepy71.png', 'imagepy72.png', 'imagepy73.png', 'imagepy74.png', 'imagepy75.png', 'imagepy76.png', 'imagepy77.png', 'imagepy78.png', 'imagepy79.png', 'imagepy80.png', 'imagepy81.png', 'imagepy82.png', 'imagepy83.png', 'imagepy84.png', 'imagepy85.png', 'imagepy86.png', 'imagepy87.png', 'imagepy88.png', 'imagepy89.png', 'imagepy90.png', 'imagepy91.png', 'imagepy92.png', 'imagepy93.png', 'imagepy94.png', 'imagepy95.png', 'imagepy96.png', 'imagepy97.png', 'imagepy98.png', 'imagepy99.png', 'imagepy100.png', 'imagepy101.png', 'imagepy102.png', 'imagepy103.png', 'imagepy104.png', 'imagepy105.png', 'imagepy106.png', 'imagepy107.png', 'imagepy108.png', 'imagepy109.png', 'imagepy110.png', 'imagepy111.png', 'imagepy112.png', 'imagepy113.png', 'imagepy114.png', 'imagepy115.png', 'imagepy116.png', 'imagepy117.png', 'imagepy118.png', 'imagepy119.png', 'imagepy120.png', 'imagepy121.png', 'imagepy122.png', 'imagepy123.png', 'imagepy124.png', 'imagepy125.png', 'imagepy126.png', 'imagepy127.png', 'imagepy128.png', 'imagepy129.png', 'imagepy130.png', 'imagepy131.png', 'imagepy132.png', 'imagepy133.png', 'imagepy134.png', 'imagepy135.png', 'imagepy136.png', 'imagepy137.png', 'imagepy138.png', 'imagepy139.png', 'imagepy140.png', 'imagepy141.png', 'imagepy142.png', 'imagepy143.png', 'imagepy144.png', 'imagepy145.png', 'imagepy146.png', 'imagepy147.png', 'imagepy148.png', 'imagepy149.png', 'imagepy150.png', 'imagepy151.png', 'imagepy152.png', 'imagepy153.png', 'imagepy154.png', 'imagepy155.png', 'imagepy156.png', 'imagepy157.png', 'imagepy158.png', 'imagepy159.png', 'imagepy160.png', 'imagepy161.png', 'imagepy162.png', 'imagepy163.png', 'imagepy164.png', 'imagepy165.png', 'imagepy166.png', 'imagepy167.png', 'imagepy168.png', 'imagepy169.png', 'imagepy170.png', 'imagepy171.png', 'imagepy172.png', 'imagepy173.png', 'imagepy174.png', 'imagepy175.png', 'imagepy176.png', 'imagepy177.png', 'imagepy178.png', 'imagepy179.png', 'imagepy180.png', 'imagepy181.png', 'imagepy182.png', 'imagepy183.png', 'imagepy184.png', 'imagepy185.png', 'imagepy186.png', 'imagepy187.png', 'imagepy188.png', 'imagepy189.png', 'imagepy190.png', 'imagepy191.png', 'imagepy192.png', 'imagepy193.png', 'imagepy194.png', 'imagepy195.png', 'imagepy196.png', 'imagepy197.png', 'imagepy198.png', 'imagepy199.png', 'imagepy200.png']

is this what you were looking for?

  • Related