Can’t import my own modules in Python

In your particular case it looks like you’re trying to import SomeObject from the myapp.py and TestCase.py scripts. From myapp.py, do since it is in the same folder. For TestCase.py, do However, this will work only if you are importing TestCase from the package. If you want to directly run python TestCase.py, you would have to mess with … Read more

How to read a file without newlines?

You can read the whole file and split lines using str.splitlines: Or you can strip the newline by hand: Note: this last solution only works if the file ends with a newline, otherwise the last line will lose a character. This assumption is true in most cases (especially for files created by text editors, which often do add an … Read more

How to use an image for the background in tkinter?

One simple method is to use place to use an image as a background image. This is the type of thing that place is really good at doing. For example: You can then grid or pack other widgets in the parent as normal. Just make sure you create the background label first so it has a lower stacking order. Note: if you are … Read more

Multiprocessing vs Threading Python

The threading module uses threads, the multiprocessing module uses processes. The difference is that threads run in the same memory space, while processes have separate memory. This makes it a bit harder to share objects between processes with multiprocessing. Since threads use the same memory, precautions have to be taken or two threads will write to the same memory … Read more

TypeError: ‘float’ object has no attribute ‘__getitem__’,python

The __getitem__ is a special python function which is equivalent to the operator [] or the indexing or the “get item” operator. So, the error is basically saying that there is a variable which is a float. And to this variable you’ve called the __getitem__ function – probably by doing an index operator to it. Based on the traceback which shows … Read more