1

I am currently working on a django project and trying to import models from a python source file

I typed python manage.py shell < dummy_source.py in cmd and it resulted in an error:

observer.join()

^

SyntaxError: invalid syntax

However, when I just typed python dummy_source.py, it worked without any problems. I have gone online to find something useful but there are not any.

I would love to know why does this happen, thanks in advance.

Here is the content of dummy_source.py:

import os, time, sys
import subprocess as proc
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class MyHandler(FileSystemEventHandler):
    def on_created(self, event):
        print("Created!")
        os.system('cmd /c "mkdir workspace"')
        print("Deleted!")
        os.system('cmd /c "rmdir /s /q workspace"')


event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, path = 'media/submited_files', recursive = False)
observer.start()

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    observer.stop()
observer.join()
Community
  • 1
  • 1
KM02
  • 111
  • 2
  • You are using the django shell wrong. To import a script into django interactive shell follow: https://stackoverflow.com/questions/16853649/how-to-execute-a-python-script-from-the-django-shell – Cristian Gabor May 31 '20 at 17:28
  • @CristianGabor Oh thank you for the useful link. – KM02 Jun 01 '20 at 00:26

0 Answers0