check if a file is open in Python

I assume that you’re writing to the file, then close it (so the user can open it in Excel), and then, before re-opening it for append/write operations, you want to check that the file isn’t still open in Excel? This is how you could do that:

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

Why is parenthesis in print voluntary in Python 2.7?

In Python 2.x print is actually a special statement and not a function*. This is also why it can’t be used like: lambda x: print x Note that (expr) does not create a Tuple (it results in expr), but , does. This likely results in the confusion between print (x) and print (x, y) in Python 2.7 However, since print is a special syntax statement/grammar construct in Python 2.x then, without … Read more