checked for python3 compatibility:

use "print('foo')" instead of "print 'foo'"
and "except(error) as e" instead of "except error,e"
This commit is contained in:
Martin Diehl 2013-09-14 10:52:02 +00:00
parent 5f973a21c0
commit 3eb8aa1362
3 changed files with 12 additions and 12 deletions

View File

@ -52,7 +52,7 @@ class ASCIItable():
import sys import sys
try: try:
self.__IO__['output'] == [] or self.__IO__['out'].write('\n'.join(self.__IO__['output']) + '\n') self.__IO__['output'] == [] or self.__IO__['out'].write('\n'.join(self.__IO__['output']) + '\n')
except IOError, e: except(IOError) as e:
return False return False
if clear: self.output_clear() if clear: self.output_clear()
return True return True
@ -89,7 +89,7 @@ class ASCIItable():
# ... without any labels # ... without any labels
try: try:
self.__IO__['dataStart'] = self.__IO__['in'].tell() # current file position is at start of data self.__IO__['dataStart'] = self.__IO__['in'].tell() # current file position is at start of data
except IOError: except(IOError):
pass pass
if self.__IO__['validReadSize'] == 0: # in case no valid data length is known if self.__IO__['validReadSize'] == 0: # in case no valid data length is known
@ -137,12 +137,12 @@ class ASCIItable():
for label in labels: for label in labels:
try: try:
idx.append(self.labels.index(label)) idx.append(self.labels.index(label))
except ValueError: except(ValueError):
idx.append(-1) idx.append(-1)
else: else:
try: try:
idx = self.labels.index(labels) idx = self.labels.index(labels)
except ValueError: except(ValueError):
idx = -1 idx = -1
return idx return idx
@ -221,7 +221,7 @@ class ASCIItable():
if len(self.data) <= idx: if len(self.data) <= idx:
self.data_append(['n/a' for i in xrange(idx+1-len(self.data))]) # grow data if too short self.data_append(['n/a' for i in xrange(idx+1-len(self.data))]) # grow data if too short
self.data[idx] = str(what) self.data[idx] = str(what)
except ValueError: except(ValueError):
pass pass
return idx return idx

View File

@ -62,8 +62,8 @@ class Environment():
if licenses[0]-licenses[1] >= noNeeded: if licenses[0]-licenses[1] >= noNeeded:
return 0 return 0
else: else:
print licenses[1] + noNeeded - licenses[0], 'missing licenses for %s'%software print(licenses[1] + noNeeded - licenses[0], 'missing licenses for %s'%software)
return licenses[1] + noNeeded - licenses[0] return licenses[1] + noNeeded - licenses[0]
except IndexError: except IndexError:
print 'Could not retrieve license information for %s'%software print('Could not retrieve license information for %s'%software)
return 127 return 127

View File

@ -26,9 +26,9 @@ def outStdout(cmd,locals):
exec(cmd[3:]) exec(cmd[3:])
elif cmd[0:3] == '(?)': elif cmd[0:3] == '(?)':
cmd = eval(cmd[3:]) cmd = eval(cmd[3:])
print cmd print(cmd)
else: else:
print cmd print(cmd)
return return
#------------------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------------------
@ -271,11 +271,11 @@ file = open(args[0])
content = file.readlines() content = file.readlines()
file.close() file.close()
print '\033[1m'+scriptName+'\033[0m\n' print('\033[1m'+scriptName+'\033[0m\n')
if options.filetype not in ['spectral','geom']: if options.filetype not in ['spectral','geom']:
options.filetype = os.path.splitext(args[0])[1][1:] options.filetype = os.path.splitext(args[0])[1][1:]
print '\nparsing %s...'%options.filetype, print('\nparsing %s...'%options.filetype,)
sys.stdout.flush() sys.stdout.flush()
(grid,size,homog,microstructures) = {\ (grid,size,homog,microstructures) = {\
@ -283,7 +283,7 @@ sys.stdout.flush()
'spectral': parse_spectralFile, 'spectral': parse_spectralFile,
}[options.filetype](content,options.homogenization) }[options.filetype](content,options.homogenization)
print '%i microstructures in %s with grid %s and homogenization %i\n'%(len(list(set(microstructures))),str(size),str(grid),homog) print('%i microstructures in %s with grid %s and homogenization %i\n'%(len(list(set(microstructures))),str(size),str(grid),homog))
cmds = [\ cmds = [\