如果你真的很讨厌在
try/except各处使用s,请编写一个辅助函数:
def RepresentsInt(s): try: int(s) return True except ValueError: return False>>> print RepresentsInt("+123")True>>> print RepresentsInt("10.0")False它将需要更多的代码来完全覆盖Python认为是整数的所有字符串。我说这是pythonic。



