Moving from perl to python: questions
Gaetan Corneau
Gaetan_Corneau at baan.com
Wed Feb 16 09:52:39 EST 2000
> > > 2) How to implement a no-frills file slurp() function
> >
> > What is a "slurp" function?
>
> Hum... The attachment of my code didn't make it. Let's try
> this again...
Something like this?
def slurp(filename):
"Slurp all the lines of a file into an array"
return open(filename).readlines()
You can simplify "chomp", too:
# I didn't try it, but it should work :)
def chomp(lines):
"remove the end of line markers from array"
import os
nl_len = len(os.linesep) # length of os dependent line seperator
for i in range(0, len(lines)):
lines[i] = lines[i][:-nl_len]
Hope ths helps,
______________________________________________________
Gaetan Corneau
Software Developer
Software Engineering Process Group
BaaN Supply Chain Solutions
http://www.baan.com
E-mail: Gaetan_Corneau at baan.com
Tel: (418) 266-8252
______________________________________________________
"Profanity is the one language all programmers know best"
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/B/MU d- s+:++ a C++
UL+ P--- W+ N- K- W++ t--
!5 X- R+ tv-- b++ DI++
G e++ h---- r+++ y++++
------END GEEK CODE BLOCK------
More information about the Python-list
mailing list