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

Beginner question: module organisation

Hello :)

I am new to python and I don't have much expirience in object-oriented
technologies neither.

The problem is the following: I have to create a simple python
template script that will always follow the same algorithm, let's say:
- read a mesh
- transform the mesh (let's say, refine)

The last step should be a kind of a black box:
- the same input data format
- some algorithme inside
- the same output data format

A number of different refine methods should be implemented. The end-
user must be able to write easily a new method and call it from the
base script without any major change.

Something like this would be a solution (no classes created, no OO
programming):
- a module defining REFINE1(mesh), REFINE2(mesh), ...
- in the script:
from MODULE import REFINE2 as REFINE
REFINE(mesh)

Is it a proper solution for this kind of problem? How would you
implement this kind of task?

May 14 '07 #1
5 1177
On May 14, 9:09 am, Mail.To.Nathan...@gmail.com wrote:
Hello :)

I am new to python and I don't have much expirience in object-oriented
technologies neither.

The problem is the following: I have to create a simple python
template script that will always follow the same algorithm, let's say:
- read a mesh
- transform the mesh (let's say, refine)

The last step should be a kind of a black box:
- the same input data format
- some algorithme inside
- the same output data format

A number of different refine methods should be implemented. The end-
user must be able to write easily a new method and call it from the
base script without any major change.

Something like this would be a solution (no classes created, no OO
programming):
- a module defining REFINE1(mesh), REFINE2(mesh), ...
- in the script:
from MODULE import REFINE2 as REFINE
REFINE(mesh)

Is it a proper solution for this kind of problem? How would you
implement this kind of task?
Why not OO? This is a good problem for OO. For example: there is a
base class (BaseMesh) that will take care of loading your
mesh,provide a generic (possibly empty) refine() method, output the
mesh and have a bunch of utility functions. You can put that in a
module like meshing.py.

Then the user will do:
--------------------------------------------
from meshing import BaseMesh
class UsersMesh(BaseMesh):
def __init__(self,...):
BaseMesh.__init__(self,...)
....etc. initializer...
def refine(self,...):
...user's refine method would go here...
--------------------------------------------------

So for each different refine() method the user can derive a new class
from BaseMesh and overload the refine(...) method.

Hope that helps,
-Nick Vatamaniuc
May 14 '07 #2
Ma***************@gmail.com wrote:
Hello :)

I am new to python and I don't have much expirience in object-oriented
technologies neither.

The problem is the following: I have to create a simple python
template script that will always follow the same algorithm, let's say:
- read a mesh
- transform the mesh (let's say, refine)

The last step should be a kind of a black box:
- the same input data format
- some algorithme inside
- the same output data format

A number of different refine methods should be implemented. The end-
user must be able to write easily a new method and call it from the
base script without any major change.

Something like this would be a solution (no classes created, no OO
programming):
- a module defining REFINE1(mesh), REFINE2(mesh), ...
- in the script:
from MODULE import REFINE2 as REFINE
REFINE(mesh)

Is it a proper solution for this kind of problem? How would you
implement this kind of task?
Hello.

Have a look at the classical GangOfFour design pattern book. You can
especially with the template methode design the processing of your data.
The strategy pattern will help you to vary the algroithm in your processing.

To be concret, in your base class you define the processing of the data.
There are two distinct methods to do it.
delegate the variation of the algorithmns to other objects =strategy
pattern
override the steps of the processing in subclasses =template method

Regards,
Rainer
--
_________________________creating IT solutions
Rainer Grimm
scVENUS Schulungsleiter science + computing ag
phone +49(0)7071 9457-253 Hagellocher Weg 73
fax +49(0)7071 9457-511 D-72070 Tuebingen, Germany
r.*****@science-computing.de www.science-computing.de
May 19 '07 #3
On May 14, 7:09 am, Mail.To.Nathan...@gmail.com wrote:
Hello :)

I am new to python and I don't have much expirience in object-oriented
technologies neither.

The problem is the following: I have to create a simple python
template script that will always follow the same algorithm, let's say:
- read a mesh
- transform the mesh (let's say, refine)

The last step should be a kind of a black box:
- the same input data format
- some algorithme inside
- the same output data format

A number of different refine methods should be implemented. The end-
user must be able to write easily a new method and call it from the
base script without any major change.

Something like this would be a solution (no classes created, no OO
programming):
- a module defining REFINE1(mesh), REFINE2(mesh), ...
- in the script:
from MODULE import REFINE2 as REFINE
REFINE(mesh)

Is it a proper solution for this kind of problem? How would you
implement this kind of task?
How about this:

refineModule.py:
---------------
def refine(userfunc, mesh):
#process mesh
func(mesh)

aprogram.py:
------------
import refineModule

def myRefine(mesh):
print mesh

refineModule.refine(myRefine, "hello world")

May 19 '07 #4
On May 19, 10:45 am, 7stud <bbxx789_0...@yahoo.comwrote:
>
refineModule.py:
---------------
def refine(userfunc, mesh):
#process mesh
func(mesh)
The last line should be:

userfunc(mesh)

May 19 '07 #5
Thank you for all your help!

I'll study the proposals to chose the one I prefer or to create
something new :) Anyway, this is a perfect start-up for me.

Nathaniel.

Jun 5 '07 #6

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

Similar topics

0
by: David M. Wilson | last post by:
Hello! I maintain a small package for talking to the API of BulkSMS.co.uk. I have been adding support for some new features recently, and found myself slightly indecisive over how best to lay...
18
by: fred.dixon | last post by:
i have read the book and searched the group too ---------------------------------------------- im not gettin it. i want to read a global (OPTIONS) from file1 from a class method (func1) in file2...
11
by: Svens | last post by:
Hey everyone! I'm a math student working on a short script involving logs. I have a function on my scientific calculator, and was wondering if there was a similar funtion in python. For example:...
2
by: Paul | last post by:
Hi, I'm curious how others would deal with something I'm building. The app itself is a form of diary; it allows the organisation of diary entries and a number of other data types. Each diary...
18
by: mitchellpal | last post by:
Hi guys, am learning c as a beginner language and am finding it rough especially with pointers and data files. What do you think, am i being too pessimistic or thats how it happens for a beginner?...
3
by: h.silent57 | last post by:
hi.. I m new to kernel programming..for my in-house project, I chose to create a device driver for mouse for which I am required to understand Kernel module programming..I tried to execute this...
3
by: Chrism2671 | last post by:
I'm new to XSLT/XML and I have a very simple, quick question. i've been trying to convert simple xml files into CSV files and have made a simple XSLT template using the w3 tutorials, but it doesn't...
3
by: Ben Keshet | last post by:
I have a probably simple beginner's question - I have a script that I am currently able to print its output. instead, i want to write it into a file - I tried different versions of write() but...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.