Python: First Impressions
Well, I’ve finished the first half of O’Reilley’s Learning Python book and I’m impressed. The language is clean and not too hard to learn, especially given my experience with similar languages like Tcl/Tk. There are however a few things that intrigue and concern me:
- No Magic.Python seems really big on the “No Magic” idea, meaning that if the result of an operation is ambiguous then it simply doesn’t do it. This was particularly frustrating for me with TclTk as it was frequently difficult to determine if a string would be considered a Number (for addition) or a string (for Concatenation). This most frequently was a problem when you were trying to do string processing operations on numbers, you wound up with a string like “042″ that it started interpreting as Octal 42. That Python warns you & forces you to typecast is somewhat nice.
- Immutable vs Mutable: In C you can spend alot of time getting the hang of “Pass by Reference” vs “Pass by Value”. In Python it seems you spend alot of time trying to get the hang of Mutable vs Immutable. The reference is similar when it comes to function arguments, but this distinction effects the code at all levels. From what I see, it’s mostly a theoretical problem that in practice doesn’t really happen much. I mean, honestly, how often have you ever had to modify a number “in place”. I’m betting never. “2″ is “2″, and you probably want it to stay that way. Where I figure I’ll get burned is with “tuples”, the immutable form of a list.
- Generators/Iterators: This is just a neat gizmo here. Having functions that “yield” a value instead of “return” seems a bit awkward, but I can already see the huge benefits you can reap from this.
And, of course, there’s plenty more. I’m just getting started. VTK has Python Bindings (I believe the new Paraview 3.0 is Python-based even) so I’ve spent the last few days trying to get VTK+Python setup on my Windows Workstation at the office and on our SGI Irix system. It’s proven to be difficult, partly because of the wierd architectures and partly because of VTK, but it’s done. So I present to you, my first functional VTK+Python script.
[tag:python][tag:source][tag:vtk][tag:script][tag:software][tag:programming]
| # import VTK from vtk import * # Open the cquads file # Skip the first line dataPoints = vtkPoints() # Split the line into a list, by spaces grid.InsertNextCell(quad.GetCellType(), pointList) grid.SetPoints(dataPoints) print “Writing file…” |

