3

I am creating a simple network monitoring web application in Python.

Given:

  • I want to manage everything from the GUI. No requirement post-install to touch files on the host server.
  • I want to be able to define custom checks in Python, and store those functions/checks in a SQLite database.

Questions:

  • How should I store that textarea (python function) in the SQLite database?

  • How do I call that function from another python script after I've pulled it out of the SQLite database?

2
  • 2
    Sounds like an interesting project. Out of interest what is the motivation behind storing the python functions in a Database rather than in modules on the filesystem? Commented Oct 8, 2013 at 21:38
  • I think you'd want to use a lookup table instead of this convoluted way... Commented Oct 8, 2013 at 21:39

2 Answers 2

2

SQLite TEXT field is fine for that. And you can call function from the code like this:

>>> code = """
... def hello():
...     print 'Hello world'
... """
>>> exec code
>>> hello()
Hello world

But I suggest you to save the code on disk with random filename. Then filename can be saved in database and code can be used like a normal module.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use pickle - Python Object Serialization to convert your function to text and store this text in the database. See: http://docs.python.org/2/library/pickle.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.