Y
Y
Yrets1692021-12-23 22:15:53
Python
Yrets169, 2021-12-23 22:15:53

How to remake condition in python 3.10?

Good evening, there is a condition that works on python 3.9 version

for i in files_dict:
    if 'FULL.zip'.lower() in i['key']:
        time_create = i['value']
        print(time_create)
    if i['value'] < time_create:
        print(i['value'])


however, on version 3.10 I get an error

Traceback (most recent call last):
  File "F:\python proj\proj1\main.py", line 42, in <module>
    if i['value'] < time_create:
NameError: name 'time_create' is not defined


How to remake the code for 3.10?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-12-23
@Yrets169

It's not the python version, but the fact that you don't have the "full.zip" string in i['key'] for the first i. In this case, python 3.9 will give exactly the same error, since the first if will not work, and the second will call time_create.
But why this is so is a completely different question. Maybe different packages are installed on two versions of python. Maybe it's just that the files in files_dict end up in a slightly different order. I would advise to fix the algorithm as a whole, i.e. initialize time_create with some value before the loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question