0

I am using the following f-strings in a web application. When I run it locally (before trying on the web) I am getting a name error:

NameError: name 'path' is not defined

But path prints properly and seems to be defined to my mind. What am I doing wrong?

path = f'{PROJECT_PATH["raw_data"]}/cashValues'
print("PATH", path)
filenames = [f'{path}/{i}' for i in filenames]

Thanks

Full traceback:

Traceback (most recent call last):
  File "scripts/TableTransform.py", line 8, in <module>
    class TableTransform(object):
  File "scripts/TableTransform.py", line 14, in TableTransform
    Filenames = [f'{path}/{i}' for i in filenames]
  File "scripts/TableTransform.py", line 14, in <listcomp>
    Filenames = [f'{path}/{i}' for i in filenames]
NameError: name 'path' is not defined
Woody Pride
  • 13,539
  • 9
  • 48
  • 62

1 Answers1

0

It seems that list comprehension in python 3.6.5 has its own scope and is not aware of variables outside of that scope. This is why it was failing.

Woody Pride
  • 13,539
  • 9
  • 48
  • 62