AttributeError: ‘module’ object has no attribute

You have mutual top-level imports, which is almost always a bad idea. If you really must have mutual imports in Python, the way to do it is to import them within a function: Now a.py can safely do import b without causing problems. (At first glance it might appear that cause_a_to_do_something() would be hugely inefficient because it does an import every … Read more

‘int’ object has no attribute ‘__getitem__’

The error: means that you’re attempting to apply the index operator [] on an int, not a list. So is col not a list, even when it should be? Let’s start from that. Look here: Use a different variable name inside, looks like the list comprehension overwrites the col variable during iteration. (Not during the iteration when you set col, but during the following … Read more

Python throws ValueError: list.remove(x): x not in list

You should not remove items from a list you are looping over. Create a copy instead: and Modifying a list while looping over it, affects the loop: Removing items from a list you are looping over twice makes things a little more complicated still, resulting in a ValueError: When creating a copy of the lists … Read more

Relative paths in Python

In the file that has the script, you want to do something like this: This will give you the absolute path to the file you’re looking for. Note that if you’re using setuptools, you should probably use its package resources API instead. UPDATE: I’m responding to a comment here so I can paste a code sample. 🙂 … Read more