Bret <bret.wortman at gmail.com> writes: > nextport=42000 > > def getNextPort(): > nextport += 1 > return nextport If you have to do it that way, use: def getNextPort(): global nextport nextport += 1 return nextport the global declaration stops the compiler from treating nextport as local and then trapping the increment as to an uninitialized variable.