Phyton - DVR convert clip list to string

Get answers to your questions about color grading, editing and finishing with DaVinci Resolve.
  • Author
  • Message
Offline

jensenni

  • Posts: 23
  • Joined: Wed Jan 27, 2021 12:26 am
  • Real Name: Jens Klein

Phyton - DVR convert clip list to string

PostSat Jan 30, 2021 9:45 pm

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!
Offline

Shrinivas Ramani

Blackmagic Design

  • Posts: 3030
  • Joined: Wed Sep 20, 2017 10:19 am

Re: Phyton - DVR convert clip list to string

PostMon Feb 01, 2021 6:43 am

Python has a join function.
Code: Select all
string_val = ','.join(list_of_stringables)
Offline

jensenni

  • Posts: 23
  • Joined: Wed Jan 27, 2021 12:26 am
  • Real Name: Jens Klein

Re: Phyton - DVR convert clip list to string

PostMon Feb 01, 2021 5:10 pm

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',
Offline
User avatar

Igor Riđanović

  • Posts: 1630
  • Joined: Thu Jul 02, 2015 5:11 am
  • Location: Los Angeles, Calif.

Re: Phyton - DVR convert clip list to string

PostMon Feb 01, 2021 9:47 pm

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'
www.metafide.com - DaVinci Resolve™ Apps

Return to DaVinci Resolve

Who is online

Users browsing this forum: Bing [Bot], Mads Johansen, panos_mts, sjubussen and 291 guests