Port codebase from Python 2 to Python 3

Replace Python 2-only constructs throughout libs/: print statements,
ConfigParser -> configparser, sets.Set -> builtin set, string.split ->
str.split, xrange -> range, dict.has_key()/.iteritems() -> in/.items(),
old-style raise Exception, "msg" syntax, and __cmp__ -> __eq__/__lt__
via functools.total_ordering (Python 3 dropped cmp()/__cmp__, which
max()/.sort() rely on). Also cleaned up mixed tab/space indentation
that Python 3's stricter tokenizer rejects.

Fixed two latent bugs that only surfaced once end-to-end runs were
possible under Python 3's stricter error handling:
- HandleBestellung() compared G.Anzahl (a bound method) to an int
  instead of calling G.Anzahl() - silently "worked" under Python 2's
  permissive cross-type ordering, raises TypeError under Python 3.
- LeuteAllein() raised KeyError for VIP-group members, who are never
  added to the regular Gruppen container; now skips people with no
  group entry instead of crashing.

Verified end-to-end: bin/platz.sh --indir work/test1 and --indir
work/test2 (VIP group included) both run to completion and produce
correctly formatted output.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Michael Stangl
2026-07-09 12:27:27 +02:00
parent 1e2eedc62b
commit 6e3649ed27
6 changed files with 289 additions and 278 deletions
+12 -12
View File
@@ -11,7 +11,7 @@ __license__ = "Python"
from ga import *
from Strukturdaten import *
import ConfigParser
import configparser
import optparse
@@ -33,7 +33,7 @@ if __name__ == '__main__':
parser.error( "--indir '%s' ist kein Verzeichnis" % InDir )
# lade Vorgaben fuer Optimierungszyklus und
config = ConfigParser.ConfigParser()
config = configparser.ConfigParser()
ConfigPath= os.path.join( os.getenv('PLATZ_CFG'), 'platz.cfg')
config.read( os.path.expandvars( ConfigPath ))
@@ -55,26 +55,26 @@ if __name__ == '__main__':
Z = Zyklus()
Z.laden( Zyklusconfig, Zyklusart )
print Z
print(Z)
SL = Strafliste()
SL.laden( Strafenconfig )
print SL
print(SL)
TE = Tische()
TE.laden( Tischconfig )
print TE
print(TE)
InputFile = XMLConfig()
[ PN, GN, VIPGruppe, VIPListePT ] = InputFile.laden( Bestellung )
print PN
print GN
print VIPGruppe
print VIPListePT
print(PN)
print(GN)
print(VIPGruppe)
print(VIPListePT)
print "\n-- Erzeuge Farm:"
print("\n-- Erzeuge Farm:")
F1 = Farm( Z, Sitzplatzverteilung, Tische=TE, Gruppen=GN, Strafen=SL, VIPListe=VIPListePT, VIPs=VIPGruppe )
#print F1
#print(F1)
S = F1.Bester()
print S
print(S)
S.speichern( AusgabeTP, AusgabePT )
else: