由于我的python源文档全部用uft-8编码。在把wxpython下新版pyshell merge到我的自己的修改中时,
发现了这个问题,当我把文件加上utf-8的magic code时,有时merge会出现乱码,因为我的utf-8源文
件有中文字符,不得已只好外挂了另一个merge软件。而且其merge实在太简单了
。
ygao的网络日志 | ygao’s blog
由于我的python源文档全部用uft-8编码。在把wxpython下新版pyshell merge到我的自己的修改中时,
发现了这个问题,当我把文件加上utf-8的magic code时,有时merge会出现乱码,因为我的utf-8源文
件有中文字符,不得已只好外挂了另一个merge软件。而且其merge实在太简单了
。
我以为wxPython下的Pycrust或pyshell不再有变化,我自行增强了部分功能。
不过最近的wxPython版本,有些功能和我增加的功能有重合。不过我的更完美一些。
比如退出时自动保存的功能,只要是输入或输出都会自动保存。
不过它有的功能,我会整合进我的版本中来。
2006.03.19
不想另写一篇blog了,已有功能整合完毕。Extended the saving of the config info and other new features to the PyShell app、PyCrust。我把这个功能扩展到pyalamode了。


todo:
最大的愿望,把调试功能整合进来。
python跟ruby在本质上没有不同。都是面向对象的脚本语言。我不认为ruby比python更OO.
特别是从python2.2版开始。当然从语言来说,后起的ruby在OO上给予了更多的灵活性。
ROR现在是风头一时无出其右,但要经得住时间的考验,难说。
在web上才是真正需要考虑性能的地方。在性能上它能跟PHP比吗?我指的是在客户端上表现出来的能力。python在这一点是不能跟php比的。Eric Raymond说过的:"python最大的不足之处在于:(运行的时候)效率不高,太慢,不但跟编译语言相比慢,就是跟其他脚本语言相比也显得慢。"在web上可以这样说吧。
zope/plone当年不也是很风光吗,但至今也未进入主流。那时多少人认为python将是明日新星。
zope/plone把python语言的强大及不足都做到了语言所给予的极致。
最初是在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 [ 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.
Imgsizer is a utility that rewrites WWW pages so that image-inclusion tags
get the right image size parameters automatically plugged in (this speeds up
page loading on many browsers). You can find sources and documentation in the
URL WWW tools subdirectory of the
ibiblio archive.
The dynamic string handling and sophisticated regular-expression matching
required would have made imgsizer quite painful to write in C or C++; that
version would also have been much larger and harder to read. Java would have
solved the implicit memory-management problem, but is hardly more expressive
than C or C++ at text pattern
matching.
In Chapter?1
we examined the fetchmail/fetchmailconf pair as an example of one
way to separate implementation from interface. Python’s strengths are well
illustrated by fetchmailconf.
fetchmailconf uses the Tk toolkit to implement a multi-panel GUI
configuration editor (Python bindings also exist for GTK+ and other toolkits,
but Tk bindings ship with every Python interpreter).
In expert mode, the GUI supports editing of about sixty attributes divided
among three panel levels. Attribute widgets include a mix of checkboxes, radio
buttons, text fields, and scrolling listboxes. Despite this complexity, the
first fully-functional version of the configurator took me less than a week to
design and code, counting the four days it took to learn Python and Tk.
Python excels at rapid prototyping of GUI interfaces, and (as
fetchmailconf illustrates) such prototypes are often deliverable. Perl and Tcl have
similar strengths in this area (including the Tk toolkit, which was written for
Tcl) but are hard to control at the complexity level (approximately 1400 lines)
of fetchmailconf. Emacs Lisp is not
suited for GUI programming. Choosing Java would
have increased the complexity overhead of this programming task without
delivering significant benefits for this nonspeed-intensive
application.
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.
<<Programming Ruby: The Pragmatic Programmer’s Guide>>
你怎么谈起了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.
Since then a lot of people have become interested in Ruby. Believe it or not, Ruby is actually more popular than Python in Japan right now. I hope that eventually it will be just as well received all over the world.
以上不与perl比而直接与python比。
我并未看到Ruby从什么语言而来,它横空出世。相反python能自称从什么而来。它没有python那么样的历史。
它是这样来的:
Years later I talked with colleagues about scripting languages, about their power and possibility. As an object-oriented fan for more than fifteen years, it seemed to me that OO programming was very suitable for scripting too. I did some research on the ‘net for a while, but the candidates I found, Perl and Python, were not exactly what I was looking for. I wanted a language more powerful than Perl, and more object-oriented than Python.
Then, I remembered my old dream, and decided to design my own language. At first I was just toying around with it at work. But gradually it grew to be a tool good enough to replace Perl. I named it Ruby—after the precious red stone—and released it to the public in 1995.
我们没有能看到它的来历,只看到一瞬间的创造。
最后,在绪言中的某些部分,用python换掉Ruby再读未尝不可。
我知道python中自省的提法,来自于某个专家。我看过原文,其作者也并未完全肯定这种说法是否适当。
真是“忽如一夜春风来,千树万树梨花开”,这之后我看到过多种出现在python这种概念的场合,不知道在讲什么。作为学术性的提法,无可厚非。“自省”只有人才有吧。从未看到过有哪种语言有这种美称。把无数的光
环加到某个事物上,并不能改变它的本质。是概念就都要准确的反映事物的本质。
当然:反对一个东西,只有提出来了你的解决方法,你的反对才有效。
我曾在某个地方看到过:反射这个概念的提法。我以为这个适合代替“自省”的提法。
Lisp、Python、Ruby 和 Smalltalk 等语言也有反射。面向对象的语言多少总有一些。
至于强不强大,无损于反射这个概念的使用。它们的本质是一样的。
下面是两种观点:
Bruce Tate:
http://www-128.ibm.com/developerworks/cn/opensource/os-lightweight7/
反射(Reflection) 是使用 API 找到给定对象基本构建块的能力。在 Ruby 中,反射是很容易的。一切都是对象,一切都是类。可以向任何类询问它的类、它的父类或它所支持的方法。
侯捷观点:
http://www.wnetw.com/jclub/technology/read.jsp?itemid=601
一般而言,开发者社群说到动态语言,大致认同的一个定义是:“程序运行时,允许改变程序结构
或变量类型,这种语言称为动态语言”。从这个观点看,Perl,Python,Ruby是动态语言,C+
+,Java,C#不是动态语言。
尽管在这样的定义与分类下Java不是动态语言,它却有着一个非常突出的动态相关机制:
Reflection。这个字的意思是“反射、映象、倒影”,用在Java身上指的是我们可以于运行时加
载、探知、使用编译期间完全未知的classes。换句话说,Java程序可以加载一个运行时才得知名
称的class,获悉其完整构造(但不包括methods定义),并生成其对象实体、或对其fields设
值、或唤起其methods1。这种“看透class”的能力(the ability of the program to
examine itself)被称为introspection(内省、内观、反省)。Reflection和
introspection是常被并提的两个术语。