[Tutor] assigning list to keys

2009-07-14 Thread Todd Matsumoto
Hello,

The other day I needed to pack a dictionary, the value of each key was a list. 
In the code I was packing the list and the dictionary at the same time. First I 
tried something like this:

list = []
dict = {}
x = 1

dict['int'] = list.append(x)

The result was {'int': None}. Why is the value None?

Cheers,

T
-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread Todd Matsumoto
Okay,

So how would you break out from this situation?

T
 Original-Nachricht 
> Datum: Tue, 14 Jul 2009 06:57:41 +
> Von: sli1...@yahoo.com
> An: "Todd Matsumoto" 
> Betreff: Re: [Tutor] While and for loops

> Your break is for the for loop not the while. The condition true never
> goes false so your in a infinite loop
> Sent from my Verizon Wireless BlackBerry
> 
> -Original Message-
> From: "Todd Matsumoto" 
> 
> Date: Tue, 14 Jul 2009 08:49:59 
> To: 
> Subject: [Tutor] While and for loops
> 
> 
> Hello,
> 
> The other day I was playing with a while loop with a for loop nested
> inside.
> 
> Within the for loop I had a condition to break the loop, but when loop ran
> it never existed the loop. I went back and looked in Programming Python to
> read about loops and I've got two questions (related to each other).
> 
> Can you run for loops in while loops and if yes, why did my if condition
> not break the loop?
> 
> I read that loops sort of have an order of precedence, does that have
> anything to do with this problem?
> 
> while True:
> 
> for i in items:
> if i > 10:
> break
> else:
> 
> 
> 
> -- 
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread wesley chun
> Can you run for loops in while loops and if yes, why did my if condition not 
> break the loop?
>
> I read that loops sort of have an order of precedence, does that have 
> anything to do with this problem?


todd,

welcome to Python! you're right in that your questions are related to
each other because the answer to both of your questions is the same:
you can only break out of the innermost loop (from where you have your
break statement). if you need to break out of the outer one, you need
another break statement not contained in another loop.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread A.T.Hofkamp

Todd Matsumoto wrote:

while True:

for i in items:
if i > 10:
break
else:




> Okay,
>
> So how would you break out from this situation?
>

finished = False
while not finished:
 
 for i in items:
 if i > 10:
 finished = True  # Do not do the next while-iteration
 break# and break out of the for loop
 else:
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread Todd Matsumoto
Okay,

I'm not sure if this is good practice, but I could assign a variable within the 
while loop, that is assigned something that will then break the outer loop.

while True:
breakout = True

for i in items:
if i > 10:
breakout = False
else:

if break is False:
break

Is the above do-able? Is there a better way?

T
 Original-Nachricht 
> Datum: Tue, 14 Jul 2009 00:05:30 -0700
> Von: wesley chun 
> An: Todd Matsumoto 
> CC: tutor@python.org
> Betreff: Re: [Tutor] While and for loops

> > Can you run for loops in while loops and if yes, why did my if condition
> not break the loop?
> >
> > I read that loops sort of have an order of precedence, does that have
> anything to do with this problem?
> 
> 
> todd,
> 
> welcome to Python! you're right in that your questions are related to
> each other because the answer to both of your questions is the same:
> you can only break out of the innermost loop (from where you have your
> break statement). if you need to break out of the outer one, you need
> another break statement not contained in another loop.
> 
> hope this helps!
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Core Python Programming", Prentice Hall, (c)2007,2001
> "Python Fundamentals", Prentice Hall, (c)2009
> http://corepython.com
> 
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com

-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread wesley chun
>> So how would you break out from this situation?
>
> finished = False
> while not finished:
>     
>     for i in items:
>         if i > 10:
>             finished = True  # Do not do the next while-iteration
>             break            # and break out of the for loop
>         else:
>             


this solution is workable as well, plus it avoids having 2 break
statements in the code. it "breaks" out of the while-loop in a natural
way, making its conditional False.

-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Python Web Development with Django", Addison Wesley, (c) 2009
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread Todd Matsumoto
Okay,

Thanks guys.

That explains it.

Cheers,

T
 Original-Nachricht 
> Datum: Tue, 14 Jul 2009 00:16:30 -0700
> Von: wesley chun 
> An: "A.T.Hofkamp" 
> CC: Todd Matsumoto , "tutor@python.org" 
> Betreff: Re: [Tutor] While and for loops

> >> So how would you break out from this situation?
> >
> > finished = False
> > while not finished:
> >     
> >     for i in items:
> >         if i > 10:
> >             finished = True  # Do not do the next while-iteration
> >             break            # and break out of the for loop
> >         else:
> >             
> 
> 
> this solution is workable as well, plus it avoids having 2 break
> statements in the code. it "breaks" out of the while-loop in a natural
> way, making its conditional False.
> 
> -- wesley
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "Python Web Development with Django", Addison Wesley, (c) 2009
> http://withdjango.com
> 
> wesley.j.chun :: wescpy-at-gmail.com
> python training and technical consulting
> cyberweb.consulting : silicon valley, ca
> http://cyberwebconsulting.com

-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assigning list to keys

2009-07-14 Thread wesley chun
> The other day I needed to pack a dictionary, the value of each key was a 
> list. In the code I was packing the list and the dictionary at the same time. 
> First I tried something like this:
>
> list = []
> dict = {}
> x = 1
>
> dict['int'] = list.append(x)
>
> The result was {'int': None}. Why is the value None?


the reason why the value is None is because the output of the list
append() method is None (and will always be None unless they change
it).

the sole purpose of the append() method is to add an element to the
end of a list. in your case, you added the integer 1 to your list
named 'list'. that's all it does... 'list' is changed, and no value to
return is necessary, hence the reason why Python returns None. if you
want the last value you appended in your code, you need to access
list[-1].

on another note: you should avoid naming your variables with the same
names as data types, i.e., list, str, dict, tuple, int, etc., because
you shadow/hide the factory function of the same name. in other words,
in your code above, you can no longer access list() nor dict().

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Python Web Development with Django", Addison Wesley, (c) 2009
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread wesley chun
> So how would you break out from this situation?

as i mentioned in my other msg, you need another break statement that
is *not* in another loop. in your case, not in the for-loop. you need
a break statement somewhere within your while block (again, that's not
in any other loop). IOW, it should be indented at the same level as
the for-loop. it's up to you to determine the logic with which you
call your break, because if you just put it out there, your while will
only run at most once (or less than once).

-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread wesley chun
> I'm not sure if this is good practice, but I could assign a variable within 
> the while loop, that is assigned something that will then break the outer 
> loop.
>
> while True:
>    breakout = True
>    
>    for i in items:
>        if i > 10:
>            breakout = False
>        else:
>            
>    if break is False:
>        break
>
> Is the above do-able? Is there a better way?

this will work (once you fix the typo), but i prefer the previous
solution by A.T. since you're trying to do the same thing.

my original suggestion would've been to expand on the problem to find
a proper case to break out of each individual loop separately, i.e.,
you have a reason to break out of the inner one, and a different
reason for breaking out of the outer one.

but in your case, it looks like you're trying to break out of both due
to a single reason, and for that, A.T.'s solution is a more elegant
way to do what you just did above.

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assigning list to keys

2009-07-14 Thread Christian Witts

Todd Matsumoto wrote:

Hello,

The other day I needed to pack a dictionary, the value of each key was a list. 
In the code I was packing the list and the dictionary at the same time. First I 
tried something like this:

list = []
dict = {}
x = 1

dict['int'] = list.append(x)

The result was {'int': None}. Why is the value None?

Cheers,

T
  

Hi,

Appending to a list does so in-place and returns None.  If you wish to 
do what you posted you will need to do it in 2 steps with:


   list.append(x)
   dict['int'] = list

You should also avoid shadowing built-in names like "list", "dict", 
"file" etc as you can very easily end up with unexplained errors.


Hope that helps.

--
Kind Regards,
Christian Witts


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread Alan Gauld
"wesley chun"  wrote 


as i mentioned in my other msg, you need another break statement that
is *not* in another loop. in your case, not in the for-loop. you need
a break statement somewhere within your while block (again, that's not
in any other loop). IOW, it should be indented at the same level as
the for-loop. it's up to you to determine the logic with which you
call your break, because if you just put it out there, your while will
only run at most once (or less than once).


And for completeness that would probably look like:

while True:
   
   for i in items:
   if i > 10:
   break# out of the for
   else:
   
   if i > 10:
   break   # out of the while under the same conditions

But as Wesley said, for this specific case the Found / notFound 
sentinel approach is nicer.


Although there is a school of thought says break statements 
are only slightly less evil than goto and should be avoided if 
possible. In that case you can do it by inverting the logic of 
the tests:


i = 0
while i <= 10:
   
   for i in items:
   if i <= 10:
  

But, as usual with purist approaches the result might look 
neater buts it is far less efficient and less flexible!


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While and for loops

2009-07-14 Thread A.T.Hofkamp

Todd Matsumoto wrote:

Okay,

I'm not sure if this is good practice, but I could assign a variable within the 
while loop, that is assigned something that will then break the outer loop.

while True:
breakout = True

for i in items:
if i > 10:
breakout = False
else:

if break is False:
break


The statement "if break is False:" is wrong.

Your variable is called "breakout" not "break". In fact, you cannot have 
"break" as variable, the above code will not be accepted by the Python 
interpreter.


There are also a few improvements possible:

You want to use "==" for comparing values. The "is" that you use compares 
objects rather than values.


Also, comparing boolean values with True or False in a condition is not 
needed, you can use the boolean value directly. In this case "not breakout" 
will give you the same result.



Albert
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pythonify this code!

2009-07-14 Thread Muhammad Ali
Hi everyone,

Thanks for the comments Dave and Alan!

Based on these I have updated the code... I don't know if this is more
readable.

@Dave: I kept the original separate and combine function with bases as I
thought I would move them to a math library if I need to work in other
bases, however now I have followed your advice and made them more specific
to the solution. I couldn't understand the bit about how to use format.
Could you check it out in the context of the new code? Also didn't get the
bit about zip() either, however it got me thinking and I used map instead.

I am still not very happy about the separateToList function :( and I hope I
haven't been overzealous in using map(). I have also changed the text
concatenation.

Here's the code:

import Image

ENDTEXT = '~~'

def separateToList(num):
"""
changes an integer into a list with 0's padded to the left if the number
is in tens or units
"""
assert(num <= 255)
s = str(num)
li = []
if len(s) > 2:
li = [s[0:1], s[1:2], s[2:3]]
elif len(s) > 1:
li = [0, s[0:1], s[1:2]]
elif len(s) > 0:
li = [0, 0, s[0:1]]

return map(int, li)

def getCharFromRGB(rgb):
"""
takes an rgb tuple and changes it to an ascii char by taking the unit
digits of each color
"""
rgb = map(lambda x: x %10, rgb)
ordChar = int(''.join(map(str, rgb)))
assert(ordChar <= 255)
return chr(ordChar)

def hidePartOfCharInColor(color, charDigit):
"""
take a color as integer not exceeding 255 and replace the unit digit
with one of the ascii char's digit
"""
assert(color <= 255)
color -= (color % 10)
color += charDigit
if (color > 255):
color -= 10
return color

def incrementRowCol(imgWidth, row, col):

row += 1
if row == imgWidth:  row, col = 0, col+1
return row, col

def encode(img, text):
"""
Takes PIL image and any string, encodes the text in the image, saving
the changes to the image
Returns False if text size is greater than pixels
"""
x = 0
y = 0
height, width = img.size
text = text + ENDTEXT

if len(text) > height * width:
return False

pix = img.load()

for c in text:
ordAsList = separateToList(ord(c))
rgb = pix[x, y]
pix[x,y] = tuple(map(hidePartOfCharInColor, rgb, ordAsList))
x, y = incrementRowCol(width, x, y)

img.save(img.filename)
return True

def decode(img):
x = 0
y = 0
charList = []
c = ""
height, width = img.size
pix = img.load()
while True:
lastc = c
c = getCharFromRGB(pix[x, y])
charList.append(c)

if (c + lastc  == ENDTEXT):
return ''.join(charList[:-2])

x, y = incrementRowCol(width, x, y)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pythonify this code!

2009-07-14 Thread A.T.Hofkamp

Muhammad Ali wrote:

def separateToList(num):
"""
changes an integer into a list with 0's padded to the left if the number is 
in tens or units
"""
assert(num <= 255)




s = str(num)
li = []
if len(s) > 2:
li = [s[0:1], s[1:2], s[2:3]]
elif len(s) > 1:
li = [0, s[0:1], s[1:2]]
elif len(s) > 0:
li = [0, 0, s[0:1]]

return map(int, li)


return [int(v) for v in ("00" + str(num))[-3:]]


Albert
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Saving class instances

2009-07-14 Thread Thomas Scrace


On 13 Jul 2009, at 22:04, "Alan Gauld"   
wrote:



That's one way and you can find an example and some advice
on how to handle subclassing in the OOP topic of my tutor.



Wow; thanks!  That tutorial  was really useful, I will have to check  
out the rest

of the site now.


I am sure this has an obvious and easy answer but I just cannot find
it anywhere!


Actually no. Saving and retrieving object instances (known as
persisting objects in OOP speak) was one of the biggest challenges
facing the OOP paradigm when it got started in the real world. Many
different solutions have evolved from flat text files to dedicated  
Object

databases, and everyting in between, but it remains a task frought
with difficulty, especially on large scale projects.



Good to know I wasn't being totally dense.  Now that I have got the  
pickle thing

under my belt I am going to have a go at sqllite.

Thanks again everybody.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pythonify this code!

2009-07-14 Thread Dave Angel

A.T.Hofkamp wrote:
Muhammad 
Ali wrote:

def separateToList(num):
"""
changes an integer into a list with 0's padded to the left if the 
number is in tens or units

"""
assert(num <= 255)




s = str(num)
li = []
if len(s) > 2:
li = [s[0:1], s[1:2], s[2:3]]
elif len(s) > 1:
li = [0, s[0:1], s[1:2]]
elif len(s) > 0:
li = [0, 0, s[0:1]]

return map(int, li)


return [int(v) for v in ("00" + str(num))[-3:]]


Albert




Or
def separateToList(num):
   """
   changes an integer 0-255 into a list of ints, size exactly 3
   """
   return map(int, list(format(num, "03d")))


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pythonify this code!

2009-07-14 Thread A.T.Hofkamp

Dave Angel wrote:

def separateToList(num):
"""
changes an integer 0-255 into a list of ints, size exactly 3
"""
return map(int, list(format(num, "03d")))


Nice!

Note that the "list" conversion is not needed; when you iterate over a string 
you automatically get each character in turn:


map(int, ("%03d" % num))


Albert
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] University student struggling!

2009-07-14 Thread Andrea Semenik
Hello Python Tutors! 

I am a non-computer science major taking a computer programming course.  That 
is the first red flag you should know. Second red flag, the course is poorly, I 
mean poorly written. third red flag, it is a distance education course, so it 
is done online. Needless to say I am in big trouble.  I have been working on 
this assignment for days and have gotten nowhere. here are the directions:

For this assignment, you will create a web script that lets the user explore 
RGB colours. 

On the first page the user sees, they should specify two RGB colours. When they 
submit this page, they should be presented with a range of colours in between 
the two. The intermediate colours will be calculated by your program. 

For example, if the user enters the colours red (100% red, 0% green, 0% blue) 
and white (100% red, 100% green, 100% blue), your program might output a page 
containing this: 
(image of a color box)

If you want, you can experiment with an example of a working colour explorer. 
You can copy HTML and CSS code from this example if you wish. 

The easiest way to create one of the blocks of colour is with a  like 
this: 

 

 
There are a couple of new things here. First, note that you can indicate style 
information with the style attribute on an HTML tag. This is generally a bad 
idea, but it's possible for cases just like this where you want to control the 
style of individual elements in very specific ways.
 
Second, you can specify an RGB colour in CSS by specifying three percentages as 
in rgb(100%, 50%, 0%). This isn't used as commonly as the hexadecimal method 
we've used in the course up to now, but it is supported by modern web browsers 
and will be much easier to work with in our program. In this example, the 
colour will have a lot of red (100%=F), half green (50%≅7) and no blue (0%=0) 

Here's how you calculate the in-between colours: I'm going to assume the 
percentage of red the user specified for the first colour is an integer in red1 
and the amount of red for colour two is in red2. The number of steps the user 
requested is in nsteps. If you want the amount of red (as a percent) for colour 
block i, you can do this (assuming i goes from 0 to nsteps-1): 

fraction = (i+1.0)/nsteps
r = (1-fraction)*red1 + fraction*red2 

After this, the variable r will contain the correct percent (as a floating 
point value). The calculation for green and blue are exactly the same. (You 
don't have to repeat the calculation of fraction, of course.) 
Here are some other points about how the program should behave: 

•   You will have to apply a style sheet to the  tags so they are 
large enough to see. Something like this might be appropriate: 
colourblock { width: 10em; height: 1em; } 

•   Your program must never output more than 150 total colours, no matter 
how many the user asks for. If the users asks for more, it should only output 
150. 
Having a limitation like this is an essential security measure. If not, someone 
could ask for 100 steps; this would overload the server and someone would 
probably come asking you why you used so much of the University's bandwidth. 
[Actually, the course web server automatically limits the size of the page your 
script can create. This isn't the case on most web servers so you should get 
into the habit of paying attention to the amount of output you generate. Python 
scripts on the server are limited to 60k of output.] 

•   You don't have to worry about catching errors in the user's input. That 
is, don't worry about the possibility of them entering "abcd" as the number of 
steps. 

•   You have to be careful about the spacing when outputting the RGB 
percentage values. You will have to convert the numbers to strings and 
concatenate them. For example, this statement will output part of the style 
attribute: 
print 'style="background-color: rgb(' + str(r) + '%' 

•   All of your XHTML (including generated XHTML) and CSS must be valid. 

I have no idea how to begin!! can you help me?

Thank you,

Andrea Semenik
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] browser encoding standards?

2009-07-14 Thread Kent Johnson
On Mon, Jul 13, 2009 at 7:55 PM, Alan Gauld wrote:

> OK, What kind of meta tag should I include?
> I have a couple, but not very many meta tags in my files. I try to
> minimalise
> content and maintain HTML 3.2 compatibility for oldr browsers.
>
> What would a content-type meta line look like to get round this
> quoting problem? My O'Reilly pocket reference suggests:
>
> 
>
> Would that suffice?

Yes, that should do it. The other alternative, if you have control of
the web server, is to set the actual content-type header sent by the
server. The meta tag is a way to simulate that from the contents of
the page.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assigning list to keys

2009-07-14 Thread Kent Johnson
On Tue, Jul 14, 2009 at 2:58 AM, Todd Matsumoto wrote:
> Hello,
>
> The other day I needed to pack a dictionary, the value of each key was a 
> list. In the code I was packing the list and the dictionary at the same time. 
> First I tried something like this:
>
> list = []
> dict = {}
> x = 1
>
> dict['int'] = list.append(x)

I don't know what you mean by "pack a dictionary". A fairly common
requirement is for a dictionary that maps keys to a list of values,
and a way to accumulate the values from a list of key, value pairs
where the keys may repeat.

collections.defaultdict is helpful for this, for example:
In [3]: from collections import defaultdict

In [4]: d = defaultdict(list)

In [5]: pairs = [ ('int', 1), ('float', 2.5), ('int', 3), ('float', 3.14) ]

In [6]: for k, v in pairs:
   ...: d[k].append(v)

In [7]: d
Out[7]: defaultdict(, {'int': [1, 3], 'float': [2.5,
3.1401]})

The value of d[k] will be a list, either an empty list or a previously
created one, so d[k].append() adds a new value to the list.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] University student struggling!

2009-07-14 Thread Kent Johnson
On Mon, Jul 13, 2009 at 7:23 PM, Andrea Semenik wrote:



> I have no idea how to begin!! can you help me?

What have you done so far? Do you know how to serve and form and
respond to form submission? Do you know how to dynamically generate
and serve a page of HTML? What are you using to program the server, is
it CGI?

Here is a place to start:
- create a page that shows a form allowing the user to specify the colors
- make a CGI that receives the form submission and displays the two
specified colors

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] University student struggling!

2009-07-14 Thread bob gailer

Andrea Semenik wrote:





> I have no idea how to begin!! can you help me?
  

It sounds like this is not the first assignment in the course. True?

If so did you complete them successfully?

If so is there anything in the prior assignments that you can build on?

Also note that your question includes Python, web servers, HTML. Have 
you asked the question in other fora?


Is there a link to this and prior problems that we can visit?


--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assigning list to keys

2009-07-14 Thread bob gailer

Christian Witts wrote:

Todd Matsumoto wrote:

Hello,

The other day I needed to pack a dictionary, the value of each key 
was a list. In the code I was packing the list and the dictionary at 
the same time. First I tried something like this:


list = []
dict = {}
x = 1

dict['int'] = list.append(x)

The result was {'int': None}. Why is the value None?

Cheers,

T
  

Hi,

Appending to a list does so in-place and returns None.  If you wish to 
do what you posted you will need to do it in 2 steps with:


   list.append(x)
   dict['int'] = list


Don't you mean dict['int'] = list[-1]?


You should also avoid shadowing built-in names like "list", "dict", 
"file" etc as you can very easily end up with unexplained errors.


Hope that helps.




--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] unittests, testing a type

2009-07-14 Thread Todd Matsumoto
Hi,

Does anyone know how to do a unittest assert for a type? 

So If you have a program returning a Decimal, lets say Decimal("1"), and you 
want to make sure that what is returned is a Decimal object.

At first I thought of importing Decimal and making my own Decimal("1") and 
doing an assertEquals, but this implies I know what the return type is before 
getting it.

Cheers,

T
-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unittests, testing a type

2009-07-14 Thread A.T.Hofkamp

Todd Matsumoto wrote:

Hi,

Does anyone know how to do a unittest assert for a type? 


So If you have a program returning a Decimal, lets say Decimal("1"), and you 
want to make sure that what is returned is a Decimal object.

At first I thought of importing Decimal and making my own Decimal("1") and

doing an assertEquals, but this implies I know what the return type is before
getting it.


For new-style classes, you should be able to do


type(result) is Decimal



(since the class is a singleton, 'is' should work).


Albert
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unittests, testing a type

2009-07-14 Thread Todd Matsumoto
Okay,

Thanks that worked. 

I still needed to import the Decimal class and I'm not sure that is okay. The 
reason why is I'm receiving the Decimal value from another program, if I 
already know that the value will be a Decimal why test it?

Perhaps I'm getting to caught up in this test-driven development thing.

Cheers,

T


 Original-Nachricht 
> Datum: Tue, 14 Jul 2009 15:45:18 +0200
> Von: "A.T.Hofkamp" 
> An: Todd Matsumoto 
> CC: "tutor@python.org" 
> Betreff: Re: [Tutor] unittests, testing a type

> Todd Matsumoto wrote:
> > Hi,
> > 
> > Does anyone know how to do a unittest assert for a type? 
> > 
> > So If you have a program returning a Decimal, lets say Decimal("1"), and
> you want to make sure that what is returned is a Decimal object.
> > 
> > At first I thought of importing Decimal and making my own Decimal("1")
> and
> doing an assertEquals, but this implies I know what the return type is
> before
> getting it.
> 
> 
> For new-style classes, you should be able to do
> 
> 
> type(result) is Decimal
> 
> 
> 
> (since the class is a singleton, 'is' should work).
> 
> 
> Albert

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unittests, testing a type

2009-07-14 Thread Kent Johnson
On Tue, Jul 14, 2009 at 9:45 AM, A.T.Hofkamp wrote:
> Todd Matsumoto wrote:
>>
>> Hi,
>>
>> Does anyone know how to do a unittest assert for a type?

> For new-style classes, you should be able to do
>
>
> type(result) is Decimal

When possible, it's better to use assertEqual() rather than a plain
assert_() because you will get a better error message on failure.

If you write
  self.assert_(type(result) is Decimal)
on failure you will get an uninformative message like "assertion failed"

If you write
  self.assertEqual(type(result), Decimal)
you will get an error more like "float != Decimal"

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unittests, testing a type

2009-07-14 Thread Kent Johnson
On Tue, Jul 14, 2009 at 9:59 AM, Todd Matsumoto wrote:
> Okay,
>
> Thanks that worked.
>
> I still needed to import the Decimal class and I'm not sure that is okay.

Sure, why not?

> The reason why is I'm receiving the Decimal value from another program, if I 
> already know that the value will be a Decimal why test it?

Well, why are you testing it? What was the motivation for your
original question?

It's fine to right a test that verifies that the other program is
doing what you expect. That's all any passing test really does, is
verify expected behaviour. The benefit is that if the behaviour ever
changes your test will fail and you will find out.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] University student struggling!

2009-07-14 Thread Kent Johnson
Forwarding to the list with my reply. Please use Reply All to respond
to the list.

On Tue, Jul 14, 2009 at 11:01 AM, Andrea Semenik wrote:
> Thank you so much for your quick response. This is really the first 
> assignment of its kind with this course, there was no warm up to get us 
> familiar with python. the only thing we had to do was program a page that 
> showed the current time. But that was easy because all we had to do was use 
> time.asctime(). For this assignment this is what I have done
>
> import cgi
> form = cgi.FieldStorage()
>
> # print HTTP/HTML header stuff
> print "Content-type: text/html"
> print
> print""" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
> 
> Colour Blend
> 
> #blend {
>  width: 10em;
>  padding: 0;
>  border: 1px solid black;
>  margin-left: 3em;
> }
> .colourblock {
>  width: 10em;
>  height: 1em;
> }
> 
> 
> 
> """
> print
>
> print "", form["red1"].value, ""
> print "", form["green1"].value, ""
> print "", form["blue1"].value, ""
> print "", form["red2"].value, ""
> print "", form["green2"].value, ""
> print "", form["blue2"].value, ""
> print "", form["steps"].value, ""
> print
>
>
> I am not sure if that is even right. My page is now showing the values that 
> were input by the user on the previous page. But I feel like that could be 
> the start to something. like there is another step that will then connect 
> these values into making a color box. But I just don't know, I have been 
> trying to read as much as I can about python, but I am overwhelmed.

This is a good start. Can you modify this program to show the actual
colors in a , rather than just echoing the numbers?

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to pass command line variables to this python code...

2009-07-14 Thread J Cook

Hello,

I have some autogenerated code from Selenium which I cannot figure out 
how to pass some command line variables to. For example I could export 
the same in Perl and it would be for example:



use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;

my $sel = Test::WWW::Selenium->new( host => "localhost",
port => ,
browser => "*chrome",
browser_url => 	 
"http://www.google.com/"; );


$sel->open_ok("/");
$sel->type_ok("q", "red sox");


I could then go in and add something like:

my ($arg1) = shift || "default";

which would pick up the first command line parameter and then I could do 
something like:


$sel->(type_ok, $arg1);

All is good here, now Selenium will export the following for Python:


from selenium import selenium
import unittest, time, re

class NewTest(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", , "*chrome", 
"http://www.google.com/";)

self.selenium.start()

def test_new(self):
sel = self.selenium
sel.open("/")
sel.type("q", "red sox")

def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
unittest.main()


Now I am confused on how to pass a command line parameter here. Any 
suggestions? I would like to be able to run something like:


$ python selenium-google-test.py "yankees"

Suggestions?


TIA

Justin
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to pass command line variables to this python code...

2009-07-14 Thread vince spicer
First off, selenium is a great tool and the python driver is very powerful

there are numerous ways to access cli variables,

the quickest

import sys
print sys.srgv

sys.argv will it output a array of all command line args

./selenium-google-test.py yankees
will out put:

['selenium-google-test.py', 'yankees']

so

args = sys.argv

args[0] == 'yankees'
True

for a more functional way, check out
http://docs.python.org/library/getopt.html



On Tue, Jul 14, 2009 at 11:11 AM, J Cook  wrote:

> Hello,
>
> I have some autogenerated code from Selenium which I cannot figure out how
> to pass some command line variables to. For example I could export the same
> in Perl and it would be for example:
>
> 
> use strict;
> use warnings;
> use Time::HiRes qw(sleep);
> use Test::WWW::Selenium;
> use Test::More "no_plan";
> use Test::Exception;
>
> my $sel = Test::WWW::Selenium->new( host => "localhost",
>port => ,
>browser => "*chrome",
>browser_url =>   "
> http://www.google.com/"; );
>
> $sel->open_ok("/");
> $sel->type_ok("q", "red sox");
> 
>
> I could then go in and add something like:
>
> my ($arg1) = shift || "default";
>
> which would pick up the first command line parameter and then I could do
> something like:
>
> $sel->(type_ok, $arg1);
>
> All is good here, now Selenium will export the following for Python:
>
> 
> from selenium import selenium
> import unittest, time, re
>
> class NewTest(unittest.TestCase):
>def setUp(self):
>self.verificationErrors = []
>self.selenium = selenium("localhost", , "*chrome", "
> http://www.google.com/";)
>self.selenium.start()
>
>def test_new(self):
>sel = self.selenium
>sel.open("/")
>sel.type("q", "red sox")
>
>def tearDown(self):
>self.selenium.stop()
>self.assertEqual([], self.verificationErrors)
>
> if __name__ == "__main__":
>unittest.main()
> 
>
> Now I am confused on how to pass a command line parameter here. Any
> suggestions? I would like to be able to run something like:
>
> $ python selenium-google-test.py "yankees"
>
> Suggestions?
>
>
> TIA
>
> Justin
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Saving class instances

2009-07-14 Thread Alan Gauld


"Thomas Scrace"  wrote 



Good to know I wasn't being totally dense.  Now that I have got the  
pickle thing under my belt I am going to have a go at sqllite.


Again, you might find the database topic ijn my tuorial a useful 
starting point for using SqlLite from Python...



--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to pass command line variables to this python code...

2009-07-14 Thread Alan Gauld


"J Cook"  wrote 

Now I am confused on how to pass a command line parameter here. Any 
suggestions? I would like to be able to run something like:


$ python selenium-google-test.py "yankees"


Try the Talking to the User topic in my tutorial, it includes a section 
on accessing command line args.



--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to pass command line variables to this python code...

2009-07-14 Thread J Cook

Ok,

So I added the following:


from selenium import selenium
import unittest, time, re
import sys # added this

q = sys.argv[1] # added this
print q # added this just to see

class NewTest(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", , "*chrome", 
"http://www.google.com/";)

self.selenium.start()

def test_new(self):
sel = self.selenium
sel.open("/")
sel.type("q", q) # this is where I want the argument to end up

def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
unittest.main()


I run the following:

$ python selenium-google-test.py yankees
yankees
Traceback (most recent call last):
  File "selenium-google-test.py", line 24, in 
unittest.main()
  File "/usr/lib/python2.6/unittest.py", line 816, in __init__
self.parseArgs(argv)
  File "/usr/lib/python2.6/unittest.py", line 843, in parseArgs
self.createTests()
  File "/usr/lib/python2.6/unittest.py", line 849, in createTests
self.module)
  File "/usr/lib/python2.6/unittest.py", line 613, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python2.6/unittest.py", line 584, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'yankees'

How do I get the argument over to where I need it to be?

Justin

vince spicer wrote:

First off, selenium is a great tool and the python driver is very powerful

there are numerous ways to access cli variables,

the quickest

import sys
print sys.srgv

sys.argv will it output a array of all command line args

./selenium-google-test.py yankees
will out put:

['selenium-google-test.py', 'yankees']

so

args = sys.argv

args[0] == 'yankees'
True

for a more functional way, check out
http://docs.python.org/library/getopt.html



On Tue, Jul 14, 2009 at 11:11 AM, J Cook > wrote:


Hello,

I have some autogenerated code from Selenium which I cannot figure
out how to pass some command line variables to. For example I could
export the same in Perl and it would be for example:


use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;

my $sel = Test::WWW::Selenium->new( host => "localhost",
   port => ,
   browser => "*chrome",
   browser_url =>  
"http://www.google.com/"; );


$sel->open_ok("/");
$sel->type_ok("q", "red sox");


I could then go in and add something like:

my ($arg1) = shift || "default";

which would pick up the first command line parameter and then I
could do something like:

$sel->(type_ok, $arg1);

All is good here, now Selenium will export the following for Python:


from selenium import selenium
import unittest, time, re

class NewTest(unittest.TestCase):
   def setUp(self):
   self.verificationErrors = []
   self.selenium = selenium("localhost", , "*chrome",
"http://www.google.com/";)
   self.selenium.start()

   def test_new(self):
   sel = self.selenium
   sel.open("/")
   sel.type("q", "red sox")

   def tearDown(self):
   self.selenium.stop()
   self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
   unittest.main()


Now I am confused on how to pass a command line parameter here. Any
suggestions? I would like to be able to run something like:

$ python selenium-google-test.py "yankees"

Suggestions?


TIA

Justin
___
Tutor maillist  -  Tutor@python.org 
http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to pass command line variables to this python code...

2009-07-14 Thread vince spicer
Sorry I do remember that issue in the past, the unittest.main takes over the
cli variables in order to select modules to run

python selenium-google-test.py --help

so unittest is assuming yankees is a test module, you can override this
functionality however with:

unittest.main(argv=['mytestapp'])

this will cause the default run all test modules, and allow you to access
the argv

Hope that helps

Vince



On Tue, Jul 14, 2009 at 1:36 PM, J Cook  wrote:

> Ok,
>
> So I added the following:
>
> 
> from selenium import selenium
> import unittest, time, re
> import sys # added this
>
> q = sys.argv[1] # added this
> print q # added this just to see
>
> class NewTest(unittest.TestCase):
>def setUp(self):
>self.verificationErrors = []
>self.selenium = selenium("localhost", , "*chrome", "
> http://www.google.com/";)
>self.selenium.start()
>
>def test_new(self):
>sel = self.selenium
>sel.open("/")
>sel.type("q", q) # this is where I want the argument to end up
>
>def tearDown(self):
>self.selenium.stop()
>self.assertEqual([], self.verificationErrors)
>
> if __name__ == "__main__":
>unittest.main()
> 
>
> I run the following:
>
> $ python selenium-google-test.py yankees
> yankees
> Traceback (most recent call last):
>  File "selenium-google-test.py", line 24, in 
>unittest.main()
>  File "/usr/lib/python2.6/unittest.py", line 816, in __init__
>self.parseArgs(argv)
>  File "/usr/lib/python2.6/unittest.py", line 843, in parseArgs
>self.createTests()
>  File "/usr/lib/python2.6/unittest.py", line 849, in createTests
>self.module)
>  File "/usr/lib/python2.6/unittest.py", line 613, in loadTestsFromNames
>suites = [self.loadTestsFromName(name, module) for name in names]
>  File "/usr/lib/python2.6/unittest.py", line 584, in loadTestsFromName
>parent, obj = obj, getattr(obj, part)
> AttributeError: 'module' object has no attribute 'yankees'
>
> How do I get the argument over to where I need it to be?
>
> Justin
>
> vince spicer wrote:
>
>> First off, selenium is a great tool and the python driver is very powerful
>>
>> there are numerous ways to access cli variables,
>>
>> the quickest
>>
>> import sys
>> print sys.srgv
>>
>> sys.argv will it output a array of all command line args
>>
>> ./selenium-google-test.py yankees
>> will out put:
>>
>> ['selenium-google-test.py', 'yankees']
>>
>> so
>>
>> args = sys.argv
>>
>> args[0] == 'yankees'
>> True
>>
>> for a more functional way, check out
>> http://docs.python.org/library/getopt.html
>>
>>
>>
>> On Tue, Jul 14, 2009 at 11:11 AM, J Cook > jcook...@gmail.com>> wrote:
>>
>>Hello,
>>
>>I have some autogenerated code from Selenium which I cannot figure
>>out how to pass some command line variables to. For example I could
>>export the same in Perl and it would be for example:
>>
>>
>>use strict;
>>use warnings;
>>use Time::HiRes qw(sleep);
>>use Test::WWW::Selenium;
>>use Test::More "no_plan";
>>use Test::Exception;
>>
>>my $sel = Test::WWW::Selenium->new( host => "localhost",
>>   port => ,
>>   browser => "*chrome",
>>   browser_url =>  "
>> http://www.google.com/"; );
>>
>>$sel->open_ok("/");
>>$sel->type_ok("q", "red sox");
>>
>>
>>I could then go in and add something like:
>>
>>my ($arg1) = shift || "default";
>>
>>which would pick up the first command line parameter and then I
>>could do something like:
>>
>>$sel->(type_ok, $arg1);
>>
>>All is good here, now Selenium will export the following for Python:
>>
>>
>>from selenium import selenium
>>import unittest, time, re
>>
>>class NewTest(unittest.TestCase):
>>   def setUp(self):
>>   self.verificationErrors = []
>>   self.selenium = selenium("localhost", , "*chrome",
>>"http://www.google.com/";)
>>   self.selenium.start()
>>
>>   def test_new(self):
>>   sel = self.selenium
>>   sel.open("/")
>>   sel.type("q", "red sox")
>>
>>   def tearDown(self):
>>   self.selenium.stop()
>>   self.assertEqual([], self.verificationErrors)
>>
>>if __name__ == "__main__":
>>   unittest.main()
>>
>>
>>Now I am confused on how to pass a command line parameter here. Any
>>suggestions? I would like to be able to run something like:
>>
>>$ python selenium-google-test.py "yankees"
>>
>>Suggestions?
>>
>>
>>TIA
>>
>>Justin
>>___
>>Tutor maillist  -  Tutor@python.org 
>>http://mail.python.org/mailman/listinfo/tutor
>>
>>
>>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unittests, testing a type

2009-07-14 Thread Dave Angel

On Tue, Jul 14, 2009 at 9:59 AM, Todd Matsumoto wrote:

The reason why is I'm receiving the Decimal value from another program, if I 
already know that the value will be a Decimal why test it?



  
How are you receiving it?  File, pickle, pipe, socket, exit() return 
value?  When I first read your question, I assumed you meant "from 
another module."  But if it's another process, then you'd better tell us 
how you're actually getting the value.  Maybe it's a Decimal because you 
just got done converting it to one.


DaveA

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to pass command line variables to this python code...

2009-07-14 Thread Christian Witts

vince spicer wrote:

First off, selenium is a great tool and the python driver is very powerful

there are numerous ways to access cli variables,

the quickest

import sys
print sys.srgv

sys.argv will it output a array of all command line args

./selenium-google-test.py yankees
will out put:

['selenium-google-test.py', 'yankees']

so

args = sys.argv

args[0] == 'yankees'
True
That would be false, the first argument (list index zero) is the script 
name.  You would need to do

args = sys.argv[1:]
if you want to dump the filename from the list.

--
Kind Regards,
Christian Witts


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unittests, testing a type

2009-07-14 Thread Todd Matsumoto
Hi,

Thanks for all the comments so far.

DaveA, I'm receiving the value via pyODBC, after running a query on a database. 
The test is to first make sure the value is a Decimal (pyODBC returns a Decimal 
object if what is coming from the database is a decimal type). So if I don't 
have a value that is a Decimal object something is wrong.

Cheers,

T
 Original-Nachricht 
> Datum: Tue, 14 Jul 2009 22:36:14 -0400
> Von: Dave Angel 
> An: 
> CC: Todd Matsumoto , tutor@python.org
> Betreff: Re: Re: [Tutor] unittests, testing a type

> On Tue, Jul 14, 2009 at 9:59 AM, Todd Matsumoto wrote:
> >> The reason why is I'm receiving the Decimal value from another program,
> if I already know that the value will be a Decimal why test it?
> >> 
> >
> >   
> How are you receiving it?  File, pickle, pipe, socket, exit() return 
> value?  When I first read your question, I assumed you meant "from 
> another module."  But if it's another process, then you'd better tell us 
> how you're actually getting the value.  Maybe it's a Decimal because you 
> just got done converting it to one.
> 
> DaveA

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor