Replace deprecated string.split() and string.join() in /python/CFDataFile.py. Also open in text mode instead of binary mode to make the script work under python 3.x

git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@11451 282e977c-c81d-0410-88c4-b93c2d0d6712
master
anmaster 2009-02-11 21:39:10 +00:00
parent f813901342
commit f312f10445
1 changed files with 6 additions and 6 deletions

View File

@ -40,14 +40,14 @@ class CFDataFile:
def make_file(self, header):
'''creates a datafile, making the column header from a list passed in'''
try:
file = open(self.filename,'wb')
file = open(self.filename,'wt')
except:
Crossfire.Log(Crossfire.LogError, "Can't create datafile %s" % self.datafile_name)
else:
temp = []
for item in header:
temp.append(str(item))
contents = '#|%s\n' %(string.join(temp,'|'))
contents = '#|%s\n' %('|'.join(temp))
file.write(contents)
file.close()
Crossfire.Log(Crossfire.LogInfo, "New datafile created: %s" % self.datafile_name)
@ -56,7 +56,7 @@ class CFDataFile:
'''Gets the formatted file as a dictionary
The # key contains the column headers for the file and indicates the 'primary' key'''
try:
file = open(self.filename,'rb')
file = open(self.filename,'rt')
except:
raise Exception('Unable to read %s' % self.filename)
else:
@ -73,7 +73,7 @@ class CFDataFile:
def putData(self, dic):
'''Writes dictionary to formatted file - uses | character as a delimiter'''
try:
file = open(self.filename,'wb')
file = open(self.filename,'wt')
except:
raise Exception('Unable to open %s for writing' % self.datafile_name)
else:
@ -81,14 +81,14 @@ class CFDataFile:
del dic['#']
index = dic.keys()
index.sort()
contents = '#|%s\n' %(string.join(header,'|'))
contents = '#|%s\n' %('|'.join(header))
file.write(contents)
for entry in index:
tmp = []
stringlist = dic[entry]
for item in stringlist:
tmp.append(str(item))
temp = '%s|%s\n' %(entry, (string.join(tmp,'|')))
temp = '%s|%s\n' %(entry, ('|'.join(tmp)))
file.write(temp)
file.close()