title: Call Python function within a Bash Script
body: <p>I have a Python file called <code>data.py</code> that looks like this:</p>
  
  <pre><code>import json 
  
  def txtToJson(textfile):
      #rest of the code
  
  def jsontToTxt(jsonfile):
      #rest of the code 
  </code></pre>
  
  <p>I am also given a <code>run.sh</code> file to call each function from the Python file. I have tried doing this:</p>
  
  <pre><code>#!/bin/bash
  if [ "$1" = '-s' ]
  then
      if [ "$2" = '-j' ]
      then
          ##Serialize JSON
          python -c "import data; print(data.txtToJson($3))"
      fi    
  
  elif [ "$1" = '-d' ]
  then
      if [ "$2" = '-j' ]
      then
          ##Deserialize JSON
          python -c "import data; print(data.jsonToText($3))"
      fi
  fi
  </code></pre>
  
  <p>However when I try running the script I get a <code>ModuleNotFoundError: No module named 'data'</code>. How can I get the <code>run.sh</code> to call the different Python functions properly?</p>