小编zjm*_*126的帖子

'__getnewargs__'在这段代码中做了什么

class NavigableString(unicode, PageElement):

    def __new__(cls, value):
        if isinstance(value, unicode):
            return unicode.__new__(cls, value)
        return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING)

    def __getnewargs__(self):#this line
        return (NavigableString.__str__(self),)
Run Code Online (Sandbox Code Playgroud)

python

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

Django代码中的'_'做什么?

为什么这个Django代码_在'has favicon'前面使用

has_favicon = models.BooleanField(_('has favicon'))
Run Code Online (Sandbox Code Playgroud)

python django gettext internationalization

10
推荐指数
3
解决办法
4981
查看次数

为什么在课堂上定义'__new__'和'__init__'

我认为你可以在一个类中定义' __init__'或' __new__',但为什么在django.utils.datastructures.py中定义了所有.

我的代码:

class a(object):
    def __init__(self):
        print  'aaa'
    def __new__(self):
        print 'sss'

a()#print 'sss'

class b:
    def __init__(self):
        print  'aaa'
    def __new__(self):
        print 'sss'
b()#print 'aaa'
Run Code Online (Sandbox Code Playgroud)

datastructures.py:

class SortedDict(dict):
    """
    A dictionary that keeps its keys in the order in which they're inserted.
    """
    def __new__(cls, *args, **kwargs):
        instance = super(SortedDict, cls).__new__(cls, *args, **kwargs)
        instance.keyOrder = []
        return instance

    def __init__(self, data=None):
        if data is None:
            data = {}
        super(SortedDict, self).__init__(data)
        if isinstance(data, dict):
            self.keyOrder = …
Run Code Online (Sandbox Code Playgroud)

python class

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

webapp在模板标签中有'elseif'或'elif'吗?

我的代码是:你好!~~~

{% if user %}
    <p>Logged in as {{ user.first_name }} {{ user.last_name }}.</p>
{% elif openid_user%}
    <p>Hello, {{openid_user.nickname}}! Do you want to <a href="{{openid_logout_url}}">Log out?</p>
{% else %}
    <p><a href="/login?redirect={{ current_url }}">google Log in</a>.</p>
    <p><a href="/twitter">twitter Log in</a>.</p>
    <p><a href="/facebook">facebook Log in</a>.</p>
    <p><a href="{{openid_login_url}}">openid Log in</a>.</p>
    <iframe src="/_openid/login?continue=/"></iframe>
{% endif %}
Run Code Online (Sandbox Code Playgroud)

错误是:

TemplateSyntaxError: Invalid block tag: 'elif'
Run Code Online (Sandbox Code Playgroud)

webapp没有'else if'吗?

谢谢

python google-app-engine if-statement

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

'itertools'文件在哪里

import itertools
print itertools#ok
Run Code Online (Sandbox Code Playgroud)

代码还可以

但我找不到itertools文件.

谁能告诉我'itertools文件'在哪里


我的代码运行python2.5

import itertools
print itertools.__file__


Traceback (most recent call last):
  File "D:\zjm_code\mysite\zjmbooks\a.py", line 5, in <module>
    print itertools.__file__
AttributeError: 'module' object has no attribute '__file__'
Run Code Online (Sandbox Code Playgroud)

python python-itertools

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

这是什么意思...... django代码中的"name__icontains"和"description__icontains",

maps = (maps.filter(name__icontains=search_terms) |
            maps.filter(description__icontains=search_terms))
Run Code Online (Sandbox Code Playgroud)

我找不到这个过滤器.

谢谢

python django django-queryset

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

JavaScript允许getter和setter吗?

这是我的代码:

<script type="text/javascript">
var Note=function(){}
Note.prototype = {
    get id()
    {
        if (!("_id" in this))
            this._id = 0;
        return this._id;
    },

    set id(x)
    {
        this._id = x;
    }
}

var a=new Note()
alert(a.id)
</script>
Run Code Online (Sandbox Code Playgroud)

这种风格就像是python,

这是我第一次看到这段代码,

你能不能给我更多关于javascript中'get'和'set'的例子.

谢谢

javascript properties

9
推荐指数
2
解决办法
3998
查看次数

为什么这样做?if - __name__ =='__ main__'

可能重复:
<if name ==" main ":>做什么?

考虑以下代码:

if __name__ == '__main__':
    import pdb
    pdb.run("interact()\n")
Run Code Online (Sandbox Code Playgroud)

以下行是什么意思?

if(__name__=='__main__')
Run Code Online (Sandbox Code Playgroud)

我昏了过去.

python

8
推荐指数
2
解决办法
4837
查看次数

是否有任何方法来unescape'&gt;' 在JavaScript中使用'>'?

我想在JavaScript中转义一些HTML.我怎样才能做到这一点?

javascript jquery

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

如何使用python从字符串定义函数

这是我的代码:

a = \
'''def fun():\n
    print 'bbb'
'''
eval(a)

fun()
Run Code Online (Sandbox Code Playgroud)

但它显示错误:

Traceback (most recent call last):
  File "c.py", line 8, in <module>
    eval(a)
  File "<string>", line 1
    def fun():
      ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

那我该怎么办

谢谢

python string function

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