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

Module organization

I am slowly learning Python and I'm already starting to write some minor
modules for myself. Undoubtedly there are better modules available
either built-in or 3rd party that do the same as mine and much more but
I need to learn it one way or another anyway.

What I'm wondering about is module organization.

I created my own directory for storing my modules and added the full
path to this to PYTHONPATH (Windows XP platform).

This means that "import modulename" works for my modules now.

However, the name of my module is "db" or "database", a module name that
will likely conflict with other modules I might encounter later.

As such, I was thinking of doing the same that the "distutils" set of
modules have done, by creating a subdirectory and storing them there, so
I created a "lvk" directory in that directory of mine and moved the
module in there, but now "import lvk.modulename" doesn't find the module.

Is there a trick to this? Do I have to store my own modules beneath
C:\Python24\Lib? or can I use the organization I've tried just with some
minor fixes to make python locate my modules?

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Sep 28 '05 #1
2 2134
Lasse Vågsæther Karlsen schrieb:
I am slowly learning Python and I'm already starting to write some minor
modules for myself. Undoubtedly there are better modules available
either built-in or 3rd party that do the same as mine and much more but
I need to learn it one way or another anyway.

What I'm wondering about is module organization.

I created my own directory for storing my modules and added the full
path to this to PYTHONPATH (Windows XP platform).

This means that "import modulename" works for my modules now.

However, the name of my module is "db" or "database", a module name that
will likely conflict with other modules I might encounter later.

As such, I was thinking of doing the same that the "distutils" set of
modules have done, by creating a subdirectory and storing them there, so
I created a "lvk" directory in that directory of mine and moved the
module in there, but now "import lvk.modulename" doesn't find the module.

Is there a trick to this? Do I have to store my own modules beneath
C:\Python24\Lib? or can I use the organization I've tried just with some
minor fixes to make python locate my modules?


I'm also new to python. But I think the solution to your problem is:

make the directory - lvk - a python package

in order to do this you just add an file __ini__.py (two underscores
befor and after init)in the directory.
__init__.py can be empty or include some initialization for your package
or a docstring for this package

if you plan to use something like: from lvk import *

there must be a variable __all__ in this __init__.py, which refers to a
list of all modules that should be imported

as mentioned I'm new to python and this might be wrong but give it a try

Sep 28 '05 #2
Lasse Vågsæther Karlsen wrote:
I am slowly learning Python and I'm already starting to write some minor
modules for myself. Undoubtedly there are better modules available
either built-in or 3rd party that do the same as mine and much more but
I need to learn it one way or another anyway.

What I'm wondering about is module organization.

I created my own directory for storing my modules and added the full
path to this to PYTHONPATH (Windows XP platform).

This means that "import modulename" works for my modules now.

However, the name of my module is "db" or "database", a module name that
will likely conflict with other modules I might encounter later.

As such, I was thinking of doing the same that the "distutils" set of
modules have done, by creating a subdirectory and storing them there, so
I created a "lvk" directory in that directory of mine and moved the
module in there, but now "import lvk.modulename" doesn't find the module.
What you want is a package:
http://www.python.org/doc/current/tu...00000000000000
Is there a trick to this? Do I have to store my own modules beneath
C:\Python24\Lib? or can I use the organization I've tried just with some
minor fixes to make python locate my modules?


briefly put, add an (even empty) __init__.py file in your lvk directory,
and it should work fine (minus potential import problems in your
modules, but that should be easy to fix...)

HTH
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Sep 28 '05 #3

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

Similar topics

10
by: Amardeep Verma | last post by:
Hi, I would like to determine the Country and Organization from a given IP. I have to write a JSP, which when given the IP address gives the country and the organization to which the IP belongs....
4
by: Paul Gardella | last post by:
Folks, Does anyone know of a Python module for building organization charts? I've looked at gdchart and JPGraph, but neither of them do org charts, as far as I can tell. Seems it can be done...
1
by: Steven T. Hatton | last post by:
I think Danny was one cup of coffee shy of full consciousness when he wrote this, but the gist of it makes sens to me: "C++ Project Organization Guidelines Last updated May 26, 2005....
1
by: RayS | last post by:
I've begun a Python module to provide a complete interface to the Meade LX200 command set, and have searched for a style/development guide for Python Lib/site-packages type modules, but only saw...
4
by: junchan | last post by:
Greetings, I have developed a freeware ms access (mde format) application for non governmental organization. Althougt this is a freeware application i want to protect and tracking my application....
14
by: ccdetail | last post by:
http://www.tiobe.com/index.htm?tiobe_index Python is the 7th most commonly used language, up from 8th. The only one gaining ground besides VB in the top 10. We're glad, our app is written in...
32
by: Matias Jansson | last post by:
I come from a background of Java and C# where it is common practise to have one class per file in the file/project structure. As I have understood it, it is more common practice to have many...
3
by: sulekha | last post by:
Hi all, I was reading the book "Write Great Code vol 1" by Ryndall hyde in this book chapter 11 is named as Memory architecture & Organization. in this chapter there is a section named "Run time...
13
by: Rafe | last post by:
Hi, I am in a situation where I feel I am being forced to abandon a clean module structure in favor of a large single module. If anyone can save my sanity here I would be forever grateful. My...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.