huh? Python says that AttributeError: 'string' object has no attribute 'split'
schmitthead at my-deja.com
schmitthead at my-deja.com
Wed Apr 26 02:37:11 EDT 2000
I received a whole folder full of files with MacOS type text files, with
different newline characters. I thought, a perfect job for python.
Below is my attempt, but it generates the following error message:
>mac2dos tt_prvt.h
Traceback (innermost last):
File "C:\bin\mac2dos.py", line 33, in ?
mac2dos( directory )
File "C:\bin\mac2dos.py", line 24, in mac2dos
os.path.walk( os.getcwd(), callbackfunc, '' )
File "d:\python\Lib\ntpath.py", line 265, in walk
func(arg, top, names)
File "C:\bin\mac2dos.py", line 18, in callbackfunc
mac2dosfile( file )
File "C:\bin\mac2dos.py", line 9, in mac2dosfile
lines = myline.split( myline, chr(10) )
AttributeError: 'string' object has no attribute 'split'
#mac2dos.py-------------------------------------------------------------
import os
import sys
import string
#-----------------------------------------------------------------------
def mac2dosfile( file ):
myline = file.read()
lines = myline.split( myline, chr(10) )
for l in lines:
l = l.strip( l )
file.writelines( lines )
#-----------------------------------------------------------------------
def callbackfunc( junk, dir, names ):
for name in names:
file = open( name, 'r+' )
mac2dosfile( file )
close( file )
#-----------------------------------------------------------------------
def mac2dos( dir ):
os.path.walk( os.getcwd(), callbackfunc, '' )
#-----------------------------------------------------------------------
if __name__ == '__main__':
if ( len(sys.argv) < 2 ):
directory = os.getcwd()
else:
directory = sys.argv[1]
mac2dos( directory )
#-end-of-mac2dos.py-----------------------------------------------------
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list