473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Re: is this a good way to do imports ?

Stef Mientki wrote:
hello,

I can't find any good documentation or examples of packages,
so I'm not sure if this is good / correct way, although it seems to work.

root
/ dir1
/ file1.py
/ general.py

/ dir2
/ file2.py

/ general_root.py

Now I want to be able to use functions of file2 in file1,
and vice-versa.
In practice the directory structure is more complex and nested more deeply,
and basically I want all modules to be reachable by all other modules.
One straightforward way is plain old absolute imports. Assume root is
in the import path (for instance, in site packages)
>
==== file1.py ====
import general
from root.dir1 import general
import file2
from root.dir2 import file2
or even
from root.dir2.file2 import func
This will break if the tree changes. So will new relative imports.
Pulling everything into root in its __init__.py breaks if there are
duplicate module names.

Anyway, above is what I am doing with my current 3-level
(pac.subpac.mod) package until I learn something really better, given
that the interdependencies in my package should remain relatively sparse.

tjr

Nov 5 '08 #1
0 962

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hallvard B Furuseth | last post by:
Is there any reason not to structure my program like this? def ... def ... var = ... var = ... import ... import ... main_function()
1
by: Steven K | last post by:
Hello, Is there a way to declare imports so that they don't have to be declared both in Master Page.vb and the Content Page.vb? For example, I have the following in the Master Page.vb Imports...
8
by: John A Grandy | last post by:
what are the various alternatives to including a group of imports statements in every module ? imports <namespace1.class1> imports <namespace2.class1> imports <namespace2.class2> etc.
1
by: Supra | last post by:
' 2004 'An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll 'Additional information: Object reference not set to an instance of an object. Option...
5
by: jg | last post by:
I followed the pattern in the MSDN dot net example for .net server and I tried a making simple .net dll as COM from Option Explicit On Option Strict On Imports System Imports...
2
by: jimmyfishbean | last post by:
Hi, I have created a VB.Net windows service. Everything was working fine until I attempted to add a setup project. Now, for some strange, when I try and run the application (using INSTALLUTIL...
7
by: pcnerd | last post by:
In Java I can use, for example, " Imports java.util.* ". Can I use, for example, " Imports System.* " instead of several different "Imports" statements? Thank you. David
13
by: Edje.Rommel | last post by:
Hello, I've have a problem with a webservice. I just want to validate a VAT number by country code and VAT numer. The return value should be like "it's valid" and/or the name where it's...
1
by: Arpan | last post by:
What's the difference between "Imports" & "Inherits"? For e.g. both the codes below work without any errors: Imports System Imports System.Data Imports System.Web.UI Namespace Constructors...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.