Benutzer:Alva2004/Programme/py2or3
Zur Navigation springen
Zur Suche springen
'python 2 and 3 support'
import sys
if sys.version_info[ 0 ] == 3: # python3
from collections import UserDict, UserList
from functools import reduce
def execfile( name, globals={},locals={} ):
fid = open( name, 'r' )
inh = fid.read()
fid.close()
exec( expr, globals, locals )
class file:
#----------------------------------------------------------------------
def __init__(self,name,mode):
self.name=name
self.__dat=open(name,mode)
#----------------------------------------------------------------------
def readlines(self):
return self.__dat.readlines()
#----------------------------------------------------------------------
def write(self,zeilen):
self.__dat.write(zeilen)
#----------------------------------------------------------------------
def close(self):
self.__dat.close()
#----------------------------------------------------------------------
def flush(self):
self.__dat.flush()
#----------------------------------------------------------------------
else:
from UserDict import UserDict
from UserList import UserList
from __builtin__ import file