Page 1 of 1

Phyton - DVR convert clip list to string

PostPosted: Sat Jan 30, 2021 9:45 pm
by jensenni
Hi, is there a way to convert a list to a string value in ONE LINE? In other words, my script generates a directory path as shown below:

Code: Select all
fullPathName = mediaDir + project.GetName() + "/" + "footage" + "/" + dirLoc + "/" + newFileName

# usual line by line output
/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_C0010/FW_A01_C0010.dng
/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_C0021/FW_A01_C0021.dng
/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_C0190/FW_A01_C0190.dng

# I need the entire list in one line, seperate by a comma
'/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_C0010/FW_A01_C0010.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_C0021/FW_A01_C0021.dng', '/Volumes/RAID/Data/Media/TWO_CHAIRS/footage/FW_A01_C0190/FW_A01_C0190.dng',


.. any ideas?

Thank you!

Re: Phyton - DVR convert clip list to string

PostPosted: Mon Feb 01, 2021 6:43 am
by Shrinivas Ramani
Python has a join function.
Code: Select all
string_val = ','.join(list_of_stringables)

Re: Phyton - DVR convert clip list to string

PostPosted: Mon Feb 01, 2021 5:10 pm
by jensenni
Thank you for your input! ...after trying that I get a comma after every letter. But I think this is getting close. Any ideas?

Code: Select all
fullPathName = mediaDir + project.GetName() + "/" + "footage" + "/" + dirLoc + "/" + newFileName


The code above outputs this:
/Volumes/Media/TWO_CHAIRS/footage/FW_C0001/FW_C0001_000000.dng

Code: Select all
string_val = ','.join(fullPathName)
        print("String: " + string_val)


Adding the join function outputs this:
String: ,V,o,l,u,m,e,s,/,M,e,d,i,a,/,T,W,O,_,C,H,A,I,R,S,/,f,o,o,t,a,g,e,/,F,W,_,C,0,0,0,1,/,F,W,_,C,0,0,0,1,_,0,0,0,0,0,0,.,d,n,g

The output I would like instead is this (with an empty space after the comma):
String:
'/Volumes/Media/TWO_CHAIRS/footage/FW_A01_C0001/FW_A01_C0001_000000.dng',

Re: Phyton - DVR convert clip list to string

PostPosted: Mon Feb 01, 2021 9:47 pm
by Igor Riđanović
It's because you're using join() on a string. You must supply a list to join like:
Code: Select all
>>> ','.join(['list','of','strings'])
'list,of,strings'