I am an experienced java enterprise developer but very new to python enterprise development shop. I am currently, struggling to understand why some imports work while others don’t. Some background: Our dev team recently upgraded python from 3.6 to 3.10.5 and following is our package structure Now, inside the moduleA.py, I am trying to import subpackage2/moduleZ.py like so But, I
Tag: python-import
ImportError: cannot import name ‘RightsMaster’ from partially initialized module ‘DATABASE.models’ (most likely due to a circular import)
from DATABASE.models import ModuleMaster, PageMaster, RightsMaster ImportError: cannot import name ‘RightsMaster’ from partially initialized module ‘DATABASE.models’ (most likely due to a circular import) (C:UsersADMINDesktoppython serverDATABASEmodels_init_.py) module_page.py rights_master.py user_rights.py init.py Answer I fixed it I was trying to import ModuleMaster in user_rights.py But it is already connected with Foreign_key in PageMaster
Performance impact in having a single import per line
does anybody know if there is a performance difference between having all imports from one module in a single line vs one per line. For example, having: instead of: I’m trying to convince my team to use reorder-python-imports in our pre-commit hooks and this doubt is the only obstacle that prevents me from adding it. Answer Combining imports is technically
Why did I get ModuleNotFoundError?
I tried the following code to import pprint from pprint module like import matplotlib.pyplot as plt. But I got an error instead. Why did I get this error? Answer Because there’s no module pprint.pprint, only a module pprint. You mean: (From the module pprint import the name pprint as p.)
Why can’t I access tkinter objects after importing tkinter as something?
I’m following a simple tutorial, learning about the tkinter library. In the tutorial, they do this: I was told the above is not good practice so instead I did: However, later on in the code I have to do something like this: This gives me an error because I didn’t import ttk as its own module. I would assume something
Import module dynamically
I have a program that supports different communication protocols. The idea is, that the user chooses the protocol during startup and then the module supporting the respective protocol is imported. The function below populates the protocol module with all functions and variables from the user-chosen protocol. protocol.py: name is provided by the user at program startup. The issue is, that
3 level chained python import is failing
I have the following folder structure across 3 levels: folder1 contains folder1_1 which again contains folder1_1_1. Now we have a .py file in each folder (besides the ‘init.py’ which is apparently needed, and sorry I don’t know how to put those 2 lines before and after). File contents file1.py file1_1.py file1_1_1.py So each file imports from the directly lower folder.
Import a single file from another directory
I’m kind of new with python and there is something troubling me. I’m using pandas to read an excel file. All works well if I have the excel in the same directory as my .py file. What I want to know is what is the best way to get a file that is in a completely different path. I’ve searched
Is it possible to import a function from another script without importing the variables from such file?
I have two scripts 1 and 2, I would need these two script to work independently from one another, but I also need script 2 to be able to use the function in script 1 if needed. I tried to automate as much as possible, so each script has a number of variables inside already defined. Here is an oversimplified
How to find everything imported by an import statement from python documentation?
I was trying to some code in python and noted this peculiar case. The above code runs fine in python 3.7 but not in python 3.10.2. In python 3.10.2, i get the following error: I tried to look at the documentation as to whether the behaviour of the above code got changed somehow. But couldn’t find it. The documentations i