This is exactly what divmod
was invented for:
>>> def decdeg2dms(dd):
... mnt,sec = divmod(dd*3600,60)
... deg,mnt = divmod(mnt,60)
... return deg,mnt,sec
>>> dd = 45 + 30.0/60 + 1.0/3600
>>> print dd
45.5002777778
>>> decdeg2dms(dd)
(45.0, 30.0, 1.0)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…