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

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 nev

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: 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 =

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:

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: >      

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

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

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 >     >    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 {'int'

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

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

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:

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 a

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

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

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

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 > > d

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 th

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 inc

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(

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

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 deve

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

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

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 wi

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

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

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 Auth

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

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 = selen

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

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

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: ['s

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