[Tutor] "Object designer" applications - are there any?

2011-08-05 Thread Flynn, Stephen (L & P - IT)
I'm about to embark on a project in Python (primarily in order to learn the 
language and equally importantly, to make my life easier at work).

I'm an IBM MVS Operations Analyst by trade by recently I've been spending more 
and more time working on Data Migrations; legacy systems in VSAM files, ADABAS, 
DB2, Oracle, SQL Server, Sybase and most recently we're about to start off on 
Tandem, which should be interesting!

Anyway, nearly all of this work, at some point, involves me reading a Data 
Dictionary for the source system and converting it to an Oracle table 
definition. More often than not this DDL is in text form and I convert it to 
Oracle DDL such as

Create Table wibble
( clientrefNUMBER(10) not null,
  bthdteNUMBER(5) not null,
  natinr_no VARCHAR2(16) not null,
etc
)

It struck me that if I write a "read in Sybase DDL and spit out Oracle DDL" 
routine and so forth, I'd get a lot of reuse out of it. However, I've not done 
much OOP at all and consequently, my object design skills are somewhat 
non-existent. Whilst I have a rough idea of what my properties my "table" 
object will have I was looking for something to help me design it - something 
which I can say "this is a table object, it has a name and multiple columns. 
Columns have a type, a width (which may be further comprised of scale and 
precision or just an integer depending on the column type) and a "nullable" 
flag.). Oh, and there may be multiple columns... so maybe a column should be an 
object too... etc.

Anyone know if there are any such kinds of programs out there already (freeware 
please - I'll be doing this off my own back so funds are tight for commercial 
software). Failing that, does anyone use something for this kind of thing 
already, Visio maybe or a spreadsheet. Maybe just notepad or a post-it?

Perhaps most people just design their objects on paper and let the code do the 
documentation for them... I don't know as I've never done this before.

It doesn't strike me as being a complicated project at first glance - all it's 
doing is translating structured DDL into structured Oracle DDL, but I'd like to 
get my first principles correct so that I don't end up 3 weeks in and realise 
I've made a fundament design flaw ("Crap - I didn't think of anything to 
describe table indexes" or "Hmm - views is a "view" just another "table" or 
should I describe a view in the SQL it'll actually use, so it's just a piece of 
text and how does that translate to a materialized view" and so forth...) 
and have to re-do chunks... or maybe I do  want to do that, to make sure I get 
my design nailed before a line of code is ground out.


I'm open to suggestions on what useful tools are out there to make my learning 
experience easier, more pleasant and satisfying - if that involves the back of 
fag packets, so be it. :)


-- 
Steve Flynn
Technical Architect
Tel 01242 670864
 
CLPS Elixir Project Office
Capita Life & Pensions Services
S4, The Grange
Bishops Cleeve
GL52 8XX
 
www.capita-lps.co.uk
Part of the Capita Group plc - www.capita.co.uk
Capita Life & Pensions Services Limited is registered in England No 4359665
Capita Life & Pensions Regulated Services Limited is registered in England No 
2424853
Registered Office: 71 Victoria Street, Westminster, London, SW1H 0XA



This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Object designer" applications - are there any?

2011-08-05 Thread Christian Witts

On 2011/08/05 01:01 PM, Flynn, Stephen (L & P - IT) wrote:



It struck me that if I write a "read in Sybase DDL and spit out Oracle DDL" routine and so forth, I'd 
get a lot of reuse out of it. However, I've not done much OOP at all and consequently, my object design skills are 
somewhat non-existent. Whilst I have a rough idea of what my properties my "table" object will have I 
was looking for something to help me design it - something which I can say "this is a table object, it has a 
name and multiple columns. Columns have a type, a width (which may be further comprised of scale and precision or 
just an integer depending on the column type) and a "nullable" flag.). Oh, and there may be multiple 
columns... so maybe a column should be an object too... etc.

Anyone know if there are any such kinds of programs out there already (freeware 
please - I'll be doing this off my own back so funds are tight for commercial 
software). Failing that, does anyone use something for this kind of thing 
already, Visio maybe or a spreadsheet. Maybe just notepad or a post-it?





You could take a look at SQLAlchemy [1] and possibly the migrate [2] 
portion of it for schema management. It supports connectivity for both 
Sybase and Oracle as well as being able to generate the DDL [3]


[1] http://www.sqlalchemy.org/docs/
[2] 
http://packages.python.org/sqlalchemy-migrate/versioning.html#experimental-commands
[3] 
http://www.sqlalchemy.org/trac/wiki/FAQ#HowcanIgettheCREATETABLEDROPTABLEoutputasastring


--

Christian Witts
Python Developer

//
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Object designer" applications - are there any?

2011-08-05 Thread Flynn, Stephen (L & P - IT)
I'll certainly give it a look-see - thanks Christian

 

I'm going to end up writing converters anyway, as at some point I'm
going to be given (for example) a COBOL copybook for a file and have to
translate that into an Oracle table version (actually I already have
tools to do this, but if I'm going to be learning python via a project,
I might as well do it properly).

 

S.

 

 



From: Christian Witts [mailto:cwi...@compuscan.co.za] 
Sent: Friday, August 05, 2011 1:10 PM
To: Flynn, Stephen (L & P - IT)
Cc: Tutor List
Subject: Re: [Tutor] "Object designer" applications - are there any?

 

On 2011/08/05 01:01 PM, Flynn, Stephen (L & P - IT) wrote: 


 
It struck me that if I write a "read in Sybase DDL and spit out Oracle
DDL" routine and so forth, I'd get a lot of reuse out of it. However,
I've not done much OOP at all and consequently, my object design skills
are somewhat non-existent. Whilst I have a rough idea of what my
properties my "table" object will have I was looking for something to
help me design it - something which I can say "this is a table object,
it has a name and multiple columns. Columns have a type, a width (which
may be further comprised of scale and precision or just an integer
depending on the column type) and a "nullable" flag.). Oh, and there may
be multiple columns... so maybe a column should be an object too... etc.
 
Anyone know if there are any such kinds of programs out there already
(freeware please - I'll be doing this off my own back so funds are tight
for commercial software). Failing that, does anyone use something for
this kind of thing already, Visio maybe or a spreadsheet. Maybe just
notepad or a post-it?
 

 


You could take a look at SQLAlchemy [1] and possibly the migrate [2]
portion of it for schema management. It supports connectivity for both
Sybase and Oracle as well as being able to generate the DDL [3]

[1] http://www.sqlalchemy.org/docs/
[2]
http://packages.python.org/sqlalchemy-migrate/versioning.html#experiment
al-commands
[3]
http://www.sqlalchemy.org/trac/wiki/FAQ#HowcanIgettheCREATETABLEDROPTABL
Eoutputasastring

-- 

Christian Witts
Python Developer

 

Click here
  to report this email
as spam.



This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Object designer" applications - are there any?

2011-08-05 Thread Alan Gauld

On 05/08/11 12:01, Flynn, Stephen (L & P - IT) wrote:


Anyway, nearly all of this work, at some point, involves me reading a Data 
Dictionary

> for the source system and converting it to an Oracle table definition.


More often than not this DDL is in text form and I convert it to Oracle DDL 
such as

Create Table wibble
( clientrefNUMBER(10) not null,
   bthdteNUMBER(5) not null,
   natinr_no VARCHAR2(16) not null,
etc
)

It struck me that if I write a "read in Sybase DDL and spit out Oracle DDL" 
routine

> and so forth, I'd get a lot of reuse out of it.


However, I've not done much OOP at all


I'm not sure you need OOP for this. As you say a "routine" ie a function 
might be all you need along with some data structures - probably 
dictionaries to define the translations needed.



Perhaps most people just design their objects on paper and let

>  the code do the documentation for them...

It depends on the complexity. For a big project (say >25 classes)
I'd use a UML design tool like IBM RSA (Rational Rose as was) or Borland 
Together. But for small projects Visio/Power[point and some 
documentation in the code would suffice. And for very small

designs (2 or 3 classes) it would just be the code!

Biut for this it seems that a simple function to generte the DDL
based on an input translation table should be feasible, with
no objects required. (You could use objects of course if you really want 
but I don't think they're necessary, or even particularly

helpful, in this case.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Object designer" applications - are there any?

2011-08-05 Thread python
Stephen,

You might check out the SQL management tools from Embarcadero.
They may provide some of the conversion capabilities you are
looking for. And they generate beautiful documentation.

Perhaps you could wrap the features of this product with Python
scripts to acheive your goals?

Malcolm
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Object designer" applications - are there any?

2011-08-05 Thread Flynn, Stephen (L & P - IT)
> > However, I've not done much OOP at all
> 
> I'm not sure you need OOP for this. As you say a "routine" ie a
function
> might be all you need along with some data structures - probably
> dictionaries to define the translations needed.

I suspect you're correct Alan, but as I'm using this an a learning
exercise for the language it seemed too good an opportunity to miss - I
can relate a table to an "object" in my head quite easily - just need to
know how to do it in Python...


S.



This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Object designer" applications - are there any?

2011-08-05 Thread Robert Sjöblom
> It struck me that if I write a "read in Sybase DDL and spit out Oracle DDL" 
> routine and so forth, I'd get a lot of reuse out of it. However, I've not 
> done much OOP at all and consequently, my object design skills are somewhat 
> non-existent. Whilst I have a rough idea of what my properties my "table" 
> object will have I was looking for something to help me design it - something 
> which I can say "this is a table object, it has a name and multiple columns. 
> Columns have a type, a width (which may be further comprised of scale and 
> precision or just an integer depending on the column type) and a "nullable" 
> flag.). Oh, and there may be multiple columns... so maybe a column should be 
> an object too... etc.
> 
> Anyone know if there are any such kinds of programs out there already 
> (freeware please - I'll be doing this off my own back so funds are tight for 
> commercial software). Failing that, does anyone use something for this kind 
> of thing already, Visio maybe or a spreadsheet. Maybe just notepad or a 
> post-it?
> 
> Perhaps most people just design their objects on paper and let the code do 
> the documentation for them... I don't know as I've never done this before.
> 
> It doesn't strike me as being a complicated project at first glance - all 
> it's doing is translating structured DDL into structured Oracle DDL, but I'd 
> like to get my first principles correct so that I don't end up 3 weeks in and 
> realise I've made a fundament design flaw ("Crap - I didn't think of anything 
> to describe table indexes" or "Hmm - views is a "view" just another 
> "table" or should I describe a view in the SQL it'll actually use, so it's 
> just a piece of text and how does that translate to a materialized view" 
> and so forth...) and have to re-do chunks... or maybe I do  want to do that, 
> to make sure I get my design nailed before a line of code is ground out.
> 
> 
> I'm open to suggestions on what useful tools are out there to make my 
> learning experience easier, more pleasant and satisfying - if that involves 
> the back of fag packets, so be it. :)

I'm typing this on a phone, so I'll keep it short. There are two great books 
that could be useful: "Head First Object-Oriented Analysis & Design" and 
"Python 3 Object Oriented Programming". Head First assumes knowledge of java 
but is useful for learning OO (though some keywords are different, most code is 
understandable if you know python), wjile Python 3 is very dry and technical, 
but really goes in-depth with OO programming and the philosophies behind it 
(the first chapter really helped me wrap my head around OO and inheritance and 
encapsulation and what have you). As for diagrams I believe UML is sufficient 
and there are resources abound online for that, and Visio can easily handle UML 
standards.

best regards,
Robert S.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "Object designer" applications - are there any?

2011-08-05 Thread ALAN GAULD


> > I'm not sure you need OOP for this. 
> I suspect you're correct Alan, but as I'm using this an a learning
> exercise for the language it seemed too good an opportunity to miss 

That's fine so long as we understand why you are going down the OOP route.

> can relate a table to an "object" in my head quite easily - just need to
> know how to do it in Python...

OK, So if you can conceptualise a table what are the operations 
you would perform on it?

It sounds like you want to 
- add columns - from a definition file/document?
- generate DDL based on current structure?
- export a definition document?
- Maybe autopopulate the definition from a given database connection?

So the use case nmay be something like:

Create a table connected to the old database.
The table sucks up the metadata from the database and auto-populates
itself with columns(which might be another class with name, type,size type 
details)

Create a new Table object targeted at the new database (which might not exist 
yet?)
If the table can't auto-populate then feed it the oold table object which it 
queries for 

a description. 
The new table then populates its own definition.

Finally get the new table to generate the DDL and populate the new database.

You might want different table classes each based on different databases, 
so they populate themselves based on the specific meta language and spit 
out a common  description format. They cn then generate their own dialect 
of DDL too...

Does that seem like a starter?

But really, when working with objects it helps to sit back and think through 
how you want to use them from the outside rather than thinking about what 
they look like inside. That way the internals will reflect what's actually 
needed 

for the usage rather than some random model of what might be needed.

HTH,

Alan G.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python loop isn't working

2011-08-05 Thread Susana Iraiis Delgado Rodriguez
Hello list!
I have a python script which works with other libraries in order to create
maps. The script looks for an extension in a specific directory and with
mapnik makes the thumbnails.
The module works fine from Python command line and Pyton IDLE, but I need
this program to run from MS-DOS, when I added the try statement it started
to fail. Module runs but doesn't do what I need. Console shows:

C:\Python26>shp2png.py C:\\ .png
Iniciando...
Listo

What am I doing wrong?

import mapnik
import os,fnmatch, sys
from mapnik import LineSymbolizer,PolygonSymbolizer,PointSymbolizer
from osgeo import ogr,gdal,osr

directorio = sys.argv[1]
extension = sys.argv[2]
try:
if len(sys.argv) == 3:
print 'Iniciando...'
file_list = []
folders = None
for root, folders, files in os.walk( directorio+'\\' ):
for filename in fnmatch.filter(files, extension):
file_list.append(os.path.join(root, filename))
for row, filepath in enumerate(file_list, start=1):
dir(LineSymbolizer().stroke)
shapeData = ogr.Open(filepath)
shp = 'Error al abrir el archivo' +filepath
if shapeData is None:
print shp
continue
layer = shapeData.GetLayer()
defn = layer.GetLayerDefn()
geo = defn.GetGeomType()
(ruta, filename) = os.path.split(filepath)
archivo = os.path.splitext(filename)
i = archivo[0]+'.png'

m = mapnik.Map(800,500,"+proj=latlong +datum=WGS84")
m.background = mapnik.Color('#EBEBEB')
s = mapnik.Style()
r=mapnik.Rule()

if geo == 3 or geo == -2147483645:
print "Trabajando mapa "+ruta+"\\"+filename+" con geometria
"+ str(geo)

r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color('#EB784B')))

r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('rgb(170%,170%,170%)'),0.9))
s.rules.append(r)
m.append_style('My Style',s)
lyr = mapnik.Layer('world',"+proj=latlong +datum=WGS84")
try:
lyr.datasource =
mapnik.Shapefile(base=ruta,file=archivo[0])
lyr.styles.append('My Style')
m.layers.append(lyr)
m.zoom_to_box(lyr.envelope())
mapnik.render_to_file(m,i, 'png')
print "La imagen " +i+ " fue creada."
except RuntimeError, e:
print 'Shapefile invalida'
continue

elif geo == 2 or geo == -2147483646:
print "Trabajando mapa "+ruta+"\\"+filename+" con geometria
"+ str(geo)

r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('#EB784B'),0.9))
s.rules.append(r)
m.append_style('My Style',s)
lyr = mapnik.Layer('world',"+proj=latlong +datum=WGS84")
try:
lyr.datasource =
mapnik.Shapefile(base=ruta,file=archivo[0])
lyr.styles.append('My Style')
m.layers.append(lyr)
m.zoom_to_box(lyr.envelope())
mapnik.render_to_file(m,i, 'png')
print "La imagen " +i+ " fue creada."
except RuntimeError, e:
print 'Shapefile invalida'
continue

elif geo == 1 or geo == -2147483647:
print "Trabajando mapa "+ruta+"\\"+filename+" con geometria
"+ str(geo)
blue =
mapnik.PointSymbolizer('C:\Python26\icono.png','png',50,50)
blue.allow_overlap = True
s=mapnik.Style()
r=mapnik.Rule()
r.symbols.append(blue)
s.rules.append(r)
m.append_style('My Style',s)
lyr = mapnik.Layer('world',"+proj=latlong +datum=WGS84")
try:
lyr.datasource =
mapnik.Shapefile(base=ruta,file=archivo[0])
lyr.styles.append('My Style')
m.layers.append(lyr)
m.zoom_to_box(lyr.envelope())
mapnik.render_to_file(m,i, 'png')
print "La imagen " +i+ " fue creada."
except RuntimeError, e:
print 'Shapefile invalida'
continue
else:
print "Algo fallo y no entro a ninguna de las geometrias"
print "Listo"
else:
print "Tus argumentos no son correctos"
except IndexError:
print "Tus argumentos no son correctos"
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python loop isn't working

2011-08-05 Thread Emile van Sebille

On 8/5/2011 9:14 AM Susana Iraiis Delgado Rodriguez said...


Hello list!
I have a python script which works with other libraries in order to
create maps. The script looks for an extension in a specific directory
and with mapnik makes the thumbnails.
The module works fine from Python command line and Pyton IDLE, but I
need this program to run from MS-DOS, when I added the try statement it
started to fail. Module runs but doesn't do what I need. Console shows:

C:\Python26>shp2png.py C:\\ .png
Iniciando...
Listo

What am I doing wrong?



First, get rid of the encompassing try: except block so you can see any 
actual errors instead of trapping them.  Place print statements at 
various points to test and confirm values.  Read up on pdb.set_trace() 
to assist when prints don't quite help enough. Start your diagnostics 
from there and post the the actual traceback results when you get stuck.


Emile



import mapnik
import os,fnmatch, sys
from mapnik import LineSymbolizer,PolygonSymbolizer,PointSymbolizer
from osgeo import ogr,gdal,osr

directorio = sys.argv[1]
extension = sys.argv[2]



drop this...

try:



outdent this...

 if len(sys.argv) == 3:
 print 'Iniciando...'
 file_list = []
 folders = None
 for root, folders, files in os.walk( directorio+'\\' ):
 for filename in fnmatch.filter(files, extension):
 file_list.append(os.path.join(root, filename))


throw a print statement here to confirm that file_list has valid 
contents (I suspect not)



 for row, filepath in enumerate(file_list, start=1):
 dir(LineSymbolizer().stroke)
 shapeData = ogr.Open(filepath)
 shp = 'Error al abrir el archivo' +filepath
 if shapeData is None:
 print shp
 continue
 layer = shapeData.GetLayer()
 defn = layer.GetLayerDefn()
 geo = defn.GetGeomType()
 (ruta, filename) = os.path.split(filepath)
 archivo = os.path.splitext(filename)
 i = archivo[0]+'.png'

 m = mapnik.Map(800,500,"+proj=latlong +datum=WGS84")
 m.background = mapnik.Color('#EBEBEB')
 s = mapnik.Style()
 r=mapnik.Rule()

 if geo == 3 or geo == -2147483645:
 print "Trabajando mapa "+ruta+"\\"+filename+" con
geometria "+ str(geo)

r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color('#EB784B')))

r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('rgb(170%,170%,170%)'),0.9))
 s.rules.append(r)
 m.append_style('My Style',s)
 lyr = mapnik.Layer('world',"+proj=latlong +datum=WGS84")
 try:
 lyr.datasource =
mapnik.Shapefile(base=ruta,file=archivo[0])
 lyr.styles.append('My Style')
 m.layers.append(lyr)
 m.zoom_to_box(lyr.envelope())
 mapnik.render_to_file(m,i, 'png')
 print "La imagen " +i+ " fue creada."
 except RuntimeError, e:
 print 'Shapefile invalida'
 continue

 elif geo == 2 or geo == -2147483646:
 print "Trabajando mapa "+ruta+"\\"+filename+" con
geometria "+ str(geo)

r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('#EB784B'),0.9))
 s.rules.append(r)
 m.append_style('My Style',s)
 lyr = mapnik.Layer('world',"+proj=latlong +datum=WGS84")
 try:
 lyr.datasource =
mapnik.Shapefile(base=ruta,file=archivo[0])
 lyr.styles.append('My Style')
 m.layers.append(lyr)
 m.zoom_to_box(lyr.envelope())
 mapnik.render_to_file(m,i, 'png')
 print "La imagen " +i+ " fue creada."
 except RuntimeError, e:
 print 'Shapefile invalida'
 continue

 elif geo == 1 or geo == -2147483647:
 print "Trabajando mapa "+ruta+"\\"+filename+" con
geometria "+ str(geo)
 blue =
mapnik.PointSymbolizer('C:\Python26\icono.png','png',50,50)
 blue.allow_overlap = True
 s=mapnik.Style()
 r=mapnik.Rule()
 r.symbols.append(blue)
 s.rules.append(r)
 m.append_style('My Style',s)
 lyr = mapnik.Layer('world',"+proj=latlong +datum=WGS84")
 try:
 lyr.datasource =
mapnik.Shapefile(base=ruta,file=archivo[0])
 lyr.styles.append('My Style')
 m.layers.append(lyr)
 m.zoom_to_box(lyr.envelope())
 mapnik.render_to_file(m,i, 'png')
 print "La imagen " +i+ " fue creada."
 except RuntimeError, e:
 print 

[Tutor] Re : Python loop isn't working

2011-08-05 Thread kliat...@gmail.com
Can you try to split it into fonctions
Because it is hard to read it.

Envoyé depuis mon HTC

- Reply message -
De : "Susana Iraiis Delgado Rodriguez" 
Pour : 
Objet : [Tutor] Python loop isn't working
Date : ven., août 5, 2011 18:14
Hello list! 
I have a python script which works with other libraries in order to create 
maps. The script looks for an extension in a specific directory and with mapnik 
makes the thumbnails.
The module works fine from Python command line and Pyton IDLE, but I need this 
program to run from MS-DOS, when I added the try statement it started to fail. 
Module runs but doesn't do what I need. Console shows:



C:\Python26>shp2png.py C:\\ .png
Iniciando...
Listo

What am I doing wrong?

import mapnik
import os,fnmatch, sys
from mapnik import LineSymbolizer,PolygonSymbolizer,PointSymbolizer
from osgeo import ogr,gdal,osr



directorio = sys.argv[1] 
extension = sys.argv[2] 
try:
    if len(sys.argv) == 3:    
        print 'Iniciando...'
        file_list = []
        folders = None
        for root, folders, files in os.walk( directorio+'\\' ):


            for filename in fnmatch.filter(files, extension):
                file_list.append(os.path.join(root, filename))
        for row, filepath in enumerate(file_list, start=1): 
            dir(LineSymbolizer().stroke)


            shapeData = ogr.Open(filepath)
            shp = 'Error al abrir el archivo' +filepath
            if shapeData is None:
                print shp
                continue
            layer = shapeData.GetLayer()


            defn = layer.GetLayerDefn()
            geo = defn.GetGeomType()
            (ruta, filename) = os.path.split(filepath) 
            archivo = os.path.splitext(filename)
            i = archivo[0]+'.png'


    
            m = mapnik.Map(800,500,"+proj=latlong +datum=WGS84")
            m.background = mapnik.Color('#EBEBEB')
            s = mapnik.Style()
            r=mapnik.Rule()
    


            if geo == 3 or geo == -2147483645:
                print "Trabajando mapa "+ruta+"\\"+filename+" con geometria "+ 
str(geo)
                
r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color('#EB784B')))


                
r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('rgb(170%,170%,170%)'),0.9))
                s.rules.append(r)
                m.append_style('My Style',s)
                lyr = mapnik.Layer('world',"+proj=latlong +datum=WGS84")


                try:
                    lyr.datasource = mapnik.Shapefile(base=ruta,file=archivo[0])
                    lyr.styles.append('My Style')
                    m.layers.append(lyr)
                    m.zoom_to_box(lyr.envelope())


                    mapnik.render_to_file(m,i, 'png')
                    print "La imagen " +i+ " fue creada."
                except RuntimeError, e:
                    print 'Shapefile invalida'


                    continue                
       
            elif geo == 2 or geo == -2147483646:
                print "Trabajando mapa "+ruta+"\\"+filename+" con geometria "+ 
str(geo)


                
r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('#EB784B'),0.9))
                s.rules.append(r)
                m.append_style('My Style',s)
                lyr = mapnik.Layer('world',"+proj=latlong +datum=WGS84")


                try:
                    lyr.datasource = mapnik.Shapefile(base=ruta,file=archivo[0])
                    lyr.styles.append('My Style')
                    m.layers.append(lyr)
                    m.zoom_to_box(lyr.envelope())


                    mapnik.render_to_file(m,i, 'png')
                    print "La imagen " +i+ " fue creada."
                except RuntimeError, e:
                    print 'Shapefile invalida'


                    continue            

            elif geo == 1 or geo == -2147483647:
                print "Trabajando mapa "+ruta+"\\"+filename+" con geometria "+ 
str(geo)


                blue = 
mapnik.PointSymbolizer('C:\Python26\icono.png','png',50,50)
                blue.allow_overlap = True
                s=mapnik.Style()
                r=mapnik.Rule()
                r.symbols.append(blue)


                s.rules.append(r)
                m.append_style('My Style',s)
                lyr = mapnik.Layer('world',"+proj=latlong +datum=WGS84")
                try:
                    lyr.datasource = mapnik.Shapefile(base=ruta,file=archivo[0])


                    lyr.styles.append('My Style')
                    m.layers.append(lyr)
                    m.zoom_to_box(lyr.envelope())
                    mapnik.render_to_file(m,i, 'png')


                    print "La imagen " +i+ " fue creada."
                except RuntimeError, e:
                    print 'Shapefile invalida'
                    continue            


            else:
                print "Algo fallo y no entro a ninguna de las geometrias"
        print "Listo"
    else:
            print "Tus argumentos no son correc

Re: [Tutor] Python loop isn't working

2011-08-05 Thread Alan Gauld

On 05/08/11 17:14, Susana Iraiis Delgado Rodriguez wrote:


The module works fine from Python command line and Pyton IDLE, but I
need this program to run from MS-DOS, when I added the try statement it
started to fail. Module runs but doesn't do what I need. Console shows:

C:\Python26>shp2png.py C:\\ .png
Iniciando...
Listo

What am I doing wrong?


What makes you think it doesn't work?
The first pruint is near the start of your code, the last near the end.
So your program appears to have run.

What else were you expecting to see happen?
What is different when you run it from "Python command line"?

In practice there should be no difference between you typing

C:\Python26>shp2png.py C:\\ .png

and typing


C:\Python26> python shp2png.py C:\\ .png

Or are you doing something at the Python >>> prompt?
If so what? How are you "running" it when it works?


Alan G.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Converting from a single module to a package

2011-08-05 Thread Tim Johnson
I'm been coding in python now for close to 10 years.  one of the
modules that I have composed for re-use has gotten pretty big:

It is implemented as 

import tlib as std

I am thinking about 'downsizing' this module and breaking it up into
smaller components, thus a package. And I would like to do this
without a lot of code revisions.

I would welcome references to URLs on this topic.

thanks
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Indexing a list with nested tuples

2011-08-05 Thread Christopher King
On Tue, Aug 2, 2011 at 10:44 PM, Alexander Quest wrote:
>
> have [0] to indicate that I want to go to the second value within that
> first item, which is the
> point value
>
Actually [0] is the first element. I would go with [1].
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Converting from a single module to a package

2011-08-05 Thread Christopher King
To make a package, you make a folder named what you want to name the
package, for example: virus_toolkit. Then you make a file in it called
__init__.py. This is what you import if you import the virus_toolkit. You
usually put documentation and general functions in this I believe (I'm not
100% sure on package etiquette.) Then you put various modules inside the
folder, such as brute force, worms, and Trojan_horse. Then you can do from
virus_toolkit import worms, and such, or if you want to unleash a full out
attack and import them all, do from virus_toolkit import *.

On Fri, Aug 5, 2011 at 3:25 PM, Tim Johnson  wrote:

> I'm been coding in python now for close to 10 years.  one of the
> modules that I have composed for re-use has gotten pretty big:
>
> It is implemented as
>
> import tlib as std
>
> I am thinking about 'downsizing' this module and breaking it up into
> smaller components, thus a package. And I would like to do this
> without a lot of code revisions.
>
> I would welcome references to URLs on this topic.
>
> thanks
> --
> Tim
> tim at johnsons-web dot com or akwebsoft dot com
> http://www.akwebsoft.com
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [Python-ideas] multiple intro statements [was: combine for/with statement]

2011-08-05 Thread Christopher King
I give +0. I'm sure that it could come in use somewhere, as long as it isn't
used everywhere.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Converting from a single module to a package

2011-08-05 Thread Tim Johnson
* Christopher King  [110805 12:03]:
> To make a package, you make a folder named what you want to name the
> package, for example: virus_toolkit. Then you make a file in it called
> __init__.py. This is what you import if you import the virus_toolkit. You
> usually put documentation and general functions in this I believe (I'm not
> 100% sure on package etiquette.) Then you put various modules inside the
> folder, such as brute force, worms, and Trojan_horse. Then you can do from
> virus_toolkit import worms, and such, or if you want to unleash a full out
> attack and import them all, do from virus_toolkit import *.
> 
 Thanks Christopher. Your take on the issue is pretty much the same
 as mine. However, my question is really how to make the transition
 from a single module to a package with the least amount of code
 changes. I'm guessing that I'm going to have to bite the bullet on
 this one. Example:

 # current way
 import tlib as std
 
 std.htmlButton(*arglist)

 # New way, after transition 
 import tlib as std
 std.html.button(*arglist)
 #OR 
 import html from tlib
 html.button(*arglist)
 #...
 oh well. Probably best to leave the original as is, for backwards
 compatibility.

 cheers
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Indexing a list with nested tuples

2011-08-05 Thread Alexander Quest
My bad- meant to say [1]. Thanks.

-Alexander

On Fri, Aug 5, 2011 at 12:36 PM, Christopher King wrote:

>
>
> On Tue, Aug 2, 2011 at 10:44 PM, Alexander Quest wrote:
>>
>> have [0] to indicate that I want to go to the second value within that
>> first item, which is the
>> point value
>>
> Actually [0] is the first element. I would go with [1].
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Converting from a single module to a package

2011-08-05 Thread Emile van Sebille

On 8/5/2011 4:22 PM Tim Johnson said...

* Christopher King  [110805 12:03]:

To make a package, you make a folder named what you want to name the
package, for example: virus_toolkit. Then you make a file in it called
__init__.py. This is what you import if you import the virus_toolkit. You
usually put documentation and general functions in this



But you can provide for both methods if in tlib.__init__ you provide for 
backward compatibility.




  # current way
  import tlib as std
  
  std.htmlButton(*arglist)

  # New way, after transition
  import tlib as std


in tlib.__init__, include the following:

import html
htmlButton = html.button


  std.html.button(*arglist)
  #OR
  import html from tlib
  html.button(*arglist)


Emile

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Converting from a single module to a package

2011-08-05 Thread Tim Johnson
* Emile van Sebille  [110805 15:51]:
> On 8/5/2011 4:22 PM Tim Johnson said...
> >* Christopher King  [110805 12:03]:
> >>To make a package, you make a folder named what you want to name the
> >>package, for example: virus_toolkit. Then you make a file in it called
> >>__init__.py. This is what you import if you import the virus_toolkit. You
> >>usually put documentation and general functions in this
> 
> 
> But you can provide for both methods if in tlib.__init__ you provide
> for backward compatibility.
> 
> 
> >  # current way
> >  import tlib as std
> >  
> >  std.htmlButton(*arglist)
> >
> >  # New way, after transition
> >  import tlib as std
> 
> in tlib.__init__, include the following:
> 
> import html
> htmlButton = html.button
  Yes. That's what I'm talking about.
  Thank you Emile. :)
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor