最初是在CU上看到类似的问题,于是我把问题简化到comp.lang.python 去问,起先这个问题让
我迷惑不解,没想到有人也同样吃惊。
>>> s = "g"
>>> t = ""
>>> s[0:0+len(t)] == t
True
>>> s[1:1+len(t)] == t
True
用序列来解释字符序列可行,至少前后一致了。
还有就是 r="dafda\"或r="dafda\\\" 这样的形式会报错。
because it is not legal to end a regular expression with a single backslash (or an odd number of backslashes).
也就是说raw string主要用于regular expression中。
这是一种看法。
特别的, raw string 不能用\作结尾, (因为它会转义接下来的单引号或双引号).
甚至在raw string不能用\作为逻辑行的用法,也就是不能用这个手段把一个物理行拆为两个物理行。
由于我主要在windows下使用python,想收集一下python在这方面的应用,我自己也写了一些小应用。
其中的一个是:最基础的是直接在python在脚本控制系统环境变量,就是set xxxx = yyyy的这种形式。
添加add to pythonpath到右键菜菜;直接在命令行使用脚本,使脚本程序如同真正的程序一样。

Summing up: Python's best side is that it encourages clean, readable code and combines accessibility with scaling up well to large projects. Its worst side is inefficiency and slowness, not just relative to compiled languages but relative to other scripting languages as well.
试译:
总结:python最出色的方面在于,它提倡清晰易读的代码,把这些特
征与可扩展性的大型项目配合得非常好。
最大的不足之处在于:(运行的时候)效率不高,太慢,不但跟编译语言相比慢,就是跟其他脚本语言相比也显得慢。 |
|
|
|
Python is a scripting language designed for
close integration with C. It can both import
data from and export data to dynamically loaded C libraries, and can be called
as an embedded scripting language from C. Its syntax is rather like a cross
between that of C and the Modula family, but has the unusual feature that block
structure is actually controlled by indentation (there is no analog of explicit
begin/end or C curly brackets). Python was first publicly released in 1991.
The Python language is a very clean, elegant design with excellent modularity
features. It offers designers the option to write in an object-oriented style
but does not force that choice (it can be coded in a more classically procedural
C-like way). It has a type system comparable in expressive power to Perl's, including dynamic container objects and
association lists, but less idiosyncratic (actually, it is a matter of record
that Perl's object system was built in imitation
of Python's). It even pleases Lisp hackers with
anonymous lambdas (function-valued objects that can be passed around and used by
iterators). Python ships with the Tk toolkit, which can be used to easily build
GUI interfaces.
The standard Python distribution includes client classes for most of the
important Internet protocols (SMTP, FTP, POP3, IMAP, HTTP) and generator classes
for HTML. It is therefore very well suited to building protocol robots and
network administrative plumbing. It is also excellent for Web CGI work, and
competes successfully with Perl at the
high-complexity end of that application area.
Of all the interpreted languages we describe, Python and Java are the two most clearly suited for scaling up to
large complex projects with many cooperating developers. In many ways Python is
simpler than Java, and its friendliness to rapid prototyping may give it an edge
over Java for standalone use in applications that are neither hugely complex nor
speed critical. An implementation of Python in Java, designed to facilitate
mixed use of these two languages, is available and in production use; it is
called Jython.
Python cannot compete with C or C++ on raw execution speed (though using a
mixed-language strategy on today's fast processors probably makes that
relatively unimportant). In fact it's generally thought to be the least
efficient and slowest of the major scripting languages, a price it pays for
runtime type polymorphism. Beware of rejecting Python on these grounds, however;
most applications do not actually need better performance than Python offers,
and even those that appear to are generally limited by external latencies such
as network or disk waits that entirely swamp the effects of Python's
interpretive overhead. Also, by way of compensation, Python is exceptionally
easy to combine with C, so performance-critical Python modules can be readily
translated into that language for substantial speed gains.
Python loses in expressiveness to Perl for
small projects and glue scripts heavily dependent on regular-expression
capability. It would be overkill for tiny projects, to which shell or Tcl might be
better suited.
Like Perl, Python has a well-established development community with a central website carrying a great
many useful Python implementations, tools and extension modules.
The definitive Python reference is Programming Python [Lutz].
Extensive on-line documentation on Python extensions is also available at the
Python website.
Python programs tend to be quite portable between Unixes and even across
other operating systems; the standard library is powerful enough to
significantly cut the use of nonportable helper programs. Python implementations
are available for Microsoft operating systems
and for MacOS. Cross-platform GUI development is
possible with either Tk or two other toolkits. Python/C applications can be
‘frozen’, quasi-compiled into pure C sources that should be portable to systems
with no Python installed.
Summing up: Python's best side is that it encourages clean, readable code and
combines accessibility with scaling up well to large projects. Its worst side is
inefficiency and slowness, not just relative to compiled languages but relative
to other scripting languages as well.
PIL, the Python Imaging Library, supports the manipulation of bitmap
graphics. It supports many popular formats, including PNG, JPEG, BMP, TIFF, PPM, XBM, and GIF. Python programs can use it to
convert and transform images; supported transformations include cropping,
rotation, scaling, and shearing. Pixel editing, image convolution, and
color-space conversions are also supported. The PIL distribution includes Python
programs that make these library facilities available from the command line.
Thus PIL can be used either for batch-mode image transformation or as a strong
toolkit over which to implement program-driven image processing of bitmaps.
The implementation of PIL illustrates the way Python can be readily augmented
with loadable object-code extensions to the Python interpreter. The library
core, implementing fundamental operations on bitmap objects, is written in C for speed. The upper levels and sequencing logic
are in Python, slower but much easier to read and modify and extend.
The analogous toolkit would be difficult or impossible to write in Emacs
Lisp or shell,
which don't have or don't document a C extension interface at all. Tcl has a good C extension facility, but PIL would be
an uncomfortably large project in Tcl. Perl has
such facilities (Perl XS), but they are ad-hoc, poorly documented, complex, and
unstable by comparison to Python's and use of them is rare. Java's Native Method Interface appears to provide a
facility roughly comparable to Python's; PIL would probably have made a
reasonable Java project.
The PIL code and documentation is available at the project
website.
一个老外写的blog,关于python的,与我的风格相似,值得一看。
比我要强多了!
祝大家新年快乐!
Peter's blog关于 python部分的
摘要:你怎么谈起了Ruby?曾看到有人拿其与python作比较。既然能作比较,自然有可比的地方。今天我不想比什么,只对第一印象谈一谈看法。在这本书中,把python和perl并在一起谈,把Ruby区别于它们。 Perl, TCL, and Python have all been called scripting languages.但Ruby不是“脚本语言”,它是什么?它是--We call Ruby a transparent language.Ruby是transparent language.当然是一门新的语言了。我不知道作者要在这里鼓吹什么?python和Ruby有本质的不同吗?我还是那句话,把光环加于某个事物上,并不能改变其本质。more object-oriented than Python并未能导致Ruby的本质发生改变,至少现在是。Ruby要代替什么?But gradually it grew to be a tool good enough to replace Perl. (全文共1769字)——点击
此处阅读全文
摘要:
我知道python中自省的提法,来自于某个专家。我看过原文,其作者也并未完全肯定这种说法是否适当。
真是“忽如一夜春风来,千树万树梨花开”,这之后我看到过多种出现在python这种概念的场合,不知道在讲什么。作为学术性的提法,无可厚非。“自省”只有人才有吧。从未看到过有哪种语言有这种美称。把无数的光
环加到某个事物上,并不能改变它的本质。是概念就都要准确的反映事物的本质。
当然:反对一个东西,只有提出来了你的解决方法,你的反对才有效。
我曾在某个地方看到过:反射这个概念的提法。我以为这个适合代替“自省”的提法。
Lisp、Python、Ruby 和 Smalltalk 等语言也有反射。面向对象的语言多少总有一些。
至于强不强大,无损于反射这个概念的使用。它们的本质是一样的。
下面是两种观点:
Bruce Tate:
此处阅读全文
Preferences->user interface
font 选simsun字体。
Encoding 选 gb-2312等支持中文的。
摘要:我为什么这样执着---为什么只选一两种开发工具。工具只是工具。把各种各样的工具使用了个遍,仍然只是工具。我最反感那种推荐文章,这个也不错,那个也好。说了等于没说。不分出高下,没什么大用。当然这是我的看法。高下有多种标准。没有基于某个标准的评论,等于瞎说,这只能反映一个人的概念和思路不清。回正题。komodo的调试功能有欠缺,有时在其中断后,与其解释器交互,有时并不能改变被调试程序的行为。我观察了一下,发现它好象仍然是基于python的自带的调试器。其于python自带的调试器调试行为会有限。我的想法越来越被证实。于是我转向了wingIDE2.0,另一个集成开发环境,着重试用了一下它的调试器,比komodo3.1强大多了,惊喜不已。我猜测它的调试器是在解释器的c代码一级,换句话说,可以和解释器平起平坐了。komodo好象是python代码级别。肯定要受限于解释器本身的限制。我对IDE选择调试器的功能应该是第一的。这让我两难了。 (全文共488字)——点击
此处阅读全文
虽然,python容易学,但要想深入,则非朝夕之间就可以,要得心应手,则需要不断实践。
任何语言的学习,都有一个过程。学习是有规律的,尊循规律事半功倍,最终才会有信心学下去,否则没有
大毅力,你不能坚持下去,你对它的看法会动摇。在python的学习上更是如此。在学习的道路上没有经捷径可走,浅尝辄止,往往是不得要领,只能只见树木,不见森林。
登堂易,入室难。不得不承认的是,学习的最后结果,会分出层次高下之别,“万事开头难”,如果说这是一
个错误,那么在你开始时就已经种下了。
在学习阶段,以学习为主,以进行项目为辅;反之,在创造阶段,以开发项目为主,以学习为辅。
明确你自己在哪个阶段是重要的。颠倒这个次序,欲速则不答,如镜中花,如水中月,可望不可及。
在开始时你把错误种下了,你能收获什么?!