小编sha*_*fty的帖子

如何在pyquery中获得单独的CSS样式

您可以使用以下几种方法设置 css样式:

p = PyQuery('<p></p>')
p.css('font-size','16px')
p.css(['font-size'] = '16px'
p.css = {'font-size':'16px'}
Run Code Online (Sandbox Code Playgroud)

太好了,但如何一个单独的 CSS样式?

p.css('font-size') # jquery-like method doesn't work
[<p>]
p.css['font-size'] # pythonic method doesn't work!
[<p>]
p.css.font_size # BeardedO's suggestion.
[<p>]
p.attr('style')    # too much information.
'font-size: 16px; font-weight: bold'
Run Code Online (Sandbox Code Playgroud)

这看起来很奇怪,不方便,不精确和unpython就好!前两个中的一个应该返回样式文本,当然?

有没有办法单独获得单一的CSS风格而不使用split()等工具?

css python pyquery

8
推荐指数
1
解决办法
650
查看次数

如何找出mercurial存储库的大小?

那么,例如,如果有一个mercurial存储库https://code.google.com/p/potentiallyLarge有一个命令,可以让我在克隆它之前找出它的大小?就像是

hg size https://code.google.com/p/potentiallyLarge
Run Code Online (Sandbox Code Playgroud)

另外,是否有针对subversion存储库执行此操作的命令?

mercurial command

8
推荐指数
1
解决办法
2341
查看次数

为什么webapp.WSGIApplication的实例总是被定义为谷歌应用引擎代码中的全局变量?

我开始学习使用谷歌应用引擎,并且在我遇到的大部分代码中,他们将webapp.WSGIApplication的实例声明为全局变量.这似乎没有必要,因为代码在main函数中本地声明时工作正常.我总是被告知应该避免全局变量.那么这样做是否有好的,甚至不那么好的理由?

例:

class Guestbook(webapp.RequestHandler):
  def post(self):
    greeting = Greeting()

    if users.get_current_user():
      greeting.author = users.get_current_user()

    greeting.content = self.request.get('content')
    greeting.put()
    self.redirect('/')

application = webapp.WSGIApplication([  ('/', MainPage),  ('/sign', Guestbook)], debug=True)

def main():
  wsgiref.handlers.CGIHandler().run(application)
Run Code Online (Sandbox Code Playgroud)

为什么不这样做,这也有效:

class Guestbook(webapp.RequestHandler):
  def post(self):
    greeting = Greeting()

    if users.get_current_user():
      greeting.author = users.get_current_user()

    greeting.content = self.request.get('content')
    greeting.put()
    self.redirect('/')

def main():
  application = webapp.WSGIApplication([  ('/', MainPage),  ('/sign', Guestbook)], debug=True)
  wsgiref.handlers.CGIHandler().run(application)
Run Code Online (Sandbox Code Playgroud)

这也适用于具有多个请求处理程序的示例.

python google-app-engine global-variables

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

无法使用方法在python中设置类属性

初始化Foo对象确实运行方法func(),但无论如何,self.a的值都设置为None.

如何使用以下代码?

#!/usr/bin/env python

class Foo(object):

    def __init__(self, num):
        self.a = self.func(num)
        print self.a

    def func(self, num):
        self.a = range(num)
        print self.a

    def __str__(self):
        return str(self.a)


def main():
    f = Foo(20)
    print f

if __name__ == "__main__":
    main()
Run Code Online (Sandbox Code Playgroud)

输出是:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
None
None
Run Code Online (Sandbox Code Playgroud)

python attributes class

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

pygame mouse.get_pos()不起作用

我无法获得一个非常简单的pygame脚本来工作:

import pygame

class MainWindow(object):

    def __init__(self):
        pygame.init()

        pygame.display.set_caption('Game')
        pygame.mouse.set_visible(True)
        # pygame.mouse.set_visible(False) # this doesn't work either!

        screen = pygame.display.set_mode((640,480), 0, 32)

        pygame.mixer.init()

        while True:
            print pygame.mouse.get_pos()

        pygame.mixer.quit()
        pygame.quit()

MainWindow()
Run Code Online (Sandbox Code Playgroud)

当我在窗口上移动鼠标时,这只是输出(0,0):

(0, 0)
(0, 0)
(0, 0)
(0, 0)
(0, 0)
Run Code Online (Sandbox Code Playgroud)

有人可以检查吗?

编辑-固定代码:

import pygame

class MainWindow(object):

    def __init__(self):
        pygame.init()

        pygame.display.set_caption('Game')
        pygame.mouse.set_visible(True)
        # pygame.mouse.set_visible(False) # this doesn't work either!

        screen = pygame.display.set_mode((640,480), 0, 32)

        pygame.mixer.init()

        while True:
            for event in pygame.event.get():
                if event.type == pygame.MOUSEMOTION:
                    print pygame.mouse.get_pos()

        pygame.mixer.quit()
        pygame.quit()

MainWindow()
Run Code Online (Sandbox Code Playgroud)

python mouse pygame

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

将带有"px"的值插入jquery的attr方法时,图像属性设置为零

我发现jquery attr()方法不喜欢接受带有"px"的值.生成的图像最终为零宽度和高度!这是一个错误,一个疏忽或一些功能?

这很容易解决,但我真的不喜欢没有单位设置值.它可能导致不可预测的行为.

在firefox 3.6和opera 11中测试了以下内容:

<html>
<head>
<script type="text/javascript" src="../jquery-1.4.min.js"></script>
<script type="text/javascript" src="return.js"></script>
</head>

<body>
<div id="links" style="width:500px; background:#000;">
  <img src="images/ref.png" width="500px" height="500px" alt="reference" />
</div>

</body>
</html>

$(document).ready(function(){

$('div#links').css({ 'height':"300px" });
$('div#links img').attr({ 'width':"100px", 'height':"100px" }); // This doesn't work!
//$('div#links img').attr({ 'width':"100", 'height':"100" }); // This works.

});
Run Code Online (Sandbox Code Playgroud)

jquery attributes attr

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

Python/Google应用引擎数据存储性能

在python/google应用程序引擎应用程序中,我可以选择将一些静态数据(大小为KB)存储在本地json/xml文件中,或者将其放入数据存储区并从那里查询.数据是由我创建的,所以数据格式不正确也没有问题.在特定的术语,如节省配额,减少资源使用和应用程序速度,这是更好的方法吗?

我猜想使用simplyjson从json文件读取会更好,因为这种方法不需要数据存储区查询,同时仍然相当快.

更进一步,该应用程序不需要大型数据存储(目前约400KB),所以是否值得将所有数据移动到json文件以绕过配额限制?

python performance google-app-engine json google-cloud-datastore

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

Python的问题是无测试?

我喜欢对空变量使用is None测试,它非常灵活,简单且有用.它现在似乎停止了工作:

>"" is None
False

>[] is None
False

>{} is None
False
Run Code Online (Sandbox Code Playgroud)

这是怎么回事?

我在Debian/Sid i686 GNU/Linux上使用Python 2.6.6(r266:84292,2010年12月27日,00:02:40)[GCC 4.4.5].

编辑:来自Sven Marnach的使用bool("")的精彩提示.brb,关闭编辑一些代码......

python

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

在不同的浏览器中使用Jquery

编辑澄清

我发现不同的浏览器对jquery(javascript)错误有不同的容忍度.例如,缺少一个分号,或者在数组中给最后一个元素添加一个逗号,但是有些人忽略了它,但是没有被其他人忽略.当我使用.css('width', - myfunc(iwidth))而不是.css('width',myfunc(-iwidth))时,发生了ie8独有的一个问题.它抛出了涉及jquery1.4.js文件的无用错误消息.

我试图在Firefox中将javascript错误设置为严格,但是被消息淹没到荒谬的程度.

有没有办法设置严格的js设置,所以前面提到的类型的错误导致错误消息,没有洪水?

澄清:

让我澄清一下,因为人们似乎误解了我.我想我的批评是jquery,当时这不是我真正的问题.我的意图不是让错误的代码工作.显然,如果可以的话,我会写出完整的代码,没有错别字和错误,但后来我不会成为人类.我使用不同的浏览器调试我的js/jquery代码并调试插件,例如firefox上的firebug.但是,这看起来似乎不足,因为浏览器试图修复错误的代码.

我将尝试使用xsfer建议使用jslint.有没有类似jslint的东西我可以在本地使用,在Linux上离线,如果浏览器不合适?

error-handling jquery cross-browser

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