title: Running a Python program returns: bash: syntax error near unexpected token '('
body: <p>This is code for a DSLR timer I'm running on my RaspberryPi. The problem is that whenever I run the file it returns the error: </p>
  
  <blockquote>
    <p>bash: syntax error near unexpected token `(' </p>
  </blockquote>
  
  <p>I'm assuming that the error must relate to one of the characters following a bracket, but I've searched for around an hour and can't find anything. The lower portion of the script I did from scratch, and as I don't have too much experience with python there may be an error (or errors) there as well. Any help is greatly appreciated.</p>
  
  <p>Some of the code was pulled from this video: <a href="https://www.youtube.com/watch?v=1eAYxnSU2aw" rel="nofollow noreferrer">https://www.youtube.com/watch?v=1eAYxnSU2aw</a></p>
  
  <pre><code>#Imports various modules.
  from time import sleep
  from datetime import datetime
  from sh import gphoto2 as gp
  import signal, os, subprocess
  import threading
  
  
  #######################################################################
  
  
  #Closes the gphoto2 popup.
  def killGphoto2Process():
      p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
      out, err = p.communicate()
  
      for line in out.splitlines():
          if b'gvfsd-gphoto2' in line:
              pid = int(line.split(None,1)[0])
              os.kill(pid, signal.SIGKILL)
  
  #Creates values for when the pictures were taken. 
  shot_date = datetime.now().strftime("%Y-%m-%d")
  shot_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  
  #Names the pictures "Sunrises".
  picID = "Sunrises"
  
  #Creates commands to take and download pictures then stores them in the
  #variables "triggerCommand" and "downloadCommand".
  captureCommand = ["--capture-image"]
  downloadCommand = ["--get-all-files"]
  
  
  #Creates a folder to store captured pictures and gives it a location.
  folder_name = shot_date + picID
  save_location = "/home/pi/Desktop/gphoto/" + folder_name
  
  #Creates or changes where the pictures are saved.
  def createSaveFolder():
      try:
          os.makedirs(save_location)
      except:
          print("Failed to create the new directory.")
      os.chdir(save_location)
  
  #Captures and downloads the pictures.
  def captureImages():
      gp(captureCommand)
      gp(downloadCommand)
  
  #Renames the captured images.
  def renameFiles(ID):
      for filename in os.listdir("."):
          if len(filename) &lt; 13:
              if filename.endswith(".JPG"):
                  os.rename(filename, (shot_time + ID + ".JPG"))
  
  
  #######################################################################
  
  
  #Creates a loop that runs every 30 seconds.
  def printit():
      threading.Timer(30, printit).start()
  
      #Imports the "time" module to get the time.
      import time
  
      #Creates variables for hour and minute.
      hour = int(time.strftime("%H"))
      minutePart1 = int(time.strftime("%M"))
      colon = ":"
  
      #Puts a "0" in front of "minute" if "minute" is less than 10.
      #This prevents: time(7:9) not equaling sunrise(7:09).
      if minutePart1 &lt; 10:
          minute = ("0" + str(minutePart1))
      else:
          minute = (minutePart1)
  
      #Converts the time from 24-Hour to 12-Hour.
      if int(hour) &gt; 12:
         hour = hour - 12
  
      #Creates variables "time" and "sunrise".
      time = (str(hour) + colon + str(minute))
      sunrise = "7:09"
  
      #Takes a picture if the time is 7:09 AM.
      if time == sunrise :
          killGphoto2Process()
          createSaveFolder()
          captureImages()
          #renameFiles(picID)
          print("Sunrise!")
  
          print("Currently running \"Camera Controller.py\" ")
  
      printit()
  </code></pre>