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