Moving from perl to python: questions

Skip Montanaro skip at mojam.com
Wed Feb 16 10:23:40 EST 2000


    David>   1) Best way to convert array argv[1:] into string to pass functions

import string
args = string.join(sys.argv[1:])

    David>   2) How to implement a no-frills file slurp() function

By "slurp" I presume you mean to read it all in one chunk.  This presents
the file line-by-line to the programmer through the line variable:

    f = open("foo")
    for line in f.readlines():
	do_fun_stuff()

This just stuffs the file's contents into a variable:

    f = open("foo")
    data = f.read()

More elaborate structures are useful for very large files.  The topic is
discussed occasionally in the newsgroup.  Check the archives at deja.com for 
details.

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