.pythonrc
In Python 3000 sind nun endlich print und exec Funktionen. Dies bedeutet aber, dass meine .pythonrc nicht mehr ohne Änderungen auf beiden Versionen funktioniert. Da ich in meiner aktuellen .pythonrc auch Features verwende, die vor 2.5 nicht verfügbar sind, habe ich das jetzt etwas modularer gestaltet: die .pythonrc schaut nur noch nach der ausgeführten Python-Version und führt dann .pythonrcx.y.z aus, wobei x, y und z für die Teile der Versionsnummer stehen. .y und .z dürfen weggelassen werden:
def getpythonrc():
import sys
import os.path
l = len(sys.version_info)
for i in xrange(l):
version = ".".join([str(x) for x in sys.version_info[:l-i]])
pythonrc_name = os.path.expanduser("~/.pythonrc") + version
try:
pythonrc = open(pythonrc_name)
except:
pass
else:
print("Using " + repr(pythonrc_name) + " as startup file")
return pythonrc
pythonrc = getpythonrc()
if pythonrc is not None:
exec(pythonrc)
del pythonrc, getpythonrc
try:
del __file__
except:
pass
Diese Version läuft bei mir jetzt von Python 2.1 bis Python 3000. Eventuell möchte man, dass alle gefundenen Dateien ausgeführt werden (also für Python 2.5 .pythonrc2.5.0, .pythonrc2.5 und .pythonrc2 - am besten noch in umgekehrter Reihenfolge), das habe ich mir noch nicht genau überlegt.