我有一个包含主窗口小部件的主窗口,其中设置了垂直布局。向布局添加了一个QTableWidget(暂时)。
当我启动应用程序并在 main_window 上调用 show 时,只显示了其中的一部分QTableWidget。我可以手动扩展窗口以查看所有内容,但我希望窗口的大小能够很好地适应QTableWidget.
谷歌搜索这个问题发现了很多关于如何使用调整大小为任意大小的帖子,并调用resize(int)工作正常,但这并不是我要问的
许多其他帖子不够明确,例如“使用 sizePolicy”或“使用frameGeometry”或“使用几何”或“使用sizeHint”。我相信他们所有人都可能是对的,但是一个关于如何做的例子会很棒。
这是一个非常简单的程序:
a = [[]]*3
print str(a)
a[0].append(1)
a[1].append(2)
a[2].append(3)
print str(a[0])
print str(a[1])
print str(a[2])
Run Code Online (Sandbox Code Playgroud)
这是我期待的输出:
[[], [], []]
[1]
[2]
[3]
Run Code Online (Sandbox Code Playgroud)
但相反,我得到了这个:
[[], [], []]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3]
Run Code Online (Sandbox Code Playgroud)
我真的没有到达这里!
当我编程时,我喜欢给我的变量非常有意义的名字.根据我的理解,在C++和其他编译语言中,这两行是完全等价的:
第1行:
bool a = true;
Run Code Online (Sandbox Code Playgroud)
第2行:
bool bob_likes_very_much_to_eat_strawberry_on_friday_evening = true;
Run Code Online (Sandbox Code Playgroud)
原因是:它将被编译,变量名称在进程中丢失(?).
另一方面,这就是我要问的,似乎以下两个在python中不相同:
第1行:
a = True
Run Code Online (Sandbox Code Playgroud)
第2行:
bob_likes_very_much_to_eat_strawberry_on_friday_evening = True
Run Code Online (Sandbox Code Playgroud)
原因是它被解释了,解释器将使用一些带有变量名的字典作为它将要查询的键(?).我不知道这些字典是如何实现的,但对于我来说,散列长变量名可能需要更长时间(?)并且在某些情况下会产生影响并不是很疯狂.
那么,在某些情况下我应该小心保持我的变量名称长度合理吗?
注1:这个线程非常相似: 你如何命名变量对应用程序的内存使用有什么影响? 但没有关于python出现的明确答案(选择的答案说它一般会对解释语言产生影响,其他答案说它对python没有特别的影响)
注2:我的观点不是提倡由于代码不可读而导致错误的微优化.我想要知道如果通过提供额外的长名称,我在执行速度方面做了某种妥协.
在一个模块中,我有两个测试:
@pytest.fixture
def myfixture(request):
prepare_stuff()
yield 1
clean_stuff()
# time.sleep(10) # in doubt, I tried that, did not help
def test_1(myfixture):
a = somecode()
assert a==1
def test_2(myfixture):
b = somecode()
assert b==1
Run Code Online (Sandbox Code Playgroud)
当这两个测试单独执行时,一切都ok,即两者
pytest ./test_module.py:test_1
Run Code Online (Sandbox Code Playgroud)
紧接着:
pytest ./test_module.py:test_2
Run Code Online (Sandbox Code Playgroud)
运行直至完成并成功通过。
但:
pytest ./test_module.py -k "test_1 or test_2"
Run Code Online (Sandbox Code Playgroud)
报告:
collected 2 items
test_module.py .
Run Code Online (Sandbox Code Playgroud)
并永远挂起(经过调查:test_1成功完成,但第二次调用prepare_stuff挂起)。
在我的具体设置中prepare_stuff,clean_stuff和somecode已经相当进化,即它们创建和删除一些共享内存段,如果做得错误,可能会导致一些挂起。所以这里可能存在一些问题。
但我的问题是:在两次调用pytest(案例1)之间是否发生了在同一“pytest进程”(案例2)的调用test_1和test_2来自同一“pytest进程”(案例2)的调用之间发生的事情,这可以解释为什么“案例1”工作正常,而“案例 2" 挂在test_1和之间test_2 …
我正在尝试在Windows 8上安装MLPack.我使用以下命令配置CMakeLists.txt文件:
set(ARMADILLO_LIBRARY "C:\\Program Files (x86)\\armadillo\\lib")
set(ARMADILLO_INCLUDE_DIR "C:\\Program Files (x86)\\armadillo\\include")
Run Code Online (Sandbox Code Playgroud)
然后,当我运行CMake时,我发出了一系列警告,如下所示:
WARNING: Target "mlpack" requests linking to directory "C:\Program Files (x86)\armadillo\lib". Targets may link only to libraries. CMake is dropping the item.
Run Code Online (Sandbox Code Playgroud)
在\ mlpack-1.0.4\src\mlpack目录中,我找到了另一个CMakeLists文件:
target_link_libraries(mlpack
${ARMADILLO_LIBRARIES}
${Boost_LIBRARIES}
${LIBXML2_LIBRARIES}
)
Run Code Online (Sandbox Code Playgroud)
我改为(不确定这是不是一个好主意):
target_link_libraries(mlpack
${Boost_LIBRARIES}
)
link_directories(mlpack
${ARMADILLO_LIBRARIES}
${LIBXML2_LIBRARIES}
)
Run Code Online (Sandbox Code Playgroud)
然后CMake似乎运行顺利:
-- Found Armadillo: C:\Program Files (x86)\armadillo\lib (found suitable version "3.800.2", minimum required is "2.4.2")
-- Found LibXml2: C:\cpp\libraries\libxml2-2.7.8.win32\lib (found suitable version "2.7.8", minimum required is "2.6.0")
-- Boost version: 1.53.0
-- Found …Run Code Online (Sandbox Code Playgroud) 我有一个(相对)大项目C++,可以在ubuntu上编译和运行(使用cmake/catkin).它在mac os上编译很好,但在尝试启动可执行文件时,我收到错误消息:
dyld: Library not loaded: <name of library>.dylib
Referenced from:
<path to executable>/<executable>
Reason: image not found
Run Code Online (Sandbox Code Playgroud)
运行命令时:
otool -l <executable> | grep LC_RPATH -A2
Run Code Online (Sandbox Code Playgroud)
我得到输出:
cmd LC_RPATH
cmdsize 64
path <correct absolute path to folder containing library> (offset 12)
cmd LC_RPATH
cmdsize 24
path /sw/lib (offset 12)
cmd LC_RPATH
cmdsize 32
path /usr/X11/lib (offset 12)
cmd LC_RPATH
cmdsize 32
path /opt/local/lib (offset 12)
cmd LC_RPATH
cmdsize 32
path /opt/X11/lib (offset 12)
Run Code Online (Sandbox Code Playgroud)
我不清楚为什么找不到图书馆.运行:
otool -L <executable>
Run Code Online (Sandbox Code Playgroud)
打印:
<executable name>: …Run Code Online (Sandbox Code Playgroud) 我的理解是gitlab只允许在以下语境中对代码进行注释:
事情在这里发展.
这在持续集成的背景下具有完全意义.然而,在某些情况下,我发现非常有用的是评论一个提交的完整代码,独立于其与其他提交的差异.我的理解是这在gitlab上是不可能的,但我可能错了?
ps:我有企业版,以防万一.
在服务器上,我们将持续集成作业作为奇点图像的运行脚本运行,例如
wget url_to_mysingularityimage.sif
chmod +x ./mysingularityimage.sif
./mysingularityimage.sif
Run Code Online (Sandbox Code Playgroud)
如果这是相关的:在我们的具体情况下,运行脚本是一个 bash 脚本。效果很好。
执行作业后,图像将被删除。
rm ./mysingularityimage.sif
Run Code Online (Sandbox Code Playgroud)
但看起来对应的循环设备仍然存在,即
losetup -a | grep mysingularityimage.sif
Run Code Online (Sandbox Code Playgroud)
输出类似:
/dev/loop27: []: (/path/to/mysingularityimage.sif (deleted)), offset 40960, sizelimit 831307776
Run Code Online (Sandbox Code Playgroud)
当我们运行作业时,循环设备的数量会增加。在某些时候,达到了循环设备的限制数量,奇点失败并出现错误:
FATAL: container creation failed: mount /proc/self/fd/3->/usr/local/var/singularity/mnt/session/rootfs error: while mounting image /proc/self/fd/3: failed to find loop device: could not attach image file to loop device: no loop devices available
Run Code Online (Sandbox Code Playgroud)
我们是不是做错了什么?是否有一个命令我们需要在每个作业结束时运行以确保循环设备被“释放”?
(注意:我们使用bamboo进行持续集成,并且bamboo总是在新目录中执行工作,这可以解释为什么相同的循环设备没有被重用。Bamboo:https: //www.atlassian.com/software/bamboo) 。
下面的测试通过了,但我怀疑我是否正确使用了 asyncio:
import asyncio
import threading
import pytest
import websockets
async def echo(websocket):
async for message in websocket:
await websocket.send(message)
async def websocket_server():
async with websockets.serve(echo, "localhost", 8765):
await asyncio.Future()
def _run_server():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(websocket_server())
loop.close()
@pytest.fixture
def run_server():
thread = threading.Thread(target=_run_server)
thread.start()
yield thread
# no idea how to stop the loop here
thread.join()
@pytest.mark.asyncio
async def test_websocket(run_server):
async with websockets.connect("ws://localhost:8765") as websocket:
await websocket.send("Hello!")
response = await websocket.recv()
assert response == "Hello!"
Run Code Online (Sandbox Code Playgroud)
(注意:为了停止循环,我尝试了此处提出的解决方案(How …
python websocket pytest python-multithreading python-asyncio
在我看来,构造函数可以共享相同的代码,例如:
public class Foo {
private int foo;
{foo = 5;}
public Foo(){}
public Foo(int v){this.foo = v;}
public int getFoo(){return foo;}
}
Run Code Online (Sandbox Code Playgroud)
代码"foo = 5;" 两个构造函数都被调用.
在我看来你不能,但我想确定.是不是可以创建使用参数的公共代码?
例如,像:
public class Foo {
private int foo;
(int m){foo = m*5;}
public Foo(int m){}
public Foo(int v,int m){this.foo = v;}
public int getFoo(){return foo;}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,唯一的方法是创建一个由所有构造函数调用的私有void init(int m)?
ps:我打电话给{foo = 5;}"公共代码",但我想这个功能有另一个官方名称?
编辑(1):
我正在寻找的术语是初始化程序块
这个问题与询问构造函数是否也可以调用另一个构造函数不同.因为在使用初始化程序块时,代码被称为AUTOMATICALLY,即.没有风险调用构造函数而忘记调用它
我对使用"void init"的评论并不好,实际上在这种情况下调用另一个构造函数更好.
简而言之,我的问题是:初始化程序块可以采用参数吗?这与强制实现所有构造函数的某些参数有点相同.
编辑(2):
我现在想知道实现我要求的唯一方法是使用继承来强制使用特定的构造函数.