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

How to create a module?

440 256MB
Hi ,


I have set of Python files,How to make that Python files as module?.

Is it compulsory that we have to make all the python files as module?.What I understood about module in python is that ,it is similar to Library and DLL in programming languages.

When we have to say that we have to create a Module?


Thanks in advance
PSB
Mar 7 '07 #1
6 4447
bartonc
6,596 Expert 4TB
Hi ,


I have set of Python files,How to make that Python files as module?.

Is it compulsory that we have to make all the python files as module?.What I understood about module in python is that ,it is similar to Library and DLL in programming languages.

When we have to say that we have to create a Module?


Thanks in advance
PSB
You misunderstand your terminology:
Each .py file is a "module".
Modules may be put into a directory with an __init__ file to make a package.
You have been given links to PI and py2exe previously. Please see the posts by truelove911 in the python>articles section of this forum (links in the announcement and in the sticky above).
Mar 7 '07 #2
psbasha
440 256MB
Thanks for the reply.

I have to read on modules to know more about it.

- PSB
Mar 7 '07 #3
bvdet
2,851 Expert Mod 2GB
Thanks for the reply.

I have to read on modules to know more about it.

- PSB
It's not as complex as you might think. Here is a partial directory listing for my 'modules'.:
Expand|Select|Wrap|Line Numbers
  1. Directory of C:\SDS2_7.0\macro\macrolib\
  2.  
  3. __init__.py
  4. __init__.pyc
  5. angle.py
  6. angle.pyc
  7. AngleBetMemTrue.py
  8. AngleBetMemTrue.pyc
  9. Basis3D.py
  10. Basis3D.pyc
  11. beam_point_list.py
  12. ...........................
Most of these files can be run as stand-alone scripts with this code:
Expand|Select|Wrap|Line Numbers
  1. if __name__ == '__main__':
  2.     ....execute the function or class defined in this file........
To import a function or class from a module:
Expand|Select|Wrap|Line Numbers
  1.     from macrolib.Basis3D import BasisTransToGlobal
The parent directory to macrolib must be on the system path.
Mar 7 '07 #4
psbasha
440 256MB
Hi,

In my project I am creating each class ( they have minimum 500 to 1000 LOC) as different python file ( .py).But as per discussion in the forum ,each python file is called as a module.

I would like to know whether I am proceeding in a right direction.

Sample1.py

class Sample1:
.......

Sample2.py

class Sample2:
.......

Samplen.py

class Samplen:

Is the above approach is right?. or is there any best way to handle the approach.

Thanks in advance
PSB
Mar 7 '07 #5
bartonc
6,596 Expert 4TB
Hi,

In my project I am creating each class ( they have minimum 500 to 1000 LOC) as different python file ( .py).But as per discussion in the forum ,each python file is called as a module.

I would like to know whether I am proceeding in a right direction.

Sample1.py

class Sample1:
.......

Sample2.py

class Sample2:
.......

Samplen.py

class Samplen:

Is the above approach is right?. or is there any best way to handle the approach.

Thanks in advance
PSB
Generally, it is OK to have one class per module. Naming as you have suggested can become a little confusing for beginners, but is valid and often used. ie:
Expand|Select|Wrap|Line Numbers
  1. import samle1
  2. mySampleObject = sample1.sample1()
For encapsulation with the Model/View/Control model in mind, I usually end up with low level (model) class(es) and functions in one module that will run without any GUI. Then build the GUI (View/Control) on top of that work in a separate module. Ultimately, there is one module to get the whole thing running, with separate modules importing the classes and functions that they need. Keep and eye on the Code sub section of this forum for updates soon.
Mar 7 '07 #6
bvdet
2,851 Expert Mod 2GB
Hi,

In my project I am creating each class ( they have minimum 500 to 1000 LOC) as different python file ( .py).But as per discussion in the forum ,each python file is called as a module.

I would like to know whether I am proceeding in a right direction.

Sample1.py

class Sample1:
.......

Sample2.py

class Sample2:
.......

Samplen.py

class Samplen:

Is the above approach is right?. or is there any best way to handle the approach.

Thanks in advance
PSB
There is no reason why each class has to be in a separate file. I prefer to name the module file different than the functions and class defined in it. I would:
Expand|Select|Wrap|Line Numbers
  1. from samples import Sample1, Sample2, Samplen, sampler, .........
That's just my preference.
Mar 7 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tim Werth | last post by:
I am trying to use reflection to add an event handler for the RowUpdated event of the OracleDataAdapter object (ODP.NET), but the same thing can be said for SqlDataAdapter if you only use...
5
by: John | last post by:
Hi, I have an application which is built from many modules. I re-use the modules in different applications. I'd like to have each of my modules implement a "SaveState()" method. The method...
1
by: Ellis Yu | last post by:
Dear all, I want to create some kinds of common functions like "Instr" function in microsoft.visualbasic library. I create a new project and a module to store all these kinds of functions...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
27
by: max | last post by:
Hello, I am a newbye, and I'm trying to write a simple application. I have five tables with three columns; all tables are identical; I need to change some data in the first table and let VB...
5
by: Steven W. Orr | last post by:
I have two seperate modules doing factory stuff which each have the similar function2: In the ds101 module, def DS101CLASS(mname,data): cname = mname+'DS101' msg_class = globals() msg =...
7
by: johnny | last post by:
Any Good tools to create CSV Files? ReportLab only creates pdf files. I need something to create CSV files. Thank you.
5
by: Gruik | last post by:
Hi people, I'm currently working on python embedding with C++. My goal is that the C++ part handle files writing/reading so that the Python part only works with buffers. I succeeded in buffer...
0
by: dudeja.rajat | last post by:
On Mon, Aug 25, 2008 at 12:57 PM, <dudeja.rajat@gmail.comwrote: Ok...now I found the way to do that. But I'm stuck further. my code is as below: main module ********************** myRoot...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.