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

Module clarification

Hi.
I'm a Java guy and I'm playing around Python these days...
In Java, we organize our classes into packages and then jarring the
packages into JAR files.
What are modules in Python?
What is the equivalent of modules in Java?
Please correct me if I'm wrong:
I saved my Python code under the file Wow.py
Wow.py is now a module and I can use it in other Python code:
import Wow

Thanks.
Jul 28 '08 #1
7 913
On Jul 28, 9:54*am, Hussein B <hubaghd...@gmail.comwrote:
Hi.
I'm a Java guy and I'm playing around Python these days...
In Java, we organize our classes into packages and then jarring the
packages into JAR files.
What are modules in Python?
An importable or runable (i.e. script) collection of classes,
functions, variables etc...
What is the equivalent of modules in Java?
Don't know. Not even sure if it exists, but my Java is old and never
been great.
Please correct me if I'm wrong:
I saved my Python code under the file * Wow.py
Wow.py is now a module and I can use it in other Python code:
import Wow
Indeed, you can now access things defined in Wow as Wow.foo
Regards
Floris

Jul 28 '08 #2
On Jul 28, 6:55 am, Floris Bruynooghe <floris.bruynoo...@gmail.com>
wrote:
On Jul 28, 9:54 am, Hussein B <hubaghd...@gmail.comwrote:
Hi.
I'm a Java guy and I'm playing around Python these days...
In Java, we organize our classes into packages and then jarring the
packages into JAR files.
What are modules in Python?

An importable or runable (i.e. script) collection of classes,
functions, variables etc...
What is the equivalent of modules in Java?

Don't know. Not even sure if it exists, but my Java is old and never
been great.
Please correct me if I'm wrong:
I saved my Python code under the file Wow.py
Wow.py is now a module and I can use it in other Python code:
import Wow

Indeed, you can now access things defined in Wow as Wow.foo

Regards
Floris
If I have a couple of modules, is there a way to package them? or
there is no such a thing in Python?
Jul 28 '08 #3
Hussein B wrote:
Hi.
I'm a Java guy and I'm playing around Python these days...
In Java, we organize our classes into packages and then jarring the
packages into JAR files.
What are modules in Python?
What is the equivalent of modules in Java?
Read the docs:

http://docs.python.org/tut/node8.html

And read about eggs, the jars of python:

http://peak.telecommunity.com/DevCenter/PythonEggs

Diez
Jul 28 '08 #4
Hussein B <hu********@gmail.comwrote:
If I have a couple of modules, is there a way to package them? or
there is no such a thing in Python?

It sounds rather as though you haven't yet gone through the Python
tutorial. You really should read it, even if you just skim through it to
see what topics are covered. The tutorial explains both modules and
packages: http://docs.python.org/tut/node8.html

What it doesn't cover is that you can import modules or packages directly
from a zip file.

Then read about eggs.

--
Duncan Booth http://kupuguy.blogspot.com
Jul 28 '08 #5
On Jul 28, 4:54*am, Hussein B <hubaghd...@gmail.comwrote:
Hi.
I'm a Java guy and I'm playing around Python these days...
In Java, we organize our classes into packages and then jarring the
packages into JAR files.
What are modules in Python?
What is the equivalent of modules in Java?
I'm new myself, coming from Perl and Java. Take my comments with the
appropriate salt.

Here's my understanding:

1) JARs are a bit of a Java oddity. The other languages I've worked
with don't really combine their packaging method for transport with
their packaging method of access. Put another way, you may get a
zipfile or tarball of library files, but they aren't USED in that
format, they are just transported in that format. You unzip them and
use the compiled libraries directly. Java appears to be unusual
there. I could be wrong (it's a big world), but such is my experience
in the C and Perl worlds.

2) Java also dictates a single class per file (basically). Other
languages do not have that restriction which leads to different
collections. A file in Python (a module) may have several classes, or
just one, or none. A package in Python is a directory containing
modules (and possibly other packages) as well as a __init__.py file.
This means that you cannot have the Java case of two packages offering
the same fully qualified resource, because the namespace is tied to
the filesystem (note you can alter this when importing the packages).

3) Java uses "import" to create a shortcut to the namespace, a
convenience for the programmer that has little to no bearing on the
execution of the code. Namespace is determined by the classloader.
Python uses "import" to declare how a namespace is used by the code
itself, which can be very significant, (For example, Java can access
any fully qualified package without an import statement. Python
cannot access any package until it has been made available by import.)

Hope that helps and is remotely accurate. I'm sure someone will
correct me if I'm wrong.
Jul 28 '08 #6
On Jul 28, 8:11 am, Duncan Booth <duncan.bo...@invalid.invalidwrote:
Hussein B <hubaghd...@gmail.comwrote:
If I have a couple of modules, is there a way to package them? or
there is no such a thing in Python?

It sounds rather as though you haven't yet gone through the Python
tutorial. You really should read it, even if you just skim through it to
see what topics are covered. The tutorial explains both modules and
packages:http://docs.python.org/tut/node8.html

What it doesn't cover is that you can import modules or packages directly
from a zip file.

Then read about eggs.

--
Duncan Boothhttp://kupuguy.blogspot.com
I'm reading "Learning Python, 3rd Edition"
What do you think about it?
Jul 28 '08 #7
Hi Hussein,

Basically a module is a FILE and is considered as a singleton model. Yes
ur wow.py assumption is correct.
I recommend getting Mark Lutz Learning Python book to get you started.

Marcus.CM

Hussein B wrote:
Hi.
I'm a Java guy and I'm playing around Python these days...
In Java, we organize our classes into packages and then jarring the
packages into JAR files.
What are modules in Python?
What is the equivalent of modules in Java?
Please correct me if I'm wrong:
I saved my Python code under the file Wow.py
Wow.py is now a module and I can use it in other Python code:
import Wow

Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Jul 28 '08 #8

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

Similar topics

4
by: debbie | last post by:
Well I'm finally trying out class modules...I have a great book I'm using but its ADO and I use DAO so it's a challenge for me...I've looked most of today, in my book and here but can not find an...
8
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I...
4
by: | last post by:
When I add a new module in the project explorer pane, the wizard inserts a Module1 scope, so any variables I will put there can be accessed with a qulification, e.g. dim a as integer will be...
15
by: Laserson | last post by:
Hi! I can't understand what difference between modules and classes in VB.NET project?
17
by: Paul Helmuth | last post by:
All, (here's an easy one)... This is probably a stupid question - please bare with me as I am new to dotNet. How does one reference objects on a form from a module? In 6.0 you could simply...
8
by: Joshua J. Kugler | last post by:
So, I have: ModTest __init__.py AModule.py BModule.py CModule.py All works fine. However, when I import ModTest, I would like it to discover and store the names of the modules beneath it,...
0
by: thirunavukarasukm | last post by:
Hai.. Is thers possible to use module class in web application.. in web application i have one module class.. the module class one variable declared to assing particular value then i am...
2
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I am using Visual Studio 2005 to develop C++ DLL (in-process COM). There is a setting in Linker --Input called Module definition file. This setting makes me confused, 1. I...
4
by: Traclo | last post by:
Hello all, I was hoping that someone could help me out with a python programming question. I have a main program that imports a module which consists of a class. What I cannot seem to do is get a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
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...

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.