1

I use PyCharm and I'm trying to import a class/module from a script into another script.

My two scripts are in the same directory:

>|-my_directory

>>|--script_A

>>|--script_B

script_A:

class Number:
    def __init__(self):
        self.var = 1

    # some other methods

script_B:

from script_A import *

# some other code

But the issue is, if I run script_B there is an error:

Traceback (most recent call last):
...
    from script_A import *
ImportError: attempted relative import with no known parent package

So why this doesn't work? Why is there an error? And how can I fix it?

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
BlackBreez
  • 21
  • 1
  • 3

1 Answers1

1

Script_A and Script_B are in the same dir. So you can directly import Script_A with import Script_A even import Script_A.*** as XXX

Steven.hsu
  • 23
  • 8