菜鸟学Python(2):学而不思则罔(从一个Python Bug谈开)
---温铭 http://blog.csdn.net/wayne92
(转贴请注明出处)
在Python Tutorial Python3.7.1节里面有一个这样的程序:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
在IDLE下编译运行没有问题,但在 Eclipse3.2.0+Pydev1.2.2下运行就会有问题:不管输入什么,都不会从ask_ok函数中退出。很是怪异。
设置断点调试以后才发现:我输入一个字符串后按回车,ok的值就变成了 输入的字符串+'/r' ,多在后面加了一个'/r'。如果在上面程序中每个和ok比较的字符串后面都加'/r',则程序可以在 Eclipse3.2.0+Pydev1.2.2下面按我原来想的那样运行,但就不能在IDLE下运行了:(
把问题发到邮件列表里面请教,有人建议:在 ok= raw_input(prompt)之后加一个 ok = ok.strip(),去掉最后的回车符。果然,这样在两个地方都可以正常运行了。
”学而不思则罔“,为什么会出现这种情况类?在Python Shell 里面help一下:
help(raw_input)
Help on built-in function raw_input in module __builtin__:
raw_input(...)
raw_input([prompt]) -> string
Read a string from standard input. The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled. The prompt string, if given,
is printed without a trailing newline before reading.
所以,我觉得是Pydev对Python的支持不好,在处理 raw_input函数 的时候没有把最后输入的回车符去掉,以至于引起错误。
PS:啥时候有时间去看看Python的源代码,是用c写的,呵呵,应该看的懂吧:)
补记(2006年7月30日):将这个bug提交给了Pydev的用户组, Fabio Zadrozny 的回复是:
Nope, this is a python bug mixed with a bad specification on how a shell is supposed to behave.
Usually shells put a '/n' when you press enter, but the Eclipse console puts '/r/n' and python does not handle it well, as this is not specified anywhere, and does not seem such awkward, my feeling is that it's a python bug, but you can surely argue the other way... so, you can submit a bug to eclipse.org and python.org and see who'll fix it... (or you can handle it in your program).
Cheers,
Fabio
菜鸟学Python(2):学而不思则罔(从一个Python Bug谈开)相关推荐
- python出现file stdin_第一个Python程序hello.py提示出现File stdin,line 1错误
写第一个Python程序hello.py,内容仅有一句,print 'hello world', 运行 Python hello.py 出错,提示: File "" , line ...
- python将一个json字典转换为一个python对象
python将一个json字典转换为一个python对象 示例代码: from collections import OrderedDict import jsondata = '{"nam ...
- 自学python 编程基础知识_一个python编程自学者的历程以及给自学新手的一些建议...
文章原本昨晚已经在电脑写好了,今天准备用手机润润色再发表,结果误操作给删了,又要重新码字,真是日了狗了. 由于手机码字,以下python就用py简称代替了.写之前其实也犹豫再三,一则自己编程水平实在有 ...
- python语言例子_第一个Python实例
1. 第一个Python实例 Python随着时代的进步,变得越来越受欢迎,当然也有它受人喜欢的道理.下面我们首先通过对比来了解一下. 不知道大家有没有学过C或C++,在C语言中输出一个简单的'Hel ...
- 【Python】我的第一个Python游戏:石头剪刀布
最近有粉丝朋友跟云朵君聊到用Python做个石头剪刀布的小游戏.我一寻思,还挺好玩.其实游戏编程是学习如何编程的一个好方法,它会使用许多我们在现实世界中看到的工具,还可以玩一个游戏来测试我们的编程结果 ...
- python如何运行?第一个python小程序示范
我们想要用python编程首先要做的就是安装一些工具,随后学会应用.那么问题来了,我们需要安装什么?python又是怎样运行的呢? 安装什么工具? 1.Python 3.6.5(我安装的,还有很多版本 ...
- python怎么新建工程_pycharm新建一个python工程步骤
小编最近由于工作原因要用到python,一门新的知识需要接触,对于我来说难度还是很大的. python工程目录结构 每次创建一个python工程 PyCharm会创建如下目录 创建时会把python运 ...
- python 第三课 第一个python程序
什么是命令行模式和Python交互模式. 命令行模式 在Windows开始菜单选择"命令提示符",就进入到命令行模式,它的提示符类似C:\>: ┌────────────── ...
- python 2048源码_一个python的2048简单实现
一个python的2048简单实现 2018-11-28 # -*- coding: utf8 -*- import random data = [[0, 0, 0, 0], [0, 0, 0, 0] ...
最新文章
- make: *** [ext/fileinfo/libmagic/apprentice.lo] Er
- SectionIndexer中的getSectionForPosition()与getPositionForSection()
- java(13)内部类
- php自动生成新闻页,自动发布新闻页面的php代码
- python开发笔记软件_图解Python编程神器Jupyter Notebook
- [Unity][FlowCanvas] 预制体中新建的组件无法拖入 GameObject 类型的黑板的解决办法:关闭预制体之后再打开
- 如何部署 OB 社区版
- Apache Spark源码走读之22 -- 浅谈mllib中线性回归的算法实现
- Fiddler抓包7-post请求(json)
- 我来学网络——三种数据通信方式
- arduino超声波测距接线图详细_Arduino:超声波传感器+测距
- 怎么利用计算机求一元三次方程,一元三次方程怎么快速把解求出来?
- priority的用法
- android设置标题颜色设置颜色,设置标题背景颜色
- 网页打开速度很慢,怎么解决?
- 发一些收藏的收费MD5
- 如何建立自己的知识体系?
- vue.js 2 引导 (maybe it is a whiny posts)
- 关于IntelliJ IDEA中的代码自动对齐快捷键没有响应
- scilab安装EMD工具箱