Using sockets or telnetlib to finger?

Skip Montanaro skip at mojam.com
Sat Feb 12 07:02:52 EST 2000


    André> The latest stable version of the Linux kernel is:     2.2.14
    André> The latest beta version of the Linux kernel is:       2.3.43
    André> The latest prepatch (alpha) version *appears* to be:  2.3.44-8
    André> 
    André> I need to access the version numbers alone, since I want to
    André> translate the rest of the text. 

Jumping in a bit late...

Your kernel_info string contains all the data from the finger operation.
I think you'll find parsing it somewhat less fragile if you split it into
lines and then grab the text you want from individual lines:

    import string
    lines = string.split(kernel_info, "\n")
    stable = string.split(lines[2])[-1]
    beta = string.split(lines[3])[-1]
    alpha = string.split(lines[4])[-1]

You can make it even less fragile by searching for relevant substrings in
the appropriate lines before extracting.  Depending on how crucial stability
of this code is, you may well simply find it easier to adjust your
application if format changes to the finger output break it...

Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/
"Languages that change by catering to the tastes of non-users tend not to do
so well." - Doug Landauer




More information about the Python-list mailing list