It works fine here. I entered your commands exactly and the second one does not provide any output.

What shell do you have? And what version of Python and Django? And what OS?


On 21/04/2022 22.28, [email protected] wrote:

Yes I agree.  But why does it complain that datetime doesn't exist when I do "  ./manage.py shell < test " ?

Shouldn't it also not do anything like when I paste into a Python3 or Django shell as you did?

cs

On Thursday, April 21, 2022 at 2:10:39 PM UTC-5 [email protected] wrote:

    On Thu, Apr 21, 2022 at 2:53 PM [email protected] <[email protected]> wrote:
    >
    > The script should quietly exist without error.
    >
    > I actually have a longer script that is the real workhorse.
    > I just made this tiny one to showcase the issue.
    >
    > I can past
    >
    > import datetime ; [datetime for e in [1, 2]]
    >
    > into a regular Python3 shell as well as the Django shell and all is fine.

    $ python3
    Python 3.8.10 (v3.8.10:3d8993a744, May 3 2021, 08:55:58)
    [Clang 6.0 (clang-600.0.57)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import datetime ; [datetime for e in [1, 2]]
    [<module 'datetime' from
    
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/datetime.py'>,

    <module 'datetime' from
    
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/datetime.py'>]


    It does not do anything.

    >
    > The problem I think has something to do with how I inject
    > it into the Django shell via "< test".
    >
    > cs
    > On Thursday, April 21, 2022 at 12:18:04 PM UTC-5 [email protected] 
wrote:
    >>
    >> On Thu, Apr 21, 2022 at 1:06 PM [email protected] <[email protected]>
    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
    >>
    >> What do you expect to happen?
    >
    > --
    > 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 [email protected].
    > To view this discussion on the web visit
    
https://groups.google.com/d/msgid/django-users/c4a36ffb-8c7a-477f-9d26-f6b898178d91n%40googlegroups.com.


--
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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dcb3ee25-cb8b-4aa9-84d7-ac0772e677f6n%40googlegroups.com <https://groups.google.com/d/msgid/django-users/dcb3ee25-cb8b-4aa9-84d7-ac0772e677f6n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/34d916a3-479c-03c4-25bf-636c257374cf%40antonischristofides.com.

Reply via email to