Class Inheritance from different module
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Sep 20 10:31:16 EDT 2014
More information about the Python-list mailing list
Sat Sep 20 10:31:16 EDT 2014
- Previous message (by thread): Class Inheritance from different module
- Next message (by thread): Class Inheritance from different module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Juan Christian wrote:
[...]
> In the API, the module users.py 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.
--
Steven
- Previous message (by thread): Class Inheritance from different module
- Next message (by thread): Class Inheritance from different module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list