当前位置:首页 » 编程语言 » pythonifverbose

pythonifverbose

发布时间: 2023-03-30 06:42:06

1. python脚本中verbosity是什么意思

这里的verbosity是一个选项,表示测试结果的信息复杂度,有三个值x0dx0a0 (静凯旁默模式): 你只能获得总的测试用例数和总的结果 比如 总共100个 失败20 成功80x0dx0a1 (默认模式): 非常类似静默模式 只是在每个成功的用例前面有个“.” 每个失败的用例前面有个 “F”x0dx0a2 (详细模式):测试结果会显配孙知示每个测试用例的所有相关的信息x0dx0a并且 你在命令行里加入不同的参数可以起到一样的效果x0dx0a加入培消 --quiet 参数 等效于 verbosity=0x0dx0a加入--verbose参数等效于 verbosity=2x0dx0a什么都不加就是 verbosity=1

2. python中if verbose是啥意思呀

当bool(verbose)为True时

3. 用python编写一个字符串压缩程序(要求为自适应模型替代法)

你好,并掘下面是LZ777自适应压缩算法的一个简单实现,你可以看看
import math
from bitarray import bitarray
class LZ77Compressor:
"""
A simplified implementation of the LZ77 Compression Algorithm
"""
MAX_WINDOW_SIZE = 400
def __init__(self, window_size=20):
self.window_size = min(window_size, self.MAX_WINDOW_SIZE)
self.lookahead_buffer_size = 15 # length of match is at most 4 bits
def compress(self, input_file_path, output_file_path=None, verbose=False):
"""
Given the path of an input file, its content is compressed by applying a simple
LZ77 compression algorithm.
The compressed format is:
0 bit followed by 8 bits (1 byte character) when there are no previous matches
within window
1 bit followed by 12 bits pointer (distance to the start of the match from the
current position) and 4 bits (length of the match)

If a path to the output file is provided, the compressed data is written into
a binary file. Otherwise, it is returned as a bitarray
if verbose is enabled, the compression description is printed to standard output
"""
data = None
i = 0
output_buffer = bitarray(endian='big'指唤)
# read the input file
try:
with open(input_file_path, 'rb') as input_file:
data = input_file.read()
except IOError:
print 'Could not open input file ...'
raise
while i < len(data):
#print i
match = self.findLongestMatch(data, i)
if match:
# Add 1 bit flag, followed by 12 bit for distance, and 4 bit for the length
# of the match
(bestMatchDistance, bestMatchLength) = match
output_buffer.append(True)
output_buffer.frombytes(chr(bestMatchDistance >> 4))
output_buffer.frombytes(chr(((bestMatchDistance & 0xf) << 4) | bestMatchLength))
if verbose:
print "<1, %i, %i>"绝逗核 % (bestMatchDistance, bestMatchLength),
i += bestMatchLength
else:
# No useful match was found. Add 0 bit flag, followed by 8 bit for the character
output_buffer.append(False)
output_buffer.frombytes(data[i])

if verbose:
print "<0, %s>" % data[i],
i += 1
# fill the buffer with zeros if the number of bits is not a multiple of 8
output_buffer.fill()
# write the compressed data into a binary file if a path is provided
if output_file_path:
try:
with open(output_file_path, 'wb') as output_file:
output_file.write(output_buffer.tobytes())
print "File was compressed successfully and saved to output path ..."
return None
except IOError:
print 'Could not write to output file path. Please check if the path is correct ...'
raise
# an output file path was not provided, return the compressed data
return output_buffer

def decompress(self, input_file_path, output_file_path=None):
"""
Given a string of the compressed file path, the data is decompressed back to its
original form, and written into the output file path if provided. If no output
file path is provided, the decompressed data is returned as a string
"""
data = bitarray(endian='big')
output_buffer = []
# read the input file
try:
with open(input_file_path, 'rb') as input_file:
data.fromfile(input_file)
except IOError:
print 'Could not open input file ...'
raise
while len(data) >= 9:
flag = data.pop(0)
if not flag:
byte = data[0:8].tobytes()
output_buffer.append(byte)
del data[0:8]
else:
byte1 = ord(data[0:8].tobytes())
byte2 = ord(data[8:16].tobytes())
del data[0:16]
distance = (byte1 << 4) | (byte2 >> 4)
length = (byte2 & 0xf)
for i in range(length):
output_buffer.append(output_buffer[-distance])
out_data = ''.join(output_buffer)
if output_file_path:
try:
with open(output_file_path, 'wb') as output_file:
output_file.write(out_data)
print 'File was decompressed successfully and saved to output path ...'
return None
except IOError:
print 'Could not write to output file path. Please check if the path is correct ...'
raise
return out_data

def findLongestMatch(self, data, current_position):
"""
Finds the longest match to a substring starting at the current_position
in the lookahead buffer from the history window
"""
end_of_buffer = min(current_position + self.lookahead_buffer_size, len(data) + 1)
best_match_distance = -1
best_match_length = -1
# Optimization: Only consider substrings of length 2 and greater, and just
# output any substring of length 1 (8 bits uncompressed is better than 13 bits
# for the flag, distance, and length)
for j in range(current_position + 2, end_of_buffer):
start_index = max(0, current_position - self.window_size)
substring = data[current_position:j]
for i in range(start_index, current_position):
repetitions = len(substring) / (current_position - i)
last = len(substring) % (current_position - i)
matched_string = data[i:current_position] * repetitions + data[i:i+last]
if matched_string == substring and len(substring) > best_match_length:
best_match_distance = current_position - i
best_match_length = len(substring)
if best_match_distance > 0 and best_match_length > 0:
return (best_match_distance, best_match_length)
return None

4. python需要设置哪些环境变量我只知道一个PYTHONHOME指向安装目录。

1、首先,右键点击-计算机(此电脑),点击进入属性,如图所示。

5. python下正则表达式加VERBOSE是怎么起作用的

shmget 的内部实现包含了许多重要的系统 V 共享内存机制; shmat 在把共享内存区域映射到进程空间时,并不真正改变进程的页 表。当进程第一次访问内搏拿存映射区域访问时,会因为没有物理页表的塌银敏分配而导致一个缺团枝页异常,然后内核再根据相应的存储管理机制为共享内存映射区域分配相应的 页表。

6. 你好打扰了 python设置 PYTHONVERBOSE变量怎么设置呢

可碰搭以用命令行笑兄拿选项:
python -v xxx.py

也可以设置环境变量尘激:
PYTHONVERBOSE=1; export PYTHONVERBOSE

python xxx.py

7. python 常用的系统函数有哪些

1.常用内置函数:(不用import就可以直接使用)
help(obj) 在线帮助, obj可是任何类型
callable(obj) 查看一个obj是不是可以像函数一样调用
repr(obj) 得到obj的表示字符串,可以利用这个字符串eval重建该对象的一个拷贝
eval_r(str) 表示合法的python表达式,返回这个表达式
dir(obj) 查看obj的name space中可见的name
hasattr(obj,name) 查看一个obj的name space中是否有name
getattr(obj,name) 得到一个obj的name space中的一个name
setattr(obj,name,value) 为一个obj的name space中的一个name指向vale这个object
delattr(obj,name) 从obj的name space中删除一个name
vars(obj) 返回一个object的name space。用dictionary表示
locals() 返回一个局部name space,用dictionary表示
globals() 返回一个全局name space,用dictionary表示
type(obj) 查看一个obj的类型
isinstance(obj,cls) 查看obj是不是cls的instance
issubclass(subcls,supcls) 查看subcls是不是supcls的子类

类型转换函数
chr(i) 把一个ASCII数值,变成字符
ord(i) 把一个字符或者unicode字符,变成ASCII数值
oct(x) 把整数x变成八进制表示的字符串
hex(x) 把整数x变成十六进制表示的字符串
str(obj) 得到obj的字符串描述
list(seq) 把一个sequence转换成一个list
tuple(seq) 把一个sequence转换成一个tuple
dict(),dict(list) 转换成一个dictionary
int(x) 转换成一个integer
long(x) 转换成一个long interger
float(x) 转换成一个浮点数
complex(x) 转换成复数
max(...) 求最大值
min(...) 求最小值
用于执行程序的内置函数
complie 如果一段代码经常要使用,那么先编译,再运行会更快。

2.和操作系统相关的调用
系统相关的信息模块 import sys
sys.argv是一个list,包含所有的命令行参数.
sys.stdout sys.stdin sys.stderr 分别表示标准输入输出,错误输出的文件对象.
sys.stdin.readline() 从标准输入读一行 sys.stdout.write("a") 屏幕输出a
sys.exit(exit_code) 退出程序
sys.moles 是一个dictionary,表示系统中所有可用的mole
sys.platform 得到运行的操作系统环境
sys.path 是一个list,指明所有查找mole,package的路径.

操作系统相关的调用和操作 import os
os.environ 一个dictionary 包含环境变量的映射关系 os.environ["HOME"] 可以得到环境变量HOME的值
os.chdir(dir) 改变当前目录 os.chdir('d:\\outlook') 注意windows下用到转义
os.getcwd() 得到当前目录
os.getegid() 得到有效组id os.getgid() 得到组id
os.getuid() 得到用户id os.geteuid() 得到有效用户id
os.setegid os.setegid() os.seteuid() os.setuid()
os.getgruops() 得到用户组名称列表
os.getlogin() 得到用户登录名称
os.getenv 得到环境变量
os.putenv 设置环境变量
os.umask 设置umask
os.system(cmd) 利用系统调用,运行cmd命令
操作举例:
os.mkdir('/tmp/xx') os.system("echo 'hello' > /tmp/xx/a.txt") os.listdir('/tmp/xx')
os.rename('/tmp/xx/a.txt','/tmp/xx/b.txt') os.remove('/tmp/xx/b.txt') os.rmdir('/tmp/xx')
用python编写一个简单的shell
#!/usr/bin/python
import os, sys
cmd = sys.stdin.readline()
while cmd:
os.system(cmd)
cmd = sys.stdin.readline()

用os.path编写平台无关的程序
os.path.abspath("1.txt") == os.path.join(os.getcwd(), "1.txt")
os.path.split(os.getcwd()) 用于分开一个目录名称中的目录部分和文件名称部分。
os.path.join(os.getcwd(), os.pardir, 'a', 'a.doc') 全成路径名称.
os.pardir 表示当前平台下上一级目录的字符 ..
os.path.getctime("/root/1.txt") 返回1.txt的ctime(创建时间)时间戳
os.path.exists(os.getcwd()) 判断文件是否存在
os.path.expanser('~/dir') 把~扩展成用户根目录
os.path.expandvars('$PATH') 扩展环境变量PATH
os.path.isfile(os.getcwd()) 判断是否是文件名,1是0否
os.path.isdir('c:\Python26\temp') 判断是否是目录,1是0否
os.path.islink('/home/huaying/111.sql') 是否是符号连接 windows下不可用
os.path.ismout(os.getcwd()) 是否是文件系统安装点 windows下不可用
os.path.samefile(os.getcwd(), '/home/huaying') 看看两个文件名是不是指的是同一个文件
os.path.walk('/home/huaying', test_fun, "a.c")
遍历/home/huaying下所有子目录包括本目录,对于每个目录都会调用函数test_fun.
例:在某个目录中,和他所有的子目录中查找名称是a.c的文件或目录。
def test_fun(filename, dirname, names): //filename即是walk中的a.c dirname是访问的目录名称
if filename in names: //names是一个list,包含dirname目录下的所有内容
print os.path.join(dirname, filename)
os.path.walk('/home/huaying', test_fun, "a.c")

文件操作
打开文件
f = open("filename", "r") r只读 w写 rw读写 rb读二进制 wb写二进制 w+写追加
读写文件
f.write("a") f.write(str) 写一字符串 f.writeline() f.readlines() 与下read类同
f.read() 全读出来 f.read(size) 表示从文件中读取size个字符
f.readline() 读一行,到文件结尾,返回空串. f.readlines() 读取全部,返回一个list. list每个元素表示一行,包含"\n"\
f.tell() 返回当前文件读取位置
f.seek(off, where) 定位文件读写位置. off表示偏移量,正数向文件尾移动,负数表示向开头移动。
where为0表示从开始算起,1表示从当前位置算,2表示从结尾算.
f.flush() 刷新缓存
关闭文件
f.close()

regular expression 正则表达式 import re
简单的regexp
p = re.compile("abc") if p.match("abc") : print "match"
上例中首先生成一个pattern(模式),如果和某个字符串匹配,就返回一个match object
除某些特殊字符metacharacter元字符,大多数字符都和自身匹配。
这些特殊字符是 。^ $ * + ? { [ ] \ | ( )
字符集合(用[]表示)
列出字符,如[abc]表示匹配a或b或c,大多数metacharacter在[]中只表示和本身匹配。例:
a = ".^$*+?{\\|()" 大多数metachar在[]中都和本身匹配,但"^[]\"不同
p = re.compile("["+a+"]")
for i in a:
if p.match(i):
print "[%s] is match" %i
else:
print "[%s] is not match" %i
在[]中包含[]本身,表示"["或者"]"匹配.用

表示.
^出现在[]的开头,表示取反.[^abc]表示除了a,b,c之外的所有字符。^没有出现在开头,即于身身匹配。
-可表示范围.[a-zA-Z]匹配任何一个英文字母。[0-9]匹配任何数字。
\在[]中的妙用。
\d [0-9]
\D [^0-9]
\s [ \t\n\r\f\v]
\S [^ \t\n\r\f\v]
\w [a-zA-Z0-9_]
\W [^a-zA-Z0-9_]
\t 表示和tab匹配, 其他的都和字符串的表示法一致
\x20 表示和十六进制ascii 0x20匹配
有了\,可以在[]中表示任何字符。注:单独的一个"."如果没有出现[]中,表示出了换行\n以外的匹配任何字符,类似[^\n].
regexp的重复
{m,n}表示出现m个以上(含m个),n个以下(含n个). 如ab{1,3}c和abc,abbc,abbbc匹配,不会与ac,abbbc匹配。
m是下界,n是上界。m省略表下界是0,n省略,表上界无限大。
*表示{,} +表示{1,} ?表示{0,1}
最大匹配和最小匹配 python都是最大匹配,如果要最小匹配,在*,+,?,{m,n}后面加一个?.
match object的end可以得到匹配的最后一个字符的位置。
re.compile("a*").match('aaaa').end() 4 最大匹配
re.compile("a*?").match('aaaa').end() 0 最小匹配
使用原始字符串
字符串表示方法中用\\表示字符\.大量使用影响可读性。
解决方法:在字符串前面加一个r表示raw格式。
a = r"\a" print a 结果是\a
a = r"\"a" print a 结果是\"a
使用re模块
先用re.compile得到一个RegexObject 表示一个regexp
后用pattern的match,search的方法,得到MatchObject
再用match object得到匹配的位置,匹配的字符串等信息
RegxObject常用函数:
>>> re.compile("a").match("abab") 如果abab的开头和re.compile("a")匹配,得到MatchObject
<_sre.SRE_Match object at 0x81d43c8>
>>> print re.compile("a").match("bbab")
None 注:从str的开头开始匹配
>>> re.compile("a").search("abab") 在abab中搜索第一个和re_obj匹配的部分
<_sre.SRE_Match object at 0x81d43c8>
>>> print re.compile("a").search("bbab")
<_sre.SRE_Match object at 0x8184e18> 和match()不同,不必从开头匹配
re_obj.findall(str) 返回str中搜索所有和re_obj匹配的部分.
返回一个tuple,其中元素是匹配的字符串.
MatchObject的常用函数
m.start() 返回起始位置,m.end()返回结束位置(不包含该位置的字符).
m.span() 返回一个tuple表示(m.start(), m.end())
m.pos(), m.endpos(), m.re(), m.string()
m.re().search(m.string(), m.pos(), m.endpos()) 会得到m本身
m.finditer()可以返回一个iterator,用来遍历所有找到的MatchObject.
for m in re.compile("[ab]").finditer("tatbxaxb"):
print m.span()
高级regexp
| 表示联合多个regexp. A B两个regexp,A|B表示和A匹配或者跟B匹配.
^ 表示只匹配一行的开始行首,^只有在开头才有此特殊意义。
$ 表示只匹配一行的结尾
\A 表示只匹配第一行字符串的开头 ^匹配每一行的行首
\Z 表示只匹配行一行字符串的结尾 $匹配第一行的行尾
\b 只匹配词的边界 例:\binfo\b 只会匹配"info" 不会匹配information
\B 表示匹配非单词边界
示例如下:
>>> print re.compile(r"\binfo\b").match("info ") #使用raw格式 \b表示单词边界
<_sre.SRE_Match object at 0x817aa98>
>>> print re.compile("\binfo\b").match("info ") #没有使用raw \b表示退格符号
None
>>> print re.compile("\binfo\b").match("\binfo\b ")
<_sre.SRE_Match object at 0x8174948>
分组(Group) 示例:re.compile("(a(b)c)d").match("abcd").groups() ('abc', 'b')
#!/usr/local/bin/python
import re
x = """
name: Charles
Address: BUPT

name: Ann
Address: BUPT
"""
#p = re.compile(r"^name:(.*)\n^Address:(.*)\n", re.M)
p = re.compile(r"^name:(?P.*)\n^Address:(?P.*)\n", re.M)
for m in p.finditer(x):
print m.span()
print "here is your friends list"
print "%s, %s"%m.groups()
Compile Flag
用re.compile得到RegxObject时,可以有一些flag用来调整RegxObject的详细特征.
DOTALL, S 让.匹配任意字符,包括换行符\n
IGNORECASE, I 忽略大小写
LOCALES, L 让\w \W \b \B和当前的locale一致
MULTILINE, M 多行模式,只影响^和$(参见上例)
VERBOSE, X verbose模式

8. python注释符号是什么+

不是, Python中的注释有单行注释和多行注释,Python中单行注释以#符号开头,多行注释用三个单引号'''符号或者三个双引号"""符号将注释括起来。

一、python单行注释符号(#):井号(#)常被用作单行注释符号,在代码中使用#时,它右边的任何数据都会被忽略,当做是注释。print 1 #输出1,#号右边的内容在执行的时候是不会被输出的。

二、批量、多行注释符号:在python中也会有注释有很多行的时候,这种情况下就需要批量多行注释符了。多行注释是用三引号''' '''包含的。

python正则表达式的注释方法:学过正则都知道,那简直是天书,为了提高正则的可读性,正则表达式中提供了X(VERBOSE): 详细模式。这个模式下正则表达式可以是多行,忽略空白字符,并可以加入注释。

以Python语言为例:

注:Python版本 3.0+

#Coding:UTF-8

a = input(" ")

b = input(" ")

if a != b:

print("a不等于b")

else:

print("a等于b")

9. python verbose=false是什么含义

python中 布尔值是 True、False(第一个之母要大写)。
false表示名称睁禅为‘false’的宏姿变量悉绝尘(若未赋值时,false=nil)
verbose=false-----的含义是将变量 false 的值赋给变量 verbose

热点内容
分类信息网站的源码 发布:2024-05-09 03:31:18 浏览:98
sqlupdate日期 发布:2024-05-09 03:27:14 浏览:880
java培训有人要吗 发布:2024-05-09 03:21:16 浏览:970
c语言多次输入数据 发布:2024-05-09 03:12:50 浏览:738
pythonide使用 发布:2024-05-09 02:56:52 浏览:350
社区电商源码 发布:2024-05-09 02:33:00 浏览:150
辽事通登记需要的密码是什么 发布:2024-05-09 02:25:45 浏览:284
云服务器选择什么系统 发布:2024-05-09 01:55:51 浏览:968
mel脚本编程全攻略 发布:2024-05-09 01:54:43 浏览:479
如何在机房安装ntp服务器 发布:2024-05-09 01:13:57 浏览:206