简体   繁体   中英

Need convert function output to string from use as an arguement Python

Creating Hazel rule that triggers a script when a .mp4 file is dropped in.

Here is the script:

import os
from os import path

from vimeo import VimeoClient

a = "/Path/to/MyVimeoDirectory"

def myfile():
    for file in os.listdir("/Path/to/MyVimeoDirectory"):
        if file.endswith(".mp4"):
            return os.path.join(a, file)

vimeo = VimeoClient("blahblahvimeotoken")

vimeo.upload(myfile)

So basically vimeo.upload() requires a string argument. I've done a ton of research and saw some examples but I can't get them to work for me here. How do I get the resulting path of myfile() to put quotes around the output so I can use it as a string? Thoughts?

In your final line, consider that you are passing myfile as an argument, and not myfile() -- and what the difference is.

A few suggestions: don't use file as the loop variable name since it ghosts the Python file builtin and at the very least makes it confusing to read quickly; Are you sure the loop does what you want? It appears to return just the first appearing .mp4 file from the list of files as os.listdir orders them. myfile does not return all of the .mp4 files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM