Handling lines with something-separated fields for PythonAs a system administrator, I spend a bunch of my time dealing with
files made up of lines that are composed of fields separated by some
character. A classical example is This only takes a little bit of extra work to implement on top of
our previous
class FieldLine(SetMixin, list):
separator = ":"
def __init__(self, line):
n = line.split(self.separator)
super(FieldLine, self).__init__(n)
def __str__(self):
return self.separator.join(self)
class PasswdLine(FieldLine):
fields = gen_fields('name', 'passwd',
'uid', 'gid', 'gecos',
'dir', 'shell')
(Where Now that I've written these entries, I have a confession: this is
actually what I started out doing. I didn't first build a general
ordered list with named fields class and then realized it could be used
to deal with (In fact this is the cleaned up and idealized version of this class. The
real one in my program does not subclass (5 comments.)
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |