1

I am trying to import a Python class from another file but it is not working. I've tried everything posted on relative imports but it is still not working.

My folder hierarchy is as follows:

hierarchy

I need to access the class Victim in victim.py file from test_db_debug.py file.

victim.py

class Victim:
    def __init__():
       ...

test_db_debug.py

import sqlite3
import sys
from code.victim import Victim

When i run the code, i get the error: ModuleNotFoundError: No Module names 'code.victim'; 'code' is not a package.

Can someone please help ?

davidism
  • 110,080
  • 24
  • 357
  • 317
Mervin Hemaraju
  • 1,376
  • 1
  • 16
  • 51

1 Answers1

1

I think it's about naming conflict.

Try to rename "code" to something else.

Check: https://stackoverflow.com/a/36066463/479933

acala
  • 161
  • 2
  • 9