Pho3nix
Pho3nix

Reputation: 45

Importing module: Exception has occurred: NameError name 'name' is not defined

I'm new to python and i'm making a program to delete items older than 3 days in a specific folder. Now everything works fine, but i want to split up my file extensions to a module (so it's easier to add or delete extensions later) and import it into my main program.

Now i have following code:

extensions.py

extension = [".pdf",".csv",".xls",".xlsx",".txt",".DS_Store",".jpg",".png",".docx",".zip"]

Deleter.py

import extensions
for ext in extension:
    print(ext)

I'm using Visual Studio Code to write my program and it underlines the "extension" in my Deleter.py file.

I've been searching for hours now and tried everything (have an empty init.py file in the same folder, tried to work with subfolder,... but nothing works). I'm using Python 3.7 Can someone help me please?

Upvotes: 1

Views: 1124

Answers (1)

Mayank Bansal
Mayank Bansal

Reputation: 2075

The problem here is that you are not creating any instance of extensions. So try this:

import extensions
for ext in extensions.extension:
    print(ext)

Upvotes: 2

Related Questions