473,721 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strange error I can't figure out...

Hello,

I have an odd kind of Heisenbug in what looks like a pretty simple program. The
program is a progress bar code I got at the Python Cookbook:

http://aspn.activestate.com/ASPN/Coo.../Recipe/168639

(including the code below)
If you uncomment the one print statement I added in the progressBar class, you get
the error:

File "test_progress2 .py", line 19
diffFromMin = float(self.amou nt - self.min)
^
SyntaxError: invalid syntax
yet, without the print statement, it works fine. what am I overlooking here?
thanks,
bb

#------------------------------------------------------------------------

class progressBar:
def __init__(self, minValue = 0, maxValue = 10, totalWidth=12):
self.progBar = "[]" # This holds the progress bar string
self.min = minValue
self.max = maxValue
self.span = maxValue - minValue
self.width = totalWidth
self.amount = 0 # When amount == max, we are 100% done
self.updateAmou nt(0) # Build progress bar string

def updateAmount(se lf, newAmount = 0):
if newAmount < self.min: newAmount = self.min
if newAmount > self.max: newAmount = self.max
self.amount = newAmount

# print "hello" #<-------------- uncomment line to break

# Figure out the new percent done, round to an integer
diffFromMin = float(self.amou nt - self.min)
percentDone = (diffFromMin / float(self.span )) * 100.0
percentDone = round(percentDo ne)
percentDone = int(percentDone )

# Figure out how many hash bars the percentage should be
allFull = self.width - 2
numHashes = (percentDone / 100.0) * allFull
numHashes = int(round(numHa shes))

# build a progress bar with hashes and spaces
self.progBar = "[" + '#'*numHashes + ' '*(allFull-numHashes) + "]"

# figure out where to put the percentage, roughly centered
percentPlace = (len(self.progB ar) / 2) - len(str(percent Done))
percentString = str(percentDone ) + "%"

# slice the percentage into the bar
self.progBar = self.progBar[0:percentPlace] + percentString +
self.progBar[percentPlace+le n(percentString ):]

def __str__(self):
return str(self.progBa r)
if __name__ == "__main__":

import time
prog = progressBar(0, 100, 77)
for i in xrange(101):
prog.updateAmou nt(i)
print prog, "\r",
time.sleep(.05)
Feb 18 '06 #1
3 1355
It works fine for me. You must be having an indentation problem.

Also, get rid of the comma at the end of that last print statement.

Brian Blais wrote:
Hello,

I have an odd kind of Heisenbug in what looks like a pretty simple
program. The program is a progress bar code I got at the Python Cookbook:

http://aspn.activestate.com/ASPN/Coo.../Recipe/168639

(including the code below)
If you uncomment the one print statement I added in the progressBar
class, you get the error:

File "test_progress2 .py", line 19
diffFromMin = float(self.amou nt - self.min)
^
SyntaxError: invalid syntax
yet, without the print statement, it works fine. what am I overlooking
here?
thanks,
bb

#------------------------------------------------------------------------

class progressBar:
def __init__(self, minValue = 0, maxValue = 10, totalWidth=12):
self.progBar = "[]" # This holds the progress bar string
self.min = minValue
self.max = maxValue
self.span = maxValue - minValue
self.width = totalWidth
self.amount = 0 # When amount == max, we are 100% done
self.updateAmou nt(0) # Build progress bar string

def updateAmount(se lf, newAmount = 0):
if newAmount < self.min: newAmount = self.min
if newAmount > self.max: newAmount = self.max
self.amount = newAmount

# print "hello" #<-------------- uncomment line to break

# Figure out the new percent done, round to an integer
diffFromMin = float(self.amou nt - self.min)
percentDone = (diffFromMin / float(self.span )) * 100.0
percentDone = round(percentDo ne)
percentDone = int(percentDone )

# Figure out how many hash bars the percentage should be
allFull = self.width - 2
numHashes = (percentDone / 100.0) * allFull
numHashes = int(round(numHa shes))

# build a progress bar with hashes and spaces
self.progBar = "[" + '#'*numHashes + ' '*(allFull-numHashes) + "]"

# figure out where to put the percentage, roughly centered
percentPlace = (len(self.progB ar) / 2) - len(str(percent Done))
percentString = str(percentDone ) + "%"

# slice the percentage into the bar
self.progBar = self.progBar[0:percentPlace] + percentString +
self.progBar[percentPlace+le n(percentString ):]

def __str__(self):
return str(self.progBa r)
if __name__ == "__main__":

import time
prog = progressBar(0, 100, 77)
for i in xrange(101):
prog.updateAmou nt(i)
print prog, "\r",
time.sleep(.05)

Feb 18 '06 #2
John Zenger wrote:
It works fine for me. You must be having an indentation problem.

Also, get rid of the comma at the end of that last print statement.

Brian Blais wrote:
Hello,

I have an odd kind of Heisenbug in what looks like a pretty simple

If you uncomment the one print statement I added in the progressBar
class, you get the error:


talk about a Heisenbug...it disappeared after reading this post...without changing
anything. :)

It reminds me of the many times that IT problems disappear then the tech looks at it.
thanks,
bb

--
-----------------

bb****@bryant.e du
http://web.bryant.edu/~bblais
Feb 18 '06 #3
John Zenger wrote:
Also, get rid of the comma at the end of that last print statement.


This would break the progress bar functionality I think, which is meant
to update a single line.

--
Brian Beck
Adventurer of the First Order
Feb 19 '06 #4

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

Similar topics

2
1508
by: Jeff Homan | last post by:
Hello, I don't know where to begin with this as it's kind of a strange error and I can't figure it out. I've got a form that I pass several variables to a php page. One of the variables is a file that is getting uploaded. The INPUT is type "file" and the form enctype is set to "multipart/form-data"
2
1937
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net files\spsweb\0e3514bf\cb1844e7\assembly\dl2\3b163f 16\00452d31_84e5c301\infragistics.webui.ultrawebgrid.v3.dll' could not be found
3
1693
by: Jim in Arizona | last post by:
I'm going insane! I don't know if it's just that the .net 2.0 framework is buggy or if it really is my code. This is pretty hard to explain since I can't even begin to nail down why this is happening. I have two text boxes. One is for the ID number, which when postback occurs, inserts into the related table as the foreign key. The other text box is for notes that go along side the foreign key of the the related table. Basically, the...
0
1473
by: Wescotte | last post by:
<?php global $TABLE_GL_DATA; global $connect; $PREPARED_SQL = odbc_prepare($connect, "INSERT INTO $TABLE_GL_DATA VALUES (?,?,?,?,?,?,?)"); function Generate_GL_Data() {
1
1555
by: JoReiners | last post by:
Hello, I have a really strange problem. I'm unable to figure it out on my own. I parse very simple xml documents, without any check for their form. These files look very similar and are encoded in UTF-8. Now minidom is always able to parse these files with minidom.parse("file") . Now when fetching I use this expression: xmldoc.getElementsByTagName('DocNumb').firstChild.data.encode('latin1')
11
2487
by: Mike C# | last post by:
Hi all, I keep getting a strange error and can't pin it down. The message is: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. However I'm not purposely requesting that the Runtime terminate in an "unusual way." The line that is causing me headaches is:
4
1842
by: tony | last post by:
Hello! My question is about calling this method CollectData below but I get a compile error that I shouldn't have because the type parameter is correct. The compile error is the following: C:\PK\Development\Products\UTCAS\4.0\SRC\MeltPracApplication\Dialog\Composit ionForm.cs(942): Argument '1': cannot convert from 'ref MeltPracData.MeltPracDataComposition' to 'ref MeltPracCommon.IDialogPostData'
11
1848
by: VijaKhara | last post by:
Hi all, I just write a very simple codes in C and vthere is a very strange bug which I cannot figure out why. The first loop is for v, and the second for k. There is no relationship between v and k but if I debug and watch the change of the variable after each command. When the sencond loop happends for k, the values of vs change and are set to be equal some values of k. Specifically, v is
5
1624
by: GuyBowden | last post by:
Hi I'm trying to figure out why a certain server is rendering out strange html Sometimes it renders out html code to the browser window. See here: http://www.itsnotallwork.com/Picture%204.png The source code is absolutely fine - the page always validates. it just sometimes renders out some of the source (different bits each
0
8840
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8007
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.