473,221 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

lesson to learn

Hi,

I spent a couple hours today trying to track down this bug

It went something like this

def fcn(day):
print "day is ", day
if (day < 10):
print "day is less than 10"
else:
if day < 20 :
print "day is less than 20 but greater than 10"
fcn(14)

It never fell into the < 20 but > 10 loop in my 'code from my file'

but if i ran interactively it always did.

And thats what drove me crazy until I came up with this check
as a replacement:

instead of if day < 10:

i tried

if (10 - day) > 0:
blah......

And when I did that I got an exception immediately saying I couldn't
compare a string to an int.

And that was when I remembered, in my code (file version) there was a point
where under certain circumstances I was setting day to "N/A" and indeed it
was really a string.

In the file version this was just one function of a 600 line file. So its
almost like I could have saved myself the trouble by either using some sort
of hungarian notation or perhaps make some rules, or just always do checks
like that to catch little sneaky errors.....

David
Jul 18 '05 #1
2 1325
David R. Stockwell (wg-xiao) wrote:
def fcn(day):
you could add the following line here:

assert type(day) is int, "day must be int"

or:
if type(day) is not int:
raise TypeError("day must be int")
print "day is ", day
if (day < 10):
print "day is less than 10"
else:
if day < 20 :
print "day is less than 20 but greater than 10"


--Irmen
Jul 18 '05 #2
David R. Stockwell (wg-xiao) wrote:
def fcn(day):
print "day is ", day
if (day < 10):
print "day is less than 10"
else:
if day < 20 :
print "day is less than 20 but greater than 10"


Why not use elif: instead of else: if:?
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Rob | last post by:
i know javascript, vbscript, asp css and alot more and im only 14 i was wondering which is easier to learn php or cgi. any help?
19
by: Onideus Mad Hatter | last post by:
http://www.backwater-productions.net/_test_platform/cbstory/ Works perfect in IE but in Netscape/Firefox it fuxors. The problem is the transparent image overlays. The obvious approach would be...
4
by: Jaga | last post by:
DataSet & XML Lesson 1 multidimensional XML data This is a known issue (KnowledgeBase 325696) "Although this XML document is well formed, it contains structure that Data view cannot display....
0
by: Jaga | last post by:
DataSet & XML Lesson 2 2*complex + 2*simple = 2much ? Hello, I have a XSD file with a valid schema (see below). I can see the schema-diagram in the XML-Designer of VisualStudio well, but when...
2
by: DCMyers1 | last post by:
I am trying to create a database to store my lesson plans in and I have hit a problem that I am sure is simple to solve but my lack of access (2000) ability is getting in the way. What I want to...
0
by: Joe Mayo | last post by:
I've recently updated the C# Tutorial at C# Station with a new addition, Lesson 17: Enums. The C# Tutorial may be found at http://www.csharp-station.com/Tutorial.aspx. Other updates include:...
3
by: Juan R. | last post by:
In http://canonicalscience.blogspot.com/2006/04/scientific-language-canonml-is.html] I presented some generic requirements for a markup language for science and mathematics. Basic features of...
31
by: anand devarajan | last post by:
hi friends, im anand im just a beginner in c learning for the past two weeksnow i can write simple prgs can anyone help me to get well known to c lang so that i should able to write even tough...
4
by: Dave White | last post by:
Hello everyone, I would like to assign a lesson to many students as a group rather than individually. Any suggestions would be appreciated. Dave White
65
by: Chris Carlen | last post by:
Hi: From what I've read of OOP, I don't get it. I have also found some articles profoundly critical of OOP. I tend to relate to these articles. However, those articles were no more objective...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.