[Tutor] Instantiating a list of strings into a list of classes

2010-03-05 Thread Daryl V
Hello All-

I cut my teeth of Fortran95, and in the distant past rode the turtle, and
while I enjoy the mind-bendy feeling of shifting my programming paradigm
(and LOVE LOVE LOVE Python), I get sheepish when I feel I'm missing
something basic.

So:
I have a csv list of data, of the form:
plot, utmN83_X, utmN83_Y, plot_radius_m
Spring1,348545,3589235,13.2
etc.

I built a nifty ClassGPSPoint(Xpos,Ypos,plotRadius,workPaths) that eats the
X&Y positions, the plot radius, and previously instantiated object holding
all of the appropriate paths definitions to access the LiDAR LAS files.

I make a nice CSV reader with one line (did I mention I LOVE python?)...

plotReader =
csv.reader(open("N:\\GIS_Projects\\095_ForestMetrics\\7_Analyses\\FinalCylinders\\Plots.csv"))

What I want to do is use the first entry in that row (row[0]) as the
variable name for the instantiated class.  I'd get an instantiated GPSPoint
object called 'Spring1' that would yield all my methods and defined values
(Spring1.pathLASfile, Spring1.perturbXY(), etc)
Hence, in pseudocode:

for row in plotReader:
   row[0] = GPSPoint(row[1],row[2],18.3,workPaths)

But that doesn't work.  I'm probably missing something basic and profound,
(I was trying to use global to track my paths until I got my mind around the
passing the instantiated object thing, but whaddya gonna do?  Sequential to
OO is a big shift, you know?)

Thanks ya'll -

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


Re: [Tutor] How to convert seconds to hh:mm:ss format

2012-02-16 Thread Daryl V
You've gotten some really excellent advice about how to approach working
with the time format.  Here's a chunk of code I use quite a bit.  It's
probably sub-optimal, but playing with it might help you come up with a
solution that works for your application.


 def Int2Digit(integer):
if integer < 9:
strInteger = "0"+str(integer)
else:
strInteger = str(integer)
return strInteger

def TimeStampMaker():
import datetime
t = datetime.datetime.now()
strTmonth = Int2Digit(t.month)
strTday = Int2Digit(t.day)
strThour = Int2Digit(t.hour)
strTminute = Int2Digit(t.minute)
timeStamp = str(t.year)+strTmonth+strTday+strThour+strTminute
return timeStamp

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