newbie file/DB processing
Paul Watson
pwatson at redlinepy.com
Thu May 19 10:42:00 EDT 2005
"len" <lsumnler at gmail.com> wrote in message
news:1116445969.381550.99280 at f14g2000cwb.googlegroups.com...
> I am an old time
> cobol programmer from the IBM 360/370 eria and this ingrained idea of
> file processing using file definition (FD's) I believe is causing me
> problems because I think python requires a different way of looking at
> datafiles and I haven't really gotten my brain around it yet.
Welcome, Len.
> I would
> like to create a small sequential file, processing at first to store a
> group id, name, amount, and date which I can add to delete from and
> update
In addition to the suggestions already given, you might take a look at the
struct module. This will let you use fixed-width binary records.
The concept of streams found in UNIX takes some getting used to. Many files
are maintained as text using delimited, variable length fields with a
newline at the end. Try 'cat /etc/passwd' on a UNIX/Linux host to see such
a file using a colon ':' as the delimiter.
I turn to the 'od' command when I want the truth. Use it to see what bytes
are -really- in the file. The following should work on Linux or under
Cygwin if you are still using Windows.
od -Ax -tcx1 thefile.dat
You can use od to look at data in the stream. The output of the print
command is going into the od command.
$ print "now"|od -Ax -tcx1
000000 6e 6f 77 0a
n o w \n
6e 6f 77 0a
000004
More information about the Python-list
mailing list