Git Product home page Git Product logo

pyzh's Issues

请教:函数的默认参数是列表时我不理解

9.3 注意函数的默认参数
def foo(x=[]): x.append(1); print(x)
foo(); foo()
得到:
[1]
[1, 1]

第一次调用foo() 得到x =[] ,然后x = [1],x指向列表[1]内存中的地址。
但是第二次调用foo() , x = [] 不是把x指向另一个列表[] 的地址吗?

随处翻译

其实我以前想过建立这样一个网站,用户可以对网站浏览的文章的某一部分内容进行评价,标注和翻译,并且可以被其他用户看到,类似于django-book这种形式。然后定期对用户评注内容进行整理。这样对于每一个阅读者,同时他们也是文档编辑的参与者。

不错的项目

觉得需要分类组织一下,否则文章多了后检索很麻烦的。

13. Python Realtime 重复内容

HTTP/1.1还引入了 块传输协议 。 它允许讲响应分解为成更小的数据块,并将它们立即发送到客户端,而不是一直等到完成HTTP请求。

这一部分重复了, 而且是它允许相应

Python描述器引导中的翻译问题

“1.4. 描述器的调用”里面出现了一些混乱。
原文有两段:

For objects, the machinery is in object.__getattribute__() which transforms ...
For classes, the machinery is in type.__getattribute__() which transforms ...

翻译中却变为:

对于对象来讲,方法 type.__getattribute__() 把 。。。

把两段和为了一段,且中间的一部分消失了。

python描述器引导(翻译)疑问

http://pyzh.readthedocs.org/en/latest/Descriptor-HOW-TO-Guide.html#id11

在讲述资料描述符和非资料描述符的区别的时候
资料描述器和非资料描述器的区别在于:相对于实例的字典的优先级。如果实例字典中有与描述器同名的属性,如果描述器是资料描述器,优先使用资料描述器,如果是非资料描述器,优先使用字典中的属性。
译者注:这就是为何实例 a 的方法和属性重名时,比如都叫 foo Python会在访问 a.foo 的时候优先访问实例字典中的属性,因为实例函数的实现是个非资料描述器

这里的原因应该是访问的时候属性查找顺序造成的。先查找obj.__dict__再查找type(obj).__dict__。属性在前一个字典里面,函数在后一个字典里面。data和no-data的主要区别根据描述可以知道仅仅用于区分属性被调用的时候是使用obj.__dict__还是使用描述符规则。

以下例子可能比较合适

class reify(object):
    def __init__(self, wrapped):
        self.wrapped = wrapped

    def __get__(self, inst, objtype=None):
        val = self.wrapped(inst)
        setattr(inst, self.wrapped.__name__, 10)
        return val

    # def __set__(self, instance, value):
    #     return


class A(object):

    @reify
    def a(self):
        return 4

a = A()
print(a.a)

注释掉__set__no-data description,调用a属性使用a.__dict__不注释则为data description,使用描述符规则

另外根据你的注解好像意思是实例字典是一个资料描述符而实例函数是一个非资料描述符。这里的实例字典是指代的obj.__dict__吗?实例函数的实现我没明白指代的是什么。使用isinstance(obj.__dict__,dict)得到True可以看出obj.__dict__实质就是一个dict,是没有__get____set__属性的,因此和data-description&no-data description没有关系

以上如有错误请指出,谢谢~~

如何解决Theme error?

hi.

as3:~/pyzh/docs# make html
sphinx-build -b html -d _build/doctrees . _build/html
Making output directory...
Running Sphinx v1.2b1
loading translations [Zh_CN]... done
loading pickled environment... not yet created

Theme error:
no theme named 'rux' found (missing theme.conf?)
make: *** [html] Error 1
as3:/pyzh/docs# cd ..
as3:
/pyzh# find . -name theme.conf
as3:/pyzh# cd docs
as3:
/pyzh/docs# find . -name theme.conf
as3:~/pyzh/docs#

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.