當前位置:首頁 » 編程語言 » python352

python352

發布時間: 2023-01-24 08:01:38

python append方法是什麼

python append方法是:

>>> mylist = [1,2,0,'abc']

>>> mylist

[1, 2, 0, 'abc']

>>> mylist.append(4)

>>> mylist

[1, 2, 0, 'abc', 4]

>>> mylist.append('haha')

>>> mylist

[1, 2, 0, 'abc', 4, 'haha']

注意事項:

使用完append()函數以後的新的列表

weibo=[]

wei=[1,23,34,5,6,6,6,624,624,32,534,352,2352,2525,2152]

weibo.append(wei)

print weibo

返回結果:[[1, 23, 34, 5, 6, 6, 6, 624, 624, 32, 534, 352, 2352, 2525, 2152]]

print type(weibo)

返回結果:<type 'list'>

若此時要判斷wei列表與weibo列表是否相同我們如果使用isinstance函數就會出現錯誤

print isinstance(weibo,wei)

返回結果:TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types

因為isinstance()比較必須是一個類,類型,或元組的類和類型

在python還有一個相似的extend()其只能對列表進行黏貼。

❷ 怎麼用sublime text 3搭建python 的ide

背景:

最經遇到一件很苦惱的事情,就是在Sublime text 3中寫的python代碼直接挪到python原生的ide中老是報格式的錯誤(有時讓人討厭的縮進),沒有辦法,看到Sublime text 3 可以自己搭建python的ide,就收集各方資料,算是一個整理貼吧!

step1: 下載安裝Sublime text 3



至此,快捷鍵就設置完成了,其實此時的f5 就和python 自帶的 ide 的 f5 功能一樣了,相當於執行程序了。

執行之前,一定要保存,保存,保存!

❸ python 怎麼獲取mp4的解析度

獲得H.264視頻解析度的方法
From: http //www cnblogs.com/likwo/p/3531241.html
在使用ffmpeg解碼播放TS流的時候(例如之前寫過的UDP組播流),在連接時往往需要耗費大量時間。經過debug發現是av_find_stream_info(已拋棄,現在使用的是avformat_find_stream_info)這個方法十分耗時,而且是阻塞的。av_find_stream_info方法主要是獲得相應的流信息,其中對我的應用最有用的就是視頻的解析度。在av_find_stream_info中是要不斷的讀取數據包,解碼獲得相應的信息,而其中除了解析度信息以外的東西對我的應用中是無用的。所以,考慮自己手動從H.264碼流中解析出視頻的解析度信息。
以下內容主要參考了這篇文章:http //www myexception.cn/internet/586390.html
H.264碼流的流信息都存儲在了特殊的結構中,叫做SPS(Sequence Parameter Set)。要解析SPS就需要知道一些H.264碼流的格式信息。
在H.264碼流中,都是以0x00 0x00 0x01 或者 0x00 0x00 0x00 0x01為開始碼的(在我的應用中為後者),之後通過檢測開始碼後第一個位元組的後五位是否為7(00111)來判斷其是否為SPS。得到SPS之後,就可以解析出視頻的解析度。SPS中有兩個成員,pic_width_in_mbs_minus1和pic_height_in_map_units_minus_1,分別表示圖像的寬和高,但是要注意的是它們都是以16為單位(在面積上就是以16*16的塊為單位)再減1,所以實際的寬是(pic_width_in_mbs_minus1 + 1)*16,高為(pic_height_in_map_units_minus_1+1)*16。
歡迎轉載,轉載請註明出處:http //guoyb.com/Tech/34.html
以下是解析寬高的代碼:
轉載http //guoyb.com/Tech/34.html
以下部分 轉自 http //blog.csdn.NET/pkueecser/article/details/7367641
使用RTP傳輸H264的時候,需要用到sdp協議描述,其中有兩項:Sequence Parameter Sets (SPS) 和Picture Parameter Set (PPS)需要用到,那麼這兩項從哪裡獲取呢?答案是從H264碼流中獲取.在H264碼流中,都是以"0x00 0x00 0x01"或者"0x00 0x00 0x00 0x01"為開始碼的,找到開始碼之後,使用開始碼之後的第一個位元組的低5位判斷是否為7(sps)或者8(pps), 及data[4] & 0x1f == 7 || data[4] & 0x1f == 8.然後對獲取的nal去掉開始碼之後進行base64編碼,得到的信息就可以用於sdp.sps和pps需要用逗號分隔開來.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
如何解析SDP中包含的H.264的SPS和PPS串
http //www pernet.tv.sixxs.org/thread-109-1-1.html
SDP中的H.264的SPS和PPS串,包含了初始化H.264解碼器所需要的信息參數,包括編碼所用的profile,level,圖像的寬和高,deblock濾波器等。
由於SDP中的SPS和PPS都是BASE64編碼形式的,不容易理解,附件有一個工具軟體可以對SDP中的SPS和PPS進行解析。
用法是在命令行中輸入:
spsparser sps.txt pps.txt output.txt
例如sps.txt中的內容為:
Z0LgFNoFglE=
pps.txt中的內容為:
aM4wpIA=
最終解析的到的結果為:
Start mping SPS:
profile_idc = 66
constrained_set0_flag = 1
constrained_set1_flag = 1
constrained_set2_flag = 1
constrained_set3_flag = 0
level_idc = 20
seq_parameter_set_id = 0
chroma_format_idc = 1
bit_depth_luma_minus8 = 0
bit_depth_chroma_minus8 = 0
seq_scaling_matrix_present_flag = 0
log2_max_frame_num_minus4 = 0
pic_order_cnt_type = 2
log2_max_pic_order_cnt_lsb_minus4 = 0
delta_pic_order_always_zero_flag = 0
offset_for_non_ref_pic = 0
offset_for_top_to_bottom_field = 0
num_ref_frames_in_pic_order_cnt_cycle = 0
num_ref_frames = 1
gaps_in_frame_num_value_allowed_flag = 0
pic_width_in_mbs_minus1 = 21
pic_height_in_mbs_minus1 = 17
frame_mbs_only_flag = 1
mb_adaptive_frame_field_flag = 0
direct_8x8_interence_flag = 0
frame_cropping_flag = 0
frame_cropping_rect_left_offset = 0
frame_cropping_rect_right_offset = 0
frame_cropping_rect_top_offset = 0
frame_cropping_rect_bottom_offset = 0
vui_parameters_present_flag = 0
Start mping PPS:
pic_parameter_set_id = 0
seq_parameter_set_id = 0
entropy_coding_mode_flag = 0
pic_order_present_flag = 0
num_slice_groups_minus1 = 0
slice_group_map_type = 0
num_ref_idx_l0_active_minus1 = 0
num_ref_idx_l1_active_minus1 = 0
weighted_pref_flag = 0
weighted_bipred_idc = 0
pic_init_qp_minus26 = 0
pic_init_qs_minus26 = 0
chroma_qp_index_offset = 10
deblocking_filter_control_present_flag = 1
constrained_intra_pred_flag = 0
rendant_pic_cnt_present_flag = 0
transform_8x8_mode_flag = 0
pic_scaling_matrix_present_flag = 0
second_chroma_qp_index_offset = 10
/////////////////////////////////////////////////////////////////////////////////////////////////
這里需要特別提一下這兩個參數
pic_width_in_mbs_minus1 = 21
pic_height_in_mbs_minus1 = 17
分別表示圖像的寬和高,以宏塊(16x16)為單位的值減1
因此,實際的寬為 (21+1)*16 = 352
spsparser.rar
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
http //krdai.info.sixxs.org/blog/mp4-sps-pps-data.html
最近在做跟 h264 encode/decode 相關的研究,目標是希望可以從 Android 的 MediaRecorder 當中取出 h264 的資訊。目前問題是在於 SPS 以及 PPS 到底要怎樣得到。由於 MediaRecorder 是寫入 mp4 檔案中,所以不得已只好來去分析一下 mp4 的檔案格式,發現沒有想像中的困難. 主要是參照 ISO/IEC 14496-15 這部份. 在 mp4 的檔案之中, 找到 avcC 這個字串, 之後就是接上 AVCDecoderConfigurationRecord. AVCDecoderConfigurationRecord 的 format 如下:
aligned(8) class AVCDecoderConfigurationRecord {
unsigned int(8) configurationVersion = 1;
unsigned int(8) AVCProfileIndication;
unsigned int(8) profile_compatibility;
unsigned int(8) AVCLevelIndication;
bit(6) reserved = '111111'b;
unsigned int(2) lengthSizeMinusOne;
bit(3) reserved = '111'b;
unsigned int(5) numOfSequenceParameterSets;
for (i=0; i< numOfSequenceParameterSets; i++) {
unsigned int(16) sequenceParameterSetLength ;
bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit;
}
unsigned int(8) numOfPictureParameterSets;
for (i=0; i< numOfPictureParameterSets; i++) {
unsigned int(16) pictureParameterSetLength;
bit(8*pictureParameterSetLength) pictureParameterSetNALUnit;
}
}
對照一下這樣就可以找到 SPS 和 PPS
+++++++++++++++++++++++++++++++++++++++++++++
vlc沒有收到pps和sps
2010-10-08 16:16
問題 packetizer_h264 packetizer warning: waiting for SPS/PPS
是因為解碼器只是在第一次執行編碼的時候,才編碼出 SPS、PPS、和I_Frame;
h264 packetizer has set so, that it sends sps/pps only first keyframe,
I'm trying to figure what breaks if that is changed so sps/pps is written in every keyframe.
[出自| http //trac.videolan.org/vlc/ticket/1384]
解決辦法:
1、編碼器編碼出每個關鍵幀都加上SPS、PPS ,據說通常情況編碼器編出的 SPS、PPS是一樣的,所以這種方法耗費資源。
2、在伺服器接收到客戶端請求時,發送第一個package 加上 SPS、PPS。
具體如下:
1、在 VideoOpenFileSource 添加一個變數 isFirstFrame;
2、構造時初始化 isFirstFrame = true;
3、在int VideoOpenFileSource::readFromBufferChain() 修改如下:
1 if(isFirstFrame == true)
2 {
3 memcpy(fTo, h264_header, sizeof(h264_header)); /* h264_header = pps +sps*/
4 offset = sizeof(h264_header);
5 framesize = BufferChain_get(fInput.video_bufs, fTo + offset);
6 offset += framesize;
7 isFirstFrame = false;
8 printf("this is the first fime\n");
9 sleep(1);
10 }
11 else
12 {
13 framesize = BufferChain_get(fInput.video_bufs, fTo + offset);
14 offset += framesize;
15 }
1
[http //topic.csdn.net/u/20100801/17/ef35e664-92ff-4144-a35f-3984dcf11da3.html| 參考]
========================================================================
sdp 關於pps和sps的疑問:
packetization-mode 主要是定義包的模式,單一 NALU單元模式(0);非交錯(non-interleaved)封包模式(1);交錯(interleaved)封包模式(2)
sprop-parameter-sets 等於H.264 的序列參數集和圖像參數 NAL單元,base64轉換;(即= sps+pps)
profile-level-id 這個參數用於指示 H.264 流的 profile 類型和級別。這知道這個是啥東東
ffmpeg decode 關於pps sps問題:
stackoverflow.com/questions/3493742/problem-to-decode-h264-video-over-rtp-with-ffmpeg-libavcodec/3500432#3500432
如何用C語言取出H.264ES文件里的nal(sps,pps)信息。比如width, height, profile等等
請高手指點指點。。。 http //www oschina.net/question/225813_35707
解析sps,pps的代碼在ffmpeg裡面就有, 抄出來就行了, 我以前也自己寫過...
ffmpeg的libavcodec/h264_parser.c,
h264_ps.c
函數
ff_h264_decode_seq_parameter_set
ff_h264_decode_picture_parameter_set
自己可以看代碼.
H264參數語法文檔: SPS、PPS、IDR http //blog.csdn.net/heanyu/article/details/6205390
H.264碼流第一個 NALU 是 SPS(序列參數集Sequence Parameter Set)
對應H264標准文檔 7.3.2.1 序列參數集的語法進行解析

❹ python 使用jieba分詞出錯

猜測你使用的 Python 版本為 Python2 但是使用 coding: utf-8 設置中文編碼只在 Python 3 有效

所以 設置默認編碼 應在代碼開始部分應該加上

importsys
reload(sys)
sys.setdefaultencoding('UTF-8')

❺ 您好,有關於Python的問題,想要請教你,方便加您的可以直接溝通的方式嗎

可以呀
Common Stumbling Blocks
本段簡單的列出容易使人出錯的變動(初學者應該注意)。
· print語句被print()函數取代了,可以使用關鍵字參數來替代老的print特殊語法。例如:
Old: print "The answer is", 2*2
New: print("The answer is", 2*2)

Old: print x, # 使用逗號結尾禁止換行
New: print(x, end=" ") # 使用空格代替換行

Old: print # 輸出新行
New: print() # 輸出新行

Old: print >>sys.stderr, "fatal error"
New: print("fatal error", file=sys.stderr)

Old: print (x, y) # 輸出repr((x, y))
New: print((x, y)) # 不同於print(x,y)!

你可以自定義輸出項之間的分隔符:
print("There are <", 2**32, ">possibilities!", sep="")
輸出結果是:
There are <4294967296> possibilities!

注意:

print()函數不支持老print語句的"軟空格"特性,例如,在python2.x中,print "A\n", "B"會輸出"A\nB\n",而python3.0中,print("A\n","B")會輸出"A\n B\n"

使用 2to3 源碼轉換工具時,所有的print語句被自動轉換成print()函數調用,對大項目,這是無需爭論的。
· python3.0使用字元串(strings)和bytes代替Unicode字元串和8位字元串,這意味著幾乎所有使用Unicode編碼和二進制數據的代碼都要改動。這個改動很不錯,在2.x的世界裡,無數的bug都是因為編碼問題。
· map()和filter()返回迭代器(iterators)
· dict方法keys(),items(),values()返回視圖(同樣是迭代器)而不是列表(list)
· 內建的sorted()方法和list.sort()方法不再接受表示比較函數的cmp參數,使用key參數代替。
· 1/2返回浮點數,使用1//2能得到整數。
· repr()函數對於long整數不再包含拖尾的L,所以不加判斷的去除最後一個字元會導致去掉一個有用的數字。
String and Bytes
· 現在只有一種字元串:str,它的行為和實現都很像2.x的unicode串。
· basestring超類已經去掉了,2to3 工具會把每個出現的basestring替換成str。
· PEP3137:新類型bytes,用來表示二進制數據和編碼文本,str和bytes不能混合,需要時,必須進行顯示的轉換,轉換方法是str.encode()(str->bytes)和bytes.decode()(bytes->str).
· 在原始字元串(raw strings)中所有反斜線都按字面量解釋,不再特殊處理Unicode轉義字元。
· PEP3112:bytes字面量,例如b"abc",創建bytes實例。
· PEP3120:默認源文件編碼為UTF-8
· PEP3131:可以使用非ASCII標識符(然而,除了注釋中貢獻者的名字之外,標准庫仍然只包含ASCII)
· PEP3116:新的IO實現,API幾乎100%向後兼容,二進制文件使用bytes代替strings
· 去除了StringIO和cStringIO模塊,取而代之的是io.StringIO或者io.BytesIO
PEP3101:字元串格式化的新方法
· str.format方法(原文提到替代了%操作符,實際上,format方法和%的用法差別很大,各有所長)。
PEP3106:修補了dict的keys(),items(),values()方法
· 刪除了dict.iterkeys(),dict.itervalues()和dict.iteritems()
· dict.keys(),dict.values()和dict.items()返回dict相關數據的引用
PEP3107:函數註解(FunctionAnnotations)
· 註解函數參數和返回值的標准化方法
Exception Stuff
· PEP352:異常類必須繼承自BaseException,它異常結構的基類。
· 移除了StandardError
· Dropping sequence behavior (slicing!)and message attribute of exception instances.
· PEP3109:拋出異常:現在必須使用raiseException(args)而不是原來的raise Exception, args
· PEP3110:捕獲異常,現在必須使用exceptException as identifier而不是原來的except Exception,identifier
· PEP3134:異常鏈(Exceptionchain)。
· 改良了一些windows不能載入模式時的異常信息,具有本地化處理。
New Class and Metaclass Stuff
· 移除了classic class
· PEP3115:新的metaclass語法
· PEP3119:抽象基類。
· PEP3129:類包裝。
· PEP3141:數字抽象基類
其他的語言變化

這里列出大多數的Python語言核心和內建函數的變化。
· 移除了backticks(使用repr()代替)
· 移除了<>(不等號,使用!=代替)
· as和with變成了關鍵字
· True,False和None變成了關鍵字
· PEP237:long不存在了,只有int,它和原來的long一樣。不再支持以L結尾的數字字面量。移除sys.maxint,因為int現在已經是無限大了
· PEP238:int相除,返回float
· 改變了順序操作符的行為,例如x<y,當x和y類型不匹配時拋出TypeError而不是返回隨即的bool值
· 移除了__getslice__,語法a[i:j]被解釋成a.__getitem__(slice(i,j))
· PEP3102:keyword-only arguments.在函數參數列表中,出現在*args之後的命名參數只能使用"關鍵字參數"的形式調用
· PEP3104:nonlocal聲明。使用nonlocal可以聲明一個外部變數(不是global變數)
· PEP3111:raw_input() 改名為input(),也就是說,新的input()函數從標准輸入設備(sys.stdin)讀取一行並返回(不包括行結束符),如果輸入過早終止,該函數拋出EOFError,如果想使用老的input(),可以使用(input())代替。
· xrange()改名為range(),range()現在不是產生一個列表(list),而是一個迭代器。
· PEP3113:移除了"元組參數拆包(tuple parameter unpacking)"。這種寫法已經不行了:
1. deffoo(a, (b, c)):…
2.
3. 現在要這樣寫:
4.
5. deffoo(a, b_c):
6. b,c = b_c
· PEP3114:next()重命名為__next__(),新的內建函數next()可以調用一個對象的__next__()方法。
· PEP3127:新的八進制字面量,二進制字面量和bin()函數。你應該寫0o666而不是0666,oct()函數也做了響應的改動。同樣,0b1010等價於10,bin(10)返回"0b1010″。0666這種寫法現在是錯誤的。
· PEP3132:支持迭代器拆包。現在你可以這樣寫:
1 a,b, *rest = some_seqence
2
3 甚至象這樣:
4
5 *rest,a = stuff
6 一般情況下,rest對象是list,而等號右邊的對象是可迭代的
· PEP3135:新的super()。你可以不適用任何參數調用super(),正確的參數和實例會被正確選擇。如果使用參數,它的行為不變,和以前一樣。
· zip(),map(),filter()返回迭代器。
· 移除了string.letters和它的小夥伴們(string.lowcase和string.uppercase),現在上場的是string.ascii_letters等
· 移除了apply(),callable(),exefile(),file(),rece(),reload()
· 移除了dict.has_key()。使用in操作符進行測試
· exec語句沒有了,現在是exec()函數
· 移除了__oct__()和__hex__()特殊方法。oct()和hex()方法使用__index__()
· 移除了對__members__和__methods__的支持
· nb_nonzero重命名為nb_bool,__nonzero__()重命名為__bool__()
Optimizations
· 一般情況下,python 3.0比python 2.5慢33%左右。不過仍有提升空間。
模塊變動(新的,改進的和廢棄的)
· 移除了cPickle模塊,可以使用pickle模塊代替。最終我們將會有一個透明高效的模塊。
· 移除了imageop模塊
· 移除了audiodev, Bastion, bsddb185,exceptions, linuxaudiodev, md5, MimeWriter, mimify, popen2, rexec, sets, sha,stringold, strop, sunaudiodev, timing和xmllib模塊
· 移除了bsddb模塊(單獨發布,可以從獲取)
· 移除了new模塊
· os.tmpnam()和os.tmpfile()函數被移動到tmpfile模塊下
· tokenize模塊現在使用bytes工作。主要的入口點不再是generate_tokens,而是tokenize.tokenize()
Build and C API Changes

Python's build process和C API的改動包括:
· PEP3118:新的Buffer API
PEP3121:擴展模塊的的Initialization& Finalization
· PEP3123:使PyObject_HEAD符合標准C
其他的改動和修復

❻ python 中的e.message

最近發現還有人在處理Exception的時候還在使用 e.message 來輸出異常(錯誤)信息。

程序中的一個舉例(日誌):

現在Python的最新版本已經是 python2.7.13/python3.6.2, 而 e.message 則是python2.5.x 的語法了。

PEP 352 -- Required Superclass for Exceptions
https://www.python.org/dev/peps/pep-0352/
簡介:

DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 exception. class , exception.message,
https://stackoverflow.com/questions/13063212/deprecationwarning-baseexception-message-has-been-deprecated-as-of-python-2-6-e

簡介:

Proper way to declare custom exceptions in modern Python?
https://stackoverflow.com/questions/1319615/proper-way-to-declare-custom-exceptions-in-modern-python/26938914#26938914

BaseException.message deprecated in Python 2.6

熱點內容
sql資料庫項目 發布:2025-07-20 14:06:11 瀏覽:162
linux查看selinux狀態 發布:2025-07-20 13:36:35 瀏覽:914
福利資源解壓密碼 發布:2025-07-20 13:34:10 瀏覽:269
我的世界怎麼在手機搞伺服器 發布:2025-07-20 13:26:07 瀏覽:906
android系統鍵盤 發布:2025-07-20 13:19:38 瀏覽:500
程序化交易演算法 發布:2025-07-20 13:09:58 瀏覽:973
已關閉伺服器是什麼意思 發布:2025-07-20 13:06:49 瀏覽:710
三星s5密碼多少錢 發布:2025-07-20 12:55:14 瀏覽:961
密碼忘記了怎麼找回 發布:2025-07-20 12:46:18 瀏覽:534
華為的密碼鎖為什麼開不了 發布:2025-07-20 12:45:35 瀏覽:133