最近pythonのいくつかの関数とライブラリの総括を学びます
1314 ワード
, , python , py .test , ,
with as :
, ,:
file=open("aa.txt","r")
data=file.read()
file.close()
, try :
<pre name="code" class="python">file=open("aa.txt","r")
try:
data=file.read()
finally:
file.close()
好吧学习python的大多看这样觉得顺眼:with open("aa.txt","r") as file: data=file.read()
assertという関数を見続けます.
assertという関数はある条件が本当であることを宣言するために使用されます.hasattrという関数を見続けます.>>> a=1 >>> assert a==1 >>> assert a==2 Traceback (most recent call last): File "<stdin>", line 1, in <module> AssertionError >>>
この関数は、オブジェクトobjectにパラメータが含まれているかどうかを強く表示するプロパティ(フィーチャー):>>> hasattr(list,"append") True >>> hasattr(list,"pop") True >>> hasattr(list,"add") False >>> hasattr(list,"del") False