self.textBrowser_s.append(rel_ins) TypeError: append(self, text: str): argument 1 has unexpected type 'int'
时间: 2024-02-25 09:57:42 浏览: 102
这个错误是因为`self.textBrowser_s.append()`方法期望的参数类型是字符串类型,但是你传入了一个整数类型的参数`rel_ins`。你需要将`rel_ins`转换成字符串类型后再传入`self.textBrowser_s.append()`方法中。可以使用`str()`函数将整数类型转换成字符串类型,示例如下:
```python
self.textBrowser_s.append(str(rel_ins))
```
这样就可以将`rel_ins`转换成字符串类型,并将其添加到`self.textBrowser_s`中了。
相关问题
import wx class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "多个菜单栏不同菜单界面的切换", size=(800, 600)) self.panel = wx.Panel(self) self.createMenuBar1() self.createMenuBar2() self.createMenuBar3() self.switchMenuBar1() def createMenuBar1(self): self.menuBar1 = wx.MenuBar() menuItem1 = wx.MenuItem(self.menuBar1, -1, '菜单1') self.menuBar1.Append(menuItem1, '菜单1') self.Bind(wx.EVT_MENU, self.onSwitchMenuBar1, menuItem1) self.SetMenuBar(self.menuBar1) self.panel1 = wx.Panel(self, style=wx.BORDER_SUNKEN) self.panel1.SetPosition((0, 25)) self.panel1.SetSize((800, 575)) def createMenuBar2(self): self.menuBar2 = wx.MenuBar() menuItem2 = wx.MenuItem(self.menuBar2, -1, '菜单2') self.menuBar2.Append(menuItem2, '菜单2') self.Bind(wx.EVT_MENU, self.onSwitchMenuBar2, menuItem2) self.panel2 = wx.Panel(self, style=wx.BORDER_SUNKEN) self.panel2.SetPosition((0, 25)) self.panel2.SetSize((800, 575)) def createMenuBar3(self): self.menuBar3 = wx.MenuBar() menuItem3 = wx.MenuItem(self.menuBar3, -1, '菜单3') self.menuBar3.Append(menuItem3, '菜单3') self.Bind(wx.EVT_MENU, self.onSwitchMenuBar3, menuItem3) self.panel3 = wx.Panel(self, style=wx.BORDER_SUNKEN) self.panel3.SetPosition((0, 25)) self.panel3.SetSize((800, 575)) def onSwitchMenuBar1(self, event): self.SetMenuBar(self.menuBar1) self.panel2.Hide() self.panel3.Hide() self.panel1.Show() def onSwitchMenuBar2(self, event): self.SetMenuBar(self.menuBar2) self.panel1.Hide() self.panel3.Hide() self.panel2.Show() def onSwitchMenuBar3(self, event): self.SetMenuBar(self.menuBar3) self.panel1.Hide() self.panel2.Hide() self.panel3.Show() def switchMenuBar1(self): self.SetMenuBar(self.menuBar1) self.panel2.Hide() self.panel3.Hide() self.panel1.Show() if __name__ == '__main__': app = wx.App() frame = MyFrame() frame.Show(True) app.MainLoop()报错TypeError: MenuItem(): argument 1 has unexpected type 'MenuBar'咋解决
这是因为 `menuItem1`, `menuItem2`, `menuItem3` 的第一个参数应该是一个菜单对象,而不是一个菜单栏对象。你可以把它们改为这样:
```python
menuItem1 = wx.MenuItem(self.menuBar1, -1, '菜单1')
```
换句话说,把 `self.menuBar1` 改为对应的菜单对象即可。其他两个菜单也需要做同样的修改。
这是类的定义,class SelfAttention(nn.Module): def __init__(self, in_channels, reduction=4): super(SelfAttention, self).__init__() self.avg_pool = nn.AdaptiveAvgPool1d(1) self.fc1 = nn.Conv1d(in_channels, in_channels // reduction, 1, bias=False) self.relu = nn.ReLU(inplace=True) self.fc2 = nn.Conv1d(in_channels // reduction, in_channels, 1, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, x): b, c, n = x.size() y = self.avg_pool(x) y = self.fc1(y) y = self.relu(y) y = self.fc2(y) y = self.sigmoid(y) return x * y.expand_as(x),而这是使用该类的位置:self.SA_modules.append( nn.Sequential( PointnetSAModuleMSG( npoint=cfg.RPN.SA_CONFIG.NPOINTS[k], radii=cfg.RPN.SA_CONFIG.RADIUS[k], nsamples=cfg.RPN.SA_CONFIG.NSAMPLE[k], mlps=mlps, use_xyz=use_xyz, bn=cfg.RPN.USE_BN, channel_out=channel_out ), SelfAttention(channel_out=channel_out) ) ),但是运行时报错:File "/root/autodl-tmp/project/tools/../lib/net/pointnet2_msg.py", line 125, in __init__ SelfAttention(channel_out=channel_out) TypeError: __init__() got an unexpected keyword argument 'channel_out',为什么呢?如何解决
在你的代码中,SelfAttention类的初始化方法中只接收两个参数in_channels和reduction,而你在使用该类时传递了一个名为channel_out的参数,导致了TypeError。
解决方法是修改SelfAttention类的定义,为其增加一个名为channel_out的参数,并在初始化方法中接收和使用该参数。修改后的类定义如下:
```
class SelfAttention(nn.Module):
def __init__(self, in_channels, channel_out, reduction=4):
super(SelfAttention, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool1d(1)
self.fc1 = nn.Conv1d(in_channels, in_channels // reduction, 1, bias=False)
self.relu = nn.ReLU(inplace=True)
self.fc2 = nn.Conv1d(in_channels // reduction, channel_out, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
b, c, n = x.size()
y = self.avg_pool(x)
y = self.fc1(y)
y = self.relu(y)
y = self.fc2(y)
y = self.sigmoid(y)
return x * y.expand_as(x)
```
然后在使用SelfAttention类时,需要传递in_channels和channel_out参数,例如:
```
self.SA_modules.append(
nn.Sequential(
PointnetSAModuleMSG(
npoint=cfg.RPN.SA_CONFIG.NPOINTS[k],
radii=cfg.RPN.SA_CONFIG.RADIUS[k],
nsamples=cfg.RPN.SA_CONFIG.NSAMPLE[k],
mlps=mlps,
use_xyz=use_xyz,
bn=cfg.RPN.USE_BN,
channel_out=channel_out
),
SelfAttention(in_channels=channel_out, channel_out=channel_out)
)
)
```
阅读全文