0
ipdb> tps.keys()
dict_keys(['2017-01-01','2017-07-17'])

ipdb> start_date
'2017-05-22'

ipdb> [x for x in tps.keys() if x >= start_date]
*** NameError: name 'start_date' is not defined

ipdb> [x for x in tps.keys() if x >= '2017-05-22']
['2017-07-17']

Here, my list comprehension works fine when I compare elements of tps.keys() with '2017-05-22' but it gives me an error when I compare with start_date, but start_date is assigned to 2017-05-22 so I'm confused as to why this happens. Why is this the case?

Kashif
  • 3,063
  • 6
  • 29
  • 45
  • 1
    You're running this in the middle of an active debugger session. Is your current frame maybe a function, where `start_date` is a local or nonlocal but `tps` is a global? – abarnert Aug 17 '18 at 22:10
  • 1
    Looks related to https://bugs.python.org/issue21161 doesn't it? – Aif Aug 17 '18 at 22:12
  • @Aif Yeah, that's exactly what I was thinking (except that I didn't know the bug number or all the details off the top of my head, just that comprehensions can't see locals in pdb in some cases, and it had been discussed at some point…) – abarnert Aug 17 '18 at 22:16

0 Answers0