How to add method to existing class in Python?
问题 I have this really convenient high-level pd.DataFrame saving function that I want to add to pandas . How can I add this method to the pd.DataFrame class? def to_file(df, path, sep="\t", compression="infer", pickled="infer", verbose=False, **args): _ , ext = os.path.splitext(path) # Serialization if pickled == "infer": if ext in {".pkl", ".pgz", ".pbz2"}: pickled = True else: pickled = False # Compression if compression == "infer": if pickled: if ext == ".pkl": compression = None if ext == "