473,396 Members | 1,852 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,396 software developers and data experts.

Importing class from file in package

Hello,
I've two files in my package.
In the first file I want to inport a class which is declared in the
second file. How can do that without stating the absolute path to the
file, just the relative one?

Thanks,

Florian
Jul 18 '05 #1
2 1762
Florian Lindner wrote:
I've two files in my package.
In the first file I want to inport a class which is declared in the
second file. How can do that without stating the absolute path to the
file, just the relative one?


Assuming you mean by "package" that you have a folder named, say,
"mypkg" and an __init__.py file in it (that last part is required
for it to be a package in Python), and files a.py and b.py, this
works just fine if you do nothing special:

file mypkg/a.py contains:

class A:
pass
file mypkg/b.py contains:

import a
print a.A()

If I run the interpreter in the folder above mypkg,
this works just fine:
import mypkg.b

<mypkg.a.A instance at 0x00AE8120>
So that leads me to think that either you didn't try this,
or I misunderstood the question...

-Peter
Jul 18 '05 #2
from second import class
--
======================

best regards

======================
"Florian Lindner" <Fl*************@xgm.de> ????
news:31*************@individual.net...
Hello,
I've two files in my package.
In the first file I want to inport a class which is declared in the
second file. How can do that without stating the absolute path to the
file, just the relative one?

Thanks,

Florian

Jul 18 '05 #3

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

Similar topics

0
by: Rogue 9 | last post by:
Hi All, I am developing a program called oop_lb.py and it's package structure is as below: oop_lb | -------------------------------------- | | | analysis process ...
1
by: Henning Kage | last post by:
I have a library with the following structure: library /app /db /gui /interface.py /wx /class.py
0
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:...
3
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...
3
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,...
4
by: Roy | last post by:
Could someone point me in the right direction here? The current method of importing new data into our db goes something like this: 1.) txt files received via email 2.) employees clean data and...
2
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...
7
by: hg | last post by:
Hi, I have the following problem. I find in a directory hierarchy some files following a certain sets of rules: ..../.../../plugin/name1/name1.py ..... ..../.../../plugin/namen/namen.py
0
by: Chris Rebert | last post by:
On Sun, Sep 28, 2008 at 7:10 AM, David Pratt <fairwinds.dp@gmail.comwrote: Why not just catch the ImportError-s and set some variables depending on whether you were able to import the modules,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.