[Tutor] While and for loops

2009-07-14 Thread Todd Matsumoto
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

[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

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 tmatsum...@gmx.net Betreff: Re: [Tutor] While and for loops Your break is for the for loop not the while. The

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

Re: [Tutor] While and for loops

2009-07-14 Thread A.T.Hofkamp
Todd Matsumoto wrote: while True: do something for i in items: if i 10: break else: do something Okay, So how would you break out from this situation? finished = False while not finished: do something for i in items: if

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 do something for i in items: if i 10: breakout = False else:

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 wes...@gmail.com An: A.T.Hofkamp a.t.hofk...@tue.nl CC: Todd Matsumoto tmatsum...@gmx.net, tutor@python.org tutor@python.org Betreff: Re: [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

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

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    do something    for i in items:        if i 10:            breakout = False        else:      

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

Re: [Tutor] While and for loops

2009-07-14 Thread Alan Gauld
wesley chun wes...@gmail.com 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

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 do something for i in items: if i 10: breakout =

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

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 =

Re: [Tutor] Saving class instances

2009-07-14 Thread Thomas Scrace
On 13 Jul 2009, at 22:04, Alan Gauld alan.ga...@btinternet.com 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

Re: [Tutor] Pythonify this code!

2009-07-14 Thread Dave Angel
A.T.Hofkamp wrote: div class=moz-text-flowed style=font-family: -moz-fixedMuhammad 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

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:

[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

Re: [Tutor] browser encoding standards?

2009-07-14 Thread Kent Johnson
On Mon, Jul 13, 2009 at 7:55 PM, Alan Gauldalan.ga...@btinternet.com 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

Re: [Tutor] assigning list to keys

2009-07-14 Thread Kent Johnson
On Tue, Jul 14, 2009 at 2:58 AM, Todd Matsumototmatsum...@gmx.net 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

Re: [Tutor] University student struggling!

2009-07-14 Thread Kent Johnson
On Mon, Jul 13, 2009 at 7:23 PM, Andrea Semenikam...@sfu.ca wrote: snip long problem description 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

Re: [Tutor] University student struggling!

2009-07-14 Thread bob gailer
Andrea Semenik wrote: snip long problem description 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?

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'] =

[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,

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)

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

Re: [Tutor] unittests, testing a type

2009-07-14 Thread Kent Johnson
On Tue, Jul 14, 2009 at 9:45 AM, A.T.Hofkampa.t.hofk...@tue.nl 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

Re: [Tutor] unittests, testing a type

2009-07-14 Thread Kent Johnson
On Tue, Jul 14, 2009 at 9:59 AM, Todd Matsumototmatsum...@gmx.net 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

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 Semenikam...@sfu.ca 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

[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: code use strict; use warnings; use Time::HiRes qw(sleep); use Test::WWW::Selenium; use Test::More

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:

Re: [Tutor] Saving class instances

2009-07-14 Thread Alan Gauld
Thomas Scrace t.scr...@gmail.com 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...

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

2009-07-14 Thread J Cook
Ok, So I added the following: code 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 =

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: