首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python-assert用法

2012-09-06 
python---assert用法# -*- coding: utf -8 -*-from socket import gethostname, gethostbynamefrom except

python---assert用法

# -*- coding: utf -8 -*-from socket import gethostname, gethostbynamefrom exceptions import AssertionErrordef get_local_ip():    '''       Return local host ip.     '''    ip = gethostbyname(gethostname())    assert ip != '127.0.1.1', 'No network connect, please the network connect again!'   # 不应该是怎样的,就写成怎样    return iptry:    print get_local_ip()except AssertionError,  e:    print e


$ python get_localhost_ip.py
No network connect, please the network connect again!

热点排行