【python – 从PyQt中的QTextEdit获取可见文本】教程文章相关的互联网学习教程文章

python-如何获取列表的所有顺序,以使该列表等于另一个列表?【代码】

我有列表A和B,它们可以重复,例如:A = ['x', 'x', 7] B = [7, 'x', 'x']现在,我希望将列表B置换为列表A的所有索引排列:[1, 2, 0] # because [B[1], B[2], B[0]] == A [2, 1, 0] # because [B[2], B[1], B[0]] == A是否有办法在不迭代所有可能排列的情况下实现这一目标?我已经用过import itertools for p in itertools.permutations(range(len(B))):if A == permute(B,p):遍历所有可能的排列并检查我想要的排列,但是我想更快...

python-parent()或super()获取父对象?【代码】

我有两节课: 第一个(父类)在方法中实例化子类.我正在尝试修改子类中的父对象属性. (这些对象是PyQT QWidget). 这是我的父母和孩子课程的开始: 家长:class ParentClass(QtGui.QMainWindow):def __init__(self, parent=None):super(ParentClass, self).__init__()somevar=1200self.ChildItem=ChildClass()self.ChildItem.Start(somevar)小孩:class ChildClass(QtGui.QWidget):def Start(self, var):super(ChildClass, self).__in...

Kivy和Python线程-如何在它们之间获取数据【代码】

我在python(threading)和kivy上遇到一些问题: 这是一些代码:import kivy import threading import time from kivy.app import App from kivy.uix.button import Buttonclass Thread(threading.Thread):def __init__(self):threading.Thread.__init__(self) self.counter = 0 def run(self):while True:print "Thread is running "+str(self.counter)app.button.text = self.set_button(self.counter)app.button.text = ...

在Python中获取Weasyprint的基本URI【代码】

我正在将Weasyprint库用于Python,以尝试将html文件打印为pdf.我试图将图像嵌入页面的背景中.这是代码:HTML(string='''<h1>The title</h1><p>Content goes here ''', base_url=os.path.dirname(os.path.realpath(__file__))).write_pdf("hello.pdf", stylesheets=[CSS(string='body{background-image: url("example_image.png")}')])我到此代码的输出如下:Ignored `background-image: url("example_image.png")` at 1:6, Relativ...

如何使用Python urlopen()获取HTTP响应标头【代码】

在这段代码中from bs4 import BeautifulSoup import urllib2 import rehtml_page = urllib2.urlopen("http://fr.wikipedia.org/wiki/Alan_Turing")soup = BeautifulSoup(html_page, "lxml")print soup我可以返回源代码. 但是,请问如何拥有HTTP标头(在Python中)? 范例:HTTP/1.1 200 OK Server: nginx/1.9.4 Date: Thu, 10 Sep 2015 09:13:25 GMT Content-Type: text/css; charset=utf-8 Content-Length: 10699 x-content-type-opt...

python-在有向无环网络x DiGraph中获取有序节点【代码】

我有一个带有子图的有向图,其中节点的顺序很重要. 示例我的图将有两个子图,所有子图都是线性的1-> 2-> 3& 9-> 8-> 7-> 6 注意:节点名称将是随机且唯一的,图中没有循环NG = nx.DiGraph() NG.add_edges_from([(1,2),(2,3)]) NG.add_edges_from([(9,8),(8,7),(7,6)])我需要获取子图或子图中的节点列表,并根据其连接对节点进行排序. 我试过了[i.nodes() for i in list(nx.weakly_connected_component_subgraphs(NG))]导致节点列表的列...

如何获取字符串python的连续单词数【代码】

我正在尝试制作一个Python脚本,该脚本接受一个字符串并给出连续单词的计数.比方说:string = " i have no idea how to write this script. i have an idea."output = ['i', 'have'] 2 ['have', 'no'] 1 ['no', 'idea'] 1 ['idea', 'how'] 1 ['how', 'to'] 1 ['to', 'write'] 1 ...我正在尝试使用python而不导入集合,集合中的计数器.我所拥有的如下.我正在尝试使用re.findall(#whatpatterndoiuse,string)遍历字符串并进行比较,但是...

python-PyQt4,从comboBox获取当前文本【代码】

我有一个带有comboBox的非常简单的GUI,其中包含4个项目.这四个项目中的每一个都做不同的事情,需要在启用/禁用QLineEdit框以及能够基于当前选择添加占位符文本方面链接到QLineEdit框. 码:class Ui_MainWindow(object):def setupUi(self, MainWindow):self.comboBox = QtGui.QComboBox(self.centralwidget)self.comboBox.setGeometry(QtCore.QRect(10, 10, 201, 26))self.comboBox.setObjectName(_fromUtf8("comboBox"))self.comboB...

python-如何获取由“ groupby()”生成的组作为列表?【代码】

我正在测试itertools.groupby()并尝试将组作为列表获取,但无法弄清楚如何使其工作. 使用这里的例子,在How do I use Python’s itertools.groupby()?from itertools import groupbythings = [("animal", "bear"), ("animal", "duck"), ("plant", "cactus"),("vehicle", "speed boat"), ("vehicle", "school bus")]我试过了(python 3.5):g = groupby(things, lambda x: x[0]) ll = list(g) list(tuple(ll[0])[1])我以为我应该将第一...

python-如何在多索引熊猫数据框中获取随机样本?【代码】

我有一个根据以下变量建立索引的数据框:NAME-日期.名称是某种奇怪的ID,日期是..日期. 数据非常大,我想检查一下随机选择的NAME的数据. 那是, >从可能的名称中随机选择一个名称>按时间顺序检查该NAME的数据. 我不知道该怎么做.我看到我们可以使用get_level_values,但是我没有特定的名称,我只是想多次调用随机样本. 任何帮助表示赞赏!谢谢!解决方法: import pandas as pd import numpy as np import random import stringdf = pd.D...

Python从多个不同长度的列表中获取唯一对【代码】

假设在Python中我有3个列表:长度可变的a,b,c.例如 :a=[1,2,3] b=[4,5,6] c=[7,8]我想获得上述3个列表中两个元素的每个唯一组合,即. e. [1,4],[1,5],[1,6],[1,7],[1,8],[2,4],[2,5] …以及非唯一组合3个列表(例如[1,4,7],[1,4,8],…). 我看过使用itertools的solution here,这对于2个列表来说是完美的;但是,当包含第n个列表时,此解决方案将不再起作用,因为唯一组合的长度为n. 这是我尝试过的:import itertoolsa=[1,2,3] b=[4,5,6...

在没有cgi的情况下使用python从html表单获取数据【代码】

我想从基本的HTML表单中获取数据<form method="send" action="/send">Name <input type="text" name="name"/><input type="submit" value="Send"> </form>到python文件中.有可能吗?我不想使用CGI.谢谢乔希解决方法:是否需要与CGI对抗,取决于您的用例. Python框架.像Flask一样,往往开箱即用地提供自己的小型Web服务器.但是,此类服务器主要用于在开发阶段进行测试.通常通过CGI或FastCGI集成到功能强大的Web浏览器中,并且可以提供高...

python-获取数据框中列的每个元素的第一个字符【代码】

我有一个称为df的数据框.它具有称为“规范类型”的列.使用大熊猫df['Spec Type']0 NaN 1 A1 2 G7V 3 F7+K4 . . . . 169 A0e我只想为每个条目获取第一个字符,并将其作为df的新列称为“规范类型索引”.但是,以下代码给我一个错误:df['Spec Type Index'] = [i[0] for i in df['Spec Type']]‘float’ object is not subscriptable错误在i [0]部分中.我用它来获取索引元素的第一...

python-Scrapy xpath获取以<开头的元素的文本【代码】

我正在尝试从此html代码段中获取文本“< 1小时”. <div class="details_wrapper"> <div class="detail"><b>Recommended length of visit:</b><1 hour </div> <div class="detail"><b>Fee:</b>No </div> </div>这是我正在使用的xpath表达式:visit_length = response.xpath("//div[@class='details_wrapper']/""div[@class='detail']/b[contains(text(), ""'Recommended length of visit:')]/parent::div/text()" ).extract()但是它...

如何使用Scikit Learn dictvectorizer从Python中的密集数据帧获取编码数据帧?【代码】

我有一个数据框,如下所示:user item affinity 0 1 13 0.1 1 2 11 0.4 2 3 14 0.9 3 4 12 1.0由此,我要创建一个编码数据集(用于fastFM),如下所示:user1 user2 user4 user4 item11 item12 item13 item14 affinity1 0 0 0 0 0 1 0 0.10 1 0 0 1 0 0 0 0.40 0 1 0 0 0 ...