简体   繁体   中英

Python: calling function inside a class inside a route from another file

I am a complete Python newbie and am trying to add functionality to an existing code base (for complete reference, it is airnotifier - which is an open source push server. It's missing functionality which I am adding)

Here is the situation: I have a python file api/tokens.py that has this:

@route(r"/api/v2/tokens/([^/]+)")
class TokenV2HandlerGet(APIBaseHandler):
    def delete(self, token):
        """Delete a token
        """

This was mapped to a route because it is actually invoked from the UI to delete a given token

I now have another file pushservices/apns.py that I've extended to perform certain feedback checks that are missing in the code base and now I need to be able to delete a token. How do I invoke the function above from pushservices/apns.py?

Thanks

#general format
from your.package.name import some_delete_function

@route(r"/api/v2/tokens/([^/]+)")
class TokenV2HandlerGet(APIBaseHandler):
    def delete(self, token):
        """Delete a token
        """
        some_delete_function(arg1,arg2,etc)

#assuming all of this is in the same parent dir
from pushservices import apns as some_delete_function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM