runtime

Detect if a python module changes and then reload

Detect if a python module changes and then reload Question: So I’m developing a rather large python project with a number of modules. The “main” (runnable) module is a daemon (a Thrift daemon, actually) which calls off to other modules for its actual functionality. Starting up the daemon takes a long time because some of …

Total answers: 3

How do you calculate program run time in python?

How do you calculate program run time in python? Question: How do you calculate program run time in python? Asked By: feisky || Source Answers: You might want to take a look at the timeit module: http://docs.python.org/library/timeit.html or the profile module: http://docs.python.org/library/profile.html There are some additionally some nice tutorials here: http://www.doughellmann.com/PyMOTW/profile/index.html http://www.doughellmann.com/PyMOTW/timeit/index.html And the time …

Total answers: 5

Python heapq module, heapify method on an object

Python heapq module, heapify method on an object Question: Since I’m trying to be efficient in this program I’m making, I thought I’d use the built in heapq module in python, but some of my objects have multiple attributes, like name and number. Is there a way to use the heapify method to heapify my …

Total answers: 2

how to "reimport" module to python then code be changed after import

how to "reimport" module to python then code be changed after import Question: I have a foo.py def foo(): print “test” In IPython I use: In [6]: import foo In [7]: foo.foo() test Then I changed the foo() to: def foo(): print “test changed” In IPython, the result for invoking is still test: In [10]: …

Total answers: 5

How to add property to a class dynamically?

How to add property to a class dynamically? Question: The goal is to create a mock class which behaves like a db resultset. So for example, if a database query returns, using a dict expression, {‘ab’:100, ‘cd’:200}, then I would like to see: >>> dummy.ab 100 At first I thought maybe I could do it …

Total answers: 25

Python: changing methods and attributes at runtime

Python: changing methods and attributes at runtime Question: I wish to create a class in Python that I can add and remove attributes and methods. How can I acomplish that? Oh, and please don’t ask why. Asked By: Migol || Source Answers: This example shows the differences between adding a method to a class and …

Total answers: 9

Online compilers/runtime for Java, C++, Python and ObjC?

Online compilers/runtime for Java, C++, Python and ObjC? Question: Does anyone know of a good online compiler/runtime (for C++, Java, Python, ObjC etc.) that I can access on the web? What I’m looking for is something that would allow me to type in a program in a web form and to run the program and …

Total answers: 9