473,378 Members | 1,106 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,378 software developers and data experts.

How to catch these kind of bugs in Python?

Is there anyway to catch the following type of bug in Python code:

message = 'This is a message'
# some code
# some more code
if some_obscure_condition:
nessage = 'Some obscure condition occured.'
# yet more code
# still more code
print message
In the above example, message should be set to 'Some obscure condition
occured.' if some_obscure_condition is True. But due to a lack of
sleep, and possibly even being drunk, the programmer has mistyped
message. These types of bugs would easily be caught in languages that
have a specific keyword or syntax for declaring variables before use.
I'm still fairly new to using Python on a more than casual basis, so I
don't know if Python has anyway to help me out here.

-- Arcadio

Aug 19 '06 #1
3 1452
"asincero" <as******@gmail.comwrites:
In the above example, message should be set to 'Some obscure condition
occured.' if some_obscure_condition is True. But due to a lack of
sleep, and possibly even being drunk, the programmer has mistyped
message. These types of bugs would easily be caught in languages that
have a specific keyword or syntax for declaring variables before use.
I'm still fairly new to using Python on a more than casual basis, so I
don't know if Python has anyway to help me out here.
Unit testing, running pylint, pychecker, etc.

--
Jorge Godoy <jg****@gmail.com>
Aug 19 '06 #2
asincero wrote:
Is there anyway to catch the following type of bug in Python code:

message = 'This is a message'
if some_obscure_condition:
nessage = 'Some obscure condition occured.'
print message
In the above example, message should be set to 'Some obscure condition
occured.' if some_obscure_condition is True. But due to a lack of
sleep, and possibly even being drunk, the programmer has mistyped
message. These types of bugs would easily be caught in languages that
have a specific keyword or syntax for declaring variables before use.
There are tools that help (e.g. pychecker), but there are a few things
to consider:

1) If the programmer is sleepy/drunk, you're going to have other bugs
too (logical errors, not handling all cases, etc.)

2) Other languages would catch *some* types of these bugs, but would
still miss some of them (I can see a sleepy programmer also using the
wrong variable instead of just mistyping the right one).

So while a tool might assist, it's worth your while to also consider
some strategies for tackling the above two problems and, in the
process, the sleepy-programmer-mistype bugs will get caught as well.
Some type of testing is probably the best answer - be it reusable unit
tests or, at the very least, some interactive testing of code snippets
(which Python makes really easy to do).

-Dave

Aug 19 '06 #3
asincero wrote:
Is there anyway to catch the following type of bug in Python code:

message = 'This is a message'
# some code
# some more code
if some_obscure_condition:
nessage = 'Some obscure condition occured.'
# yet more code
# still more code
print message
In the above example, message should be set to 'Some obscure condition
occured.' if some_obscure_condition is True. But due to a lack of
sleep, and possibly even being drunk, the programmer has mistyped
message. These types of bugs would easily be caught in languages that
have a specific keyword or syntax for declaring variables before use.
I'm still fairly new to using Python on a more than casual basis, so I
don't know if Python has anyway to help me out here.
The keyword is "obscure condition". The solution is to use a coverage
tool and create unit tests that give you 100% code coverage.

Aug 19 '06 #4

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

Similar topics

17
by: Achim Domma | last post by:
Hi, I'm using Python 2.3s timeout sockets and have code like this to read a page from web: request = ... self.page = urllib2.urlopen(request) and later:
83
by: kartik | last post by:
there seems to be a serious problem with allowing numbers to grow in a nearly unbounded manner, as int/long unification does: it hides bugs. most of the time, i expect my numbers to be small. 2**31...
3
by: Brett C. | last post by:
Anthony Baxter, our ever-diligent release manager, mentioned this past week that Python 2.3.5 will most likely come to fruition some time in January (this is not guaranteed date). This means that...
3
by: John | last post by:
Hello I know this is extremely basic, I just want to make sure I got it right. is: try{} catch{} the same as try{}
24
by: Steven T. Hatton | last post by:
If I understand correctly, I have no assurance that I can determine the type of a simple class instance thrown as an exception unless I explicitly catch it by name. (non-derived classes having no...
2
by: robert | last post by:
When employing complex UI libs (wx, win32ui, ..) and other extension libs, nice "only Python stack traces" remain a myth. Currently I'm hunting again a rare C-level crash bug of a Python based...
8
by: shuisheng | last post by:
Dear All, We meet some problem in our project development and sincerely ask for your kind advice. We took eight months to develop a project system with about 50,000 lines of code. The code is...
3
by: yinglcs | last post by:
I read the document here about exception handling in python: http://www.diveintopython.org/file_handling/index.html Can you please tell me how can I catch all exception in python? like this in...
7
by: Mike Kent | last post by:
It's often useful for debugging to print something to stderr, and to route the error output to a file using '2>filename' on the command line. However, when I try that with a python script, all...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.