小编Dor*_*ran的帖子

如何使用python-3.x中的字典格式化字符串?

我是使用字典格式化字符串的忠实粉丝.它帮助我阅读我正在使用的字符串格式,以及让我利用现有的字典.例如:

class MyClass:
    def __init__(self):
        self.title = 'Title'

a = MyClass()
print 'The title is %(title)s' % a.__dict__

path = '/path/to/a/file'
print 'You put your file here: %(path)s' % locals()
Run Code Online (Sandbox Code Playgroud)

但是,我无法弄清楚python 3.x语法做同样的事情(或者如果可能的话).我想做以下几点

# Fails, KeyError 'latitude'
geopoint = {'latitude':41.123,'longitude':71.091}
print '{latitude} {longitude}'.format(geopoint)

# Succeeds
print '{latitude} {longitude}'.format(latitude=41.123,longitude=71.091)
Run Code Online (Sandbox Code Playgroud)

python string dictionary python-3.x

196
推荐指数
7
解决办法
15万
查看次数

如何使用buildout构建Qt,PyQt和SIP?

编辑:以下buildout.cfg用于构建Qt,PyQt和SIP


[buildout]
parts =
    pyqt

[pyqt]
recipe = zc.recipe.cmmi
url = http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-x11-gpl-4.8.4.tar.gz
#shared = True
source-directory-contains = configure.py
configure-command = ${buildout:executable} ./configure.py
configure-options = --confirm-license
    -q ${qt:location}/bin/qmake
    -b ${buildout:parts-directory}/pyqt/bin
    -p ${buildout:parts-directory}/pyqt/plugins
    -d ${buildout:parts-directory}/pyqt/lib/
    -v ${sip:location}/share
    --verbose
environment =
    PYTHONPATH=${sip:location}/lib


[sip]
recipe = zc.recipe.cmmi
url = http://www.riverbankcomputing.co.uk/static/Downloads/sip4/sip-4.12.3.tar.gz
# shared = True
source-directory-contains = configure.py
configure-command = ${buildout:executable} ./configure.py
configure-options = 
    -b ${buildout:parts-directory}/sip/bin
    -e ${buildout:parts-directory}/sip/include
    -d ${buildout:parts-directory}/sip/lib
    -v ${buildout:parts-directory}/sip/share

[qt]
recipe = zc.recipe.cmmi
url = http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.3.tar.gz
shared = True
Run Code Online (Sandbox Code Playgroud)

pyqt buildout

5
推荐指数
1
解决办法
1323
查看次数

如何在Libgdx中支持OpenGL ES GL10,GL11和GL20?

我正在编写一个使用GL10的3D游戏,但我希望该应用程序支持GL11或GL20(如果可用).支持所有3个的最佳设计是什么?或者这是一个傻瓜的差事,我应该专注于支持一个版本?

我目前的想法是将render()函数拆分为renderGL10,renderGL11,renderGL20,并根据可用的GL实例调用相应的渲染函数.每个渲染函数内部都是渲染GL版本的正确方法; GL10和GL11可能会有重叠.这是处理我的问题的合适方式还是有更好的方法?

public render(){
  if (Gdx.graphics.isGL20Available()){
    renderGL20();
  } else if (Gdx.graphics.isGL11Available()){
    renderGL11();
  } else { 
    renderGL10();
  }
}
Run Code Online (Sandbox Code Playgroud)

编辑:解决方案:如果gl1.x可用,gl10也可用(并且Gdx.gl10不为空).因此,我的渲染代码通常应该如下构造:

public render(){
  // Use Gdx.gl for any gl calls common to all versions
  if (Gdx.graphics.isGL20Available()){
    // Use Gdx.GL20 for all gl calls
  } else {
    if (Gdx.graphics.isGL11Available()){
      // Use Gdx.gl11 for any gl11 call not supported by gl10
    } 
    // Use Gdx.gl10 for all gl calls
  }
}
Run Code Online (Sandbox Code Playgroud)

java opengl-es opengl-es-2.0 libgdx

5
推荐指数
1
解决办法
6601
查看次数

在Libgdx android中提供支持多个屏幕的资源

在android中,我可以为许多屏幕分辨率提供替代资源,例如drawable-hdpi,drawable-ldpi和drawable-mdpi.libgdx会意识到它正在使用一定的屏幕密度并使用适当的资源吗?

android libgdx

4
推荐指数
1
解决办法
1213
查看次数