包装类型为QWidget的c / c ++对象已被删除(wrapped c/c++ object of type QWidget has been deleted)
class window25(QtWidgets.QMainWindow): def __init__(self): try: super(window25,self).__init__() self.lineedit=QtWidgets.QLineEdit() self.checkbox=QtWidgets.QCheckBox() self.optBox=QtWidgets.QRadioButton() self.btn=QtWidgets.QPushButton("press me") self.guichange() self.btn.clicked.connect(self.guichange) self.show() except Exception as E: print(E) def guichange(self): try: wid=QtWidgets.QWidget() # self.setCentralWidget() myLayout=QtWidgets.QVBoxLayout() myLayout.addWidget(self.btn) myLayout.addWidget(random.choice([self.lineedit,self.checkbox,self.optBox])) wid.setLayout(myLayout) self.setCentralWidget(wid) except Exception as E: print(E) app=QtWidgets.QApplication([]) ex=window25() sys.exit(app.exec_())
我试图做实验。虽然我知道QStackedWidget改变窗口,但我尝试了一些按下按钮的其他东西,随机更改mainWindow中央小部件。一些成功后(即按下按钮3,4次正确工作)“)但之后我得到了一个错误
包装类型QCheckBox的c / c ++对象已被删除
包装类型为QLineEdit的c / c ++对象已被删除
我无法理解哪条语句导致了这个错误,以及我为什么或者错在哪里
class window25(QtWidgets.QMainWindow): def __init__(self): try: super(window25,self).__init__() self.lineedit=QtWidgets.QLineEdit() self.checkbox=QtWidgets.QCheckBox() self.optBox=QtWidgets.QRadioButton() self.btn=QtWidgets.QPushButton("press me") self.guichange() self.btn.clicked.connect(self.guichange) self.show() except Exception as E: print(E) def guichange(self): try: wid=QtWidgets.QWidget() # self.setCentralWidget() myLayout=QtWidgets.QVBoxLayout() myLayout.addWidget(self.btn) myLayout.addWidget(random.choice([self.lineedit,self.checkbox,self.optBox])) wid.setLayout(myLayout) self.setCentralWidget(wid) except Exception as E: print(E) app=QtWidgets.QApplication([]) ex=window25() sys.exit(app.exec_())
I was trying to do the experiment.Although I know about QStackedWidget to change windows but I tried something else that is pressing a button randomly changes the mainWindow Central widget.After a couple of success(i.e. pressing button 3,4 times work correctly") but after that I got an error
wrapped c/c++ object of type QCheckBox has been deleted
wrapped c/c++ object of type QLineEdit has been deleted
i am unable to understand which statement caused this error and why or where I am wrong
原文:https://stackoverflow.com/questions/48125641
最满意答案
有一个在您使用的
CSV
模块的README
中生成CSV的示例:file = File.open!("test.csv", [:write, :utf8]) table_data |> CSV.encode |> Enum.each(&IO.write(file, &1))
请注意,
IO.write/2
将字节写入设备,而IO.inspect/3
根据给定选项使用IO
设备检查第二个参数 。 此外,CSV.encode/1
需要二维列表 。也就是说,您可能应该坚持使用
IO.write/2
中提到的IO.write/2
,并在count
生成一个2d列表而不是Map
:defp count(words) when is_list(words) do words |> Enum.reduce(%{}, &update_count/2) |> Enum.reduce([], fn {k, v}, acc -> [[k, v] | acc] end) end defp tocsv(map) do file = File.open!("test.csv", [:write, :utf8]) map |> IO.inspect |> CSV.encode |> Enum.each(&IO.write(file, &1)) end
在这种简单的情况下,我只是使用裸Elixir生成一个文件,但(假设
count
返回一个映射,就像在你的原始代码中一样):defp tocsv(map) do File.open("test.csv", [:write, :utf8], fn(file) -> Enum.each(map, &IO.write(file, Enum.join(Tuple.to_list(&1), ?,) <> "\n")) end) end
或者更简单:
defp tocsv(map) do File.write!("test.csv", map |> Enum.map(Enum.join(Tuple.to_list(&1), ?,)) |> Enum.join("\n")) end
There is an example of producing the CSV in the
README
of theCSV
module you use:file = File.open!("test.csv", [:write, :utf8]) table_data |> CSV.encode |> Enum.each(&IO.write(file, &1))
Please note, that
IO.write/2
writes the bytes to the device, whileIO.inspect/3
inspects the second argument according to the given options using theIO
device. Also,CSV.encode/1
expects a two-dimensional list.That said, you probably should stick with
IO.write/2
as mentioned in the example, and produce a 2d list incount
rather that aMap
:defp count(words) when is_list(words) do words |> Enum.reduce(%{}, &update_count/2) |> Enum.reduce([], fn {k, v}, acc -> [[k, v] | acc] end) end defp tocsv(map) do file = File.open!("test.csv", [:write, :utf8]) map |> IO.inspect |> CSV.encode |> Enum.each(&IO.write(file, &1)) end
In such an simple case, I would just use bare Elixir to produce a file, though (assuming
count
returns a map, as in your original code):defp tocsv(map) do File.open("test.csv", [:write, :utf8], fn(file) -> Enum.each(map, &IO.write(file, Enum.join(Tuple.to_list(&1), ?,) <> "\n")) end) end
Or, even simpler:
defp tocsv(map) do File.write!("test.csv", map |> Enum.map(Enum.join(Tuple.to_list(&1), ?,)) |> Enum.join("\n")) end
相关问答
更多-
In [3]: s.to_csv('/home/wesm/tmp/sfoo.csv') In [4]: Series.from_csv('/home/wesm/tmp/sfoo.csv') Out[4]: a 1 b 2 您也可以将header=None, index_col=0, squeeze=True传递给read_csv类似于Rutger Kassies的建议。 In [3]: s.to_csv('/home/wesm/tmp/sfoo.csv') In [4]: Series. ...
-
在for循环中写入.csv(Write .csv in a for loop)[2023-04-15]
无需使用循环。 你可以使用data.table方法,这将更有效和更快。 library(data.table) # create a column with row positions setDT(dt)[, rowpos := .I] # save each line of your dataset into a separate .csv file dt[, write.csv(.SD, paste0("output_", rowpos,".csv")), by ... -
Elixir:试图将地图写入CSV,并将其写入流结果(Elixir: Trying to Write a Map to CSV, Being Written as Stream Results)[2023-08-26]
有一个在您使用的CSV模块的README中生成CSV的示例: file = File.open!("test.csv", [:write, :utf8]) table_data |> CSV.encode |> Enum.each(&IO.write(file, &1)) 请注意, IO.write/2将字节写入设备,而IO.inspect/3 根据给定选项使用IO设备检查第二个参数 。 此外, CSV.encode/1需要二维列表 。 也就是说,您可能应该坚持使用IO.write/2中提到的IO.wri ... -
以下是您的宏必须如何将数据写入2列: VERSION BUILD=10.4.28.1074 TAB T=1 SET !DATASOURCE prefectures.csv SET !DATASOURCE_COLUMNS 1 SET !TIMEOUT_STEP 1 SET !ERRORIGNORE YES SET !LOOP 1 SET !DATASOURCE_LINE {{!LOOP}} URL GOTO=https://www.google.fr/search?q={{!COL1}} TAG POS=1 ...
-
所以我终于弄明白了。 似乎文档缺少关于Streaming API的一些关键细节。 基本上我是在正确的轨道上,我只需要在代码中更早地创建索引。 我最终使用了AbstractIndexCreationTask,我比PutIndex方法更喜欢,虽然我不确定他们是否做同样的事情。 在任何情况下,这都有效: var store = new EmbeddableDocumentStore { DataDirectory = "data" }; ...
-
您实际上没有向CSV文件写任何内容。 首先,不清楚为什么要打开文件进行写入然后再进行阅读。 然后从(现在为空)文件中读取。 然后,您从HTML中读取,并显示您想要的内容。 当然,如果您想要在其中显示数据,您将需要在某处写入CSV文件! 此外,如果您想通过Text :: CSV使用它们,最好避免使用文件句柄的裸字。 也许你需要这样的东西: my $csv = Text::CSV->new(); $csv->column_names('field1', 'field2', 'field3'); open $fh ...
-
你不断删除文件,因为每次调用toto它都会打开result.csv进行写入,因此只剩下一次写入。 您需要打开一次文件,并创建一次wirter。 您还需要为此重新定义一次函数: import re import csv import string def toto(message,writer): message = message.lower() p = re.compile('|'.join(map(re.escape, string.punctuation))) no_punc ...
-
printRecord()方法采用Iterable(每个doc )。 例如一份清单。 因此,在代码的内部循环中,我们将为该行创建一个列表,而不是打印。 具体来说,给定此设置: def FILE_HEADER = ['Bond','Discount','Row','Price'] def fileName = 'out.csv' 和这个数据聚合(作为例子): def BondCounsel = ['bc1','bc2'] def DiscountRate = ['0.1','0.2'] def ro ...
-
我想你可以明确地写出标题。 这是基于我到目前为止对我们的评论的理解 headers = ["Company_Name","Website","Street_Address", "City", "State", "Zip", "Phone","Email1", "Email2", "Email3", "Email4", "Email5"] set_headers = true csvs.each do |csv| city = csv.split(/[\/]|.csv-updated|.csv/).la ...
-
在CSV中查找字典键匹配并将值写入下一列(Find dictionary key match in CSV and write value to the next column)[2021-08-03]
你可以用lambda做到这一点,它简单快捷。 在阅读csv时也无需添加参数“names = ['Keyword']”。 import pandas as pd import datetime import os os.chdir('D:/mypc/') starter_df = pd.read_csv('keyword_results.csv') #dictionary created by function test_dic = {"John": 12, "Jake": 45, "Sarah": 3 ...