小编Szi*_*dam的帖子

是否可以编译用Python编写的程序?

我是Python编程语言的新手.我想知道是否可以编译用Python编写的程序.

是否有可能将Python脚本转换为某些较低级别的编程语言,然后可以编译为二进制代码?

正在考虑使用Python编写代码的开发人员可能希望保持开放的可能性,以便以后能够进行二进制分发.

python compilation

44
推荐指数
5
解决办法
9万
查看次数

ttk.Combobox在状态为只读且失焦时出现故障

当ttk.Combobox是只读且不在焦点时,其文本背景变为白色,这与灰色场背景不同,并使组合框看起来很丑:

例

所需的风格将是第二个.如何使组合框像这样工作?

python combobox tkinter ttk python-3.x

6
推荐指数
1
解决办法
1834
查看次数

如何装饰 asyncio.coroutine 以保留其 __name__ ?

我尝试编写一个装饰器函数,它包装asyncio.coroutine并返回完成所需的时间。下面的食谱包含按我预期工作的代码。我唯一的问题是,尽管使用了@functools.wraps. 如何保留原来协程的名称?我检查了来源asyncio.

import asyncio
import functools
import random
import time

MULTIPLIER = 5

def time_resulted(coro):
    @functools.wraps(coro)
    @asyncio.coroutine
    def wrapper(*args, **kargs):
        time_before = time.time()
        result = yield from coro(*args, **kargs)
        if result is not None:
            raise TypeError('time resulted coroutine can '
                'only return None')
        return time_before, time.time()
    print('= wrapper.__name__: {!r} ='.format(wrapper.__name__))
    return wrapper

@time_resulted
@asyncio.coroutine
def random_sleep():
    sleep_time = random.random() * MULTIPLIER
    print('{} -> {}'.format(time.time(), sleep_time))
    yield from asyncio.sleep(sleep_time)

if __name__ == '__main__':
    loop = asyncio.get_event_loop() …
Run Code Online (Sandbox Code Playgroud)

decorator coroutine python-3.x python-3.4 python-asyncio

6
推荐指数
1
解决办法
3385
查看次数