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
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
> 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
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 =
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:
>> 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:
>
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
> 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
> 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
> 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:
>
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'
"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
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
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
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:
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
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]]
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
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
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
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
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
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
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(
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
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")
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
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
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
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
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_
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
"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
"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
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
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'])
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
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
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
39 matches
Mail list logo