How to get a function name as a string?

Using __name__ is the preferred method as it applies uniformly. Unlike func_name, it works on built-in functions as well: Also the double underscores indicate to the reader this is a special attribute. As a bonus, classes and modules have a __name__ attribute too, so you only have remember one special name.

Directing print output to a .txt file

Give print a file keyword argument, where the value of the argument is a file stream. We can create a file stream using the open function: From the Python documentation about print: The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. And … Read more

Python List object attribute ‘append’ is read-only

To append something to a list, you need to call the append method: As you’ve seen, assigning to the append method results in an exception as you shouldn’t be replacing methods on builtin objects — (If you want to modify a builtin type, the supported way to do that is via subclassing).

What does “Symbol not found / Expected in: flat namespace” actually mean?

Description The problem was caused by mixing objects that compiled with libc++ and object that compiled with libstdc++. In our case, the library myMod.so (compiled with libstdc++) need boost-python that compiled with libstdc++ (boost-python-libstdc++ from now). When boost-python is boost-python-libstdc++, it will work fine. Otherwise – on computer that its boost-python has compiled with libc++ … Read more

How to include external Python code to use in other files?

You will need to import the other file as a module like this: If you don’t want to prefix your Calculate function with the module name then do this: If you want to import all members of a module then do this: Edit: Here is a good chapter from Dive Into Python that goes a bit more in depth on this … Read more