小编ava*_*chy的帖子

Pycharm:期望的类型'Integral',而不是'str'

我刚刚安装了PyCharm 3.4并获得了一些新的警告.不只是在这里,而是在很多地方.代码当然没问题.有人可以翻译PyCharm试图告诉我的内容以及如何沉默这些消息吗?

截图 更多...

python pycharm

10
推荐指数
2
解决办法
2万
查看次数

为什么在dict上迭代会改变输出中的键顺序?

可能重复:
为什么python会这样排序我的字典?

为什么迭代这个词典

d = {'tors':None,
     'head':None,
     'armr':None,
     'arml':None,
     'legl':None,     
     'legr':None}

for k in d.keys():
    print k
Run Code Online (Sandbox Code Playgroud)

将以不同的顺序输出键:

head
legl
armr
arml
tors
legr
Run Code Online (Sandbox Code Playgroud)

python

3
推荐指数
1
解决办法
146
查看次数

如果发生任何异常,则运行一些代码并运行特定的异常

我有这个功能.我的pygame的文本到矩形转换器.

def text_to_rect(text, name='default'):
    try:
        font  = load.text_style[name]['font']
        aa    = load.text_style[name]['aa']
        color = load.text_style[name]['color']
    except NameError:
        font_path = pygame.font.get_default_font()
        font = pygame.font.Font(font_path, 24)
        aa = 1
        color = (0,0,0)
        if not name=='default':
            text = text+'(ERROR: Global load object not defined.)'
    except KeyError:
        font_path = pygame.font.get_default_font()
        font = pygame.font.Font(font_path, 24)
        aa = 1
        color = (0,0,0)
        if not name=='default':
            text = text+'(ERROR: '+name+' text style does not exist.)'
    return font.render(text,aa,color)
Run Code Online (Sandbox Code Playgroud)

在两个除了之外,有4行相同的代码.如果发生任何异常,我想运行这4行,然后休息到特定的异常.

python pygame exception-handling exception python-2.7

-2
推荐指数
1
解决办法
1576
查看次数