面向对像(9day)

Posted wanchenxi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了面向对像(9day)相关的知识,希望对你有一定的参考价值。

http://www.cnblogs.com/linhaifeng/articles/6232220.html

异常处理

 

# print(x)

# int(\'asdf\')

# res1=1/0
# res2=1+\'str\'


# l=[1,2,3]
# l[100]


# print(\'=====\')
# print(\'=====\')
# print(\'=====\')
# print(\'=====\')
# d={\'a\':1}
# d[\'b\']
#
#
# print(\'111111111111\')
# print(\'111111111111\')
# print(\'111111111111\')
# print(\'111111111111\')


# x=1
#
# if x > 1
#     print(\'asdfsadfasdf\')


# class Foo:
#     x=1
#
# print(Foo.x)
# print(Foo.y)



l=[1,2,3,4,4,5,6]








# index=1000
# if len(l) > index:
#     print(l[index])


# def search():
#     print(\'search\')
# cmd_dic={
#     \'search\':search
# }
# while True:
#     choice=input(":>>").strip()
#     if choice in cmd_dic:
#         cmd_dic[choice]()



#
# try:
#     print(\'======\')
#     print(x)
#     print(\'======\')
#     print(\'======\')
# except KeyError as x:
#     print(x)
# except NameError as e:
#     print(e)
#
# print(\'继续其他的事情\')

# try:
#     print(x)
#     # l=[1,2,3]
#     # l[1000]
#     # d={\'a\':1}
#     # d[\'b\']
#
# except KeyError:
#     pass
# except ValueError:
#     pass
# except Exception:
#     pass


# s1 = \'hello\'
# try:
#     int(s1)
# except IndexError as e:
#     print(e)
# # except KeyError as e:
# #     print(e)
# # except ValueError as e:
# #     print(e)
# #except Exception as e:
# #    print(e)
# else:
#     print(\'try内代码块没有异常则执行我\')
# finally:
#     print(\'无论异常与否,都会执行该模块,通常是进行清理工作\')



# raise IndexError(\'asdfasfadsfasdfsadfasdf\')



# print(IndexError)
# print(ValueError)
#
#
# class EgonException(BaseException):
#     def __init__(self,msg):
#         self.msg=msg
#     def __str__(self):
#         return self.msg
#
#
# raise EgonException(\'类型错误\')





# x=1
# y=2
# assert x == y
# print(\'===>\')


# try:
#     l=[1,2,3]
#     l[100000]
# except Exception:
#     pass

# try:
#     for i in range(10)
#         print(i)
# except Exception:
#     pass

 

模块

http://www.cnblogs.com/linhaifeng/articles/6379069.html

# money=123123123123123123123123
# import spam

#第一件事:创建名称空间,用来存放spam.py中定义的名字
#第二件事:基于刚刚创建的名称空间来执行spam.py
#第三件事:创建名字spam指向该名称空间,spam.名字的操作,都是以spam.py为准

# print(spam.money)
#
# spam.read1()

# def read1():
#     print(\'test read1\')
#
# spam.read2()

# spam.change()
# print(money)

# print(hasattr(spam,\'money\'))

# x=1
# x1=x
# x2=x
# x3=x
# x4=x

#
# import spam
# import spam
#
# import sys
# print(sys.modules)


# import spam as x
#
# print(x.money)




# from spam import money,read1,read2
#
# money=100000000000000
# # print(money)
# # read1=123123123123123213
# # read1()
#
#
# read1=123123123123123
#
# read2()




# from spam import read1 as spamread1
#
#
# def read1():
#     print(\'test read1\')
#
# read1()
# spamread1()



# from spam import *
#
# print(money)
# print(read1)
# print(read2)


# from spam import *
# print(money)
# print(read1)
# print(read2)


# import time
#
# import spam
#
# time.sleep(10)
# import spam




import spam

 

以上是关于面向对像(9day)的主要内容,如果未能解决你的问题,请参考以下文章

面向对像(8day)

面向对像(2day)

面向对像(7day)

P61面向对像的02,回顾方法的定义

面向对像(1day)

Python-面向对像及其他