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:
# In b.py: def cause_a_to_do_something(): import a a.do_something()
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 time you call it, but in fact the import work only gets done the first time. The second and subsequent times you import a module, it’s a quick operation.)
Related Posts:
- Why do I get AttributeError: ‘NoneType’ object has no attribute ‘something’?
- Why am I getting AttributeError: Object has no attribute?
- AttributeError(“‘str’ object has no attribute ‘read'”)
- Why Python 3.6.1 throws AttributeError: module ‘enum’ has no attribute ‘IntFlag’?
- AttributeError(“‘str’ object has no attribute ‘read'”)
- AttributeError: ‘Tensor’ object has no attribute ‘_keras_history’
- AttributeError: ‘Series’ object has no attribute ‘reshape’
- pip3 error – ‘_NamespacePath’ object has no attribute ‘sort’
- How to find if directory exists in Python
- What is setup.py?
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- Cannot find module cv2 when using OpenCV
- What is the purpose and use of **kwargs? [duplicate]
- What does random.sample() method in python do?
- (Python) TypeError: ‘float’ object is not subscriptable
- ValueError: Unknown label type: ‘continuous’
- Transpose/Unzip Function (inverse of zip)?
- TypeError: unhashable type: ‘numpy.ndarray’
- python base64 to hex
- pygame.error: video system not initialized
- TypeError: ‘numpy.float64’ object is not callable
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- ‘str’ object has no attribute ‘decode’. Python 3 error?
- How to find all the indexes of a recurring item in a list?
- Is there a way to delete created variables, functions, etc from the memory of the interpreter?
- Code for Greatest Common Divisor in Python
- ‘DataFrame’ object has no attribute ‘sort’
- How to check Django version
- How to change the font size on a matplotlib plot
- How can I create a dropdown menu from a List in Tkinter?
- How to find all occurrences of a substring?
- Does “\d” in regex mean a digit?
- How do you use subprocess.check_output() in Python?
- filename.whl is not a supported wheel on this platform
- How to use torch.stack function
- (Help) TypeError: ‘str’ object cannot be interpreted as an integer
- ‘builtin_function_or_method’ object is not iterable
- Why KeyError: 0
- Contains of HashSet
in Python - How to take column-slices of dataframe in pandas
- Python: Get the first character of the first string in a list?
- How to convert string to binary?
- Python error load JSON code of google API
- How do I find the duplicates in a list and create another list with them?
- Get ZeroDivisionError: float division in python
- How do I detect collision in pygame?
- ImportError: libSM.so.6: cannot open shared object file: No such file or directory
- explain arguments meaning in res = cv2.bitwise_and(img,img,mask = mask)
- How to normalize a 2-dimensional numpy array in python less verbose?
- Remove xticks in a matplotlib plot?
- “for line in…” results in UnicodeDecodeError: ‘utf-8’ codec can’t decode byte
- TypeError: string argument without an encoding
- ValueError: cannot index with vector containing NA / NaN values
- How to append multiple values to a list in Python
- How do I do a case-insensitive string comparison?
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- How do you split a list into evenly sized chunks?
- Ignoring NaNs with str.containsv
- How to split a string into a list of characters in Python?
- Find where python is installed (if it isn’t default dir)
- SSL error : routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
- What is the best way to call a script from another script?
- Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings
- Python map object is not subscriptable
- Why does pycharm propose to change method to static
- append new row to old csv file python
- Distributed 1.21.8 requires msgpack, which is not installed
- Python Library Path
- .pyw files in python program
- Get the cartesian product of a series of lists?
- No module named googlesamples.assistant.auth_helpers
- Solution for SpecificationError: nested renamer is not supported while agg() along with groupby()
- In Flask, what is “request.args” and how is it used?
- Conda command is not recognized on Windows 10
- pyserial, ImportError: No module named serial
- TypeError: only integer arrays with one element can be converted to an index 3
- In Flask, what is “request.args” and how is it used?
- How do I determine the size of an object in Python?
- Python function pointer
- How can I change the font size using seaborn FacetGrid?
- python math domain errors in math.log function
- Append a dictionary to a dictionary
- Error “‘type’ object has no attribute ‘__getitem__'” when iterating over list[“a”,”b”,”c”]
- Python way to clone a git repository
- List append() in for loop
- How to save an image locally using Python whose URL address I already know?
- How to throw error and exit with a custom message in python
- What is the difference between random.randint and randrange?
- How do I access my webcam in Python?
- Boolean Series key will be reindexed to match DataFrame index
- What is the easiest way to clear a database from the CLI with manage.py in Django?
- Printing one character at a time from a string, using the while loop
- How to exit an if clause
- Python a &= b meaning?
- TypeError: can only concatenate tuple (not “int”) in Python
- Write a program using integers user_num and x as input, and output user_num divided by x three times
- Logical operators for Boolean indexing in Pandas
- Transposing a 1D NumPy array
- TypeError: ‘NoneType’ object has no attribute ‘__getitem__’
- File “/usr/bin/pip”, line 9, in
from pip import main ImportError: cannot import name main