Hi,
I developed a package with a structure like this
src/
tesfile.py
dir1/
__init__.py
file1.py
dir2/
__init__.py
file2.py
The testfile is meant to try the code out that is specified in file1.py
and file2.py
Now i have another project where i want to use the code from that package.
The structure of that project:
src/
file3.py
dir3/
__init__.py
file4.py
To use it, i copied the package in the root of the project:
src/
file3.py
dir3/
__init__.py
file4.py
package/
__init__.py
dir1/
__init__.py
file1.py
dir2/
__init__.py
file2.py
In my code (file3.py) i then do an "import package.dir1.fi le1 as myobj"
and access a class like this:
myobj.LMyClass( )
(where myobj and LMyClass are decent names. Used these as example)
That works but i get an error in the package files.
I then get an error in package/dir1/file1.py on an import statement
specified in that file1.py that says import dir2.file2
How come this works as standalone project and not when i try to use it
as in situation 2 it doesn't seem to find module file2.py ?
How can i solve that?
Thanks
Benedict 4 1561
> I developed a package with a structure like this src/ tesfile.py dir1/ __init__.py file1.py dir2/ __init__.py file2.py
Importing dir2/file2 from dir1/file1.py works here, because when yuo started
the testfile script the src/ directory was added to the sys.path list.
If you relocate dir1/ and dir2/ in a "package" directory here it will not
work.
--
damjan
Damjan wrote: I developed a package with a structure like this src/ tesfile.py dir1/ __init__.py file1.py dir2/ __init__.py file2.py
Importing dir2/file2 from dir1/file1.py works here, because when yuo started the testfile script the src/ directory was added to the sys.path list.
If you relocate dir1/ and dir2/ in a "package" directory here it will not work.
Indeed, when i do this, then it works
import sys
sys.path.append ('package')
However, why is it that package isn't added automatically to the pad?
Regards,
Benedict
> Indeed, when i do this, then it works import sys sys.path.append ('package')
However, why is it that package isn't added automatically to the pad?
When you execute a python program the directory where the program is is
automatically added to sys.path. No other directory is added to the default
builtin sys.path.
In you case (the second case), you can import package.dir2.fi le2.
--
damjan
Damjan wrote: Indeed, when i do this, then it works import sys sys.path.appe nd('package')
However, why is it that package isn't added automatically to the pad?
When you execute a python program the directory where the program is is automatically added to sys.path. No other directory is added to the default builtin sys.path.
In you case (the second case), you can import package.dir2.fi le2.
OK, thanks for the info
Regards,
Benedict
--
Benedict Verheyen Debian User http://www.heimdallit.be Public Key 0x712CBB8D This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mark English |
last post by:
Basic problem:
If there is a C-extension module in a package and it tries to import
another python module in the same package without using the fully
qualified path, the import fails.
Config:
Python 2.4 on Windows 2000
For example:
mypackage contains:
|
by: yzhao12 |
last post by:
Hi everyone,
I encountered an error "Need to run the object to perform this operation
Code execution exception: EXCEPTION_ACCESS_VIOLATION
" When I try to import data from Oracle to MS SQL Server with Enterprise
Manager (version 8.0) using DTS Import/Export Wizard. There are 508 rows
|
by: Little PussyCat |
last post by:
Hello,
I nee to write something that will transfer excel data into an SQL Server
table.
I have for another database application I wrote have it importing Excel
spreadsheet data using cell by cell, row by row method. This is fully
automated so the user can choose whatever spreadsheet they want to import
and press a button which sits on a VB6 frontend.
This has been good for that situsation but it can be very slow when there
|
by: Charles Krug |
last post by:
List:
I'm trying to use the example files from Programming Python, 2nd Ed.
I've copied them into c:\Python24\Examples\PP2E.
Launching any of the examples programs by themselves seems to work
spiffily.
Using regedit, I appended "c:\Python24\Examples\PP2E" to Pythonpath
|
by: Elmo Watson |
last post by:
I've been asked to develop a semi-automated type situation where we have a
database table (sql server) and periodically, there will be a comma
delimited file from which we need to import the data, replacing the old.
I naurally know that we can use to kill the other data,
but does anyone have any examples of importing a comma delimited file into
SQL Server with ASP?
| |
by: Snozz |
last post by:
The short of it:
If you needed to import a CSV file of a certain structure on a regular
basis(say 32 csv files, each to one a table in 32 databases), what
would be your first instinct on how to set this up so as to do it
reliably and minimize overhead? There are currently no constraints on
the destination table. Assume the user or some configuration specifies
the database name, server name, and filename+fullpath. The server is
SQL...
|
by: fboweb.com |
last post by:
Hey there! I have a DTS import package from an old SQL server that
takes flat text files, does some munging on the columns using ActiveX
scripts and imports those flat files to various tables.
The package itself is rather tedious because it does this munging on
a
number of large files with a number of different fields.
When I bring the package in via SSIS, importing/migrating the
|
by: MyPetSlug |
last post by:
Hello Guys,
Using Pythong 2.4 and py2exe 0.6.6. So, I've created a wxPython application that I use for testing. The idea is to have a tests directory so that every time the application starts, it looks in the directory and loads the tests it sees into a list it uses during runtime. So, I've got this working fine on my machine locally, but now I'm trying to get it working right with py2exe.
My problem is, if I include my 'tests" package in...
|
by: mypetslug |
last post by:
Hi,
I'm sorry if this has been asked before, but I can't seem to find an
answer to this anywhere and so far, trial and error hasn't gotten me
far either.
Using python 2.4, I've created a testing application. When the app
starts up, I do a from tests import * and it looks at
the /tests directory and loads up all the tests it finds at that
time. This works fine when interpreting the python code directly.
The problem I'm having is...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |