Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 19054

How Python imports an instance of a class

$
0
0

I'm trying to find out how exactly importing works in Python.Let's say I have a foo.py module that contains the following class:

class Foo:     def __init__(self, *args, **kwargs):         ... foo = Foo() 

Now, I want to import it in other modules.

Is it going to use the same instance every time that I import it or will make different instances whenever I import it and is it even a good way to instantiate a class or it'd be better to import the Foo class and create an instance in modules that imported it(As it's obvious, this class doesn't need any args and kwargs).


Viewing all articles
Browse latest Browse all 19054

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>