Error with simple subclassing of pathlib.Path: no _flavour attribute

前端 未结 3 1377
广开言路
广开言路 2020-12-21 14:46

I\'m trying to sublclass Path from pathlib, but I failed with following error at instantiation

from pathlib import Path
class Pl(Path):
    def __init__(self         


        
3条回答
  •  春和景丽
    2020-12-21 15:42

    I solved it. Mokey patching is the way to go.

    define functions just like this

    def method1(self, other):
       blah
    
    Path.method1 = method1
    
    

    The fastest, easiest, most convenient solution, zero downsides. Autosuggest in Pycharm works well.

    UPDATE:

    I got THE solution (works with linter and auto suggestor):

    class MyPath(type(Path()), Path):
        pass
    
    

提交回复
热议问题