I have a file :
def fetchArticles(topic):
testing()
def testing():
print("testing")
print("starting")
fetchArticles("World")
It is present in a app in django and when i run it as a standalone file using python3 xyz.py it runs perfectly fine but when i run it in django shell using python3 manage.py shell < xyz.py it is not able to locate the testing function.
It shows this error :
starting
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/shell.py", line 101, in handle
exec(sys.stdin.read())
File "<string>", line 12, in <module>
File "<string>", line 4, in fetchArticles
NameError: name 'testing' is not defined
Can anyone help me to resolve this issue ?