Class Inheritance from different module

Steven D'Aprano steve+comp.lang.python at
Sat Sep 20 16:31:16 CEST 2014

Juan Christian wrote:

> In the API, the module has a class 'SteamUser' and I want to
> mimic it's usage on my code, like this:
> import steamapi
> [...]
> class User(Inheritance from API):

What do you mean, "Inheritance from API"? You can't inherit from an API,
only from classes.

> def __init__(self, ID):
> steamapi.core.APIConnection(api_key = KEY)
> super( " Inheritance SteamUser" (ID)) # creates the user using the API
> [...]
> So that in my code when I need to create a new user, I just call 'usr =
> User("XXXXXXX")' instead of calling 'usr =
> steamapi.user.SteamUser(76561197996416028)', is that possible?

I would do something like this:

# untested
def make_user(ID):
    steamapi.core.APIConnection(api_key = KEY)
    return steamapi.user.SteamUser(76561197996416028)

usr = make_user("XXXXXXXXX")

No need for inheritance. make_user returns an actual SteamUser instance, not
some subclass.


More information about the Python-list mailing list