[Tutor] Update BLOB with odbc

2006-08-02 Thread Ron Phillips
It must be easier than I am making it. 


sql = UPDATE sa2.outfalls SET photo_content = %s WHERE
pppoint_id ='+record[0].strip()+';
newsql = sql%pstuff
print newsql[:150]
cursor.execute(newsql)
__
the print newsql[:150] = UPDATE sa2.outfalls SET photo_content =
ÿØÿá*EExif . . . 

and I get this error:

TypeError: argument 1 must be string without null bytes, not str

which sounds reasonable, but I don't know how to fix it. Is there some
escape thing that I'm missing?

Ron


 
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] MySQLdb question.

2006-07-28 Thread Ron Phillips


I am trying to write a script that adds data to a table using MySQLdb.py. For some reason, "INSERT" seems to work temporarily. I run a command to insert a row, and then do a select query, and it's there. After the program shuts down, though, it's gone. No rows are permanently created. SELECT works fine from MySQLdb, CREATE TABLE too, but when I add data, it's only there while the script is executing, then it's gone.

I can add data from the MySQL Query Browser, and it's fine. 

I googled, butcouldn't find anything. I'm running MySQL5, and the latest MySQLdb.py, too. Python 2.4.

I am using animal.py from http://www.kitebird.com/articles/pydbapi.html, but it's been the same thing with other scripts. Is it a setting, or a thinko, or what?

Ron
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MySQLdb question.

2006-07-28 Thread Ron Phillips

That was it all right! Thanks, Kent!Ron___Ron Phillips wrote:
 I am trying to write a script that adds data to a table using 
 MySQLdb.py.  For some reason, "INSERT" seems to work temporarily. I 
 run a command to insert a row, and then do a select query, and it's 
 there. After the program shuts down, though, it's gone. No rows are 
 permanently created. SELECT works fine from MySQLdb, CREATE TABLE too, 
 but when I add data, it's only there while the script is executing, 
 then it's gone.
Try calling conn.commit() before conn.close(). IIRC older versions of 
MySQL were set to auto-commit by default but newer versions require the 
explicit commit.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] making a python program part of xhtml

2006-06-09 Thread Ron Phillips
 Emily Fortuna  [EMAIL PROTECTED]  6/8/2006 9:19 AM 
Hola everyone,
I'm working on creating a webpage in which a user can submit data into

fields to be held in a database (there are other details, but this is 
the gist of the idea), and I need to use python. I am unfamiliar with 
manipulating data and web apps as a whole (and new to python), so I
have 
been encountering much unfamiliar terrain. I _think_ I want to somehow

embed the python into the page, but I'm really not sure how to do it. 
After googling I found some programs that generate xhtml from python, 
but I don't think that is what I want, or is it? Your help is
appreciated!
Emily

You might look at http://karrigell.sourceforge.net/: karrigell lets you
embed python in xhtml, xhtml in python, execute straight python scripts,
or execute python from a karrigell application server. Even if you don't
choose karrigell for some reason, at least the documentation can help
you sort out the variations on the python/xhtml theme!
 
Ron
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] web intefaces?

2006-05-09 Thread Ron Phillips


Ilike Karrigell ...http://www.karrigell.com/ for beingflexible, complete, lightweight, and easy to learn. I don't know how it scales, but that's not really a consideration for the applications you describe.

Ron "Chad Crabtree" [EMAIL PROTECTED] 5/8/2006 6:29 PM While everything that Alan Guald said is true, there are a couple ofoptions for you. Provided you know HTML (you must), you couldgenerate html pragmatically but, knowledge of html is still mandatory.Your options are, basicallyhttp://www.cherrypy.org Which is an app server that should be fairly easy to package up with,say py2exe.Another option, with CGI (pretty easy) is found in the standard library.http://docs.python.org/lib/module-CGIHTTPServer.html If you do this as a personal app I would make sure to use an alternateport number like 11224, or something.HTHBest of Luck.On 5/6/06, Alfonso  [EMAIL PROTECTED]  wrote: I would like to experiment with web interfaces and python. After some googling, I'm quite confused, does somebody know of a good link about this topic / what do you think that is the best software option to design web user intefaces with python? I mean web interfaces for common programms (so it's not important to me to have a very robust web server), the web server should run in the machine of the user of the programm.And it should be easy installed, as bundle, when I distribute the programm. Thank very much for your help. __ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com  ___ Tutor maillist - Tutor@python.org  http://mail.python.org/mailman/listinfo/tutor 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Brain In Vice: Why is this so fun to me?

2006-04-21 Thread Ron Phillips


Regex aside, just for a moment — the subject line gets my vote for "Most Succinct Description of Programmer Mindset", if there's a competition on.

Ron
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Printing

2005-12-28 Thread Ron Phillips

 "John Corry"  [EMAIL PROTECTED]  12/24/2005 12:28 PM Hi + Season's Greetings!I have put together a program that queries and modifies a Gadfly database.I have captured my output. I now want to print it to paper.I have written the output to a text file. I have searched the tutor mailinglist and used the mailing list advice to get my data into nice lookingcolumns + tables.I am using Python 2.4, Glade 2, pygtk2.8.0 + wxWidgets2.6.1.I have downloaded win32, win32com, Preppy and PIL. I have had a go at usingthem but can't get them to work. At the moment I can't even print the textfile.Is there a good helpguide/FAQ page which deals with printing text files oris there simple code which prints a text file?Thanks,John.You might want to look at karrigell ( http://karrigell.sourceforge.net/ ) and consider making your output an html text file, styled with css, that you can view/print using the browser. I think karrigell is simple for desktop apps - - certainly simpler than wxWidgets, etc.TurboGears ( http://www.turbogears.org ) is more oriented toward a full website. Both frameworks are built on CherryPy, which is coming on strong as a full-featured, lightweight 'Pythonic" server.I like to use the browser for output because it does so much of the formatting for you and it's cross-platform, and I like using a framework because if you ever want to use your program over the web, you're nearly done. Ron
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Favourite modules - Wiki Was Re: TurboGears - and some issues

2005-11-15 Thread Ron Phillips
 Ismael Garrido [EMAIL PROTECTED] 11/14/2005 11:55 PM 
Kent Johnson wrote:

Maybe we should start a thread of favorite addons. For me, Jason
Orendorff's path module is definitely #1 on the list, probably followed
by Fredrik Lundh's ElementTree.
 http://www.jorendorff.com/articles/python/path/ 
 http://effbot.org/zone/element-index.htm 
 

A wonderful idea! I have created a wiki page in Python.org with a list

of such 'favourite' modules.
Please take a look:
http://wiki.python.org/moin/UsefulModules 

I put some of the modules I could remember being praised here. I hope I

didn't miss any (well, save for web frameworks, I haven't been paying 
much attention)

I hope I haven't made a mess, it was my first edit into python's wiki.
I 
wasn't sure where to stick it, so I added it under DevelopmentTools.

I hope the page helps somebody!
(Today I'm hopey :)

Bye,
Ismael
+++
 
That is a good idea, and a nice page. Another would be to implement
some social tagging as on del.icio.us. It's kind of a popularity
contest, but that's really what's wanted here, I think. OTOH, the wiki
is probably the first place anyone would look, and I saw most of the
modules I already use, and I learned about a couple that look very
promising. 
 
One that I use a lot is Amara
(http://uche.ogbuji.net/tech/4suite/amara/manual) for making xml more
pythonic. Not to take anything away from ElementTree, it's a fine
package; but I find Amara easier to use. Some others that seem
'missing': PIL and NumPy. I didn't try to put it on the wiki page
because I wanted the tutors to have a chance to comment first. 

Anyway, thanks for the page. I have it bookmarked!

Ron

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Thanks, you prevented Coder's Remorse

2005-10-03 Thread Ron Phillips
Thanks to everyone who responded to my Prevent Coder's Remorse
posting;
the result of combining the ideas that you contributed is below. 

It's a little long, but I'm delighted with it so far, and maybe someone
else can use it. 
It's nice for representing a sparse table, where all the records share
columns, 
but a lot of the values in any given column are the same. Geographic
points (my original
question) are just a special case.

One example is a table where the Null value isn't predefined but is
represented by a
'magic value' that means null in that table. I realize now that I might
have been
better off just to use a database; they know all about nulls, tables.
types, defaults, etc. 

Still, I learned a LOT.  So, no remorse!

Thanks again,
 
Ron

#magicvaluetable.py
###
# -*- coding: utf-8 -*-

#may use a guid to keep things straight
import guid

# Make it work with Python 2.3
try:
set
except NameError:
from sets import Set as set

class MVTRecord(dict):
A record belonging to a magic value table (MVTable).
Requires a parent MVTable and an id assigned by it.
Other attributes (column values) may be assigned.
Attributes not specifically assigned at the record level
are deferred to the parent MVTable's attDict.

def __init__(self,mvtParent,id,**args):
dict.__init__(self)
self.mvtParent = mvtParent
self.id = id
for arg in args:
self[arg]=args[arg]

def __getitem__(self, key):
if key in self.keys():
return dict.__getitem__(self, key)
else: 
return self.mvtParent.attDict[key]
raise KeyError,'Key %s was not found in MVTRecord or
MVTable'%key

def __setitem__(self, key, value):
(nullValue,valueType)=self.__testType(value)
if key not in self.mvtParent.attDict.keys():
self.mvtParent.addAttribute(key,nullValue)
   
(whoCares,columnType)=self.__testType(self.mvtParent.attDict[key])
 # make sure what's set is proper type or can degrade to proper
type
if valueType == columnType:
dict.__setitem__(self, key, value)
else:
if columnType == 'float'and valueType=='int':
dict.__setitem__(self, key, float(value))
elif columnType == 'string':
dict.__setitem__(self, key, str(value))
else:
msg = 'The %s attribute requires %s data'%(key,
columnType)
raise ValueError,msg

def __delitem__(self, key):
if key in self.keys():
dict.__delitem__(self, key)
elif key in self.mvtParent.attDict.keys():
pass
else:
raise KeyError,'Key %s was not found in MVTRecord or
MVTable'%key


def __testType(self, value):
try:
if str(value)==str(int(value)):
test = (self.mvtParent.nullInt,'int')
else: 
test = (self.mvtParent.nullFloat,'float')
except ValueError:
test=(self.mvtParent.nullString,'string')
return test


class MVTable(object):
Defines a group of records (MVTRecord) with
common columns. Attributes (record values in a given
column) which are not specified at the record level are
deferred to the MVTable attDict.

Note: the nullInt, nullFloat, and nullString
are designed to hold 'magic values' for use with
data structures(CSV, DBF) having no defined 'null'.
def __init__(self, nullInt=0, nullFloat=0.0, nullString='null'):
self.nullInt=nullInt
self.nullFloat = nullFloat
self.nullString = nullString
self.attDict = {}
self.membersDict = {}

def addMember(self,id=None,**args):
if not id: id = guid.generate()
self.membersDict[id]=MVTRecord(self,id=id,**args)
return self.membersDict[id]

def delMember(self,member):
del self.membersDict[member.id]

def addAttribute(self, name, nullValue=None):
if nullValue == None:nullValue=self.nullString
self.attDict[name]=nullValue

def delAttribute(self, name):
for member in self.membersDict:
if member.has_key(name):del member[name]
del self.attDict[name]
   
def compactAttributesDictionary(self):
removes unreferenced attributes
newkeys = set()
for member in self.membersDict:
for key in self.membersDict[member].keys():
newkeys.add(key)
for key in self.attDict.keys():
if key not in newkeys: del self.attDict[key]

if __name__ == __main__:
mvt = MVTable()
me=mvt.addMember()
he=mvt.addMember(third=3, fourth=4)
mvt.addAttribute('first', 5)
#print basic functionality outputs
for column in mvt.attDict:
print 'Column:%s, me:%s, he:%s'%(column,me[column],he[column])

###

Re: [Tutor] [tutor]web development

2005-09-28 Thread Ron Phillips


Well, I won't argue with anyone who chooses otherwise, but CherryPy http://www.cherrypy.org/is easy to use, lightweight, quick, and pythonic. I write everything as plain old python, then webify it the very last thing. 

It's also the basis of a new, promising framework called TurboGears http://www.turbogears.org/, whichKevin Dangoor put together. He does a "Wiki in 20 minutes" tutorial that's pretty impressive.



Ron PhillipsProgrammer/AnalystCounty of Summit Engineer538 E. South St.Akron, OH 44311
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Prevent Coder's Remorse?

2005-09-28 Thread Ron Phillips
Maybe it's just me. I am always haunted by coder's remorse (the
certainty that there's a more compact, beautiful, fun, maintainable way
to code anything I finish.)
 
At any rate, I am currently working on a script to model an ordered
collection of geographic points, all of which must share the same
collection of attributes. So, a little collection might be:
 
pointList = [
{lat:40.123,lon:-81.456, 
'attributes':{'msg':'example','beavers':34, 'distance':18.132}
},
{lat:40.12345,lon:-81.45678, 
'attributes':{'msg':'','beavers':0, 'distance':0.0}
}
]
 
If I add an attribute of 'newAtt':'newVal' to
pointList[1]['attributes'], I want it to automatically add
'newAtt':'default' to
all the other member's 'attributes' dictionary. If I delete an
attribute, it should delete from all the member's dictionaries. The
attributes are limited to string, integer, and float values.
 
I can do this by brute force, but:

Is there an elegant approach that occurs to anyone? 
Is there a data structure that forces all members to have the same
keys? 
Is there an object structure that will let updates to one instance
affect all instances?
Am I even asking the right questions?

I suspect there's an elegant solution, but it's beyond me right now. If
not, fine; I'll happily go on with my ham-fisted approach.

Regards,




 
 

Ron Phillips
Programmer/Analyst
County of Summit Engineer
538 E. South St.
Akron, OH 44311
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Prevent Coder's Remorse?

2005-09-28 Thread Ron Phillips
Ok, I have three diverse answers from three of the tutors that I respect
most. 
 
Kent Johnson's approach: subclass dict and overloads the __getitem__ ,
__setitem__, and __delitem__ methods.
 
Alan G's idea:
 . . .
Get the init method to update a global (or class based) 
list of instances and write a del() method that removes 
itself.
 
Then a class method can iterate that instance list 
doing whatever it needs to do...

And Danny Yoo's hierarchical structure:

. . .
The idea here is that we impose some structure among the points.  We
can
keep a central Point that has a set of child points within its
satellite.

##
 centralPoint = Point(40, -81, {})
 satellitePoint = Point(40, -81, {}, centralPoint)
##

. . .

Very clever ideas, as far as I can tell. I need to play with all three
of them so that I understand them thoroughly.  I think that once I do,
I'll be able to say I really understand OOP in Python! I believe that
any one of these approaches will do what I need, though, so maybe it
comes down to style.

Maybe I should explain why I thought I wanted this object. I am trying
to read, edit, and write shapefiles (actually, a shapefile is a
collection of 3-6 files having the same filename, but different
extensions. It's a legacy format that still gets a lot of use in
geography.)

One of the constituent files in a shapefile is a variant of Xbase,
which knows nothing  about NULL, so I have to provide some value in
every column for every record when I write them. I thought that having a
data structure that enforces a common set of fields, the application
would be more robust when it's being edited. (Prevent me from deleting
an item for one record and not others, or adding a field to a record
without adding at least some default value to all the others.)

I just thought about it, but a CSV file has kind of the same problem.

Thanks, everyone; this will be a real education, however I go!

Ron
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to add python code to a webpage

2005-07-18 Thread Ron Phillips



snipMustafa Abbasi asked:

i want to create a simple page which has a formand takes in persons date of birth and give out exact age.how do i add python codeto an html page.i don't have any dreamweaver or frontpage.this is basically cuz some freinds advised me to create this isnce i am learning programming python..so please help /snip

Ifind CherryPy is easy and lightweight to get started. http://www.cherrypy.org

Ron


Header
Description: Binary data
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGIXMLRPCRequestHandler doesn't actually work, does it?

2005-06-24 Thread Ron Phillips


##Run a simple CGI server by opening a command line to the parent dir of cgi-bin and runningpython -c "import CGIHTTPServer; CGIHTTPServer.test()"

## 

Oh, dear -- I responded before I read your post, Kent. It turns out it was option b), after all. But I had NO idea I would need to do anything like the little clip above. Anything else I run under CGI, I just send an HTTP request and it works. I read, and read, and read, but never read anything about starting a CGIHTTPServer -- I'll look it up right away, but I can't see how I missed that. Maybe by Googling "XMLRPC", which was what I really wanted to do.

Anyway, thank you -- if I can find them again, I'll respond to all those other posts with a link to yours in the archives.

Ron
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGIXMLRPCRequestHandler doesn't actually work, does it?

2005-06-24 Thread Ron Phillips


Kent wrote:

CGI requires a running HTTP server in front of it. The server receives the HTTP request, sees that it is a CGI request, starts a new process with the environment set according to the CGI protocol, and runs the CGI handler. Do you understand this relationship? (I mean that kindly, your response makes me suspect there is a fair amount of black magic in this for you.)

The snippet above just starts a simple CGI-capable HTTP server. It is useful for testing, not an essential part of the recipe. If you have other CGIs working you must have a working HTTP server already, such as Apache or IIS.

In your initial post you said "I have run other CGI scripts in the same directory." Were those CGIs written in Python? How did you run them?

Kent-
Well, I understand the words, and I can see that the HTTP server (IIS, in this case) hands off CGI stuff to a CGI handler -- but I think that IS a fair amount of black magic! So no, I really can't claim any deep understanding of the process.

What I ran before were simple little test scripts of the "HelloWorld.py" variety. I would put them in the cgi-bin directoryand invoke them with the browser, or with the HTTPLib in the command line, and I would get something back. 

When I invoke any script in the cgi-bin that has CGIXMLRPCRequestHandler in it through localhost or localhost:80, the program freezes right up. Nothing returned, nothing in the IIS error log, no reply at all. However, the little test scripts that you and Joe provided run just fine as long as I don't use IIS as the server. Maybe I should haveposted "IIS and CGIXMLRPCRequestHandler doesn't work at all!!" Seriously, it looks like my IIS installation is at fault -- probably some setting I need to change. 

I wonder if that's the reason for all those unanswered posts -- it's not a Python problem, per se? Odd, though, thatIIS isperfectly happy to run a Python script unless it has CGIXMLRPCRequestHandler in it.

Ron
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CGIXMLRPCRequestHandler doesn't actually work, does it?

2005-06-24 Thread Ron Phillips


Yes, I believe you are right -- I posted a reply to the list indicating that I suspect IIS is at fault; not Python. Or perhaps I should say "my installation of IIS"; I have no confidence whatsoever in my abilities to administer IIS properly.

Thanks for looking at the documentation -- I was stuck using 2.3 because of some other modules I needed, so I didn't look at the 2.4 docs. That would have made me less angry, but the script still wouldn't have run, because the problem (evidently) is in IIS, not my code. 

I was really hard up against it -- no response at all from IIS, just a lockup, and apparently when IIS locked up, it did so prior to writing to the error log. When I tried using the CGIHTTPServer, everything I did over the past 3 days worked without a hitch. What a relief!!

Now I just need to work around IIS -- and we don't use it outside the firewall, anyway. I think I'll put Apache on my local machine and use that.

Thanks, again

Ron

 Danny Yoo [EMAIL PROTECTED] 6/24/2005 2:44:44 PM 
 The example code in the python online documentation calls a non-existant "div" function, so it was obviously a typing exercise, not actual code that anyone ever tested.Hi Ron,Ah, ok, I see. Check the bottom of: http://www.python.org/doc/lib/simple-xmlrpc-servers.htmlfor a working example of that div function in the MyFuncs class.I believe that the example you were looking at earlier, near the bottomof: http://www.python.org/doc/lib/node556.htmlhas is a documentation bug: the intent is clearly to compare and contrastSimpleXMLRPCServer and CGIXMLRPCRequestHandler, so the code should beusing the same example. The fact that it isn't is confusing, and shouldbe fixed. I'll send a bug report now. http://python.org/sf/1227181Try Kent's example again; XMLRPC stuff is itself not too bad. Your twoassumptions: 1. It's too easy to mention, and not worth talking about 2. It's too hard in practice, and not worth talking aboutare too black-and-white: XMLRPC itself is not bad at all, but CGI stuffcan be maddeningly difficult at first, because it involves not only Pythonbut also integration with an external web server.What I think you're running into is the CGI part, the part that doesn'tdebug as easily, just because error output doesn't automatically send tothe browser --- that would be a security risk! --- but instead is shuttledoff to your web server's error log file. So take a closer look at yourweb server's error logs; I wouldn't be surprised to see some Python errormessages there that should help to isolate the issue.Best of wishes to you!__This email has been scanned by the MessageLabs Email Security System.For more information please visit http://www.messagelabs.com/email __
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Am I making this harder than it needs to be?

2005-05-26 Thread Ron Phillips


Ron Phillips wrote: short version: I need a way to get max and min E and N out of  [(E0,N0),(E1,N1)...(En,Nn)] without reordering the list Kent Johnson [EMAIL PROTECTED] 5/25/2005 10:19 AM clipFor Python  2.4 you need another set of [ ] e.g. min([e for e,n in coordList])
/clip
I knew I was working too hard!! That's exactly what I needed -- for some reason, ESRI (big name in geographic work) uses Python 2.2.

Ron Phillips wrote:
 long version:  I would like a list of geographic coordinates (Easting, Northing) to  maintain a "bounding box"  [(minEasting,minNorthing),(maxEasting,maxNorthing)] attribute.I did it like this:class geoCoordinateList(UserList):def __init__(self):UserList.__init__(self)self.boundingBox = geoBox(minEN=geoCoordinate(),maxEN=geoCoordinate())def append(self, geoCoord):self.extend([geoCoord])self.boundingBox.challenge(geoCoord)#bumps the max and min if necessarybut I'd have to override almost all the UserList methods, unless there's a way to call boundingBox.challenge() on any change to the list.If you don't need too much list functionality it might be easier to wrap a list and delegate the things you need:class geoCoordinateList(object):def __init__(self):self.list = list()self.boundingBox = geoBox(minEN=geoCoordinate(),maxEN=geoCoordinate())def append(self, geoCoord):self.list.append(geoCoord) # No need for extend() here...self.boundingBox.challenge(geoCoord)#bumps the max and min if necessaryI think you will want at least __getitem__() and __len__() as well.Kent
Yep, that was my problem; I had "too much list functionality" to delegate -- your way is much better for the purpose. I can expose that class without promising all the functionality of a list.

In most languages there are a half-dozen stupid, painful ways to do a job, and maybe one that's merely painful, but in Python there's a half-dozen "ok" ways to do a job, and at least one that's a real pleasure!

Thanks for the answers!

Ron


Header
Description: Binary data
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Am I making this harder than it needs to be?

2005-05-25 Thread Ron Phillips


short version: I need a way to get max and min E and N out of [(E0,N0),(E1,N1)...(En,Nn)] without reordering the list

long version:

I would like a list of geographic coordinates (Easting, Northing) to maintain a "bounding box" [(minEasting,minNorthing),(maxEasting,maxNorthing)] attribute.

I did it like this:

class geoCoordinateList(UserList): def __init__(self): UserList.__init__(self) self.boundingBox = geoBox(minEN=geoCoordinate(), maxEN=geoCoordinate())
 def append(self, geoCoord): self.extend([geoCoord]) self.boundingBox.challenge(geoCoord)#bumps the max and min if necessary
but I'd have to override almost all the UserList methods, unless there's a way to call boundingBox.challenge() on any change to the list.

The other way I thought would be to make a getBB method, like:

 def getBB(self): new=geoBox() for gC in self: new.challenge(gC)#bumps the corners if needed
 self.boundingBox=new return(new)
but that seems like a lot of churning if nothing has changed. 

I suspect there's some slick, readable way to do this, and when I see it I'll say "Doh!"



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Opinions about this GIS script

2005-05-16 Thread Ron Phillips


I made a script that opens GIS shapefiles and turns them into python objects. I postedit at http://www.geocities.com/tiltbike/GIS/py_shape_files.zipThe only one that's mine, really, is the PyShape.py script; the others are there for support/testing.

It's my first real effort at 'shareable' python. Everything else I've done so far is either a quick-and-dirty for my own use, or a simple illustration for instructional purposes.

The script produces expected results, but if anyone is so inclined, I'd appreciate review/evaluation/critique of the 'pythonism' of the script. 

Ron Phillips
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Negative IF conditions

2005-02-14 Thread Ron Phillips



And now for something only slightly different: education research shows 
that people process "positives" far more quickly and accurately than 
"negatives", so for readability I often code like:

if os.path.exists('filename')
 #no-operation
else
 #operation

YMMV, of course.

Ron
At 08:52 AM 2/11/2005, Mark Brown wrote:
Hi,I'm a newbie and was 
  wondering which of these IF conditions is better structure:if 
not os.path.exists('filename'): if os.path.exists('filename') == False: 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re:OT

2004-12-29 Thread Ron Phillips



54 years old -- father of 3, grandfather of 4 (and counting.) 

I started Pythoning because I work for a governmental agency that does 
Civil Engineering. To support mapping, I needed a wrapper for ESRI products 
(Python, AML, VBA),to support drafting, I needed a wrapper for AutoDesk 
products (Python, LISP, VBA), and to support IT, I needed languages for Linux 
servers (Python, C, etc.) and Windows servers and desktops (Python, VB, C#, 
etc.) and WindowsCE(Python, VBCE).

What option did I really have, then? Besides, it's just so COOL.

Ron
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: [ANN] RUR: a Python Learning Environment (alpha)

2004-12-13 Thread Ron Phillips



Can't get it running -- it keeps saying:

Traceback (most recent call last): File 
"C:/source/RUR/RURmain.py", line 28, in ? 
messenger.loadImages() # load them up here after initialising 
Handlers File "C:\source\RUR\messenger.py", line 27, in 
loadImages HIT_WALL_IMAGE = 
wxImage('ouch2.png').ConvertToBitmap() File 
"C:\Python23\Lib\site-packages\wx\_core.py", line 2282, in 
ConvertToBitmap return _core_.Image_ConvertToBitmap(*args, 
**kwargs)wx._core.PyNoAppError: The wx.App object must be created 
first!

Ron
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Re: PDF and Python

2004-12-10 Thread Ron Phillips



I just happened across an answer yesterday. PIL writes PDF s.

http://www.pythonware.com/products/pil/

Ron
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Graphics coordinates (bump?)

2004-12-10 Thread Ron Phillips



I sent the following yesterday, but since it was my first request to the 
list, I got an autoreply. It never showed up in my digest of the list, and I 
haven't seen a response.It's in the archives, butI am thinking that 
archiving/autoreply was all that happened (no actual posting.)

Anyway, I am looking hard at PIL, and a little at PyGame. Still looking for 
suggestions, though.


I work for a Civil Engineering organization. I need to give our users a 
means to generate geographic coordinates forour projects and structures. 


I plan to do this by making a viewer which will accept a graphic file (png 
or jpg) and two points (pixels) in that image for which geographic 
coordinates are given. Users can then click on the image where appropriate to 
generate a list of geographic points of interest for their work. The list will 
be saveable as an xml file or a shp file (a widely used geographic binary 
format.) In addition, other programs that I write will use the vieweras a 
dialog box: will call the viewer directly and get the points from it, just 
like a color picker dialog.

What I am looking for: thoughts on which Python modulesare most 
appropriate and generally applicable for this. PIL? Piddle? PyGIS? some of 
Hobu's modules? I believe I can write the glue-code, but I don't want to 
reinvent the wheel if there areexisting modules thatdo 
almost(or even better, exactly) what I need.

I work onWinXp, Linux, and WindowsCE.WindowsCE has a fairly 
plain-vanilla Python build, so it's better if I stick to the core modules as far 
as possible.

Ron Phillips
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Graphics coordinates

2004-12-09 Thread Ron Phillips



I work for a Civil Engineering organization. I need to give our users a 
means to generate geographic coordinates forour projects and structures. 


I plan to do this by making a viewer which will accept a graphic file and 
two points (pixels) in that image for which geographic coordinates are 
given. Users can then click on the image where appropriate to generate a list of 
geographic points of interest for their work. The list will be saveable as an 
xml file or a shp file (a widely used geographic binary format.) In addition, 
other programs that I write will use the vieweras a dialog box: will 
call the viewer directly and get the points from it, just like a color picker 
dialog.

What I am looking for: thoughts on which Python modulesare most 
appropriate and generally applicable for this. PIL? Piddle? PyGIS? some of 
Hobu's modules? I believe I can write the glue-code, but I don't want to 
reinvent the wheel if there areexisting modules thatdo 
almost(or even better, exactly) what I need.

I work onWinXp, Linux, and WindowsCE.WindowsCE has a fairly 
plain-vanilla Python build, so it's better if I stick to the core modules as far 
as possible.

Ron Phillips
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor