Tcl / Tk程序员学习Python - 有什么建议吗? [英] A Tcl/Tk programmer learns Python--any advice?

查看:83
本文介绍了Tcl / Tk程序员学习Python - 有什么建议吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-----开始PGP签名消息-----

哈希:SHA1


我是Tcl / Tk的开发者一段时间以来一直在使用Python,

但是没有看到真正学习该语言的令人信服的理由。

Tkinter中的编程对我来说似乎是多余的,因为我已经有了/>
通过Tcl直接访问该工具包,以及其他Python GUI工具包

我试过--PyQt和wxPython - 对他们的学习曲线感到沮丧。


好​​吧,我终于找到了一个更深入学习Python的好理由:

语言已经直接支持我想要做的事情我的

下一个项目(特别是Mac OS X中的Carbon模块),而Tcl

在我开始之前需要在C中进行大量扩展。我已经决定学习Python的方式可能不那么重要了,如果我坚持使用Tkinter,那么学习曲线将是是

减少。


我已经获得了学习Python所需的所有资源(docs,

书籍,教程) ,所以我的问题是:有没有陷阱

Tcl程序员经常在学习Python时遇到过?我在思考

,特别是关于可能需要忘却的习惯。例如,

如grokking面向对象(现在嵌入了Tcl程序

深入脑中)。


任何建议特别是来自其他有很多经验的程序员在Tcl中获得
,我们表示赞赏。


- -

干杯,< br $>

Kevin Walzer,博士

WordTech软件 - 驯服终端
http://www.wordtech-software.com

sw wordtech-software.com

----- BEGIN PGP SIGNATURE -----

版本:GnuPG v1.4.1(达尔文)

评论:使用GnuPG和Thunderbird - http://enigmail.mozdev.org


iD8DBQFDb3sLJmdQs + 6YVcoRAq5xAJoCbDYeMO58yRPqid4K5W Td1 + PbcgCbBATL

0UppdVmVdcb + AfFUIsvrdrY =

= Hk8w

----- END PGP SIGNATURE -----

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I''m a Tcl/Tk developer who has been dabbling with Python for some time,
but had not seen a compelling reason to really learn the language.
Programming in Tkinter seemed redundant to me since I already have
direct access to that toolkit via Tcl, and the other Python GUI toolkits
I tried--PyQt and wxPython--were frustrating with their learning curve.

Well, I have finally found a good reason to learn Python in more depth:
the language already directly supports things that I want to do in my
next project (specifically the Carbon modules in Mac OS X), whereas Tcl
would require a lot of extending in C before I could get started. I''ve
decided that it''s probably less work to learn the Python way of doing
things, and if I stick with Tkinter, then the learning curve will be
reduced.

I''ve gotten all the approropriate resources for learning Python (docs,
books, tutorials), so my question is this: are there any "gotchas" that
Tcl programmers often encounter in learning Python? I''m thinking
specifically about habits that may require "unlearning," for instance,
such as grokking object orientation (Tcl procedures are now embedded
deep in my brain).

Any advice, particularly from other programmers with a lot of experience
in Tcl, is appreciated.

- --
Cheers,

Kevin Walzer, PhD
WordTech Software - "Tame the Terminal"
http://www.wordtech-software.com
sw at wordtech-software.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDb3sLJmdQs+6YVcoRAq5xAJoCbDYeMO58yRPqid4K5W Td1+PbcgCbBATL
0UppdVmVdcb+AfFUIsvrdrY=
=Hk8w
-----END PGP SIGNATURE-----

推荐答案

在文章< ef *************************** @ FUSE.NET>,

Kevin Walzer< sw@wordtech-software.com>写道:
In article <ef***************************@FUSE.NET>,
Kevin Walzer <sw@wordtech-software.com> wrote:


" Kevin Walzer" < sw@wordtech-software.com>写道:
"Kevin Walzer" <sw@wordtech-software.com> wrote:
我已经获得了学习Python(文档,书籍,教程)的所有合适资源,所以我的问题是:有没有陷阱 ;那个Tcl程序员经常在学习Python时遇到过吗?我正在思考
特别关于可能需要忘却的习惯。例如,像grokking对象取向(Tcl程序现在嵌入我的大脑深处)。
I''ve gotten all the approropriate resources for learning Python (docs,
books, tutorials), so my question is this: are there any "gotchas" that
Tcl programmers often encounter in learning Python? I''m thinking
specifically about habits that may require "unlearning," for instance,
such as grokking object orientation (Tcl procedures are now embedded
deep in my brain).




我不知道Tcl,但是python并没有强迫你成为OO;如果你愿意的话,你可以写出
100%的程序代码。 OTOH,你可能需要其他

人的代码是OO,所以至少你必须能够获得
来阅读和用它。幸运的是,使用现有的OO模块/库比设计和编写它要容易得多,所以你可以轻而易举地使用它来实现



George



I don''t know Tcl, but python doesn''t force you to be OO; you can write
100% procedural code if you want to. OTOH, you''ll probably need other
people''s code that is OO, so at the very least you''ll have to be able
to read and use it. Fortunately, using an existing OO module/library is
much easier than designing and writing it, so you can get away with it
with little effort.

George


文章< ef ****************** *********@FUSE.NET>,

Kevin Walzer< sw@wordtech-software.com>写道:
In article <ef***************************@FUSE.NET>,
Kevin Walzer <sw@wordtech-software.com> wrote:
我是Tcl / Tk的开发人员,他一直在研究Python一段时间,...
好吧,我终于找到了一个学习的好理由更深入的Python:...

任何建议,尤其是来自Tcl中具有丰富经验的其他程序员,都表示赞赏。
I''m a Tcl/Tk developer who has been dabbling with Python for some time,...
Well, I have finally found a good reason to learn Python in more depth:...

Any advice, particularly from other programmers with a lot of experience
in Tcl, is appreciated.




在Tkinter中,你不能命名小部件来指定它们的层次结构;而是当你创建一个新的小部件时,你指定它的父级是
。一个tk名称确实为你生成了

,但你永远不需要它。


你可以使用字典设置和获取Tkinter小部件的属性

表示法:

curr_value = wdg [" property_name"]

wdg [" property_name"] = new_value

如果你不想在

一次设置很多属性,这是非常方便的。


Tkinter中的网格没有比在TK。使用Tkinter的网格时,你可能应该使用
指定行和列。


如果你试图混合tk和Tkinter,请注意清理的Tkinter对象

自己起来。例如,tkFont.Font对象表示在tk中命名为

的字体,但是如果在python中丢失了对它的所有引用,则tk中的

命名字体将被销毁。 br />

完整集成且值得使用的Python特性包括:

- 对象

- 集合类(包括列表,字典)并设置)

- 异常处理

- 函数的默认参数


tcl是一个不寻常的解析每个字符串的愿望作为一个命令。它b / b
有加号和减号,但无论如何,你必须学会​​没有(就像转换到几乎任何其他语言时那样)。


- Russell



In Tkinter you don''t name widgets to specify their hierarchy; instead
when you create a new widget you specify it''s parent. A tk name does get
generated for you, but you''ll never need it.

You can set and get properties on Tkinter widgets using dictionary
notation:
curr_value = wdg["property_name"]
wdg["property_name"] = new_value
this is very convenient if you don''t want to set a lot of properties at
once.

Grid in Tkinter has less useful defaults than in tk. You should probably
specify row and column when using Tkinter''s gridder.

If you try to mix tk and Tkinter, beware of Tkinter objects that clean
up after themselves. For instance a tkFont.Font object represents a
named font in tk, but if you lose all references to it in python, the
named font in tk is destroyed.

Features of Python that are well integrated and well worth using include:
- objects
- collection classes (including list, dict and set)
- exception handling
- default arguments for functions

tcl is a unusual in its desire to parse every string as a command. It
has plusses and minuses, but in any case, you''ll have to learn to do
without (as you would when switching to almost any other language).

-- Russell


这篇关于Tcl / Tk程序员学习Python - 有什么建议吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆