How to run one-off python script on Heroku
Question: I have a Django app up and running on Heroku. I want to run a simple script
called import.py, which imports a CSV file into my models. It works great on
my local computer. When I try to run the script on Heroku using this commmand:

    
    
    heroku run python manage.py < import.py
    

All it does is read the script back to me, but not execute any of the content.
What am I doing wrong?

Edit:

This is the start of the result I get when I run: heroku run python manage.py
< import.py

    
    
    Type "help", "copyright", "credits" or "license" for more information.
    (InteractiveConsole)
    >>> import csv
    >>> from bah_api.models import withDependents, withOutDependents, ZipMHA
    >>> 
    >>> # Populate CSV file into model
    >>> def LoadCSV(file_location, my_model, delim):
    ... f = open(file_location)
      File "<console>", line 2
        f = open(file_location)
        ^
    IndentationError: expected an indented block
    >>> csv_f = csv.reader(f, delimiter=delim)
    Traceback (most recent call last):
      File "<console>", line 1, in <module>
    NameError: name 'f' is not defined
    >>> for row in csv_f:
    ... 
    Display all 182 possibilities? (y or n)
    


Answer: I think you should create command for this. Commands should be placed in
`app/management/commands` directory in your project. If this directory doesn't
exist, create it. The name of the script is the name of your command, so you
should name it `import.py` (bad name...). Another thing that has to be done is
creating `__init__.py` files in both the 'management' and 'commands'
directories, because these have to be Python packages. Tree should be like
this :

    
    
    app
    ├── admin.py
    ├── __init__.py
    ├── management
    │   ├── commands
    │   │   ├── __init__.py
    │   │   └── import.py
    │   └── __init__.py
    ├── models.py
    ... other files
    

Now you should be able to make something like this: `python manage.py import`
(really bad name...)

Or`heroku run python manage.py import` will work with heroku.

P.S. I don't know if it works with name 'import'

