Re: [Tutor] intefaces in python

2009-06-30 Thread Jan Ulrich Hasecke


Am 28.06.2009 um 17:00 schrieb Amit Sethi:

Hi , I don't suppose python has a concept of interfaces. But can  
somebody tell me if their is a way i can  implement something like a  
java interface in python.


The Web Framework Zope has a notion of interfaces.
http://pypi.python.org/pypi/zope.interface/3.5.1

There are some quite interesting things you can make with interfaces.  
Eg. the Component Architecture is build on interfaces and adapters.


http://wiki.zope.org/zope3/WhatAreInterfaces

More on this here:
http://docs.zope.org/

juh

smime.p7s
Description: S/MIME cryptographic signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] newton's method for system of nonlinear equations

2009-06-30 Thread kgotlelelok
Hi can someone help me with my program demostrating Newton's method for
system of nonlinear equations below. Line 45 gives an error saying return
is outside the function and I don't know how to rectify that. I neewd this
program to print differnt values of x until the differnce between previous
x and present x is less than tol.
Please help

Thank you

from scipy import*
tol=0.01
def swapRows(v,i,j):
if len(v.getshape()) == 1: v[i],v[j] = v[j],v[i]
else:
temp = v[i].copy()
v[i] = v[j]
v[j] = temp

def swapCols(v,i,j):
temp = v[:,j].copy()
v[:,j] = v[:,i]
v[:,i] = temp

def gaussPivot(a,b,tol=1.0e-12):
n = len(b)

  # Set up scale factors
s = zeros((n),float)
for i in range(n):
s[i] = max(abs(a[i,:]))

for k in range(0,n-1):

  # Row interchange, if needed
p = int(argmax(abs(a[k:n,k])/s[k:n])) + k
if abs(a[p,k])  tol: error.err('Matrix is singular')
if p != k:
swap.swapRows(b,k,p)
swap.swapRows(s,k,p)
swap.swapRows(a,k,p)

  # Elimination
for i in range(k+1,n):
if a[i,k] != 0.0:
lam = a[i,k]/a[k,k]
a[i,k+1:n] = a [i,k+1:n] - lam*a[k,k+1:n]
b[i] = b[i] - lam*b[k]
if abs(a[n-1,n-1])  tol: error.err('Matrix is singular')


for k in range(n-1,-1,-1):
b[k] = (b[k] - dot(a[k,k+1:n],b[k+1:n]))/a[k,k]
return b

def newtonRaphson2(f,x,tol=1.0e-9):

def jacobian(f,x):
h = 1.0e-4
n = len(x)
jac = zeros((n,n),float)
f0 = f(x)
for i in range(n):
temp = x[i]
x[i] = temp + h
f1 = f(x)
x[i] = temp
jac[:,i] = (f1 - f0)/h
return jac,f0

for i in range(30):
jac,f0 = jacobian(f,x)
if sqrt(dot(f0,f0)/len(x))  tol: return x
dx = gaussPivot(jac,-f0)
x = x + dx
if sqrt(dot(dx,dx))  tol*max(max(abs(x)),1.0): return x
print 'Too many iterations'

def f(x):
f = zeros((len(x)),float)
f[0] = sin(x[0]) + x[1]**2 + log(x[2]) - 7.0
f[1] = 3.0*x[0] + 2.0**x[1] - x[2]**3 + 1.0
f[2] = x[0] + x[1] + x[2] - 5.0
return f

x = array([1.0, 1.0, 1.0])
print newtonRaphson2(f,x)
raw_input (\nPress return to exit)



-
This email was sent using SquirrelMail.
   Webmail for nuts!
http://squirrelmail.org/

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


Re: [Tutor] newton's method for system of nonlinear equations

2009-06-30 Thread Luke Paireepinart

kgotlele...@galmail.co.za wrote:

Hi can someone help me with my program demostrating Newton's method for
system of nonlinear equations below. Line 45 gives an error saying return
is outside the function 
  

That's because you have a return outside of a function.

for k in range(n-1,-1,-1):
b[k] = (b[k] - dot(a[k,k+1:n],b[k+1:n]))/a[k,k]
return b


Where did you get this code?  You haven't given us any indication of 
your level of python knowledge or what exactly your problem is so it's a 
little difficult to help you.
We don't just fix programs here, we provide guidance.  It's tutor not 
freelanceprogrammers.  We'd much rather give you a fishing pole and 
have you fix it yourself.

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


Re: [Tutor] [Pythonmac-SIG] GASP on OSX 10.5.6

2009-06-30 Thread David Warde-Farley

On 29-Jun-09, at 7:06 PM, Chris Rebert wrote:


Mac OS X apparently not a supported platform:
https://answers.launchpad.net/gasp-code/+faq/42


It looks like the code is pure python and depends on pycairo, so in  
theory it should work provided cairo which has a Quartz backend) and  
pycairo work (and possibly pygame).


MacPorts has cairo and I imagine pycairo is easy_install'able.

It's unfortunately a lot of work for a beginner...

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


[Tutor] Needing Help

2009-06-30 Thread Bob Rea
I am jsut beginning to learn python form a book. I have run 
into a problem running a script from the book. I want to 
ask for help. Shoudl I put the whole script into my email 
or put it somewhere on the web for you to look at instead. 
Not sure how this works, script is 68 lines.

-- 
Bob Rea
mailto:gapet...@stsams.org
http://www.petard.us
http://www.petard.us/blog
http://www.petard.us/gallery

Where is Bill Stringfellow
now that we really need him?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Needing Help

2009-06-30 Thread vishwajeet singh
You can put your script in pastebin http://python.pastebin.com/
http://python.pastebin.com/I don't think any one will mind you pasting
code in mail but pastebin makes it easier to read

On Tue, Jun 30, 2009 at 10:36 PM, Bob Rea gapet...@stsams.org wrote:

 I am jsut beginning to learn python form a book. I have run
 into a problem running a script from the book. I want to
 ask for help. Shoudl I put the whole script into my email
 or put it somewhere on the web for you to look at instead.
 Not sure how this works, script is 68 lines.

 --
 Bob Rea
 mailto:gapet...@stsams.org
 http://www.petard.us
 http://www.petard.us/blog
 http://www.petard.us/gallery

 Where is Bill Stringfellow
now that we really need him?
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor




-- 
Cheers,
Vishwajeet
http://www.singhvishwajeet.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Needing Help

2009-06-30 Thread Daniel Woodhouse
You can use something like pastebin.com if you don't want to post huge
chunks of code.  You could also just tell us what problem occurred, was
there a traceback (error message)?

On Tue, Jun 30, 2009 at 8:06 PM, Bob Rea gapet...@stsams.org wrote:

 I am jsut beginning to learn python form a book. I have run
 into a problem running a script from the book. I want to
 ask for help. Shoudl I put the whole script into my email
 or put it somewhere on the web for you to look at instead.
 Not sure how this works, script is 68 lines.

 --
 Bob Rea
 mailto:gapet...@stsams.org
 http://www.petard.us
 http://www.petard.us/blog
 http://www.petard.us/gallery

 Where is Bill Stringfellow
now that we really need him?
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

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


[Tutor] PYTHONPATH

2009-06-30 Thread Bob Rea
In working my way through the book on python, i am working 
in directories for chapers. Now I am on modules, and some 
are reused in later chapters. I have set up a directory for 
the modules. How do I add it to my PYTHONPATH?
I can use sys.path.append but that only lasts for the 
session.

-- 
Bob Rea
mailto:pet...@petard.us
http://www.petard.us
http://www.petard.us/blog
http://www.petard.us/gallery
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PYTHONPATH-corrected

2009-06-30 Thread Bob Rea
In working my way through the book on python, I am working 
in directories for chapers. Now I am on modules, and some 
are reused in later chapters. I have set up a directory for 
the modules. How do I add it to my PYTHONPATH?
I can use sys.path.append but that only lasts for the 
session.

This is on a suse linux 10 box

-- 
Bob Rea
mailto:pet...@petard.us
http://www.petard.us
http://www.petard.us/blog
http://www.petard.us/gallery
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Needing Help

2009-06-30 Thread Bob Rea
On Tue June 30 2009 1:17 pm, vishwajeet singh 
dextrou...@gmail.comwrote:
 You can put your script in pastebin
 http://python.pastebin.com/
 http://python.pastebin.com/I don't think any one will
 mind you pasting code in mail but pastebin makes it
 easier to read

I am making my way through _Making Use of Python_ by Rashi 
Gupta. I am using Python 2.4.1 

I have run into problems in a script, listed at 
http://python.pastebin.com/m51bc3388

If I input my own name and dob, it works:
b...@gandalf:~/python/MakingUse/Chapter05 python code1.py
Enter your first name:  Bob
Enter your last name:  Rea
Enter your date of birth, mm-dd-:  03-05-1943
You can chose one of the following login names:
1.   BobR
2.   BobR53
3.   RBob43
4.   BRea66

If I use the data listed in the book, it fails:
b...@gandalf:~/python/MakingUse/Chapter05 python code1.py
Enter your first name:  Laura
Enter your last name:  Jones
Enter your date of birth, mm-dd-:  12-24-1980
You can chose one of the following login names:
1.   LauraJ
2.   LauraJ2412
3.   JLaura80
Traceback (most recent call last):
  File code1.py, line 67, in ?
fourth=fname[0]+lname+ age_func()
TypeError: cannot concatenate 'str' and 'NoneType' objects

What is going on here?

Bob Rea
pet...@petard.us
-- 
Bob Rea
mailto:gapet...@stsams.org
http://www.petard.us
http://www.petard.us/blog
http://www.petard.us/gallery

Where is Bill Stringfellow
now that we really need him?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PYTHONPATH-corrected

2009-06-30 Thread Steve Willoughby
On Tue, Jun 30, 2009 at 02:33:27PM -0400, Bob Rea wrote:
 In working my way through the book on python, I am working 
 in directories for chapers. Now I am on modules, and some 
 are reused in later chapters. I have set up a directory for 
 the modules. How do I add it to my PYTHONPATH?
 I can use sys.path.append but that only lasts for the 
 session.

You set the variable in your system's environment, which is
platform-dependent.  For Linux, you'd typically put a line
in your ~/.profile or ~/.cshrc or ~/.login or ~/.bashrc or
whatever your shell uses per your account set up.  

So, for example, in a bash/sh shell, you'd say:

export PYTHONPATH=/path/to/my/modules

or for csh:

setenv PYTHONPATH /path/to/my/modules

Then starting the next time you log in, that will be set
in your environment for you.

 This is on a suse linux 10 box
 
 -- 
 Bob Rea
 mailto:pet...@petard.us
 http://www.petard.us
 http://www.petard.us/blog
 http://www.petard.us/gallery
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

-- 
Steve Willoughby|  Using billion-dollar satellites
st...@alchemy.com   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Needing Help

2009-06-30 Thread Wayne
Oops, forgot my reply-to-all

On Tue, Jun 30, 2009 at 2:20 PM, Wayne sri...@gmail.com wrote:

 On Tue, Jun 30, 2009 at 1:06 PM, Bob Rea b...@telaugos.com wrote:

 snip
 If I input my own name and dob, it works:
 b...@gandalf:~/python/MakingUse/Chapter05 python code1.py
 Enter your first name:  Bob
 Enter your last name:  Rea
 Enter your date of birth, mm-dd-:  03-05-1943
 You can chose one of the following login names:
 1.   BobR
 2.   BobR53
 3.   RBob43
 4.   BRea66

 If I use the data listed in the book, it fails:
 b...@gandalf:~/python/MakingUse/Chapter05 python code1.py
 Enter your first name:  Laura
 Enter your last name:  Jones
 Enter your date of birth, mm-dd-:  12-24-1980
 You can chose one of the following login names:
 1.   LauraJ
 2.   LauraJ2412
 3.   JLaura80
 Traceback (most recent call last):
   File code1.py, line 67, in ?
fourth=fname[0]+lname+ age_func()
 TypeError: cannot concatenate 'str' and 'NoneType' objects

 What is going on here?


 Well the first line after Traceback give you the line of code and the
 filename. Which happens to be code1.py line 67.

 TypeError is the type of error - specifically you tried to do something
 with incompatible types. In this case, adding together a string and
 NoneType.

 I'll do a little digging, but my guess is you have a problem with your
 age_func() not returning any value.

 HTH,
 Wayne


I was correct:def age_func():
age=cur_year-year-1
if monthcur_month or (month==cur_month and daycur_day):
 age=age+1
return str(age)

What happens if month is  cur_month AND it's not my birthday?

You don't return a value. But if you simply unindent the return value then
it should fix it:

def age_func():
age=cur_year-year-1
 if monthcur_month or (month==cur_month and daycur_day):
age=age+1
 return str(age)

Now regardless of whether age is incremented, it will return a string.
HTH,
Wayne
-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Needing Help

2009-06-30 Thread Bob Rea
On Tue June 30 2009 3:20 pm, you wrote:
 On Tue, Jun 30, 2009 at 1:06 PM, Bob Rea 
b...@telaugos.com wrote:
  snip
  If I input my own name and dob, it works:
  b...@gandalf:~/python/MakingUse/Chapter05 python
  code1.py Enter your first name:  Bob
  Enter your last name:  Rea
  Enter your date of birth, mm-dd-:  03-05-1943
  You can chose one of the following login names:
  1.   BobR
  2.   BobR53
  3.   RBob43
  4.   BRea66
 
  If I use the data listed in the book, it fails:
  b...@gandalf:~/python/MakingUse/Chapter05 python
  code1.py Enter your first name:  Laura
  Enter your last name:  Jones
  Enter your date of birth, mm-dd-:  12-24-1980
  You can chose one of the following login names:
  1.   LauraJ
  2.   LauraJ2412
  3.   JLaura80
  Traceback (most recent call last):
File code1.py, line 67, in ?
 fourth=fname[0]+lname+ age_func()
  TypeError: cannot concatenate 'str' and 'NoneType'
  objects
 
  What is going on here?

 Well the first line after Traceback give you the line
 of code and the filename. Which happens to be code1.py
 line 67.

 TypeError is the type of error - specifically you tried
 to do something with incompatible types. In this case,
 adding together a string and NoneType.

 I'll do a little digging, but my guess is you have a
 problem with your age_func() not returning any value.

 HTH,
 Wayne

Why doe sit work with a dob in 1943 and not with one in 1980 
then, that's what really bugs me
-- 
Bob Rea
mailto:gapet...@stsams.org
http://www.petard.us
http://www.petard.us/blog
http://www.petard.us/gallery

Where is Bill Stringfellow
now that we really need him?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Needing Help

2009-06-30 Thread Marc Tompkins
On Tue, Jun 30, 2009 at 12:27 PM, Bob Rea b...@telaugos.com wrote:

 Why doe sit work with a dob in 1943 and not with one in 1980
 then, that's what really bugs me


Nothing to do with the year.  Your birth month is BEFORE June; her birth
month is after.
-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need help with python game program

2009-06-30 Thread jonathan wallis
.


 --

 Message: 4
 Date: Tue, 30 Jun 2009 14:27:34 -0500
 From: Wayne sri...@gmail.com
 To: Bob Rea b...@telaugos.com
 Cc: tutor@python.org
 Subject: Re: [Tutor] Needing Help
 Message-ID:
333efb450906301227u76274a83x53ef42fdae41f...@mail.gmail.com
 Content-Type: text/plain; charset=windows-1252

 Oops, forgot my reply-to-all

 On Tue, Jun 30, 2009 at 2:20 PM, Wayne sri...@gmail.com wrote:

  On Tue, Jun 30, 2009 at 1:06 PM, Bob Rea b...@telaugos.com wrote:
 
  snip
  If I input my own name and dob, it works:
  b...@gandalf:~/python/MakingUse/Chapter05 python code1.py
  Enter your first name:  Bob
  Enter your last name:  Rea
  Enter your date of birth, mm-dd-:  03-05-1943
  You can chose one of the following login names:
  1.   BobR
  2.   BobR53
  3.   RBob43
  4.   BRea66
 
  If I use the data listed in the book, it fails:
  b...@gandalf:~/python/MakingUse/Chapter05 python code1.py
  Enter your first name:  Laura
  Enter your last name:  Jones
  Enter your date of birth, mm-dd-:  12-24-1980
  You can chose one of the following login names:
  1.   LauraJ
  2.   LauraJ2412
  3.   JLaura80
  Traceback (most recent call last):
File code1.py, line 67, in ?
 fourth=fname[0]+lname+ age_func()
  TypeError: cannot concatenate 'str' and 'NoneType' objects
 
  What is going on here?
 
 
  Well the first line after Traceback give you the line of code and the
  filename. Which happens to be code1.py line 67.
 
  TypeError is the type of error - specifically you tried to do something
  with incompatible types. In this case, adding together a string and
  NoneType.
 
  I'll do a little digging, but my guess is you have a problem with your
  age_func() not returning any value.
 
  HTH,
  Wayne
 

 I was correct:def age_func():
 age=cur_year-year-1
 if monthcur_month or (month==cur_month and daycur_day):
  age=age+1
 return str(age)

 What happens if month is  cur_month AND it's not my birthday?

 You don't return a value. But if you simply unindent the return value
 then
 it should fix it:

 def age_func():
 age=cur_year-year-1
  if monthcur_month or (month==cur_month and daycur_day):
 age=age+1
  return str(age)

 Now regardless of whether age is incremented, it will return a string.
 HTH,
 Wayne
 --
 To be considered stupid and to be told so is more painful than being called
 gluttonous, mendacious, violent, lascivious, lazy, cowardly: every
 weakness,
 every vice, has found its defenders, its rhetoric, its ennoblement and
 exaltation, but stupidity hasn?t. - Primo Levi
 -- next part --
 An HTML attachment was scrubbed...
 URL: 
 http://mail.python.org/pipermail/tutor/attachments/20090630/fe4ba054/attachment-0001.htm
 

 --

 Message: 5
 Date: Tue, 30 Jun 2009 15:27:17 -0400
 From: Bob Rea b...@telaugos.com
 To: Wayne sri...@gmail.com
 Cc: tutor@python.org
 Subject: Re: [Tutor] Needing Help
 Message-ID: 200906301527.20516@telaugos.com
 Content-Type: text/plain;  charset=utf-8

 On Tue June 30 2009 3:20 pm, you wrote:
  On Tue, Jun 30, 2009 at 1:06 PM, Bob Rea
 b...@telaugos.com wrote:
   snip
   If I input my own name and dob, it works:
   b...@gandalf:~/python/MakingUse/Chapter05 python
   code1.py Enter your first name:  Bob
   Enter your last name:  Rea
   Enter your date of birth, mm-dd-:  03-05-1943
   You can chose one of the following login names:
   1.   BobR
   2.   BobR53
   3.   RBob43
   4.   BRea66
  
   If I use the data listed in the book, it fails:
   b...@gandalf:~/python/MakingUse/Chapter05 python
   code1.py Enter your first name:  Laura
   Enter your last name:  Jones
   Enter your date of birth, mm-dd-:  12-24-1980
   You can chose one of the following login names:
   1.   LauraJ
   2.   LauraJ2412
   3.   JLaura80
   Traceback (most recent call last):
 File code1.py, line 67, in ?
  fourth=fname[0]+lname+ age_func()
   TypeError: cannot concatenate 'str' and 'NoneType'
   objects
  
   What is going on here?
 
  Well the first line after Traceback give you the line
  of code and the filename. Which happens to be code1.py
  line 67.
 
  TypeError is the type of error - specifically you tried
  to do something with incompatible types. In this case,
  adding together a string and NoneType.
 
  I'll do a little digging, but my guess is you have a
  problem with your age_func() not returning any value.
 
  HTH,
  Wayne

 Why doe sit work with a dob in 1943 and not with one in 1980
 then, that's what really bugs me
 --
 Bob Rea
 mailto:gapet...@stsams.org
 http://www.petard.us
 http://www.petard.us/blog
 http://www.petard.us/gallery

 Where is Bill Stringfellow
now that we really need him?


 --

 Message: 6
 Date: Tue, 30 Jun 2009 12:45:00 -0700
 From: Marc Tompkins marc.tompk...@gmail.com
 To: Bob Rea b...@telaugos.com
 Cc: tutor@python.org
 Subject: Re: [Tutor] Needing Help
 Message-ID:
40af687b0906301245n3ffcc950k458e4bf629530

Re: [Tutor] Need help with python game program

2009-06-30 Thread Mark Tolonen


jonathan wallis mindboggle...@gmail.com wrote in message 
news:57b8984c0906301738w1fb0e660m6bb2123399f27...@mail.gmail.com...

My problem is simple, is their a way to make a variable equal multiple
numbers? Such as X = 5 through 10, and then the program makes x  equal
something random 5 through 10, or something similar.


Use the random module.  There are various types of random number generation 
there, such as:


   x = random.randint(5,10)

-Mark


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


Re: [Tutor] Need help with python game program

2009-06-30 Thread Luke Paireepinart
Please don't reply to messages like this.  If you are starting a new thread,
send a new e-mail to tu...@python.org.  DO NOT start a thread by replying to
another message.  If you do, it will bork on people's machines who use
threaded e-mail readers.  also, please remove long, irrelevant quotations
from your e-mails unless you reference it.  for example, the quoted text in
your e-mail is at least 10x longer than the actual content.I believe mark
already answered your question.
Thanks,
-Luke

On Tue, Jun 30, 2009 at 7:38 PM, jonathan wallis mindboggle...@gmail.comwrote:

 My problem is simple, is their a way to make a variable equal multiple
 numbers? Such as X = 5 through 10, and then the program makes x  equal
 something random 5 through 10, or something similar.

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


Re: [Tutor] Need help with python game program

2009-06-30 Thread Dave Angel

jonathan wallis wrote:


My problem is simple, is their a way to make a variable equal multiple
numbers? Such as X = 5 through 10, and then the program makes x  equal
something random 5 through 10, or something similar.
much snipping
  

For a short question, why did you quote an entire mailing list digest?


Answer to your question, certainly a variable can equal multiple 
numbers.  Several ways:

  1) one at a time.   X=5, then later  X=7.332
  2) a list of values  X = [5.3, 8.001, 17, 2]
  3) a dictionaryX = {tom:3, dick:42, harry:12}
  4) a class.  Sky's the limit here

As for random, look up the random.uniform() and random.randint() functions.

Did you have a particular programming language in mind?  I've been 
assuming Python, but you might be thinking something else.  Have you any 
experience in any other language?


DaveA

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


[Tutor] Python Programming exercise

2009-06-30 Thread Daniel Sato
I have been going through some Python Programming exercises while following
the MIT OpenCourseWare Intro to CS syllabus and am having some trouble with
the first If exercise listed on this page:

http://en.wikibooks.org/wiki/Python_Programming/Conditional_Statements#If_Exercises

I have been able to make the module quit after entering a password three
times, but can't get it to quit right away after the correct one is
entered.  I know this is really basic, please forgive me.  I have no
programming experience and have just started going through these tutorials.

My code is here:

http://python.pastebin.com/m6036b52e

-- 
Daniel Sato
http://www.danielsato.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] calculating a sort key and operator.attrgetter()

2009-06-30 Thread Vincent Davis
I have a class with an attribute which is a list rank_list this is a list
of instances f another class that has attributes quality, is_observed
if I want to sort the list by the attribute quality I can just use,
self.rank_list.sort(key=operator.attrgetter('quality'))
But I want to sort like this.
self.rank_list.sort(key=(operator.attrgetter('quality') *
operator.attrgetter('is_observed') * self.does_observe))
Will this work or is there a better way?

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