简体   繁体   中英

Storing data on the fly with Python

I have a program where I want to record the function name, parameters passed to the function and the result. I am currently recording this using a decorator. However I am unsure how to store this. Currently I am just appending to a file each time.

I want to just be able to add my decorators to any function in any python program and record the result. As such I need to be able to store the data with each time. This makes it difficult to use XML to store the data as the document would have to be parsed, added to and rewritten each time.

Any suggestions on how I can save this information?

wrap all those inside a class and then use pickle module

I have a project that do something very close to what you want: coopy

Use the logging module from the standard library. It is designed to provide a flexible framework for logging information from a running application (across modules and source files).

In particular, it supports the notion of handlers , allowing you to send logging information into various sinks: files, sockets, email, syslog daemon (on Unix) and so on. If neither of the existing handlers answers your needs, it isn't difficult to write a custom one and plug it in. For instance, you can implement a logger that writes into a database.

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