当前位置:首页 » 编程语言 » 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

热点内容
编程猫角度 发布:2025-07-20 18:40:19 浏览:507
hibernatesession的缓存 发布:2025-07-20 18:38:46 浏览:13
安卓模拟器下载电脑版哪个好 发布:2025-07-20 18:37:59 浏览:659
三星手机存储卡用不了 发布:2025-07-20 18:37:48 浏览:136
java数组返回 发布:2025-07-20 18:34:20 浏览:260
sqlserver不存在 发布:2025-07-20 18:28:05 浏览:838
原神电脑配置怎么玩不卡 发布:2025-07-20 18:07:06 浏览:955
反编译获取原代码 发布:2025-07-20 17:49:43 浏览:492
plc编译怎么找 发布:2025-07-20 17:48:56 浏览:162
无效的宏名称将编译哑宏 发布:2025-07-20 17:48:16 浏览:155