Hi all,
I am new to python. Sorry if this is too novice question, but I could
not find an answer yet.
While coding a business class library, I think it is preferable to have
one class per source file, rather than combining all classes into one
file, considering multiple developers developing the classes.
So, as per my study of python, a developer using the business class
library has to write so many imports, one per class. Like:
from person import Person
from contact import Contact
..
..
..
Is there not a simple solution, a single import and you are able to use
all the classes? Is there anything wrong in my approcah? Waiting for
suggestions.
Thanks in advance.
Sanjay 5 1888
Sanjay wrote:
I am new to python. Sorry if this is too novice question,
Don't worry and welcome.
While coding a business class library, I think it is preferable to have
one class per source file, rather than combining all classes into one
file, considering multiple developers developing the classes.
The use of one class = one sourcefile is often coming from Java.
Usually in Python people use something in the middle, putting related
names / functions / classes in the same module.
And you can put related modules in the same directory (with the
__init__ file).
Is there not a simple solution, a single import and you are able to use
all the classes? Is there anything wrong in my approcah? Waiting for
suggestions.
Other things that you may find useful to organize your names and
modules:
- the __all__ list to choose what to export;
- you can import a whole directory of modules;
- you can put many names in the same import line (from xx import xy,
yz, etc).
- Sometimes you can even use from XX import * but this can be a little
dangerous.
Bye,
bearophile
Sanjay schrieb:
Hi all,
I am new to python. Sorry if this is too novice question, but I could
not find an answer yet.
While coding a business class library, I think it is preferable to have
one class per source file, rather than combining all classes into one
file, considering multiple developers developing the classes.
So, as per my study of python, a developer using the business class
library has to write so many imports, one per class. Like:
from person import Person
from contact import Contact
.
.
.
Is there not a simple solution, a single import and you are able to use
all the classes? Is there anything wrong in my approcah? Waiting for
suggestions.
While there is nothing technically wrong, in python usually several
related classes (and functions!) are grouped in one module. Not one
class per file.
Additionally, you can use one module to import others into its
namespace. The result is that this allows to only have one import, but
get lots of modules imported with that.
foo/__init__.py:
import bar
from baz import *
foo/bar.py:
class Bar(object):
pass
foo/baz.py:
class Baz(object):
pass
can then be used as this:
import foo
foo.bar.Bar()
foo.bar.Baz()
Diez
Sanjay wrote:
Hi all,
I am new to python. Sorry if this is too novice question, but I could
not find an answer yet.
While coding a business class library, I think it is preferable to have
one class per source file, rather than combining all classes into one
file, considering multiple developers developing the classes.
The "multiple developpers" already implies the use of a CVS, so it's a
dubious argument here IMHO. Also, Python is not Java, and doesn't force
you into using classes when other constructs will do (functions, dicts
etc). The organization of the source should be done with the
hi-cohesion/low-coupling rule in mind, ie symbols that are very closely
related should go in a same module.
So, as per my study of python, a developer using the business class
library has to write so many imports, one per class. Like:
from person import Person
from contact import Contact
.
As you already noticed, this sucks.
Is there not a simple solution,
- use a CVS (not necessarily 'the' CVS - subversion is somewhat better,
and there are other options too) to address the multi-developper problem
- put closely related symbols in a same module
- put closely related modules in a same package
a single import and you are able to use
all the classes?
Python as packages: http://docs.python.org/tut/node8.htm...00000000000000
Is there anything wrong in my approcah?
cf above
HTH
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Sanjay wrote:
While coding a business class library, I think it is preferable to have
one class per source file,
.... but I don't like the consequences :-)
So, as per my study of python, a developer using the business class
library has to write so many imports, one per class. Like:
from person import Person
from contact import Contact
.
.
.
Is there not a simple solution, a single import and you are able to use
all the classes? Is there anything wrong in my approcah? Waiting for
suggestions.
Put person.py, contact.py etc into a subdirectory (which I assume is called
business). Then create a file business/__init__.py to turn the directory
into a package
#contents of business/__init__.py
from person import Person
from contact import Contact
You can then use your library like so:
from business import Person, Contact
person = Person(...)
contact = Contact(...)
or preferably:
import business
person = business.Person (...)
contact = business.Contac t(...)
Peter
Thanks a lot to all for the to-the-point info, quite vital to me...
Sanjay This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Hasan O. Zavalsiz |
last post by:
Hi , i am trying to figure out which approach is better to use .
let me explain the scenario.
i am using the "Nortwind" database . in this database i have "Customers "
table .The following is the two different ways to handle this table.
CASE 1 :
create a struct that encaplusates table "Customers" columns
public struct structCustomers
{
public string CustomerID;
|
by: John |
last post by:
Hello everyone!
I've read many articles about asp.net, business and data layers, and none of
them seem to discourage the use of HttpContext specific variables in
non-HttpContext specific layers; relying on the presence of the HttpSession
or HttpRequest variables in the business layer for example.
From what I can gather, doing this prevents these layers from being reused
by different clients (winforms for example) since this context...
|
by: Shapper |
last post by:
Hello,
I am working in a web site where all the code is placed in aspx.vb
files.
After a while I realized that many functions included in my aspx.vb
files where common to all pages.
I created a new file named common.vb where I created a class named
common and where I place all common functions:
|
by: Carlos |
last post by:
I'm using VS 2003, im trying to write a windows app that will send an emial
bt when I import the Imports System.Web.Mail give me an error, it finds
Imports System.Web but not the mail part any ideas ?
Imports System.Web
Imports System.Web.Mail ' This one can't find it
Thanks
|
by: moondaddy |
last post by:
I'm wanting to create a bindable list object made up of a list of business
classes. I'm writing this in a vb.net 1.1 winforms app and am using a code
example by Rocky Lhotka for reference material:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet02252003.asp
which makes use of the IEditableObject interface.
My situation is that my business class manages data for a table which has
about 20 columns all...
| |
by: Guy Thornton |
last post by:
I have an application in asp.net using vb.
The asp.net portion of this application is mainly the user interface. The
UI has references made to our business logic layer. And the business logic
layer uses a database class to access our data environment.
The business logic layer and database class is compiled into a class
library. The database class is a single class that contains all of our
queries there. It is implemented following...
|
by: grawsha2000 |
last post by:
Greetings,
I am developing this N-tier business app. The problem I'm facing is
when I try to pass business objects (employees, dept..etc) from
business tier to data tier,i.e., the add method in the data tier
expects business object from the business tier, I get an error saying:
Can not covert businesslayer.emp to businesslayer.emp
|
by: Chris Zopers |
last post by:
Hello,
I would like to know what's the best way to implement a business logic
layer between my user interface and my database.
I would say I'd make a dll-project for the business logic layer and make
classes that represent objects/tables. For example, if I have a table
named 'tblPersons' I would make a class named 'clsPersons' and a class
'clsPerson' that represents one person/record. In class 'clsPersons' I
can make some business...
|
by: jehugaleahsa |
last post by:
Hello:
I am trying to find what is the very best approach to business objects
in Windows Forms. Windows Forms presents an awesome opportunity to use
DataTables and I would like to continue doing so.
I have worked with dynamically generated DataTables with customized
DataRows. However, these classes are usually pretty limited. For
instance, you are limited to a select few data types and you can't
deal with nulls as well as desired (in...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |