[CALUG] Reading CSV using Python / PHP
Bryan Smith
b.j.smith at ieee.org
Thu Apr 28 11:49:19 EDT 2016
mike vore wrote:
> Sounds like something I did many years ago, probably in AWK.
I use "sed" by default, because it's "busybox" implementation is much
closer to the full version. There are only a few, base regex's it
won't do.
I.e., lots and lots of embedded shell scripting in my past.
> My source code might be on 5.25 floppies - APPLE CPM format.
> I did say MANY years ago.
I was a long time C Shell hacker, making it do things it shouldn't
(insert the standard "Csh Programming Considered Harmful" [1]
disclaimer), but kept using it because ...
A) tsch was basically the same on all platforms
B) bourne was still in various states of implemenation
C) bash had bugs, plus differences prior to v4 (which adds hashes too)
D) pdksh was only partially ksh88 compatible, ksh93 wasn't universal (yet)
However, I didn't learn Perl until ... Windows NT!
Yes, being a long-time UNIX hacker, I was fine with not using Perl,
and sticking with shell scripting. But unlike OS/2 with Rexx et al.,
NT 3.1 (and really until PowerShell in NT6/Vista+, fka MONAD in
NT5/200x) lacked any scripting capability. Someone posted a
Perl::Win32 implementation on comp.lang.perl early into the mid '90s
(this was before ActiveState of '96+, although Cygwin was coming
along), and the rest is history for me. ;)
> If I were starting from scratch in two steps:
> find the multi line records - make them into long lines
> parse on ^" (beginning of line, "," and '$ (end of line). and do your
> processing on each line.
I cannot recommend this for a new developer.
Maybe in our day (20th century) of hacking. But today, there are just
too many methods already available, and it's a good learning
experience to get familiar with a maintainable, object-oriented
language like Python.
E.g., if one learns how to handle the CSV methods and resulting
objects in Python, one is ready to tackle similar methods for XML
parsing, XMLRPC and SOAP methods and their call/return objects, etc...
I don't want to deter anyone from "hacking" with Perl or even Ruby,
doing the "raw" string manipulation. At the same time, once you learn
just the basic CSV methods already available for, say, Python, it's
really easy, and you avoid having to worry about escaping things too.
Just my view, for a new developer. ;)
-- bjs
[1] http://www.perl.com/doc/FMTEYEWTK/versus/csh.whynot
--
Bryan J Smith - http://www.linkedin.com/in/bjsmith
E-mail: b.j.smith at ieee.org or me at bjsmith.me
More information about the CALUG
mailing list