Size: 5341
Comment:
|
Size: 5284
Comment: 删除对PageComment2组件的引用
|
Deletions are marked like this. | Additions are marked like this. |
Line 80: | Line 80: |
{{{ | |
Line 83: | Line 84: |
}}} 关于强类型的问题,容易犯的错误: 1. ==判断:比如id之类字段,从HTTP的POST数据里来的,通常都是str类型,但数据库中取出的时候就是int,直接去做==判断就会得出False。 |
|
Line 84: | Line 88: |
关于强类型的问题,容易犯的错误: 1. ==判断:比如id之类字段,从HTTP的POST数据里来的,通常都是str类型,但数据库中取出的时候就是int,直接去做==判断就会得出 False。 |
|
Line 96: | Line 98: |
||<^>[[PageComment2]]||<^>[:/PageCommentData:PageCommentData]''|| |
Python最常见10问
gasolin <[email protected]> reply-to [email protected] to python-cn`CPyUG`华蟒用户组 <[email protected]> date Sat, Aug 9, 2008 at 20:44
gasolin 提议:
subject [CPyUG:61885] [https://groups.google.com/group/python-cn/browse_thread/thread/5658c99025660056 10 個所有人都會想問的關於 Python 語言的問題]
- Guido 採用了我們的10個問題,在 python wiki 上弄了個專頁吶
十问
- 為什麼 Python 既是動態語言又是強型別的語言?
[http://wiki.python.org/moin/Why_is_Python_a_dynamic_language_and_also_a_strongly_typed_language Why is Python a dynamic language and also a strongly typed language]?
[wiki:/WhyPyDynamicAndStronglyTyped 中文回答]
- 用哪個 IDE 寫 Python 比較好?
[http://wiki.python.org/moin/Which_IDE_is_good_for_Python Which IDE is good for Python]?
[wiki:/WhichBestIdeForPython 中文回答]
- 有什麼關於 Python 語言的好書?
[http://wiki.python.org/moin/Any_good_Python_book%3F Any_good_Python_book Any good Python book?]
[wiki:/WhereGoodPythonBook 中文回答]
- 學 python 語言能找到工作嗎?
[http://wiki.python.org/moin/Can_I_get_a_job_with_python%3F Can I get a job with python?]
[wiki:/CanGetPythonJob 中文回答]
- 為什麼用縮排而不是用括弧或「End」來分段?
[http://wiki.python.org/moin/Why_separate_sections_by_indentation_instead_of_by_brackets_or_%27end%27 Why separate sections by indentation instead of by brackets or 'end']
[wiki:/WhySectionsByIndentation 中文回答]
- 用哪種 GUI 好?
[http://wiki.python.org/moin/Which_GUI_is_best_for_python%3F Which GUI is best for python?]
[wiki:/WhichBestGuiForpython 中文回答]
- 為什麼 Python 比 xxx 語言慢?
[http://wiki.python.org/moin/Why_is_Python_slower_than_the_xxx_language Why is Python slower than the xxx language]?
[wiki:/WhyPythonSlowerThanxxxLanguage 中文回答]
- 如何開始學習 Python 語言?有什麼好建議嗎?
[http://wiki.python.org/moin/How_to_start_learning_Python%3F_Any_suggestions How to start learning Python? Any suggestions]?
[wiki:/HowtoStartLearningPython 中文回答]
- 有什麼小巧的 Python source 或專案項目可以參考練手?
[http://wiki.python.org/moin/Is_there_any_tiny_project_or_source_for_participation_or_reference Is there any tiny project or source for participation or reference]?
[wiki:/WhereTinyProjectSourceForParticipationReference 中文回答]
- 怎麼在 Windows 上直接跑 Python 程式 (不先安裝 Python)?
[http://wiki.python.org/moin/How_to_make_exe_on_Windows How to make exe on Windows]
[wiki:/HowtoMakeExeOnWindows 中文回答]
增补
from Gary Shi <[email protected]> reply-to [email protected] to python-cn`CPyUG`华蟒用户组 <[email protected]> date Mon, Nov 10, 2008 at 14:38 subject [CPyUG:70834] 关于10个Python语言问题的补充
1. 为什么Python的赋值操作“=”不是表达式? 比如,可以写a=10,可以写a=b=10,但不能写a=(b=10),更不能写while buf = sock.recv(4096): ... 不可否认后种写法在有些时候确实方便,可以少写不少while True: ...
2. 为什么没有do-while循环? 曾经的PEP-315,被defer了,因为老大说不喜欢……
3. 为什么try block的except和final不能一起写? 貌似在py3000中解决了,但要实用还是好遥远……
4. 为什么time.sleep()会抛OSError? 从道理上说,sleep()会返回-1所以应该对应OSError,但实际写的时候基本上新手都会中招,自己写的daemon跑着跑着一个sleep就 被直接throw到整个进程退出。我是觉得,差不多有10%的POSIX调用,返回值是不用检查的,写C的时候有这样的习惯,但在Python里如果忘 记了try..except,后果就会很严重。是不是os模块应该有一个不是那么strict的抛exception的选项?
关于缩排和括号的对比,我个人对缩排倒没有太大的意见,但在几个事情上觉得确实不方便:
1. 邮件标准一般对于行首的空格是自动干掉的,所以在邮件里贴python源代码就变得特别麻烦。 2. 无法自动re-indent,好像很少有程序可以判断原先的indent关系然后重排。 3. 调试的时候,要暂时关掉一段程序比较麻烦,只能写if False:然后把下面的部分indent进去。
关于强类型的问题,容易犯的错误: 1. ==判断:比如id之类字段,从HTTP的POST数据里来的,通常都是str类型,但数据库中取出的时候就是int,直接去做==判断就会得出False。
2. os.exec/os.spawn系调用,一定要求所有参数都是str类型的,有些比如int类型忘记转换就写进去,执行的时候就抛 OSError。
反馈
创建 by -- ZoomQuiet [DateTime(2008-08-12T02:57:01Z)]