It fails because the second datetime in your test script is taken to be a 
variable and it is not one you have already defined; hence the error: 
"NameError: name 'datetime' is not defined".

Try this instead:

echo "import datetime ; [e*e for e in [1,2]]" > test

On Thursday, 21 April 2022 at 19:06:45 UTC+2 cseb...@gmail.com wrote:

> Why does this fail?...
>
> % echo "import datetime ; [datetime for e in [1, 2]]" > test
>
> % ./manage.py shell < test
>
> Traceback (most recent call last):
>   File "./manage.py", line 8, in <module>
>     django.core.management.execute_from_command_line(sys.argv)
>   File 
> "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 
> 381, in execute_from_command_line
>     utility.execute()
>   File 
> "/usr/lib/python3/dist-packages/django/core/management/__init__.py", line 
> 375, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/usr/lib/python3/dist-packages/django/core/management/base.py", 
> line 323, in run_from_argv
>     self.execute(*args, **cmd_options)
>   File "/usr/lib/python3/dist-packages/django/core/management/base.py", 
> line 364, in execute
>     output = self.handle(*args, **options)
>   File 
> "/usr/lib/python3/dist-packages/django/core/management/commands/shell.py", 
> line 92, in handle
>     exec(sys.stdin.read())
>   File "<string>", line 1, in <module>
>   File "<string>", line 1, in <listcomp>
> NameError: name 'datetime' is not defined
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d3b34127-73f0-47ca-919a-d9de8bae920cn%40googlegroups.com.

Reply via email to