草庐IT

result_queue

全部标签

python doctest : expected result is the same as the "got" result but the test failed

我正处于使用python作为软件QA工具的学习阶段。我编写了下一个简单测试,以便在文本文件编号矩阵中找到字母“a”。问题是测试失败,即使期望值等于我得到的结果。这是为什么呢?你能告诉我我做错了什么吗?测试脚本:fin=open("abc.txt","r")arr_fin=[]forlineinfin:arr_fin.append(line.split())printarr_finforrowinarr_fin:arr_fin_1="".join('{0:4}'.format(ior"")foriinrow)printarr_fin_1deffind_letter(x,arr_fin_1

python - 与底商相比的整数除法 : why this surprising result?

//Python的“整数除法”运算符今天让我感到惊讶:>>>math.floor(11/1.1)10.0>>>11//1.19.0documentation读作“x和y的(取整)商”。那么,为什么math.floor(11/1.1)等于10,而11//1.1等于9? 最佳答案 因为1.1不能准确地用二进制形式表示;近似值略高于1.1-因此除法结果有点太小了。尝试以下操作:在Python2下,在控制台输入:>>>1.11.1000000000000001在Python3.1中,控制台将显示1.1,但在内部,它仍然是相同的数字。但是:>

python - 'result[::-1]' 是什么意思?

这个问题在这里已经有了答案:Understandingslicing(36个答案)关闭3个月前。我刚刚遇到以下python代码,这让我有点困惑:res=self.result[::-1].encode('hex')编码的东西很清楚,它应该表示为十六进制值。然而,什么这个self.result[::-1]是什么意思,尤其是冒号?

python - multiprocessing.Pipe 比 multiprocessing.Queue 还要慢?

我尝试通过multiprocessing包中的Queue对Pipe的速度进行基准测试。我认为Pipe会更快,因为Queue在内部使用Pipe。奇怪的是,Pipe在发送大型numpy数组时比Queue慢。我在这里缺少什么?管道:importsysimporttimefrommultiprocessingimportProcess,PipeimportnumpyasnpNUM=1000defworker(conn):fortask_nbrinrange(NUM):conn.send(np.random.rand(400,400,3))sys.exit(1)defmain():parent_

python - Urllib 的 urlopen 在某些站点上中断(例如 StackApps api): returns garbage results

我正在使用urllib2的urlopen函数尝试从StackOverflowapi获取JSON结果。我使用的代码:>>>importurllib2>>>conn=urllib2.urlopen("http://api.stackoverflow.com/0.8/users/")>>>conn.readline()我得到的结果:'\x1f\x8b\x08\x00\x00\x00\x00\x00\x04\x00\xed\xbd\x07`\x1cI\x96%&/m\xca{\x7fJ\...我是urllib的新手,但这似乎不是我应该得到的结果。我已经在其他地方尝试过了,我得到了我所期望的结果

python - 我是否需要将 multiprocessing.Queue 实例变量显式传递给在实例方法上执行的子进程?

关于使用Python的multiprocessing模块,我有几个基本问​​题:classSomeparallelworkerclass(object):def__init__(self):self.num_workers=4self.work_queue=multiprocessing.JoinableQueue()self.result_queue=multiprocessing.JoinableQueue()defsomeparallellazymethod(self):p=multiprocessing.Process(target=self.worktobedone).sta

python - 可见弃用警告 : using a non-integer number instead of an integer will result in an error in the future

当运行涉及以下函数的python程序时,image[x,y]=0给出以下错误消息。这是什么意思,如何解决?谢谢。警告VisibleDeprecationWarning:usinganon-integernumberinsteadofanintegerwillresultinanerrorinthefutureimage[x,y]=0Illegalinstruction(coredumped)代码defcreate_image_and_label(nx,ny):x=np.floor(np.random.rand(1)[0]*nx)y=np.floor(np.random.rand(1)[

python - Openpyxl 1.8.5 : Reading the result of a formula typed in a cell using openpyxl

我正在其中一个Excel工作表中打印一些公式:wsOld.cell(row=1,column=1).value="=B3=B4"但我不能使用它的结果来实现其他一些逻辑,如:if((wsOld.cell(row=1,column=1).value)='true'):#copythe1strowtoanothersheet即使我试图在命令行中打印结果,我最终还是打印了公式:>>>print(wsOld.cell(row=1,column=1))>>>=B3=B4如何在单元格中获取公式的结果而不是公式本身? 最佳答案 openpyxl支持

python - 为什么Python的Queue在qsize()中返回一个大概的大小?

在docqsize()它说:返回队列的近似大小。为什么它不能只返回这个队列的确切大小?我知道队列可能会被多个线程访问,但在我调用该函数的那一刻,我认为它仍然可以返回那一刻的确切大小。 最佳答案 正是因为有其他线程在访问它。当您尝试使用从qsize()返回的大小时,队列可能已经改变。如果文档阅读这样的内容会更好:Returnsthesizeofthequeue.Notethatinamulti-threadedenvironment,thesizecanchangeatanytime,makingthisonlyanapproxima

python - 溢出错误 : (34, 'Result too large' )

我遇到溢出错误(OverflowError:(34,'Resulttoolarge')我想计算pi到100位小数,这是我的代码:defpi():pi=0forkinrange(350):pi+=(4./(8.*k+1.)-2./(8.*k+4.)-1./(8.*k+5.)-1./(8.*k+6.))/16.**kreturnpiprint(pi()) 最佳答案 Pythonfloat既不是任意精度也不是无限大小。当k=349时,16.**k太大了-几乎是2^1400。幸运的是,decimal库允许任意精度并且可以处理大小:impor