Giter VIP home page Giter VIP logo

interpy-zh's Issues

带参数的装饰器的最后一个示例email_logit写的有问题,运行报错

运行代码:

email_logit._logfile = 'out3.log' # 如果需要修改log文件参数
@email_logit
def myfunc2():
    pass

myfunc2()

错误如下:


TypeError Traceback (most recent call last)
/tmp/ipykernel_74/2250255109.py in
1 email_logit._logfile = 'out3.log' # 如果需要修改log文件参数
2 @email_logit
----> 3 def myfunc2():
4 pass
5

/tmp/ipykernel_74/2465603354.py in init(self, email, *args, **kwargs)
5 def init(self, email='[email protected]',*args, **kwargs):
6 self.email = email
----> 7 super(email_logit, self).init(*args, **kwargs)
8
9 def notify(self):

TypeError: init() missing 1 required positional argument: 'func'

我进行了修改,修改后的email_logit代码如下:

class email_logit(logit):
    '''
    一个logit的实现版本,可以在函数调用时发送email给管理员
    '''
    def __init__(self, func, email='[email protected]',*args, **kwargs):
        self.email = email
        super(email_logit, self).__init__(func,*args, **kwargs)

    def notify(self):
        # 发送一封email到self.email
        # 这里就不做实现了
        print("Send email!")
        pass

再次运行后结果如下:

myfunc2 was called
Send email!

关于map的返回类型

在4.1Map小节里的"squared = list(map(lambda x: x**2, items))"里的“list”是否多余?因为map返回类型就是list。
e3d7abe2-6a3d-4921-9d19-6e3c20200477

排版错误

在pdf35页,最后一句话出现了两个错误。
1、多了一个括号
2、应该是"now you are in the welcome() function" 而不是 "now you are in the greet() function"

image

“open函数” 章节的一个错误

在 “open函数” 章节里有一处错误语句:“对于计算机来说,所有的问题件都是字节”。
正确句子应该是 “对于计算机来说,所有的文件都是字节”。

Generators章节的建议

在定义Iterable或Iterator的含义时,直接按照英文的顺序翻译过来效果并不好,中文会让人理解错误。

原文:
一个迭代器是任意一个对象,只要它定义了一个next(Python2) 或者next方法。
建议:
任意一个对象,只要定义了next(Python2) 或者next方法,它就是迭代器。

pdf版本显示不完整

文中的部分长名函数显示不全,没法换行,缩放不起作用,如图为第一个装饰器那一章

image

Filter章节中的一些疑问

less_than_zero = list(filter(lambda x: x < 0, number_list))

filter本身会生成一个列表,是否可以去掉list

Github直接阅读的体验改善

一些v2ex网友(@nightv2 )反馈,github直接阅读时,想增加回到目录的链接。

这个需要参考下别的github书籍来改进一下, 一个可改进的就是,

我们的一些小节非常短,可以合并成一个大节,这样就可以减少翻页和回到目录的需求

甚至,可以合成一个超大单页书

部分延伸内容扩充的问题

由v2ex网友glumes提出:

python 新手,想用 python 做一些更炫的事情的话,大多要导入其他模块吧。
所以,楼主能给些建议如何去知道了解有第三方模块,以及学习掌握他们呢?

17.0 lambda表达式 最后的例子-列表并行排序在python3中失效

列表并行排序,原来的代码

    data = zip(list1, list2)
    data.sort()
    list1, list2 = map(lambda t: list(t), zip(*data))

python3中报错:
AttributeError: 'zip' object has no attribute 'sort'

应该改为

    data = zip(list1, list2)
    data = sorted(data)
    list1, list2 = map(lambda t: list(t), zip(*data))

这是因为在python2中zip()返回的是list类型,而在python3中返回的是zip类型(一种可迭代类型),所以不能用sort(),而应该改为sorted()。

P.S. 原库 intermediatePython 目前也有这个问题

已捐赠

加个微信好友可好。 mcx1469

使用C扩展部分 Python/C API 有问题

int n;
char *s;
PyObject* list;
PyArg_ParseTuple(args, "siO", &n, &s, &list);

PyArg_ParseTuple(args, "siO", &n, &s, &list);&n&s 的顺序写反了。
应为

int n;
char *s;
PyObject* list;
PyArg_ParseTuple(args, "siO", &s, &n, &list);

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.