當前位置:首頁 » 編程語言 » 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

熱點內容
c語言中a10什麼意思 發布:2024-04-27 10:45:43 瀏覽:57
物聯網中ftp是什麼意思 發布:2024-04-27 10:41:17 瀏覽:985
銀行密碼保護在哪裡 發布:2024-04-27 10:25:23 瀏覽:188
tomcat源碼導入eclipse 發布:2024-04-27 10:25:15 瀏覽:193
android的api 發布:2024-04-27 10:23:39 瀏覽:682
官式訪問 發布:2024-04-27 10:04:00 瀏覽:521
國產高配置有哪些 發布:2024-04-27 09:18:26 瀏覽:947
建行手機app忘記密碼如何修改 發布:2024-04-27 08:58:59 瀏覽:393
蟻群演算法的數學模型 發布:2024-04-27 08:58:39 瀏覽:994
androidactivity生命 發布:2024-04-27 07:33:48 瀏覽:84