拼写错误! [英] Spelling mistakes!

查看:128
本文介绍了拼写错误!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了好几个小时试图找到一个简单的拼写错误

错误。


在init方法中我声明了一个变量self .someLongName


稍后在我使用的类的不同方法中

self.sumLongName

现在我的意思是self.someLongName 。

实际上我不想要一个名为sumLongName的变量。

坦率地说,你怎么知道这种类型的错误是否发生?

I''ve spent hours trying to find a bug that was a simple spelling
mistake.

in an init method I declare a variable self.someLongName

later in a different method of the class I use
self.sumLongName
Now I really meant self.someLongName.
In fact I don''t want a variable called sumLongName.
Frankly how are you ever to know if this type of error is occuring?

推荐答案

KraftDiner写道:
KraftDiner wrote:
坦率地说,你怎么知道是否发生了这种类型的错误?
Frankly how are you ever to know if this type of error is occuring?




通过追溯:


modelnine @ phoenix~



By the traceback:

modelnine@phoenix ~


python

Python 2.4.2(#1,2005年12月22日,17:27:39)
linux2上的
[GCC 4.0.2(Gentoo 4.0.2-r2,pie-8.7.8)]

键入help,copyright,credit等。或许可证或更多信息。
python
Python 2.4.2 (#1, Dec 22 2005, 17:27:39)
[GCC 4.0.2 (Gentoo 4.0.2-r2, pie-8.7.8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
class x(object):
.... def __init __(self):

.... self.somename =" hello"

.... def somemethod(self):

.... print self .sumname

.... a = x()
a.somemethod()
Traceback(最近一次调用最后一次):

文件" ;< stdin>",第1行,在?

文件"< stdin>",第5行,在某些方法中

AttributeError:''x' '对象没有属性''sumname''
class x(object): .... def __init__(self):
.... self.somename = "hello"
.... def somemethod(self):
.... print self.sumname
.... a = x()
a.somemethod() Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 5, in somemethod
AttributeError: ''x'' object has no attribute ''sumname''




AttributeError描述了这一点。请不要开始讨论如何更好地编译语言,因为他们在编译时发现了这种错误。它们根本就不是。


--- Heiko。



AttributeError describes just this. And please don''t start the war on how
much better compiled languages are because they catch this kind of error at
compile time. They simply are not.

--- Heiko.


VBScript允许您指定声明变量名称。我用

认为这很好 - 直到我意识到Python允许你使用各种技巧动态地在名称空间中分配属性。

(Setattr,使用__dict__等)。


这是用Python无法实现的。在实践中很少发生在我身上

并且很容易修复。


一切顺利,


Fuzzyman
http://www.voidspace.org.uk/python /index.shtml

VBScript allows you to specify that variable names be declared. I used
to think this was good - until I realised that Python allows you to
dynamically assign attributes in namespaces using all sorts of tricks.

(Setattr, using __dict__ etc).

It''s just not possible with Python. Rarely happens to me in practise
and is easy to fix.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml


这篇关于拼写错误!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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