对于将进行面向文件工作的 IT 类型:glob、fnmatch、os、os.path 、tempfile 和 shutil。
数据库人员一定听说过 sqlite 和 json。
模拟观众可能想了解随机。
Web 开发人员必须从客户端的角度了解 urllib2。还有 Beautiful Soup 和您选择的 XML 解析器。
Web 开发人员必须从服务器的角度了解logging 和wsgiref。
Modules to cover in a 1-2 hour slot entirely depend on your audience's interest or focus. What other classes are they taking? What are they prepared to make use of immediately?
Be sure to mention math, decimal and datetime and time and re.
For IT-types who will be doing file-oriented work: glob, fnmatch, os, os.path, tempfile, and shutil.
Database folks must hear about sqlite and json.
Simulation audience may want to hear about random.
Web developers must hear about urllib2 from a client point of view. Also Beautiful Soup and an XML parser of your choice.
Web developers must hear about logging and wsgiref from a server point of view.
I'd offer itertools and functools. These modules operate over abstractions that are found everywhere in programming, so I think they are useful to study. Among more practical things, xml modules (xml.dom, xml.sax) can be very useful.
Have a look at PyMOTW (Python Module Of The Week). Although it is not strictly stdlib, it's a great resource of obvious and not so obvious gems of the python stdlib. What's more, it also serves as excellent documentation of the introduced modules.
I'd go for a few modules which make the most sense to a typical computer user/programmer performing typical computer tasks. That way, there's the largest chance that they might actually use python on their own time.
In my opinion, the operations most people will likely perform are file operations, for example going over every file in a directory and performing some action on it.
Therefore, I'd say the modules: os and os.path are probably the most important, and also mention glob, fnmatch and shutil. Also, subprocess might be very useful too, since it tends to get used in the above mentioned context.
Lastly, I'd go with optparse, since that will get them into very quickly making usable, programmer-friendly programs, which hopefully will also encourage them to actually write programs that other people want to use.
In only a one-two hour slot, I would introduce easy_install and the PyPI repository: even if they are not in the standard lib, they enable you to install many other external modules, and it is the first place where to look when you can't find in the standard lib.
Apart from that, I would introduce numpy, re, doctest/unittest, and maybe pickle.
os 和 os.path:因为这些是任何人在 python 中编写独立于平台的代码所需的核心模块,并且学生在学习 os 和 os.path 后可以从 shell 脚本切换到 python 脚本。
os and os.path: because those are the core modules which anyone will require to write platform independent code in python and students can switch from shell script to python script after learning os and os.path.
I think everyone here got all the important ones, except for sys. If you look at actual Python code, sys is probably one of the most commonly used modules (usually because of sys.version).
Also, it's not really a module, but I would mention __future__.
And nobody should use Python without doing import this.
Aside from those you mentioned, I found subprocess and sqlite3 modules particularly useful. But I would certainly advice to students to take a look at the list of standard library modules themselves. Also, from modules outside of standard library, I would mention numpy (or numarray) and pyparsing.
I'd place some weight on the decimal module. If they are beginners at programming, they certainly won't be aware of the implications of floating point accuracy. The decimal module is extremely valuable if working with currency or other units that must retain exact decimal precision through several mathematic operations.
Of course, you'd probably want to touch on situations when you don't need to be that accurate as well.
For science student, a rarely heard but powerful module 'networkx' will be valuable. But they need to install it first. This module is well documented: http://networkx.lanl.gov/index.html
发布评论
评论(16)
1-2 小时内涵盖的模块完全取决于受众的兴趣或关注点。他们还参加哪些其他课程?他们准备立即使用什么?
请务必提及
math
、decimal
、datetime
、time
和re
。对于将进行面向文件工作的 IT 类型:
glob
、fnmatch
、os
、os.path
、tempfile
和shutil
。数据库人员一定听说过
sqlite
和json
。模拟观众可能想了解
随机
。Web 开发人员必须从客户端的角度了解
urllib2
。还有 Beautiful Soup 和您选择的 XML 解析器。Web 开发人员必须从服务器的角度了解
logging
和wsgiref
。Modules to cover in a 1-2 hour slot entirely depend on your audience's interest or focus. What other classes are they taking? What are they prepared to make use of immediately?
Be sure to mention
math
,decimal
anddatetime
andtime
andre
.For IT-types who will be doing file-oriented work:
glob
,fnmatch
,os
,os.path
,tempfile
, andshutil
.Database folks must hear about
sqlite
andjson
.Simulation audience may want to hear about
random
.Web developers must hear about
urllib2
from a client point of view. Also Beautiful Soup and an XML parser of your choice.Web developers must hear about
logging
andwsgiref
from a server point of view.我会提供
itertools
和functools
。这些模块对编程中随处可见的抽象进行操作,因此我认为它们对于研究很有用。在更实际的事情中,xml 模块(xml.dom
、xml.sax
)非常有用。I'd offer
itertools
andfunctools
. These modules operate over abstractions that are found everywhere in programming, so I think they are useful to study. Among more practical things, xml modules (xml.dom
,xml.sax
) can be very useful.查看 PyMOTW(本周 Python 模块)。虽然它不是严格意义上的 stdlib,但它是 python stdlib 的明显和不那么明显的宝石的重要资源。更重要的是,它还可以作为所引入模块的优秀文档。
Have a look at PyMOTW (Python Module Of The Week). Although it is not strictly stdlib, it's a great resource of obvious and not so obvious gems of the python stdlib. What's more, it also serves as excellent documentation of the introduced modules.
我会选择一些对于执行典型计算机任务的典型计算机用户/程序员最有意义的模块。这样,他们就很有可能在自己的时间里使用 python。
在我看来,大多数人可能执行的操作是文件操作,例如检查目录中的每个文件并对其执行某些操作。
因此,我想说模块:os和os.path可能是最重要的,并且还提到glob、fnmatch和shutil。此外,子流程也可能非常有用,因为它往往在上述上下文中使用。
最后,我会选择 optparse,因为这将使他们能够非常快速地制作可用的、程序员友好的程序,这也有望鼓励他们实际编写其他人想要使用的程序。
I'd go for a few modules which make the most sense to a typical computer user/programmer performing typical computer tasks. That way, there's the largest chance that they might actually use python on their own time.
In my opinion, the operations most people will likely perform are file operations, for example going over every file in a directory and performing some action on it.
Therefore, I'd say the modules: os and os.path are probably the most important, and also mention glob, fnmatch and shutil. Also, subprocess might be very useful too, since it tends to get used in the above mentioned context.
Lastly, I'd go with optparse, since that will get them into very quickly making usable, programmer-friendly programs, which hopefully will also encourage them to actually write programs that other people want to use.
我只记得一个很实用的模块:copy。
我经常使用其中的 deepcopy() 。
I just remember a very practical module: copy.
I use the deepcopy() from it quite often.
这在一定程度上取决于他们将要做什么以及他们的水平。
我希望有人在我开始时向我指出的一些模块是:
It depends a little on what they will be doing and what level they are.
Some modules I wish someone pointed out to me when I started are:
我会将 urllib2 添加到列表中。
I would add urllib2 to the list.
在短短一到两个小时的时间内,我将介绍 easy_install 和 PyPI 存储库:即使它们不在标准库中,它们也使您能够安装许多其他外部模块,并且它是第一个位置当您在标准库中找不到时去哪里查找。
除此之外,我还会介绍 numpy、re、doctest/unittest,也许还有 pickle。
In only a one-two hour slot, I would introduce easy_install and the PyPI repository: even if they are not in the standard lib, they enable you to install many other external modules, and it is the first place where to look when you can't find in the standard lib.
Apart from that, I would introduce numpy, re, doctest/unittest, and maybe pickle.
operator
,在已经提到的内容旁边。operator
, next to what's already mentioned.不要忘记 datetime、weakref、pickle、StringIO、heapq,可能是线程。
numpy 也值得一提,尽管它不是来自标准库。
Don't forget about datetime, weakref, pickle, StringIO, heapq, may be threading.
And numpy also worths mentioning, although it is not from the standard library.
os 和 os.path:因为这些是任何人在 python 中编写独立于平台的代码所需的核心模块,并且学生在学习 os 和 os.path 后可以从 shell 脚本切换到 python 脚本。
os and os.path: because those are the core modules which anyone will require to write platform independent code in python and students can switch from shell script to python script after learning os and os.path.
我认为这里的每个人都掌握了所有重要的内容,除了
sys
之外。如果您查看实际的 Python 代码,您会发现sys
可能是最常用的模块之一(通常是因为sys.version
)。另外,它并不是真正的模块,但我会提到
__future__
。没有人应该在不执行
import this
的情况下使用 Python。I think everyone here got all the important ones, except for
sys
. If you look at actual Python code,sys
is probably one of the most commonly used modules (usually because ofsys.version
).Also, it's not really a module, but I would mention
__future__
.And nobody should use Python without doing
import this
.除了您提到的那些之外,我发现 subprocess 和 sqlite3 模块特别有用。但我当然会建议学生自己查看标准库模块列表。另外,在标准库之外的模块中,我会提到 numpy(或 numarray)和 pyparsing。
Aside from those you mentioned, I found subprocess and sqlite3 modules particularly useful. But I would certainly advice to students to take a look at the list of standard library modules themselves. Also, from modules outside of standard library, I would mention numpy (or numarray) and pyparsing.
我会在
decimal
模块上放置一些权重。如果他们是编程初学者,他们肯定不会意识到浮点精度的含义< /a>.如果使用货币或其他必须通过多次数学运算保持精确的小数精度的单位,则十进制模块非常有价值。当然,您可能想要触及您不需要那么准确的情况。
I'd place some weight on the
decimal
module. If they are beginners at programming, they certainly won't be aware of the implications of floating point accuracy. Thedecimal
module is extremely valuable if working with currency or other units that must retain exact decimal precision through several mathematic operations.Of course, you'd probably want to touch on situations when you don't need to be that accurate as well.
对于理科学生来说,一个很少听说但功能强大的模块“networkx”将很有价值。但他们需要先安装它。该模块有详细记录:http://networkx.lanl.gov/index.html
For science student, a rarely heard but powerful module 'networkx' will be valuable. But they need to install it first. This module is well documented: http://networkx.lanl.gov/index.html
没有 timeit 就很难生活
It is hard to live without timeit