Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 另一个函数中的函数调用在django shell中不起作用_Python_Django_Python 3.x_Django Shell - Fatal编程技术网

Python 另一个函数中的函数调用在django shell中不起作用

Python 另一个函数中的函数调用在django shell中不起作用,python,django,python-3.x,django-shell,Python,Django,Python 3.x,Django Shell,我有一个文件: def fetchArticles(topic): testing() def testing(): print("testing") print("starting") fetchArticles("World") 它存在于django中的一个应用程序中,当我使用python3 xyz.py作为独立文件运行它时,它运行得非常好,但当我使用python3 manage.py shell

我有一个文件:

def fetchArticles(topic):
    testing()
def testing():
    print("testing")
print("starting")
fetchArticles("World")
它存在于django中的一个应用程序中,当我使用python3 xyz.py作为独立文件运行它时,它运行得非常好,但当我使用python3 manage.py shell 它显示了这个错误:

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
启动
回溯(最近一次呼叫最后一次):
文件“manage.py”,第22行,在
从命令行(sys.argv)执行命令
文件“/usr/local/lib/python3.5/dist-packages/django/core/management/__-init__;.py”,第363行,从命令行执行
utility.execute()
文件“/usr/local/lib/python3.5/dist-packages/django/core/management/__-init___.py”,执行中的第355行
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/usr/local/lib/python3.5/dist-packages/django/core/management/base.py”,第283行,在运行中,从
self.execute(*args,**cmd_选项)
文件“/usr/local/lib/python3.5/dist packages/django/core/management/base.py”,第330行,在execute中
输出=self.handle(*args,**选项)
文件“/usr/local/lib/python3.5/dist-packages/django/core/management/commands/shell.py”,第101行,在handle中
exec(sys.stdin.read())
文件“”,第12行,在
文件“”,第4行,在fetchArticles中
NameError:未定义名称“测试”

有人能帮我解决这个问题吗?

尝试移动
测试的定义,使其位于文件中
fetchArticles
之前。在fetchArticles函数之前编写测试函数直到不起作用。似乎有一个问题,shell没有定义这个文件,因为旧代码在django shell中运行良好,问题只出现在我添加新内容时。尝试打开新shell窗口并导入脚本againIt在python3 manage.py shell中工作正常,然后使用exec运行文件,但在我直接使用python3 manage.py shell调用它时,它仍然不工作。