473,289 Members | 2,141 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,289 software developers and data experts.

about python modules

hi friends i am new to python programming.
i am using Python 2.5 and IDLE as editor.
i have developed some functions in python those will be calling
frequently in my main method .
now i want to know how to import my functions folder to python in
sucha way that the functions in functions folder should work like
python library modules .

i have python in folder C:\python25\..
and functions folder D:\programs\Functions\

pls help me friends how to do that.
Jun 27 '08 #1
4 1167
In article
<2f**********************************@i36g2000prf. googlegroups.com>,
srinivas <sr**************@gmail.comwrote:
hi friends i am new to python programming.
i am using Python 2.5 and IDLE as editor.
i have developed some functions in python those will be calling
frequently in my main method .
now i want to know how to import my functions folder to python in
sucha way that the functions in functions folder should work like
python library modules .

i have python in folder C:\python25\..
and functions folder D:\programs\Functions\

pls help me friends how to do that.
You need to either:

1) Put your modules in some directory that's already on your python path.
To find out what your path is, do:

import sys
print sys.path

It should include a directory which ends in "site-packages". Just drop
your modules into that directory.

2) Add the directory where you modules are to your python path. The
easiest way to do this is to set PYTHONPATH in your environment.
Jun 27 '08 #2
On 21 Mag, 14:31, srinivas <srinivas.puvv...@gmail.comwrote:
hi friends i am new to python programming.
i am using Python 2.5 and IDLE as editor.
i have developed some functions in python those will be calling
frequently in my main method .
now i want to know how to import my functions folder to python in
sucha way that the functions in functions folder should work like
python library modules .

i have *python in folder C:\python25\..
and functions folder D:\programs\Functions\

pls help me friends how to do that.
You have two choices:

1. In this way you can import single modules (files) in tour folder

import sys
sys.path.append(r'D:\programs\Functions\')
import my_module_1
import my_module_2

and then use whatever you have in the modules:

my_module_1.my_function()
print my_module_1.my_variable
2.
If you add an empty python module called __init__.py inside the folder
D:\programs\Functions\,
then python will handle the folder as a package (i.e. a group of
modules) and you can import
them in this way:

sys.path.append(r'D:\programs\')
import Functions # I'm not sure this is needed ...
from Functions import my_module_1, my_module_2

And then use whatever is in your modules as in case 1.

If you put any code in __init__.py, this code will be executed when
the import Functions
statement is executed. This can be handy in some cases, e.g. if you
have subfolders of
Function folder and want to extend sys.path to include all them.

For more details, read the section 6 of Python tutorial.

HTH

Ciao
------
FB
Jun 27 '08 #3
i always just put most of my python files in the c:\python25 directory.
including ones i want to import as modules, since they import from there.
otherwise you can put the file in c:\python25\lib\site-packages

"srinivas" <sr**************@gmail.comwrote in message
news:2f**********************************@i36g2000 prf.googlegroups.com...
hi friends i am new to python programming.
i am using Python 2.5 and IDLE as editor.
i have developed some functions in python those will be calling
frequently in my main method .
now i want to know how to import my functions folder to python in
sucha way that the functions in functions folder should work like
python library modules .

i have python in folder C:\python25\..
and functions folder D:\programs\Functions\

pls help me friends how to do that.

Jun 27 '08 #4
srinivas wrote:
... i want to know how to import my functions folder to python in
sucha way that the functions in functions folder should work like
python library modules .

i have python in folder C:\python25\..
and functions folder D:\programs\Functions\

pls help me friends how to do that.
An unmentioned possibility:
Create a file named "whatever.pth" (where the "whatever" is your
choice). The contents of this file should be a line containing the
path to your directory (in your case a single line containing
"D:\programs\Functions" (w/o the quotes).
Put this file in your site-packages file (for windows in your case,
that is C:\Python25\Lib\site-packages
--Scott David Daniels
Sc***********@Acm.Org
Jun 27 '08 #5

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

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
10
by: Berthold Hoellmann | last post by:
Hello, When I use ./configure --with-thread --with-fpectl --with-signal-module \ --with-pymalloc --enable-shared --with-cxx=g++ make test on 2.3.3 I get
2
by: Olaf Meyer | last post by:
I'm having some problems compiling Python 2.3.3 on HP-UX (B.11.00). I've tried sevral different options for the configure script (e.g. enabling/disabling gcc, aCC) but I always get the same problem...
28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
6
by: Hung ho | last post by:
Hi. I just finished reading an introductory Python book called "Python Programming for the absolute beginner" by Michael Dawson. I found it very interesting, and easy to follow. Python does really...
1
by: Jerald | last post by:
Running python 2.3.4 on valgrind (a tool like purify which checks the use of uninitialized memory, etc), gives a lot of errors. See below. jfj@cluster:~/> python -V Python 2.3.4...
17
by: Jan Danielsson | last post by:
Hello all, I recently started using Python, and I must say I like it. Both the language and libraries available for it. Background: I have written an application which I use to keep track of...
1
by: Justin Johnson | last post by:
Hello, I'm trying to build Python 2.5.0 on AIX 5.3 using IBM's compiler (VisualAge C++ Professional / C for AIX Compiler, Version 6). I run configure and make, but makes fails with undefined...
0
by: mg | last post by:
When make gets to the _ctypes section, I am getting the following in my output: building '_ctypes' extension creating build/temp.solaris-2.10-i86pc-2.5/home/ecuser/Python-2.5.1/ Modules/_ctypes...
0
by: Akira Kitada | last post by:
Hi list, I was trying to build Python 2.6 on FreeBSD 4.11 and found it failed to build some of the modules. """ Failed to find the necessary bits to build these modules: _bsddb ...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...

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.