I noticed a list comprehension bombs in the "./manage.py shell" shell that I think would be ok in normal Python shell. What is different about "./manage.py shell" that makes it not like certain list comprehensions?
Here is the code erase that I run this way..."./manage.py shell < erase" import bighelp.models ACCT = bighelp.models.Account ASERV = bighelp.models.AccountService APPT = bighelp.models.Appointment for e in ACCT.objects.all()[:1]: appts = APPT.objects.filter(account = e)[:3] aservs = ASERV.objects.filter(account = e) allowed = [e.service.name for e in aservs] print(f"allowed is a list of strings => {allowed}\n\n") print(f"appts is a collection of Django objects => {appts}\n\n") print("This way of defining servs works...\n\n") servs = [] for a in appts: if a.service in allowed: servs.append(a.service) print(f"servs = {servs}\n\n") print("This way gives a mysterious error...\n\n") servs = [a.service for a in appts if (a.service in allowed)] ***THE OUTPUT**** ../manage.py shell < ./erase allowed is a list of strings => ['pet', 'cleaning'] appts is a collection of Django objects => <QuerySet [<Appointment: Appointment object (998)>, <Appointment: Appointment object (1463561)>, <Appointment: Appointment object (863)>]> This way of defining servs works... servs = ['cleaning', 'pet', 'cleaning'] This way gives a mysterious error... 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 26, in <module> File "<string>", line 26, in <listcomp> NameError: name 'allowed' 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/a0fa5dcc-2861-411b-90fc-951ef6d8d58fn%40googlegroups.com.