成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Python_異常和模塊

piglei / 899人閱讀

摘要:例如等價(jià)于到結(jié)束,但不包括。例如返回沒有每次跳躍的間距,默認(rèn)為。

異常處理

單個(gè)異常處理:

try:
    print(num)

except NameError:
    print("沒有定義變量")

except FileNotFoundError:
    print("找不到文件路徑")

print(1)

多個(gè)異常處理:

try:
    print(num)
    # 11/0
    # open("xxx.txt")
except (NameError, FileNotFoundError, ZeroDivisionError): # 多個(gè)異常統(tǒng)一處理
    print("異常")

print(1)

所有異常處理:

try:
    print(num)
except Exception: # 所有異常處理
    print("所有異常處理")

print(1)

查看原來異常輸出:

try:
    print(num)
except Exception as err:
    print(err)
print(1)    

沒有異常執(zhí)行

try:
    a = 1

execpt Exception as err:
    print(err)

else:
    print("沒有異常執(zhí)行")

finally:
    print("不管是否出現(xiàn)異常, 都執(zhí)行")

print(1)     

import time
try:
    f = open("test.txt")
    try:
        while True
            content = f.readline()
            if len(content) == 0:
                break
            time.sleep(2)
            print(content)
    except Exception:
        # pass
        print("文件產(chǎn)生異常")
    finally:
        f.close()
        print("關(guān)閉文件")
except Exception:
    print("沒有這個(gè)文件")

tryexcept需要同時(shí)存在
當(dāng)函數(shù)嵌套的時(shí)候,如果函數(shù)出現(xiàn)異常,會(huì)返回異常,然后捕獲到異常

拋出自定義異常

raise: 拋出一個(gè)自定義異常

raise語句如果不帶參數(shù),就會(huì)把當(dāng)前錯(cuò)誤原樣拋出。

def main ():
    try:
        s = input("請(qǐng)輸入-->")
        if len(s) < 3:
            raise ShortInputException(len(s), 3)
        else:
            print(s)
    except ShortInputException as result:
        print("ShortInputException: 輸入的長度是 %d, 長度至少需要是 %d" % (result.length, result.atleast))
    else:
        print("沒有異常發(fā)生.")

class ShortInputException(Exception):
    """自定義異常類"""
    def __init__(self, length, atleast):
        # super().__init()
        self.length = length
        self.atleast = atleast

main()
模塊

如何獲取當(dāng)前模塊的文件名: __file__

引入模塊

import sys導(dǎo)入模塊中的全部功能
from argv import sys, from argv import sys,executable導(dǎo)入模塊中的多帶帶功能
from sys import *
from sys as s 別名

__name__: 用于表示當(dāng)前模塊的名字,同時(shí)還能反映一個(gè)包的結(jié)構(gòu)

導(dǎo)入輸出的是當(dāng)前模塊名

模塊被直接運(yùn)行時(shí)模塊名為:__main__

if __name__ == "__main__": # 如果模塊是被直接運(yùn)行的,則代碼塊被運(yùn)行,如果模塊是被導(dǎo)入的,則代碼塊不被運(yùn)行。
    # code
常用內(nèi)建模塊
標(biāo)準(zhǔn)庫 說明
builtins 內(nèi)建函數(shù)默認(rèn)加載
os 操作系統(tǒng)接口 [系統(tǒng)級(jí)別的操作(文件和目錄)]
sys Python自身的運(yùn)行環(huán)境 [對(duì)解釋器相關(guān)的操作]
functools 常用的工具
json & pickle 編碼和解碼 JSON 對(duì)象
logging 記錄日志,調(diào)試
multiprocessing 多進(jìn)程
threading 多線程
copy 拷貝
time 時(shí)間
datetime 日期和時(shí)間
calendar 日歷
hashlib 加密算法
random 生成隨機(jī)數(shù)
re 字符串正則匹配
socket 標(biāo)準(zhǔn)的 BSD Sockets API
shutil 文件和目錄管理 [高級(jí)的 文件、文件夾、壓縮包 處理模塊(遞歸,文件復(fù)制等)]
glob 基于文件通配符搜索
shelve 一個(gè)簡單的k,v將內(nèi)存數(shù)據(jù)通過文件持久化的模塊,可以持久化任何pickle可支持的python數(shù)據(jù)格式

hashlib

import hashlib
m = hashlib.md5()   # 創(chuàng)建hash對(duì)象,md5:(message-Digest Algorithm 5)消息摘要算法,得出一個(gè)128位的密文
print m             # 
m.update("alogy")  # 更新哈希對(duì)象以字符串參數(shù)
print m.hexdigest() # 返回十六進(jìn)制數(shù)字字符串

例子:用于注冊(cè)、登錄

import hashlib
import datetime
KEY_VALUE = "alogy"
now = datetime.datetime.now()
m = hashlib.md5()
str = "%s%s" % (KEY_VALUE,now.strftime("%Y%m%d"))
m.update(str.encode("utf-8"))
value = m.hexdigest()
print(value) # c69c59b58209a94f40e6a7a425f9a977
functools
["WRAPPER_ASSIGNMENTS", "WRAPPER_UPDATES", "__builtins__", "__doc__", "__file__", "__name__", "__package__", "cmp_to_key", "partial", "reduce", "total_ordering", "update_wrapper", "wraps"]

partial()

把一個(gè)函數(shù)的某些參數(shù)設(shè)置默認(rèn)值,返回一個(gè)新函數(shù),調(diào)用這個(gè)新函數(shù)會(huì)更簡單。

import functools

def showarg(*args, **kw):
    print(args)
    print(kw)

p1 = functools.partial(showarg, 1, 2, 3)
p1()
p1(4,5,6)
p1(a="python", b="alogy")

p2 = functools.partial(showarg, a=3, b="linux")
p2()
p2(1, 2)
p2(a="python", b="alogy")

wraps()

使用裝飾器時(shí),被裝飾后等函數(shù)其實(shí)已經(jīng)是另外一個(gè)函數(shù)(函數(shù)名等函數(shù)屬性會(huì)發(fā)生變化)

添加后由于函數(shù)名和函數(shù)的doc發(fā)生了改變,對(duì)測(cè)試結(jié)果有一些影響,例如:

def note(func):
    "note function"
    def wrapper():
        "wrapper function"
        print("note something")
        return func()
    return wrapper

@note
def test():
    "test function"
    print("I am test")

test()
print(test.__doc__)

運(yùn)行結(jié)果

note something
I am test
wrapper function

所以,Python的functools包中提供了一個(gè)叫wraps的裝飾器來消除這樣的副作用。例如:

import functools
def note(func):
    "note function"
    @functools.wraps(func) # 保存外邊函數(shù)名
    def wrapper():
        "wrapper function"
        print("note something")
        return func()
    return wrapper

@note
def test():
    "test function"
    print("I am test")

test()
print(test.__doc__)

運(yùn)行結(jié)果

note something
I am test
test function
常用擴(kuò)展庫
擴(kuò)展庫 說明
requests 使用的是 urllib3,繼承了urllib2的所有特性
urllib 基于http的高層庫
scrapy 爬蟲
beautifulsoup4 HTML/XML的解析器
celery 分布式任務(wù)調(diào)度模塊
redis 緩存
Pillow(PIL) 圖像處理
xlsxwriter 僅寫excle功能,支持xlsx
xlwt 僅寫excle功能,支持xls ,2013或更早版office
xlrd 僅讀excle功能
elasticsearch 全文搜索引擎
pymysql 數(shù)據(jù)庫連接庫
mongoengine/pymongo mongodbpython接口
matplotlib 畫圖
numpy/scipy 科學(xué)計(jì)算
django/tornado/flask web框架
xmltodict xml 轉(zhuǎn) dict
SimpleHTTPServer 簡單地HTTP Server,不使用Web框架
gevent 基于協(xié)程的Python網(wǎng)絡(luò)庫
fabric 系統(tǒng)管理
pandas 數(shù)據(jù)處理庫
scikit-learn 機(jī)器學(xué)習(xí)庫

例如:讀寫excel文件

安裝esay_install工具
sudo apt-get install python-setuptools

安裝模塊
sudo easy_install xlrd
sudo easy_install xlwt

所有內(nèi)置模塊
import sys
sys.modules.keys()

["builtins", "sys", "_frozen_importlib", "_imp", "_warnings", "_thread", "_weakref", "_frozen_importlib_external", "_io", "marshal", "nt", "winreg", "zipimport", "encodings", "codecs", "_codecs", "encodings.aliases", "encodings.utf_8", "_signal", "__main__", "encodings.latin_1", "io", "abc", "_weakrefset", "site", "os", "errno", "stat", "_stat", "ntpath", "genericpath", "os.path", "_collections_abc", "_sitebuiltins", "sysconfig", "idlelib", "idlelib.run", "linecache", "functools", "_functools", "collections", "operator", "_operator", "keyword", "heapq", "_heapq", "itertools", "reprlib", "_collections", "types", "collections.abc", "weakref", "tokenize", "re", "enum", "sre_compile", "_sre", "sre_parse", "sre_constants", "_loc
ale", "copyreg", "token", "queue", "threading", "time", "traceback", "warnings", "tkinter", "_tkinter", "tkinter.constants", "idlelib.autocomplete", "string", "_string", "idlelib.autocomplete_w", "platform", "subprocess", "signal", "msvcrt", "_winapi", "idlelib.multicall", "idlelib.config", "configparser", "_bootlocale", "encodings.gbk", "_codecs_cn", "_multibytecodec", "idlelib.hyperparser", "idlelib.pyparse", "idlelib.calltips", "inspect", "ast", "_ast", "dis", "opcode", "_opcode", "importlib", "importlib._bootstrap", "importlib._bootstrap_external", "importlib.machinery", "textwrap", "idlelib.calltip_w", "idlelib.debugger_r", "idlelib.debugger", "bdb", "fnmatch", "posixpath", "idlelib.macosx", "idlelib.scrolledlist", "idlelib.windows", "idlelib.debugobj_r", "idlelib.rpc", "pickle", "struct", "_struct", "_compat_pickle", "_pickle", "select", "socket", "_socket", "selectors", "math", "socketserver", "idlelib.iomenu", "shlex", "tempfile", "shutil", "zlib", "bz2", "_compression", "_bz2", "lzma", "_lzma", "random", "hashlib", "_hashlib", "_blake2", "_sha3", "bisect", "_bisect", "_random", "locale", "idlelib.stackviewer", "idlelib.debugobj", "idlelib.tree", "idlelib.zoomheight", "pydoc", "importlib.util", "importlib.abc", "contextlib", "pkgutil", "urllib", "urllib.parse"]

內(nèi)置全局變量:vars()

{"__name__": "__main__", "__doc__": None, "__package__": None, "__loader__": , "__spec__": None, "__annotations__": {}, "__builtins__": }

第三方模塊:
anaconda: 數(shù)十個(gè)常用的第三方模塊

內(nèi)建屬性

python類的內(nèi)建屬性和方法

["__class__", "__delattr__", "__dict__", "__doc__", "__format__", "__getattribute__", "__hash__", "__init__", "__module__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__str__", "__subclasshook__", "__weakref__"]
常用專有屬性 說明 觸發(fā)方式
__init__ 構(gòu)造初始化函數(shù) 創(chuàng)建實(shí)例后,賦值時(shí)使用,在__new__后
__new__ 生成實(shí)例所需屬性 創(chuàng)建實(shí)例時(shí)
__class__ 實(shí)例所在的類 實(shí)例.__class__
__str__ 實(shí)例字符串表示,可讀性 print(類實(shí)例),如沒實(shí)現(xiàn),使用repr結(jié)果
__repr__ 實(shí)例字符串表示,準(zhǔn)確性 類實(shí)例 回車 或者 print(repr(類實(shí)例))
__del__ 析構(gòu) del刪除實(shí)例
__dict__ 實(shí)例自定義屬性 vars(實(shí)例.__dict__)
__doc__ 類文檔,子類不繼承 help(類或?qū)嵗?
__getattribute__ 屬性訪問攔截器 訪問實(shí)例屬性時(shí)
__bases__ 類的所有父類構(gòu)成元素 類名.__bases__

__getattribute__例子:

class Person(object):
    def __init__(self, subject1):
        self.subject1 = subject1

    # 屬性訪問時(shí)攔截器,打log
    def __getattribute__(self, obj):
        if obj == "subject1":
            print("log subject1")
        return "redirect python"

    def show(self):
        print("this is Person")

p = Person("python")
print(p.subject1)
內(nèi)建函數(shù)

dir(__builtins__)

["ArithmeticError", "AssertionError", "AttributeError", "BaseException", "BufferError", "BytesWarning", "DeprecationWarning", "EOFError", "Ellipsis", "EnvironmentError", "Exception", "False", "FloatingPointError", "FutureWarning", "GeneratorExit", "IOError", "ImportError", "ImportWarning", "IndentationError", "IndexError", "KeyError", "KeyboardInterrupt", "LookupError", "MemoryError", "NameError", "None", "NotImplemented", "NotImplementedError", "OSError", "OverflowError", "PendingDeprecationWarning", "ReferenceError", "RuntimeError", "RuntimeWarning", "StandardError", "StopIteration", "SyntaxError", "SyntaxWarning", "SystemError", "SystemExit", "TabError", "True", "TypeError", "UnboundLocalError", "UnicodeDecodeError", "UnicodeEncodeError", "UnicodeError", "UnicodeTranslateError", "UnicodeWarning", "UserWarning", "ValueError", "Warning", "ZeroDivisionError", "__debug__", "__doc__", "__import__", "__name__", "__package__", "abs", "all", "any", "apply", "basestring", "bin", "bool", "buffer", "bytearray", "bytes", "callable", "chr", "classmethod", "cmp", "coerce", "compile", "complex", "copyright", "credits", "delattr", "dict", "dir", "divmod", "enumerate", "eval", "execfile", "exit", "file", "filter", "float", "format", "frozenset", "getattr", "globals", "hasattr", "hash", "help", "hex", "id", "input", "int", "intern", "isinstance", "issubclass", "iter", "len", "license", "list", "locals", "long", "map", "max", "memoryview", "min", "next", "object", "oct", "open", "ord", "pow", "print", "property", "quit", "range", "raw_input", "reduce", "reload", "repr", "reversed", "round", "set", "setattr", "slice", "sorted", "staticmethod", "str", "sum", "super", "tuple", "type", "unichr", "unicode", "vars", "xrange", "zip"]

range()

range(stop) # 整數(shù)列表
range(start, stop[, step]) # 整數(shù)列表

strat: 計(jì)數(shù)從start開始,默認(rèn)是從0開始。例如:range(5)等價(jià)于range(0, 5)

stop: 到stop結(jié)束,但不包括stop。例如:range(0, 5), 返回[0, 1, 2, 3, 4]沒有5

step: 每次跳躍的間距,默認(rèn)為1。例如:range(0, 5)等價(jià)于range(0, 5, 1)

map()

map函數(shù)會(huì)根據(jù)提供的函數(shù)作為指定序列做映射

map(function, sequence[, sequence, ...]) -> list

function: 一個(gè)函數(shù)

sequence: 一個(gè)或多個(gè)序列,取決于function需要幾個(gè)參數(shù)

返回值是一個(gè)list

# 函數(shù)需要一個(gè)參數(shù)
map(lambda x: x*x, [1, 2, 3]) # [1, 4, 9]

# 函數(shù)需要兩個(gè)參數(shù)
map(lambda x, y: x+y, [1, 2, 3], [4, 5, 6]) # [5, 7, 9]


def f1( x, y ):  
    return (x, y)
l1 = [0, 1, 2, 3, 4, 5, 6]  
l2 = ["Sun", "M", "T", "W", "T", "F", "S"]
l3 = map(f1, l1, l2) 
print(list(l3))
# [(0, "Sun"), (1, "M"), (2, "T"), (3, "W"), (4, "T"), (5, "F"), (6, "S")]

filter()

filter()會(huì)對(duì)指定序列執(zhí)行過濾操作

filter(function or None, sequence) -> list, tuple, or string

function: 接受一個(gè)參數(shù),返回布爾值True或False

sequence: 序列可以是str,tuple, list

返回值list, tuple, string

filter(lambda x: x%2, [1, 2, 3, 4])
[1, 3]

filter(None, "a")
"a"

reduce()

reduce會(huì)對(duì)參數(shù)序列中對(duì)元素進(jìn)行累積

reduce(function, sequence[, initial]) -> value

function:該函數(shù)有兩個(gè)參數(shù)
sequence:序列可以是str,tuple,list
initial:固定初始值

function: 該函數(shù)有二個(gè)參數(shù)

sequence: 序列可以是str, tuple, list

initial: 固定初始值

返回value

reduce(lambda x, y: x+y, [1,2,3,4]) # 10

reduce(lambda x, y: x+y, [1,2,3,4], 5) # 15

reduce(lambda x, y: x+y, ["aa", "bb", "cc"], "dd") # "ddaabbcc"

sorted()

sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list

iterable: 迭代器

key: 函數(shù)

reverse: 正序,倒序

返回一個(gè)新的列表

sorted([1, 4, 2, 6, 3, 5]) # [1, 2, 3, 4, 5, 6]

sorted([1, 4, 2, 6, 3, 5], reverse = 1) # 倒序 # [6, 5, 4, 3, 2, 1]

sorted(["dd", "aa", "cc", "bb"]) # ["aa", "bb", "cc", "dd"]

lst = [3, -19, -1, 28, 7, 0, -2, -5, 7, 8, 0 -3, 9, 0, 11]
sorted(lst, key=lambda x: (x >= 0, -x if x >= 0 else x)) # [-19, -5, -3, -2, -1, 28, 11, 9, 8, 7, 7, 3, 0, 0] ????
sorted(lst, key=lambda x: (x >= 0, -abs(x))) # [-19, -5, -3, -2, -1, 28, 11, 9, 8, 7, 7, 3, 0, 0] ????
模塊中的__all__的作用

__all__只影響from import *這種導(dǎo)入方式

__all__ = ["test"]

def test():
    print("test")
、__init__.py的作用

某個(gè)文件夾下具有__init.py的,稱之為

__init__.py作用:

package的標(biāo)識(shí)

定義package中的__all__,用來模糊導(dǎo)入

模塊的發(fā)布和安裝

新建一個(gè)setup.py寫入:

from distutils.core import setup

setup(name="alogy", version="1.0", description="a", author="alogy", py_modules=["suba.aa"]) # suba.aa 包名.模塊名

發(fā)布:

> python setup.py build

> python setup.py sdist

安裝:

> python setup.py install
import搜索路徑
import sys
sys.path # sys.path的先后順序
重新導(dǎo)入模塊

模塊被導(dǎo)入后,import module不能重新導(dǎo)入模塊,需要重新導(dǎo)入

from imp import *
reload("module") # module模塊名
調(diào)試

pdb是基于命令行的調(diào)試工具

運(yùn)行時(shí)啟動(dòng)
python -m pdb xxx.py

l: list 查看運(yùn)行的代碼
n: next 往下行執(zhí)行
c: continue 繼續(xù)執(zhí)行代碼直到結(jié)束
b 7,b 行數(shù): break 添加斷點(diǎn)(通過c執(zhí)行)
b: 查看所有斷點(diǎn)
clear 斷點(diǎn)序號(hào): 清除指定斷點(diǎn)
s: step 進(jìn)入當(dāng)前作用域中
p 變量名: 查看指定變量名的值
a: 查看所有當(dāng)前作用域的變量名和變量值
q: quit 退出調(diào)試
r: return 快速執(zhí)行到函數(shù)最后一行

交互式調(diào)試
import pdb
pdb.run("testfun(args)") # 此時(shí)會(huì)打開pdb調(diào)試,注意:先使用s跳轉(zhuǎn)到testfun函數(shù)中,然后可以使用
程序里埋點(diǎn)

當(dāng)程序執(zhí)行到pbd.set_trace()位置時(shí)停下來調(diào)試

import pdb

pdb.set_trace()
package

常用內(nèi)置模塊:
sys: 系統(tǒng)模塊, 程序與python解釋器的交互, 用于操控python的運(yùn)行時(shí)環(huán)境
os: 操作系統(tǒng)模塊, 程序與操作系統(tǒng)的交互, 系統(tǒng)操作IO等行為
time,datetime: 時(shí)間模塊
re: 正則
json: json處理
urllib: 網(wǎng)絡(luò)處理
random: 隨機(jī)

不常用內(nèi)置模塊:
itertools: 一些特殊的函數(shù)可以操作可迭代對(duì)象或者排列組合
copy: 拷貝的函數(shù)(賦值一般是傳遞對(duì)象的引用,修改一個(gè)對(duì)象,會(huì)導(dǎo)致其它對(duì)象也受到改變)
string: String模塊包含大量實(shí)用常量和類

Naked

Naked: 一個(gè)Python命令行應(yīng)用程序框架. 可用于執(zhí)行JS代碼

from Naked.toolshed.shell import execute_js, muterun_js
import sys

response = muterun_js("file.js")
if response.exitcode == 0:
  print(response.stdout)
else:
  sys.stderr.write(str(response.stderr))
shutil

用于復(fù)制和歸檔文件和目錄樹的實(shí)用函數(shù)。

# 清dist目錄
clearDist = (len(sys.argv) == 4 and (sys.argv[3] == "--clear"))
if clearDist:
    shutil.rmtree("./dist/")
subprocess

訪問I/O流的子進(jìn)程

# 編譯vue
buildStat = subprocess.call("node build/build.js " + webPath + " " + verPath, shell=True)
if buildStat != 0:
    print("vue 編譯錯(cuò)誤")
    sys.exit(1)
six

Python 2和3兼容庫

import six


def bytes_to_str(s, encoding="utf-8"):
    """Returns a str if a bytes object is given."""
    if six.PY3 and isinstance(s, bytes):
        return s.decode(encoding)
    return s
其它
給程序傳遞參數(shù)
import sys

print(sys.argv) # 接收運(yùn)行時(shí)接受的參數(shù)
終止程序運(yùn)行
import sys
sys.exit(1)

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/41403.html

相關(guān)文章

  • python模塊之sys

    摘要:返回的信息特定于當(dāng)前線程以及當(dāng)前堆棧幀。出于某些原因,這個(gè)值可能無法計(jì)算,將返回返回安卓版本的構(gòu)建時(shí)間,以整數(shù)表示。僅適用于安卓平臺(tái)返回解釋器的檢查間隔。可操作此屬性實(shí)現(xiàn)強(qiáng)制重新加載模塊等。 sys模塊提供對(duì)由解釋器使用或維護(hù)的某些變量、與解釋器交互的函數(shù)的訪問接口。 sys.abiflags 在使用標(biāo)準(zhǔn)configure腳本構(gòu)建python的POSIX系統(tǒng)上,該屬性包含了PEP 31...

    csRyan 評(píng)論0 收藏0
  • Python標(biāo)準(zhǔn)庫---16、內(nèi)置類型:上下文管理器類型、其他、特殊屬性

    摘要:退出運(yùn)行時(shí)上下文并返回一個(gè)布爾值旗標(biāo)來表明所發(fā)生的任何異常是否應(yīng)當(dāng)被屏蔽。除了實(shí)現(xiàn)上下文管理協(xié)議以外,不同類型不會(huì)被特殊處理。其中一些并不會(huì)被內(nèi)置函數(shù)所列出。 上一篇文章:Python標(biāo)準(zhǔn)庫---15、內(nèi)置類型:集合類型、映射類型下一篇文章:Python標(biāo)準(zhǔn)庫---17、內(nèi)置異常 上下文管理器類型 Python 的 with 語句支持通過上下文管理器所定義的運(yùn)行時(shí)上下文這一概念。 此...

    zhisheng 評(píng)論0 收藏0
  • 調(diào)試分析Python腳本

    摘要:調(diào)試器可幫助程序員分析完整的代碼。我們將使用標(biāo)準(zhǔn)庫中的模塊調(diào)試我們的腳本。例外是程序執(zhí)行期間發(fā)生的錯(cuò)誤。設(shè)置斷點(diǎn)并檢查堆棧幀,并列出源代碼。輸入以繼續(xù)調(diào)試。分析和計(jì)時(shí)程序分析程序意味著測(cè)量程序的執(zhí)行時(shí)間。的模塊用于分析程序。 showImg(https://segmentfault.com/img/remote/1460000018807029?w=902&h=442); 來源 | ...

    wenzi 評(píng)論0 收藏0
  • Python2 Python3 的區(qū)別及兼容技巧

    摘要:前言最近之父龜爺終于在官方郵件組落實(shí)了的終焉之日。于之后的年月日發(fā)布,計(jì)劃作為的最后一個(gè)版本。統(tǒng)一使用作為縮進(jìn),如果和同時(shí)存在,就會(huì)觸發(fā)異常兼容技巧統(tǒng)一使用作為縮進(jìn)。兼容技巧統(tǒng)一使用內(nèi)置函數(shù)。統(tǒng)一輸出函數(shù)中的即是關(guān)鍵字又是內(nèi)置函數(shù)。 前言 最近 Python 之父 Guido van Rossum(龜爺)終于在 Python 官方郵件組落實(shí)了 Python 2.7 的終焉之日(EOL)...

    lmxdawn 評(píng)論0 收藏0
  • 詳解python2python3的區(qū)別

    摘要:認(rèn)為有極大的優(yōu)化空間,在字符串和整形操作上可以取得很好的優(yōu)化結(jié)果。的和方法返回迭代器,而之前的等函數(shù)都被廢棄。python有兩個(gè)主要的版本,python2 和 python3 ,但是python又不同于其他語言,向下兼容,python3是不向下兼容的,但是絕大多數(shù)組件和擴(kuò)展都是基于python2的,下面就來總結(jié)一下python2和python3的區(qū)別。 ? 1.性能? Py3.0運(yùn)...

    Sourcelink 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<