0

I have a Python script that asks me to select the input folder. I am running it on OSX.

The issue is that when I try to write the input path it gives me back an error. Let's say that the input folder is "Documents", here what it says:

MBPAdmin:moviep3 Admin$ python merge_videos.py
Enter path to input folder: /Documents
Traceback (most recent call last):
  File "merge_videos.py", line 13, in <module>
    input_folder = input(input_folder_label)
  File "<string>", line 1
    /Documents
    ^
SyntaxError: invalid syntax

Any help please?

Edit: Here's part of the code, if it helps.

from moviepy.editor import VideoFileClip, concatenate_videoclips

import time
import os
import sys


input_folder_label = 'Enter path to input folder: '
output_folder_label = 'Enter path to output folder: '
video_to_be_merged_label = 'Enter path to video that should be merged at the end of each video: '
default_output_folder_name = 'merged_videos' + str(time.time())

input_folder = input(input_folder_label)
input_folder = '/Users/burlicconi/Downloads/filmovi'
try:
    assert os.path.exists(input_folder)
except AssertionError as exc:
    print("Input folder was not found at {}".format(input_folder))
    sys.exit()
print('Input folder exists: {}'.format(input_folder))
martineau
  • 119,623
  • 25
  • 170
  • 301
Andrew
  • 77
  • 2
  • 2
  • 5

1 Answers1

0

The issue is that Python 2.x will try to evaluate the user input when using input(), you need to use raw_input() in Python 2.x so it doesn't attempt to do that. Change:

input_folder = input(input_folder_label)

to

input_folder = raw_input(input_folder_label)

To make it work in Python 2.x, or even better shadow out the built-in input() in Python 2.x as you won't be using it as such anyway:

# after your imports, at the beginning of your script:
try:
   input = raw_input
except NameError:
   pass  # Python 3.x, ignore...

And now you can use it both on Python 2.x and Python 3.x.

zwer
  • 24,943
  • 3
  • 48
  • 66