Re: [Tutor] list comprehension, efficiency?

2010-09-28 Thread Lie Ryan
On 09/28/10 13:57, Bill Allen wrote:
 I can now see that quite a bit of the code I write dealing with lists
 can be done with list
 comprehensions.   My question is this, is the list comprehension styled
 code generally
 more efficient at runtime?  If so, why?

Yes, because the looping in list comprehension is done in C instead of a
python construct. However, they are the type of efficiency that you
shouldn't bother yourself with unless you're microoptimizing.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2010-09-28 Thread masawudu bature
Thanks David, But the loop was suppose to produce the count of even divisors an 
integer has.
Like, 6 has 2 even divisors, which is 2 and 6, itself.
8 = 3 even divisors, which is 2, 4 ,and 8
10 = 2 even divisors, which is 2, and 10
12 = 4 even divisors, which is 2, 4, 6, and 12

sorry, I just don't know how to write a code to count the number of divisors





From: David Hutto smokefl...@gmail.com
To: masawudu bature mass0...@yahoo.ca
Cc: tutor@python.org
Sent: Mon, September 27, 2010 11:36:05 PM
Subject: Re: [Tutor] Python Help

On Tue, Sep 28, 2010 at 12:15 AM, masawudu bature mass0...@yahoo.ca wrote:
 I'm having a hard time finding the count of divisors that are even. Help
 anybody?

 Here's my code.

 The output is suppose to count the number of even divisors the range has.

 def evenCount(b) :
 for n in range(x, y+1) :
 count = 0
 if n % 2 == 0 :
 count += n/3
 count % n == 1
 return n


 ### main 

 x = input(Enter a starting value: )
 y = input(Enter a stopping value: )

 count = evenCount(x)

 for n in range(x, y+1) :
 count = 0
 if n % 2 == 0 :
 count += n/3
 print %2d:  %n, has%2d %count, even divisors,
 else :
 print %2d:  %n, has 0 even divisors,
 print



 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor



#You start with your range variables
x = input(Enter a starting value: )
y = input(Enter a stopping value: )

#You set a for loop for range
for num in range(x, y):
#If that number divided by 2 has a remainder of 0, it's of course even.
if num % 2 == 0:
#print the number
print num

And various other ways as well.

David



  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Pythonic nested lists

2010-09-28 Thread col speed
Hi all,
I've been trying to write a programme that solves sudoku problems for a
while now. I'm getting close, but would like to ask a few questions about
the most pythonic way of doing some things.
I've decided to create nested lists (row order, column order and square
order) which correspond with dictionary keys - the values of which are the
numbers given in the puzzle - so I can loop through the dict in different
orders.
I think the first two are OK, but the square order list seems extremely
messy and I would love some pointers. What I have is as follows:

roworder = [[str(j)+str(i) for i in range(9)] for j in range(9)]
colorder = zip(*roworder)
#here comes the problem!
start, index = 0,0
sqorder = []
for i in range(9):
sqorder.append([])
for j in range(start, start+3):
sqorder[i].extend(roworder[j][index:index+3])
if index == 6:
index = 0
else:
index += 3
if i == 2 or i == 5:
start += 3

Any comments at all would be gratefully received.
Thanks in advance
Colin
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if value in list of dictionaries

2010-09-28 Thread Norman Khine
thanks for the reply. i should have been more specific in my question ;)

the order in which 'other' is listed is not always the last item of
the list as it is dependent on where in the CSV file it is included.

what i was trying to do is to take create the list of dictionary items
and then find the item which has name=='other' and then put this as
the last item in the list.

so from this list http://pastie.org/1185974 how do i select the item
name == 'other' and put it at the end of the list?

On Mon, Sep 27, 2010 at 11:39 PM, Emile van Sebille em...@fenx.com wrote:
 On 9/27/2010 1:22 PM Norman Khine said...

 what is the correct way to ensure that {'industry': 'travel', 'name':
 'other','value': MSG(uOther)} is always added to the end of this
 list after all the items have been sorted?

 here is the code which returns this list:

   options.sort(key=itemgetter('name'))
   return options

 So, to answer the question you ask above, you can do:

   options.sort(key=itemgetter('name'))
   options.append({'industry':'travel',
      'name':'other','value':MSG(uOther)}
   return options

 But I don't think that's the question you're looking to get answered.

 I think you want other to be found only at the end and not elsewhere.

 Then you might try excluding other from options allowing the above to append
 it to the end:

 for index, row in enumerate(topics.get_rows()):
    if row[0] != 'other':
        options.append({'name': row[0], 'value': MSG(row[1])})

 HTH,

 Emile



 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




-- 
˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ
ǝq s,ʇǝן ʇǝʎ
% .join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ,adym,*)uzq^zqf ] )
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] trouble with list.remove() loop

2010-09-28 Thread D Ryan (2)
Hello all,
I am currently trying to write a program which can find the solution to a
game of hangman.
In a part of the program, a user inputs a letter, a tester tells him if
the word contains that letter, and then if the answer is no, all words
containing that letter are removed from the list of remaining candidates.
However, the code I've written seems to remove some, but not all the words
containing the letter. Strangely though, if i run it a few more times it
gets some of the ones it missed the 1st time round, untill after enough
iterations it gets all of them. I cant understand why it doesnt remove all
of them the first time round. I have cut the offending code and formatted
it to work on its own, and also to fit into a relatively short email.

# A sample list of words, one of which is the answer.
candidates = [abacus,amazing,
  ozimandias,
  a,alphanumeric,
  functioning]

# In the following code, the user has guessed the letter 'a',
# and the tester has told him that the letter 'a' is not in the word.

user_guess=a
tester_response=no

# The following code should eliminate all words which contain the letter
# 'a', leaving only the word 'functioning' in the list

if tester_response in (No,no,n,N,NO):
for word in candidates:
if user_guess in word:
print word, removed..
candidates.remove(word)
print candidates

Running once gives this output

abacus removed..
ozimandias removed..
alphanumeric removed..
['amazing', 'a', 'functioning']

But if i run it again it successfully removes 'amazing, and the next time
it removes 'a', leaving the correct answer. I'm perplexed by this strange
behaviour and would be most appreciative of any help. I'm very new to
python so apologies for any formatting/style errors, and also for the
simplicity of the problem.

Best regards
Dave

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread Preetinder Singh
Hi I am trying to learn how to program, I want to become a software developer 
so 
I can develop a software and also understand how to write my own software not 
copying someone else. So if there any book or online tutorials for complete 
beginners. I went to the python website and on wiki python and there are so 
many 
books to choose from, please help me choose one.


  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] help with python 3.1

2010-09-28 Thread Ralph Pat Hall
Dear Tutor:

I would like to install a program that was written with python 3.1, the 
computer that I would like to put in on has Win 98SE. I tried Python 3.1.2 MSI 
and 2.61 but got a message that a DLL was not there and would not install. I 
then tried them on a Win 7 computer and got to the 5 files that you had to say 
where they should go. They were register ext.; TCI/TK; documentation; utility 
scripts; test suite---go on the HD, local drive, not at all. My guess is HD ??? 
Do I need all 5 files ?

The writer of the program also said that you needed to download sq-3_6_23_1.zip 
and if you had XP or Vista and you wanted to print you also needed 
pywin.32-214.win32py3.1.exe. Would I need that with 98SE? He also said that any 
python before 3.1 would not be useable.

I don't know anything about python so I need any help possible

thank you 
Ralph
duoble...@live.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Basics

2010-09-28 Thread Cameron Macleod
Hi,

I'm relatively new to this mailing list (and python!) and I would greatly
appreciate some exercises to try or something to get me familiar with the
system.

Thanks,

Cameron Macleod
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pyMVPA and OSError

2010-09-28 Thread Juli
I am very much new to python, and thus I am likely to feel stupid  
about asking. But I need to get past this to continue with my work.
I need pyMVPA module to run some analysis on fMRI data, but as a start  
I want to at first play around with the sample data provided on pyMVPA  
website. I have downloaded Python2.6, my operating system is Mac  
Leopard (i get a depracation warning when I try to  import mvpa,  
which is not the problem, however, when I attempt to use the following  
line

 import mvpa.suite as mvpa
which i assume to mean the same thing, I dont get deprecation warning,  
but I do get a bunch of errors as follows:

 import mvpa.suite as mvpa

Traceback (most recent call last):
  File pyshell#14, line 1, in module
import mvpa.suite as mvpa
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/mvpa/suite.py, line 38, in module

from mvpa.algorithms.cvtranserror import *
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/mvpa/algorithms/cvtranserror.py, line 15,  
in module

from mvpa.measures.base import DatasetMeasure
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/mvpa/measures/base.py, line 31, in module

from mvpa.clfs.stats import autoNullDist
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/mvpa/clfs/stats.py, line 772, in module

if externals.exists('pylab'):
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/mvpa/base/externals.py, line 432, in exists

exec _KNOWN[dep]
  File string, line 1, in module
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/mvpa/base/externals.py, line 249, in  
__check_pylab

import pylab as P
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/pylab.py, line 1, in module

from matplotlib.pylab import *
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/matplotlib/pylab.py, line 206, in module

from matplotlib import mpl  # pulls in most modules
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/matplotlib/mpl.py, line 2, in module

from matplotlib import axis
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/matplotlib/axis.py, line 10, in module

import matplotlib.font_manager as font_manager
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/matplotlib/font_manager.py, line 1297, in  
module

_rebuild()
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/matplotlib/font_manager.py, line 1288, in  
_rebuild

fontManager = FontManager()
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/matplotlib/font_manager.py, line 980, in  
__init__

self.ttffiles = findSystemFonts(paths) + findSystemFonts()
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/matplotlib/font_manager.py, line 337, in  
findSystemFonts

for f in get_fontconfig_fonts(fontext):
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/site-packages/matplotlib/font_manager.py, line 298, in  
get_fontconfig_fonts
pipe = subprocess.Popen(['fc-list', '', 'file'],  
stdout=subprocess.PIPE)
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/subprocess.py, line 621, in __init__

errread, errwrite)
  File /opt/local/Library/Frameworks/Python.framework/Versions/2.6/ 
lib/python2.6/subprocess.py, line 1126, in _execute_child

raise child_exception
OSError: [Errno 2] No such file or directory

-

I am not sure why OSError is popping and I am sure I am doing  
something wrong, I just do not know enough to pinpoint what exactly.


Any feedback is appreciated. And I do once more apologize for asking  
very stupid questions.



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] input and raw input

2010-09-28 Thread John Chandler
you can use an re split...

import re
a=raw_input(Enter the number of your class in the school:)
regex = re.compile([ ,]) #sets the delimeters to a single space or comma
m = regex.split(a)

if you want to use any white space character than you can use [\s,]

2010/9/23 Ahmed AL-Masri ahmed...@hotmail.com

  Hi,
 any one have an idea about how we can input many number in the one time and
 change it to list.
 for example:

 a=input(Enter the number of your class in the school:) # the number
 can be enter as: 12,13,14 or 12 13 14 with a space in between.

 now how I can put these numbers into list like b=[12,13,14] with len( a )
 =3

 I tried with that but it's working only for a numbers less than 10 ex.
 1,2,3 or 1 2 3 but it's not when I go for numbers higher than 10 like in
 example above.

 a=raw_input(Enter the number of your class in the school:)
 m=[]
  for I range (len( a)):
 if a[I]==',':
 pass
 elif a[I]==' ':
 pass
 else:
 m.append(a[I])
 m=map(float,m)
 print m;print len( m )
  [1,2,3]
  3

 looking forward to seeing your help,
 regards,
 Ahmed




 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




-- 
-John Chandler
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] console output that is same in Python 2 and 3

2010-09-28 Thread Thierry Tung
Hello tutor at python.org.

How can I write strings to the console in a way that will give the same result 
in Python 3 and Python 2?

I tried sys.stdout.write('hello') on Microsoft vista.

with python 3.1.2 
sys.stdout.write('hello')
hello5


with python 2.7 
sys.stdout.write('hello')
hello

Why is the string length appended to the output with python 3.1.2?

Thanks,
Thierry



  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread vishwajeet singh
On Sun, Sep 26, 2010 at 9:20 AM, Preetinder Singh putj...@yahoo.com wrote:

 Hi I am trying to learn how to program, I want to become a software
 developer so I can develop a software and also understand how to write my
 own software not copying someone else. So if there any book or online
 tutorials for complete beginners. I went to the python website and on wiki
 python and there are so many books to choose from, please help me choose
 one.


 I would recommend Python for Absolute Beginners.





 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




-- 
Vishwajeet Singh
+91-9657702154 | dextrou...@gmail.com | http://bootstraptoday.com
Twitter: http://twitter.com/vishwajeets | LinkedIn:
http://www.linkedin.com/in/singhvishwajeet
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] console output that is same in Python 2 and 3

2010-09-28 Thread Tim Golden

On 27/09/2010 17:11, Thierry Tung wrote:

Hello tutor at python.org.

How can I write strings to the console in a way that will give the same result 
in Python 3 and Python 2?



I tried sys.stdout.write('hello') on Microsoft vista.

with python 3.1.2

sys.stdout.write('hello')

hello5




with python 2.7

sys.stdout.write('hello')

hello

Why is the string length appended to the output with python 3.1.2?


Because in Py 3.x the .write method returns the length written.
The interpreter echoes the non-None return value of any function
to stdout. This won't happen when you run the program -- you won't
get a stream of numbers. To avoid it happening in the interpreter,
simply assign the return value:

  n = sys.stdout.write(hello)

In Python 2.x n will be None; in Python 3.x it will be 5

TJG
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with list.remove() loop

2010-09-28 Thread Christian Witts

On 25/09/2010 20:44, D Ryan (2) wrote:

Hello all,
I am currently trying to write a program which can find the solution to a
game of hangman.
In a part of the program, a user inputs a letter, a tester tells him if
the word contains that letter, and then if the answer is no, all words
containing that letter are removed from the list of remaining candidates.
However, the code I've written seems to remove some, but not all the words
containing the letter. Strangely though, if i run it a few more times it
gets some of the ones it missed the 1st time round, untill after enough
iterations it gets all of them. I cant understand why it doesnt remove all
of them the first time round. I have cut the offending code and formatted
it to work on its own, and also to fit into a relatively short email.

# A sample list of words, one of which is the answer.
candidates = [abacus,amazing,
   ozimandias,
   a,alphanumeric,
   functioning]

# In the following code, the user has guessed the letter 'a',
# and the tester has told him that the letter 'a' is not in the word.

user_guess=a
tester_response=no

# The following code should eliminate all words which contain the letter
# 'a', leaving only the word 'functioning' in the list

if tester_response in (No,no,n,N,NO):
 for word in candidates:
 if user_guess in word:
 print word, removed..
 candidates.remove(word)
print candidates

Running once gives this output

abacus removed..
ozimandias removed..
alphanumeric removed..
['amazing', 'a', 'functioning']

But if i run it again it successfully removes 'amazing, and the next time
it removes 'a', leaving the correct answer. I'm perplexed by this strange
behaviour and would be most appreciative of any help. I'm very new to
python so apologies for any formatting/style errors, and also for the
simplicity of the problem.

Best regards
Dave

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

   


You are mutating the list that you are iterating over so in essence you 
are looking at the word in list index 0, testing it, and removing it, 
then moving onto list index 1 but now your list has 'amazing' in index 0 
so that does not get checked.


The simplest way is to iterate through a new list with this
for word in candidates[:]:

That will create a new list that you will iterate over while you mutate 
the original list.


--
Kind Regards,
Christian Witts


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pure function problem

2010-09-28 Thread Alan Gauld

Just home from vacation so jumping in late...

Roelof Wobben rwob...@hotmail.com wrote


class tijd :
   pass


Others have solved this for you but you don't appear to have picked
up on the point made by Jeremy that you are not initialising your
class's attributes.

By only creating the attributes within the function - and worse, by
creating different attributes depending on the logic flow - you are 
creating

a huge layer of complexity for yourself. That is why you will nearly
always see a class definition have an __init__ method. It ensures that
the minimum set of attributes are there and valid (at least with 
default

values)

If you carrry on defining classes as you are doing you will continue
to have these errors because the code that uses the object will not 
know

whether attributes exist or not. You will have to check the existence
of each atribute before you use it. That is hard work, much harder
than creating an __init__ method.


def increment(time, seconds):
   sum = tijd()
   sum.seconds = time.seconds + seconds

   if sum.seconds 60 :
   minutes, seconds = divmod(sum.seconds, 60)
   sum.seconds = seconds
   sum.minutes = time.minutes + minutes
   return sum



Traceback (most recent call last):
 File C:\Users\wobben\workspace\oefeningen\src\test.py, line 22, 
in module

   print uitkomst.minutes, uitkomst.seconds
AttributeError: tijd instance has no attribute 'minutes'

So it looks like uitkomst has no attribute minutes but uitkomst
is a instance of tijd which has a attribute minutes.


No it doesn't if seconds = 60.

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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread Jeremy Jones
On Sat, Sep 25, 2010 at 11:50 PM, Preetinder Singh putj...@yahoo.com wrote:
 Hi I am trying to learn how to program, I want to become a software
 developer so I can develop a software and also understand how to write my
 own software not copying someone else. So if there any book or online
 tutorials for complete beginners. I went to the python website and on wiki
 python and there are so many books to choose from, please help me choose
 one.


Beginning Python by Magnus lie Hetland is good.  I have the first
edition, but not the second.  I can only imagine that it got better.
Head First Programming: A Learner's Guide to Programming Using the
Python Language by David Griffiths and Paul Barry was a great read.
It's unconventional (by their nature, all Head First books are), but
excellent.  It's about programming in general, but uses Python to
demonstrate.
There's also a new book coming out shortly that will probably benefit
you: Head First Python.  Again, it's unconventional, but thoroughly
enjoyable and informative.

Disclaimer:  I tech reviewed all 3 of these books.  I don't get any
more $ for you buying them, though.

Another great read is the Python Cookbook.  You can find the recipes
online, also, but sometimes it's good to just sit with a hard copy of
the book.  The cookbook will walk you through tons of code examples,
which is really helpful when you're learning a new language (or any
language for the first time).

HTH,

- jmj




 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who never programmedbefore or have no experience in programming

2010-09-28 Thread Alan Gauld


Preetinder Singh putj...@yahoo.com wrote

copying someone else. So if there any book or online tutorials for 
complete
beginners. I went to the python website and on wiki python and there 
are so many

books to choose from, please help me choose one.


There are many because people learn in different ways.
My tutor, for example, focuses on general programming principles and 
uses 3
languages to illustrate the points. It also assumes a fair degree of 
computer
skills although no previous programming experience. Others take an 
example
based approach. Others focus on a feature by feature, in depth 
coverage of a

single language. It just depends on how you like to be taught.

My advice would be to pick two or three tutorials from the Non 
Programmers
section of the web site, follow a few of the sections in each and see 
which seems
most effecftive to you. Stick with that tutor but when you get stuck 
refer to the
second best to see how it covers the same topic. If you still can't 
understand

ask questions here.

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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-28 Thread Alan Gauld


Marc Tompkins marc.tompk...@gmail.com wrote


The parentheses are optional in 2.6, mandatory in 3.  In 2.6, print 
and

print() are alternate ways to invoke the print statement


Not strictly true. They often give the same results but not always,
see a recent thread on this. In particular


print ('a','b')


is quite different to


print 'a','b'


But that shouldn't be an issue for 'hello world'

Alan G.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] function error

2010-09-28 Thread Alan Gauld


roberto robert...@gmail.com wrote


i have the following error when i call this function:
  20 def outOfBounds():
--- 21 if abs(turtle.position()[0]) 
turtle.window_height()/2 or abs(turtle.position()[1]) 
turtle.window_width()/2:
22 return true
23 else:

TypeError: 'function' object is unsubscriptable

but i can't really figure out where is the problem with this 
function

'unsubscriptable';


This means you are trying to use [] on a function.
eg you might be doing turtle.position[1] instead of 
turtle.position()[1]


I can't see it in your code sample but I'd check carefully that your
parens() all balance correctly and are in the right place...

HTH,


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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Basics

2010-09-28 Thread Alan Gauld


Cameron Macleod cmacleod...@gmail.com wrote

I'm relatively new to this mailing list (and python!) and I would 
greatly
appreciate some exercises to try or something to get me familiar 
with the

system.


Are you new to programming? Or just new to Python?

In erither case there are a wealth of tutorials suited to your needs
on the Python web site. They nearly all have exercises in one form or 
other.


If you are already fairly experienced you might find the Python 
Challenge

web site a fun way to learn too.

HTH,


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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread Dipo Elegbede
I go with Alan.
If you however arrive at a choice book or books, send me a list of the
books, I will check if I have any of them. I have plenty books on
python now.
You may not need to send a personal mail, just send it here on the
forum and i would send you a download link.
I hope by that everyone who wishes can have a look and I would not
have violated any copyright law.
Welcome to the world of python programming.

You sure would get a great deal of help in here.
Regards,

On 9/28/10, Alan Gauld alan.ga...@btinternet.com wrote:

 Preetinder Singh putj...@yahoo.com wrote

 copying someone else. So if there any book or online tutorials for
 complete
 beginners. I went to the python website and on wiki python and there
 are so many
 books to choose from, please help me choose one.

 There are many because people learn in different ways.
 My tutor, for example, focuses on general programming principles and
 uses 3
 languages to illustrate the points. It also assumes a fair degree of
 computer
 skills although no previous programming experience. Others take an
 example
 based approach. Others focus on a feature by feature, in depth
 coverage of a
 single language. It just depends on how you like to be taught.

 My advice would be to pick two or three tutorials from the Non
 Programmers
 section of the web site, follow a few of the sections in each and see
 which seems
 most effecftive to you. Stick with that tutor but when you get stuck
 refer to the
 second best to see how it covers the same topic. If you still can't
 understand
 ask questions here.

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


 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


-- 
Sent from my mobile device

Elegbede Muhammed Oladipupo
OCA
+2348077682428
+2347042171716
www.dudupay.com
Mobile Banking Solutions | Transaction Processing | Enterprise
Application Development
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2010-09-28 Thread Alan Gauld


masawudu bature mass0...@yahoo.ca wrote

The output is suppose to count the number of even divisors the range 
has.


You need to work this through again in your head:


def evenCount(b) :


This function takes a parameter b but you never use b in the 
function...



   for n in range(x, y+1) :


What are x and y supposed to be? They must be defined
outside the function? Don;t you really want your loop to check
the values for b? So it would be range(0,b+1)?


   count = 0


You reset count to zero for each time through the loop - do
you really want to do that?


   if n % 2 == 0 :
   count += n/3


Why do you add n/3?


   count % n == 1


This is a boolean expression that will evaluate to TRue or False
and which you then ignore. It does nothing useful.


   return n


And this will always return the first value of your loop, x.

Try working through it on paper, writing down the values of each 
variable
in the function  for each time through the loop. Are they what you 
expect?


HTH,


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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] function error

2010-09-28 Thread Nitin Das
It seems that ur turtle.position doesn't return a list because of this when
indexing is done on that u get this kind of error.

--nitin

On Tue, Sep 28, 2010 at 3:39 PM, Alan Gauld alan.ga...@btinternet.comwrote:


 roberto robert...@gmail.com wrote


  i have the following error when i call this function:
  20 def outOfBounds():
 --- 21 if abs(turtle.position()[0]) 
 turtle.window_height()/2 or abs(turtle.position()[1]) 
 turtle.window_width()/2:
22 return true
23 else:

 TypeError: 'function' object is unsubscriptable

 but i can't really figure out where is the problem with this function
 'unsubscriptable';


 This means you are trying to use [] on a function.
 eg you might be doing turtle.position[1] instead of turtle.position()[1]

 I can't see it in your code sample but I'd check carefully that your
 parens() all balance correctly and are in the right place...

 HTH,


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



 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2010-09-28 Thread Steven D'Aprano
On Tue, 28 Sep 2010 02:15:52 pm masawudu bature wrote:
 I'm having a hard time finding the count of divisors that are even.
 Help anybody?

 Here's my code.

 The output is suppose to count the number of even divisors the range
 has.

I don't understand the question. What do you mean by divisors the range 
has? Perhaps you should show an example, and give the answer you 
expect.



This function is troublesome:

 def evenCount(b) :
 for n in range(x, y+1) :
 count = 0
 if n % 2 == 0 :
 count += n/3
 count % n == 1
 return n

What's b? It is never used.

Every time through the loop, you start the count at zero again.

This function will always return y, the stopping value.



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with list.remove() loop

2010-09-28 Thread Steven D'Aprano
On Tue, 28 Sep 2010 06:55:15 pm Christian Witts wrote:

 You are mutating the list that you are iterating over so in essence
 you are looking at the word in list index 0, testing it, and removing
 it, then moving onto list index 1 but now your list has 'amazing' in
 index 0 so that does not get checked.

 The simplest way is to iterate through a new list with this
  for word in candidates[:]:

 That will create a new list that you will iterate over while you
 mutate the original list.



Another technique is to iterate over the list backwards, so you are only 
ever deleting words you've already seen:

for i in range(len(candidates)-1, -1, -1)):
word = candidates[i]
if some_test():
del candidates[i]


I know the series of -1, -1, -1 is ugly, but that's what it takes.


-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list comprehension, efficiency?

2010-09-28 Thread Steven D'Aprano
On Tue, 28 Sep 2010 01:57:23 pm Bill Allen wrote:

 I can now see that quite a bit of the code I write dealing with lists
 can be done with list
 comprehensions.   My question is this, is the list comprehension
 styled code generally
 more efficient at runtime?  If so, why?


List comprehensions *are* lists, or rather, they produce lists.

A list comprehension 

result = [expr for x in seq] 

is just syntactic sugar for a for-loop:

result = []
for x in seq:
result.append(x)

except that in Python 3, the x variable is hidden. (In Python 2 it is 
not, but that was an accident.) The end result is exactly the same 
whether you use a list comp or a for-loop.

The advantage of for-loops is that you can do much more complex code. 
That complexity comes at a cost, and consequently for-loops tend to be 
a little bit slower than list comprehensions: some of the work can be 
done under the hood, faster than regular Python code. But for most 
cases, this difference is relatively small and won't make any real 
difference. What does it matter if your program runs in 24 milliseconds 
instead of 22 milliseconds? Or five hours and seventeen minutes instead 
of five hours and sixteen minutes? Who cares? Write the code that is 
most natural and easy to read and understand, and only worry about such 
tiny savings when you absolutely have to.

But there is one case where for-loops are potentially MUCH faster than 
list comps. List comps always run all the way to the end, but for-loops 
can break out early. If your problem lets you break out of the loop 
early, this is a good thing. So this for-loop:


for x in xrange(1000):
result.append(x+1)
if x  5: break


will beat the pants off this list comp:

[x+1 for x in xrange(1000) if x = 5]

There's no way to break out of the list comp early -- it has to keep 
going past 5 all the way to the end.


-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread Alif Shirali

You might also consider the following free resources that are meant for new 
programmers. They can easily be found on the internet:

How to Think Like a (Python) Programmer
by Allen Downey

Dive Into Python
20 May 2004
Copyright © 2000, 2001, 2002, 2003, 2004 Mark Pilgrim 
(mailto:m...@diveintopython.org)
This book lives at http://diveintopython.org/. If you're reading it somewhere 
else, you may not have the latest version.

and the intro python short courses at ocw.mit.edu and www.berkeley.edu
MIT is generaly open free to the public, and last I checked Berkeley was too. 
The MIT course was designed for non computer science students.

Good luck, and I agree with every comment posted in this forum about this.

Date: Sat, 25 Sep 2010 20:50:25 -0700
From: putj...@yahoo.com
To: tutor@python.org
Subject: [Tutor] I am looking for a book on Beginners who never programmed  
before or have no experience in programming



Hi I am trying to learn how to program, I want to become a software developer 
so I can develop a software and also understand how to write my own software 
not copying someone else. So if there any book or online tutorials for complete 
beginners. I went to the python website and on wiki python and there are so 
many books to choose from, please help me choose one.
 


  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor   
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread Steven D'Aprano
On Tue, 28 Sep 2010 07:37:12 pm Jeremy Jones wrote:

 Head First Programming: A Learner's Guide to Programming Using the
 Python Language by David Griffiths and Paul Barry was a great read.
 It's unconventional (by their nature, all Head First books are),


I've never heard of Head First Programming -- how are they 
unconventional?



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] filling 2d array with zeros

2010-09-28 Thread Steven D'Aprano
On Tue, 28 Sep 2010 11:56:33 am Alex Hall wrote:
  (But don't forget that Python is not necessarily written in C.
  There's Jython, written in Java, and CLPython written in Lisp, and
  many others. How they implement objects may be different. What
  happens under the hood isn't important, so long as the behaviour at
  the Python level remains the same.)

 Really? Neat! I wonder what the advantage of doing that is, since the
 end result, as you say, should be the same once you start writing
 Python code?

Different implementations can make different choices, to suit different 
needs. So long as the end result is the same, they can choose different 
mechanisms, different techniques, radically different strategies, or 
simply choose a different implementation language because they can.

CPython is a conservative implementation written in ordinary C so that 
it is available on almost any platform that has a C compiler. 
Efficiency is not its primary goal, clarity of code and simplicity of 
design is considered just as important. This is almost certainly the 
version you are using.

Unladen Swallow is a version of CPython written by Google that aims to 
speed up certain time-critical parts. If it works, it may end up being 
merged with the regular CPython. Unfortunately, after a flash of 
publicity and some promising early results, Unladen Swallow seems to 
have gone quiet.

PyPy is a version of Python written in Python. It has an incredible 
mission: to eventually produce versions of Python which are faster than 
pure C, despite being written in Python itself. Although they have a 
long, long way to go, they are making good progress, and PyPy can now 
run Python code faster than CPython. PyPy is becoming a generalised 
Just-In-Time compiler for high-level languages like Python.

IronPython and Jython are designed to integrate with Dot-Net and Java. 
IronPython is probably written in C#, like most Dot-Net software, and 
Jython is written in Java.

Stackless Python is similar to CPython except it doesn't have a function 
call stack, which is good for certain specialist applications.

Pynie is an experimental version of Python written for the Parrot 
virtual machine used by Perl 6.

CapPython is a restricted version of Python which aims to be much more 
secure, allowing you to safely run untrusted code without it eating 
your computer. 

And there are many more... I count at least 41 current or past Python 
implementations, add-ons and related projects. My favourite (apart from 
PyPy, which makes me feel all warm and tingly in that special place) is 
LikePython:

http://www.staringispolite.com/likepython/


#!usr/bin/python
# My first Like, Python script!
yo just print like hello world bro


I can't wait to put that on my resume :)




-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question

2010-09-28 Thread Roelof Wobben

Hello,


Im now studying this page :
http://openbookproject.net/thinkcs/python/english2e/ch16.html

But I don't get it why aces are now lower then deuces in the  cmp function.


Roelof

  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] filling 2d array with zeros

2010-09-28 Thread Alex Hall
On 9/28/10, Steven D'Aprano st...@pearwood.info wrote:
 On Tue, 28 Sep 2010 11:56:33 am Alex Hall wrote:
  (But don't forget that Python is not necessarily written in C.
  There's Jython, written in Java, and CLPython written in Lisp, and
  many others. How they implement objects may be different. What
  happens under the hood isn't important, so long as the behaviour at
  the Python level remains the same.)

 Really? Neat! I wonder what the advantage of doing that is, since the
 end result, as you say, should be the same once you start writing
 Python code?

 Different implementations can make different choices, to suit different
 needs. So long as the end result is the same, they can choose different
 mechanisms, different techniques, radically different strategies, or
 simply choose a different implementation language because they can.

 CPython is a conservative implementation written in ordinary C so that
 it is available on almost any platform that has a C compiler.
 Efficiency is not its primary goal, clarity of code and simplicity of
 design is considered just as important. This is almost certainly the
 version you are using.
Probably, I just got 2.6 from python.org.

 Unladen Swallow is a version of CPython written by Google that aims to
 speed up certain time-critical parts. If it works, it may end up being
 merged with the regular CPython. Unfortunately, after a flash of
 publicity and some promising early results, Unladen Swallow seems to
 have gone quiet.

 PyPy is a version of Python written in Python. It has an incredible
 mission: to eventually produce versions of Python which are faster than
 pure C, despite being written in Python itself. Although they have a
 long, long way to go, they are making good progress, and PyPy can now
 run Python code faster than CPython. PyPy is becoming a generalised
 Just-In-Time compiler for high-level languages like Python.
Okay, I now have to go investigate this and see how it is even
possible; somewhere, the Python code has to get down to machine
code...

 IronPython and Jython are designed to integrate with Dot-Net and Java.
 IronPython is probably written in C#, like most Dot-Net software, and
 Jython is written in Java.

 Stackless Python is similar to CPython except it doesn't have a function
 call stack, which is good for certain specialist applications.
I'll take your word for it, but it seems like you could then not use
OO since a function's return would have no idea where to go. I was
once forced to try LISP, MIPS machine language, and a functionless
Basic, and I hated them.

 Pynie is an experimental version of Python written for the Parrot
 virtual machine used by Perl 6.

 CapPython is a restricted version of Python which aims to be much more
 secure, allowing you to safely run untrusted code without it eating
 your computer.

 And there are many more... I count at least 41 current or past Python
 implementations, add-ons and related projects. My favourite (apart from
 PyPy, which makes me feel all warm and tingly in that special place) is
 LikePython:

 http://www.staringispolite.com/likepython/


 #!usr/bin/python
 # My first Like, Python script!
 yo just print like hello world bro

...interesting. This, too, will have to be looked at, if only because
it is so different. Thanks for all the info!


 I can't wait to put that on my resume :)




 --
 Steven D'Aprano
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor



-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pyMVPA and OSError

2010-09-28 Thread Emile van Sebille

On 2/18/2010 8:10 AM Juli said...

I am very much new to python, and thus I am likely to feel stupid about
asking. But I need to get past this to continue with my work.
I need pyMVPA module to run some analysis on fMRI data, but as a start I
want to at first play around with the sample data provided on pyMVPA
website. I have downloaded Python2.6,


Just a guess, but the pyMVPA site specifically mentions using version 
2.5, and whenever I have issues with a new package, I go back to the 
installation documentation and follow it closely as it's typically 
written by an experienced user while installing and yields a functioning 
implementation.  I'd reinstall and pay close attention to the version 
numbers and dependencies.


http://www.pymvpa.org/installation.html#macos-x

Then, always check if there's a user group for the package.  Diagnosing 
installation problems of specific packages and related dependencies are 
rarely an area of expertise outside the users of the package.  Join the 
mailing list.


See http://lists.alioth.debian.org/mailman/listinfo/pkg-exppsy-pymvpa

HTH,

Emile



my operating system is Mac Leopard
(i get a depracation warning when I try to  import mvpa, which is not
the problem, however, when I attempt to use the following line
  import mvpa.suite as mvpa
which i assume to mean the same thing, I dont get deprecation warning,
but I do get a bunch of errors as follows:
  import mvpa.suite as mvpa

Traceback (most recent call last):
File pyshell#14, line 1, in module
import mvpa.suite as mvpa
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/suite.py,
line 38, in module
from mvpa.algorithms.cvtranserror import *
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/algorithms/cvtranserror.py,
line 15, in module
from mvpa.measures.base import DatasetMeasure
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/measures/base.py,
line 31, in module
from mvpa.clfs.stats import autoNullDist
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/clfs/stats.py,
line 772, in module
if externals.exists('pylab'):
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/base/externals.py,
line 432, in exists
exec _KNOWN[dep]
File string, line 1, in module
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/base/externals.py,
line 249, in __check_pylab
import pylab as P
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pylab.py,
line 1, in module
from matplotlib.pylab import *
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pylab.py,
line 206, in module
from matplotlib import mpl # pulls in most modules
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/mpl.py,
line 2, in module
from matplotlib import axis
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axis.py,
line 10, in module
import matplotlib.font_manager as font_manager
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py,
line 1297, in module
_rebuild()
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py,
line 1288, in _rebuild
fontManager = FontManager()
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py,
line 980, in __init__
self.ttffiles = findSystemFonts(paths) + findSystemFonts()
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py,
line 337, in findSystemFonts
for f in get_fontconfig_fonts(fontext):
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py,
line 298, in get_fontconfig_fonts
pipe = subprocess.Popen(['fc-list', '', 'file'], stdout=subprocess.PIPE)
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py,
line 621, in __init__
errread, errwrite)
File
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py,
line 1126, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

-

I am not sure why OSError is popping and I am sure I am doing something
wrong, I just do not know enough to pinpoint what exactly.

Any feedback is appreciated. And I do once more apologize for asking
very stupid questions.


___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor




___
Tutor 

Re: [Tutor] pyMVPA and OSError

2010-09-28 Thread Evert Rol
  Hi,

 I am very much new to python, and thus I am likely to feel stupid about 
 asking. But I need to get past this to continue with my work.
 I need pyMVPA module to run some analysis on fMRI data, but as a start I want 
 to at first play around with the sample data provided on pyMVPA website. I 
 have downloaded Python2.6, my operating system is Mac Leopard (i get a 
 depracation warning when I try to  import mvpa,

What depracation warning?


 which is not the problem, however, when I attempt to use the following line
  import mvpa.suite as mvpa

I wouldn't do that; just seems prone to lead to confusion. Perhaps:
   import mvpa.suite as mvpas
or
   from mvpa import suite


 which i assume to mean the same thing,

It normally doesn't mean the same thing. mvpa and mvpa.suite would normally be 
quite different things. But perhaps this is how the package is setup; that 
would be in the manual.


More after the traceback.


 I dont get deprecation warning, but I do get a bunch of errors as follows:
  import mvpa.suite as mvpa
 
 Traceback (most recent call last):
  File pyshell#14, line 1, in module
import mvpa.suite as mvpa
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/suite.py,
  line 38, in module
from mvpa.algorithms.cvtranserror import *
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/algorithms/cvtranserror.py,
  line 15, in module
from mvpa.measures.base import DatasetMeasure
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/measures/base.py,
  line 31, in module
from mvpa.clfs.stats import autoNullDist
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/clfs/stats.py,
  line 772, in module
if externals.exists('pylab'):
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/base/externals.py,
  line 432, in exists
exec _KNOWN[dep]
  File string, line 1, in module
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/mvpa/base/externals.py,
  line 249, in __check_pylab
import pylab as P
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pylab.py,
  line 1, in module
from matplotlib.pylab import *
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pylab.py,
  line 206, in module
from matplotlib import mpl  # pulls in most modules
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/mpl.py,
  line 2, in module
from matplotlib import axis
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axis.py,
  line 10, in module
import matplotlib.font_manager as font_manager
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py,
  line 1297, in module
_rebuild()
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py,
  line 1288, in _rebuild
fontManager = FontManager()
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py,
  line 980, in __init__
self.ttffiles = findSystemFonts(paths) + findSystemFonts()
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py,
  line 337, in findSystemFonts
for f in get_fontconfig_fonts(fontext):
  File 
 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py,
  line 298, in get_fontconfig_fonts
pipe = subprocess.Popen(['fc-list', '', 'file'], stdout=subprocess.PIPE)


At first read, it looks like mvpa is checking for external dependencies, 
including checking for fonts to be used by matplotlib (or actually, matplotlib 
does this).
Matplotlib then tries to run an external process called 'fc-list', which 
presumably list the font-config fonts.
It looks like your system does not have this installed.

Since this is all installed through matplotlib, that would mean that somewhere 
there is a dependency check missing. 
For a start, you could try and reinstall matplotlib yourself, hoping this 
solves it. But I won't guarantee that.

Since this all done through macports, I wonder what your python is: did you 
install that through matplotlib as well, or are you using a different (system) 
python?
You mention you downloaded Python 2.6, which would suggest you're not using 
macports python, which may cause these errors as well.
In addition, if you are on Snow Leopard (not plain Leopard), you should have 
Python 2.6 as the system python, which would be a different python again (and a 
bit 

Re: [Tutor] question

2010-09-28 Thread Dave Angel



On 2:59 PM, Roelof Wobben wrote:

Hello,


Im now studying this page :
http://openbookproject.net/thinkcs/python/english2e/ch16.html

But I don't get it why aces are now lower then deuces in the  cmp function.


Roelof

  
Why would you be surprised that aces are lower than deuces?  If aces are 
represented by 1, and deuces by 2, then 1 is less than 2.


Notice that because self.suit is compared first, an ace of spades is 
higher than a deuce of hearts.  It's only within the same suit that an 
ace is less than a deuce.


DaveA




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread Wayne Werner
On Tue, Sep 28, 2010 at 6:39 AM, Alif Shirali alifshir...@hotmail.comwrote:

  You might also consider the following free resources that are meant for
 new programmers. They can easily be found on the internet:


I'll toss another recommendation into the ring:

Snake Wrangling for Kids.

It may be geared towards younger people, but I found it entertaining (maybe
my sense of humour is a little immature at times ;) and it also explained
topics fairly well. Explained so well that even adults can understand :)

my 2.5¢, adjusted for inflation
-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues In Terminal

2010-09-28 Thread Wayne Werner
On Tue, Sep 28, 2010 at 5:02 AM, Alan Gauld alan.ga...@btinternet.comwrote:


 Marc Tompkins marc.tompk...@gmail.com wrote



  The parentheses are optional in 2.6, mandatory in 3.  In 2.6, print and
 print() are alternate ways to invoke the print statement


 Not strictly true. They often give the same results but not always,
 see a recent thread on this. In particular

  print ('a','b')


 is quite different to

  print 'a','b'


 But that shouldn't be an issue for 'hello world'


And of course if you're on 2.6+ you can always add

from __future__ import print_function

and that will help prepare you for the eventual migration to 3+

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if value in list of dictionaries

2010-09-28 Thread Norman Khine
thanks for the reply, i think i have it now, perhaps it could be done better

http://pastie.org/1186545

On Tue, Sep 28, 2010 at 2:56 PM, Emile van Sebille em...@fenx.com wrote:
  Hi Norman,

 Read my reply again -- that's the second question I answered.

 Emile


 On 9/28/2010 12:56 AM Norman Khine said...

 thanks for the reply. i should have been more specific in my question ;)

 the order in which 'other' is listed is not always the last item of
 the list as it is dependent on where in the CSV file it is included.

 what i was trying to do is to take create the list of dictionary items
 and then find the item which has name=='other' and then put this as
 the last item in the list.

 so from this list http://pastie.org/1185974 how do i select the item
 name == 'other' and put it at the end of the list?

 On Mon, Sep 27, 2010 at 11:39 PM, Emile van Sebilleem...@fenx.com
  wrote:

 On 9/27/2010 1:22 PM Norman Khine said...

 what is the correct way to ensure that {'industry': 'travel', 'name':
 'other','value': MSG(uOther)} is always added to the end of this
 list after all the items have been sorted?

 here is the code which returns this list:

   options.sort(key=itemgetter('name'))
   return options

 So, to answer the question you ask above, you can do:

   options.sort(key=itemgetter('name'))
   options.append({'industry':'travel',
      'name':'other','value':MSG(uOther)}
   return options

 But I don't think that's the question you're looking to get answered.

 I think you want other to be found only at the end and not elsewhere.

 Then you might try excluding other from options allowing the above to
 append
 it to the end:

 for index, row in enumerate(topics.get_rows()):
    if row[0] != 'other':
        options.append({'name': row[0], 'value': MSG(row[1])})

 HTH,

 Emile



 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor








-- 
˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ
ǝq s,ʇǝן ʇǝʎ
% .join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ,adym,*)uzq^zqf ] )
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] filling 2d array with zeros

2010-09-28 Thread Dave Angel



On 2:59 PM, Alex Hall wrote:

On 9/28/10, Steven D'Apranost...@pearwood.info  wrote:

snip

PyPy is a version of Python written in Python. It has an incredible
mission: to eventually produce versions of Python which are faster than
pure C, despite being written in Python itself. Although they have a
long, long way to go, they are making good progress, and PyPy can now
run Python code faster than CPython. PyPy is becoming a generalised
Just-In-Time compiler for high-level languages like Python.

Okay, I now have to go investigate this and see how it is even
possible; somewhere, the Python code has to get down to machine
code...

Just-in-time compiling  (JIT) is taking some high-level construct, such 
as python byte code or a java class file, and compiling it into machine 
code, at the time of first execution.  Java uses it heavily, to achieve 
its performance level.  The standard CPython does not, but simply 
interprets those byte codes.


One advantage of just-in-time is that the translation can be specific to 
a particular processor, or even to a particular operating system and 
operating environment.  Conventional compiling is done by the developer, 
and he has to release multiple versions for multiple platforms.  And 
even then, he seldom takes advantage of the newer instructions of a 
given processor, which are changing quite frequently.  I'm sure there 
are at least a dozen different instruction supersets of the original 
Pentium processor, though most of the recent ones are relatively 
specialized (eg. for hashing, searching, encryption), and likely to 
affect libraries more than your main program.


DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread Sayth Renshaw
I read python from novice to professinal. I also read a lot of online guides
sometimes more beneficial than the books.

These links should help you

http://wiki.python.org/moin/BeginnersGuide

http://www.awaretek.com/tutorials.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question

2010-09-28 Thread Roelof Wobben


 


From: rwob...@hotmail.com
To: da...@ieee.org
Subject: RE: [Tutor] question
Date: Tue, 28 Sep 2010 14:22:17 +





 
 Date: Tue, 28 Sep 2010 10:02:27 -0400
 From: da...@ieee.org
 To: rwob...@hotmail.com
 CC: tutor@python.org
 Subject: Re: [Tutor] question
 
 
 
 On 2:59 PM, Roelof Wobben wrote:
  Hello,
 
 
  Im now studying this page :
  http://openbookproject.net/thinkcs/python/english2e/ch16.html
 
  But I don't get it why aces are now lower then deuces in the cmp function.
 
 
  Roelof
 
  
 Why would you be surprised that aces are lower than deuces? If aces are 
 represented by 1, and deuces by 2, then 1 is less than 2.
 
 Notice that because self.suit is compared first, an ace of spades is 
 higher than a deuce of hearts. It's only within the same suit that an 
 ace is less than a deuce.
 
 DaveA
 
 
 
 

Hello Dave, 
 
In some games in the Netherlands Aces can have a value of 11 or 1 .
So if Aces are 11 then Deuces is lesser then Aces.
 
Can I say that the position of the list is a representation of the value.
 
Roelof
 
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread Jeremy Jones
On Tue, Sep 28, 2010 at 7:47 AM, Steven D'Aprano st...@pearwood.info wrote:
 On Tue, 28 Sep 2010 07:37:12 pm Jeremy Jones wrote:

 Head First Programming: A Learner's Guide to Programming Using the
 Python Language by David Griffiths and Paul Barry was a great read.
 It's unconventional (by their nature, all Head First books are),


 I've never heard of Head First Programming -- how are they
 unconventional?


Both HF Programming (currently out) and HF Python (currently being
written) are very example-driven and in the course of each example,
introduce a number of concepts.  So, rather than having a chapter on
lists, the books introduce lists as a part of an evolving example.
The conventional approach (in my view) is splitting a book into
chapters of such topics as variables, operators, lists, dicts, OO,
etc.  So, I hope that I conveyed the unconventional as a good thing,
because I definitely see it as such.  I love these books.  Honestly,
it's enjoyable to me just to see the craft these folks use to evolve a
problem and weave in new concepts all along the way.



 --
 Steven D'Aprano
 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question

2010-09-28 Thread Dave Angel

 On 9/28/2010 10:22 AM, Roelof Wobben wrote:





Date: Tue, 28 Sep 2010 10:02:27 -0400
From: da...@ieee.org
To: rwob...@hotmail.com
CC: tutor@python.org
Subject: Re: [Tutor] question



On 2:59 PM, Roelof Wobben wrote:

Hello,


Im now studying this page :
http://openbookproject.net/thinkcs/python/english2e/ch16.html

But I don't get it why aces are now lower then deuces in the cmp function.


Roelof



Why would you be surprised that aces are lower than deuces? If aces are
represented by 1, and deuces by 2, then 1 is less than 2.

Notice that because self.suit is compared first, an ace of spades is
higher than a deuce of hearts. It's only within the same suit that an
ace is less than a deuce.

DaveA






Hello Dave,



In some games in the Netherlands Aces can have a value of 11 or 1 .

So if Aces are 11 then Deuces is lesser then Aces.



Can I say that the position of the list is a representation of the value.



Roelof


  

The class attribute was assigned as follows:

 ranks  =  [narf,  Ace,  2,  3,  4,  5,  6,  7,
 8,  9,  10,  Jack,  Queen,  King]


So Ace is at position 1.  And if you want an Ace, you'd have to supply a 1 to 
the constructor.

I would certainly agree that in many games this wouldn't be the desired case.  
Some games specify aces higher than kings, some have no ordering among face 
cards, some let the player choose.

If the Card class needed to cover all cases, then one might need to make the 
__cmp__() method parameterizable, so that at different times, the cards might 
sort differently.

But this is one implementation of the Card class, and hopefully it's 
self-consistent in the course.



DaveA







___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if value in list of dictionaries

2010-09-28 Thread Peter Otten
Norman Khine wrote:

 thanks for the reply, i think i have it now, perhaps it could be done
 better

  topics.sort(key=itemgetter('name'))
  for i, t in enumerate(topics):
 ... for (k, v) in t.iteritems():
 ... if v == 'other':
 ... topics.append(topics.pop(i))
 ... 
 
You should never iterate over a list or dictionary and add or remove items 
to it at the same time. That is a recipe for disaster even if it doesn't 
fail explicitly*

As Christian Witts explains in the trouble with list.remove() loop thread 
you will not see all items.

I suggest that you use a better sort key instead:

 def sort_key(topic):
... name = topic[name]
... return name == other, name
...
 topics.sort(key=sort_key)

 pprint(topics)
[{'industry': 'travel',
  'name': 'assistant-manager',
  'value': 'Assistant Manager'},

snip

 {'industry': 'travel', 'name': 'university', 'value': 'University'},
 {'industry': 'travel', 'name': 'other', 'value': 'Other'}]

The above sort_key() checks only the name key for an other value. It 
will return a (True, name) tuple if the name is other and (False, name) 
else. As 

False  True 

it ensures that topics with topic[name] == other are placed after all 
others. If (like your attempt suggests) you want to check all values instead 
of just the one associated with the name key use

def sort_key(topic):
return other in topic.itervalues(), topic[name]

Remember that both functions are case-sensitive.

Peter

(*) I'll leave it to Steven D'Aprano to add the fine print ;)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if value in list of dictionaries

2010-09-28 Thread Emile van Sebille

On 9/28/2010 7:12 AM Norman Khine said...

thanks for the reply, i think i have it now, perhaps it could be done better



I think I'd use a helper function to sort:

def sortOtherToEnd(val):
  if val['name'] == 'other:
return ''
  return val['name']

#then sort it

topics.sort(key=sortOtherToEnd)

But, generally, I'd stop once I got it going without worrying too much 
about 'better' ways -- that's a subjective measure.  There is often one 
obvious way to do it, but unless you've seen that way before, there'll 
often be many alternatives that work as well.


HTH,

Emile

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with list.remove() loop

2010-09-28 Thread Peter Otten
D Ryan (2) wrote:

 Hello all,
 I am currently trying to write a program which can find the solution to a
 game of hangman.
 In a part of the program, a user inputs a letter, a tester tells him if
 the word contains that letter, and then if the answer is no, all words
 containing that letter are removed from the list of remaining candidates.
 However, the code I've written seems to remove some, but not all the words
 containing the letter. Strangely though, if i run it a few more times it
 gets some of the ones it missed the 1st time round, untill after enough
 iterations it gets all of them. I cant understand why it doesnt remove all
 of them the first time round. I have cut the offending code and formatted
 it to work on its own, and also to fit into a relatively short email.
 
 # A sample list of words, one of which is the answer.
 candidates = [abacus,amazing,
   ozimandias,
   a,alphanumeric,
   functioning]
 
 # In the following code, the user has guessed the letter 'a',
 # and the tester has told him that the letter 'a' is not in the word.
 
 user_guess=a
 tester_response=no
 
 # The following code should eliminate all words which contain the letter
 # 'a', leaving only the word 'functioning' in the list
 
 if tester_response in (No,no,n,N,NO):
 for word in candidates:
 if user_guess in word:
 print word, removed..
 candidates.remove(word)
 print candidates
 
 Running once gives this output
 
 abacus removed..
 ozimandias removed..
 alphanumeric removed..
 ['amazing', 'a', 'functioning']
 
 But if i run it again it successfully removes 'amazing, and the next time
 it removes 'a', leaving the correct answer. I'm perplexed by this strange
 behaviour and would be most appreciative of any help. I'm very new to
 python so apologies for any formatting/style errors, and also for the
 simplicity of the problem.

I'd like to point out a robust method to avoid such pitfalls: create a new 
list instead of modifying the old one:

old_candidates = candidates
candidates = []
for word in old_candidates:
if user_guess in word:
print word, removed
else:
candidates.append(word)
print candidates

Often you can simplify that to a list comprehension like

candidates = [word for word in candidates if user_guess not in word]

Peter

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if value in list of dictionaries

2010-09-28 Thread Norman Khine
thank you, here is the updated version:

http://pastie.org/1186860

On Tue, Sep 28, 2010 at 5:50 PM, Emile van Sebille em...@fenx.com wrote:
 On 9/28/2010 7:12 AM Norman Khine said...

 thanks for the reply, i think i have it now, perhaps it could be done
 better


 I think I'd use a helper function to sort:

 def sortOtherToEnd(val):
  if val['name'] == 'other:
    return ''
  return val['name']

 #then sort it

 topics.sort(key=sortOtherToEnd)

 But, generally, I'd stop once I got it going without worrying too much about
 'better' ways -- that's a subjective measure.  There is often one obvious
 way to do it, but unless you've seen that way before, there'll often be many
 alternatives that work as well.

 HTH,

 Emile

 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




-- 
˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ
ǝq s,ʇǝן ʇǝʎ
% .join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ,adym,*)uzq^zqf ] )
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if value in list of dictionaries

2010-09-28 Thread Emile van Sebille

On 9/28/2010 9:37 AM Norman Khine said...

thank you, here is the updated version:

http://pastie.org/1186860




The only obvious redundancy is the duplicated sort of options just 
before the return.  You only need the newer sort_key based one.


Emile

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list comprehension, efficiency?

2010-09-28 Thread Bill Campbell
On Tue, Sep 28, 2010, Lie Ryan wrote:
On 09/28/10 13:57, Bill Allen wrote:
 I can now see that quite a bit of the code I write dealing with lists
 can be done with list
 comprehensions.   My question is this, is the list comprehension styled
 code generally
 more efficient at runtime?  If so, why?

Yes, because the looping in list comprehension is done in C instead of a
python construct. However, they are the type of efficiency that you
shouldn't bother yourself with unless you're microoptimizing.

True enough, but dealing with large lists can be expensive,
particularly when appending.  Before I discovered sets, I found
significant time savings by creating a dictionary, adding as
necessary, then use d.keys() to get the keys back.

This became a significant factor when I was selecting unique
lines from about 1.3 million samples.

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
Voice:  (206) 236-1676  Mercer Island, WA 98040-0820
Fax:(206) 232-9186  Skype: jwccsllc (206) 855-5792

Independent self-reliant people would be a counterproductive anachronism
in the collective society of the future where people will be defined by
their associations.  1896 John Dewey, educational philosopher, proponent
of modern public schools.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if value in list of dictionaries

2010-09-28 Thread Norman Khine
ok, great.

one thing i wanted to ask is how could i extend the class so that i
can just change the name of the csv file?

On Tue, Sep 28, 2010 at 6:53 PM, Emile van Sebille em...@fenx.com wrote:
 On 9/28/2010 9:37 AM Norman Khine said...

 thank you, here is the updated version:

 http://pastie.org/1186860



 The only obvious redundancy is the duplicated sort of options just before
 the return.  You only need the newer sort_key based one.

 Emile

 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




-- 
˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ
ǝq s,ʇǝן ʇǝʎ
% .join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ,adym,*)uzq^zqf ] )
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] function error

2010-09-28 Thread roberto
On Tue, Sep 28, 2010 at 12:35 PM, Nitin Das nitin@gmail.com wrote:
 It seems that ur turtle.position doesn't return a list because of this when
 indexing is done on that u get this kind of error.
 --nitin

it seemed to me that kind of error but then i found that it was a
list, as expected:

$  type(turtle.position())
$ type 'list'
$ abs(turtle.position()[0])
   13.858469413370102

that's why i'm going crazy ...


 On Tue, Sep 28, 2010 at 3:39 PM, Alan Gauld alan.ga...@btinternet.com
 wrote:

 roberto robert...@gmail.com wrote

 i have the following error when i call this function:
  20 def outOfBounds():
 --- 21         if abs(turtle.position()[0]) 
 turtle.window_height()/2 or abs(turtle.position()[1]) 
 turtle.window_width()/2:
    22                 return true
    23         else:

 TypeError: 'function' object is unsubscriptable

 but i can't really figure out where is the problem with this function
 'unsubscriptable';

 This means you are trying to use [] on a function.
 eg you might be doing turtle.position[1] instead of turtle.position()[1]

 I can't see it in your code sample but I'd check carefully that your
 parens() all balance correctly and are in the right place...

 HTH,


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


 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor





-- 
roberto
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] function error

2010-09-28 Thread Evert Rol
 It seems that ur turtle.position doesn't return a list because of this when
 indexing is done on that u get this kind of error.
 --nitin
 
 it seemed to me that kind of error but then i found that it was a
 list, as expected:
 
 $  type(turtle.position())
 $ type 'list'
 $ abs(turtle.position()[0])
   13.858469413370102
 
 that's why i'm going crazy ...

Perhaps if you provide the full traceback from the error (assuming you're still 
getting this error); tracebacks generally show the offending code as well. It 
may be something that's simply overlooked but shows in the traceback.



 On Tue, Sep 28, 2010 at 3:39 PM, Alan Gauld alan.ga...@btinternet.com
 wrote:
 
 roberto robert...@gmail.com wrote
 
 i have the following error when i call this function:
  20 def outOfBounds():
 --- 21 if abs(turtle.position()[0]) 
 turtle.window_height()/2 or abs(turtle.position()[1]) 
 turtle.window_width()/2:
22 return true
23 else:
 
 TypeError: 'function' object is unsubscriptable
 
 but i can't really figure out where is the problem with this function
 'unsubscriptable';
 
 This means you are trying to use [] on a function.
 eg you might be doing turtle.position[1] instead of turtle.position()[1]
 
 I can't see it in your code sample but I'd check carefully that your
 parens() all balance correctly and are in the right place...
 
 HTH,
 
 
 --
 Alan Gauld
 Author of the Learn to Program web site
 http://www.alan-g.me.uk/
 
 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
 
 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
 
 
 
 
 
 -- 
 roberto
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Writing a txt from dbf

2010-09-28 Thread Susana Iraiis Delgado Rodriguez
Hello dear pythonists:

I'm developing an application in python, I'm new using this programming
language I used to work with Java, but in my job my superiors suggested me
to develop in this language.
I'm trying to read a dbf file, I already done it but my code shows me all
the lines without spaces, I want it toshow line per line and then write the
lines into a plain txt file. My code is:

from dbf import *
from string import strip
import sys
def demo1():
 a = open (archivo.txt,w)
 dbf = Dbf('tapalpa_05_plani_point.dbf',new=False)

 for k in dbf:
  print '%s'%(strip(k[2]))

  l=()
  l=(strip(k[2]))
  a.write(l)

 dbf.close()
 a.close()


demo1()
I hope you can help me.
Thank you!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] filling 2d array with zeros

2010-09-28 Thread Alex Hall
On 9/28/10, Dave Angel da...@ieee.org wrote:


 On 2:59 PM, Alex Hall wrote:
 On 9/28/10, Steven D'Apranost...@pearwood.info  wrote:
 snip

 PyPy is a version of Python written in Python. It has an incredible
 mission: to eventually produce versions of Python which are faster than
 pure C, despite being written in Python itself. Although they have a
 long, long way to go, they are making good progress, and PyPy can now
 run Python code faster than CPython. PyPy is becoming a generalised
 Just-In-Time compiler for high-level languages like Python.
 Okay, I now have to go investigate this and see how it is even
 possible; somewhere, the Python code has to get down to machine
 code...

 Just-in-time compiling  (JIT) is taking some high-level construct, such
 as python byte code or a java class file, and compiling it into machine
 code, at the time of first execution.  Java uses it heavily, to achieve
 its performance level.  The standard CPython does not, but simply
 interprets those byte codes.

 One advantage of just-in-time is that the translation can be specific to
 a particular processor, or even to a particular operating system and
 operating environment.  Conventional compiling is done by the developer,
 and he has to release multiple versions for multiple platforms.  And
 even then, he seldom takes advantage of the newer instructions of a
 given processor, which are changing quite frequently.  I'm sure there
 are at least a dozen different instruction supersets of the original
 Pentium processor, though most of the recent ones are relatively
 specialized (eg. for hashing, searching, encryption), and likely to
 affect libraries more than your main program.
Thanks for the info. That explains why Pypy said it only works on
Intel-based systems for the moment, and why special things must be
done for 64-bit processors.

 DaveA




-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question

2010-09-28 Thread Roelof Wobben


 


From: rwob...@hotmail.com
To: da...@ieee.org
Subject: RE: [Tutor] question
Date: Tue, 28 Sep 2010 19:14:29 +





 
 Date: Tue, 28 Sep 2010 10:49:28 -0400
 From: da...@ieee.org
 To: rwob...@hotmail.com; tutor@python.org
 Subject: Re: [Tutor] question
 
 On 9/28/2010 10:22 AM, Roelof Wobben wrote:
 
 
 
  Date: Tue, 28 Sep 2010 10:02:27 -0400
  From: da...@ieee.org
  To: rwob...@hotmail.com
  CC: tutor@python.org
  Subject: Re: [Tutor] question
 
 
 
  On 2:59 PM, Roelof Wobben wrote:
  Hello,
 
 
  Im now studying this page :
  http://openbookproject.net/thinkcs/python/english2e/ch16.html
 
  But I don't get it why aces are now lower then deuces in the cmp function.
 
 
  Roelof
 
 
  Why would you be surprised that aces are lower than deuces? If aces are
  represented by 1, and deuces by 2, then 1 is less than 2.
 
  Notice that because self.suit is compared first, an ace of spades is
  higher than a deuce of hearts. It's only within the same suit that an
  ace is less than a deuce.
 
  DaveA
 
 
 
 
 
  Hello Dave,
 
 
 
  In some games in the Netherlands Aces can have a value of 11 or 1 .
 
  So if Aces are 11 then Deuces is lesser then Aces.
 
 
 
  Can I say that the position of the list is a representation of the value.
 
 
 
  Roelof
 
 
  
 The class attribute was assigned as follows:
 
 ranks = [narf, Ace, 2, 3, 4, 5, 6, 7,
 8, 9, 10, Jack, Queen, King]
 
 
 So Ace is at position 1. And if you want an Ace, you'd have to supply a 1 
 to the constructor.
 
 I would certainly agree that in many games this wouldn't be the desired case. 
 Some games specify aces higher than kings, some have no ordering among face 
 cards, some let the player choose.
 
 If the Card class needed to cover all cases, then one might need to make the 
 __cmp__() method parameterizable, so that at different times, the cards might 
 sort differently.
 
 But this is one implementation of the Card class, and hopefully it's 
 self-consistent in the course.
 
 
 
 DaveA
 
 
 
  
 
 
Oke,
 
Thanks.
Then now figuring out how to solve this problem :
 
Modify __cmp__ so that Aces are ranked higher than Kings
 
So aces with value 1 must be higher then Kings with 11 
 
I think I have to make another rule in the rank part like this 
 
If self.rank = Aces and self.rank = Kings then return -1 or 1
 
Tomorrrow I will investigate this. 
 
Roelof

 
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: Writing a txt from dbf

2010-09-28 Thread Joel Goldstick
On Tue, Sep 28, 2010 at 2:33 PM, Susana Iraiis Delgado Rodriguez
susana.delgad...@utzmg.edu.mx wrote:
 Hello dear pythonists:

 I'm developing an application in python, I'm new using this programming
 language I used to work with Java, but in my job my superiors suggested me
 to develop in this language.
 I'm trying to read a dbf file, I already done it but my code shows me all
 the lines without spaces, I want it toshow line per line and then write the
 lines into a plain txt file. My code is:

 from dbf import *
 from string import strip
 import sys
 def demo1():
  a = open (archivo.txt,w)
  dbf = Dbf('tapalpa_05_plani_point.dbf',new=False)

  for k in dbf:
   print '%s'%(strip(k[2]))

   l=()
   l=(strip(k[2]))
   a.write(l)

  dbf.close()
  a.close()


 demo1()
 I hope you can help me.
 Thank you!
 ___
 Tutor maillist  -  tu...@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor



I was going to run your code, but I am not sure what dbf module you
are using.  I am running UBUNTU 9.10 and can't find a dbf module in
the repository.

What are you running?

--
Joel Goldstick



-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Operating in Place

2010-09-28 Thread Shashwat Anand
On Wed, Sep 29, 2010 at 1:33 AM, Corey Richardson kb1...@aim.com wrote:

  Hello tutors.

 I hate doing this:
string = string.lower()

 Is there a way to do it without the string = part? Thanks.


1. string is a module which is deprecated. You should probably use str or s
in your example.
2. strings in python are immutable. If you need to change something, you
need to create a new string.


 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor




-- 
~l0nwlf
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Operating in Place

2010-09-28 Thread Steve Willoughby

On 28-Sep-10 13:03, Corey Richardson wrote:

I hate doing this:
string = string.lower()

Is there a way to do it without the string = part? Thanks.


Depends on the class.  In this specific case, string objects are 
immutable (for some good reasons which are beyond the immediate point), 
so once created, they can't be changed.  They can, of course, be used to 
create new strings, which is what string.lower() is doing.  And that new 
string is then given the name string again, replacing the old string 
object (which may still have other names referencing it elsewhere).


If you were wanting to modify a mutable object in-place, Python would be 
happy to oblige.  But not strings.


Sorry :)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Operating in Place

2010-09-28 Thread Rance Hall
On Tue, Sep 28, 2010 at 3:03 PM, Corey Richardson kb1...@aim.com wrote:
  Hello tutors.

 I hate doing this:
            string = string.lower()

 Is there a way to do it without the string = part? Thanks.


I suppose the best answer is it depends on what you are doing with
string after you do string.lower()

you can use the string.lower() directly in IF statements and such without worry


a = TEST

if a.lower() == test:
   do stuff

works for me.even on the new 3.1
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] generating independent random numbers

2010-09-28 Thread Carter Danforth
Thanks for the replies, Dave and Joel. The reason I'm not just using the
time or datetime modules for a random date is because it's restricted to
1970-2038; I'm pulling dates from 1600-3099. Thanks a lot for the pointer
about the leap years, Dave, as well the class instances; just updated it and
it's all working now, and also included the rest of the code too w/ answer
verification and time tracking.

I want to start using this program to test myself for speed calculation
using Zeller's formula, it's pretty cool for determining the days of dates -
http://mathforum.org/dr/math/faq/faq.calendar.html

Because of the way variables C and D are split up from the year in the
formula, I split up the year for self.c and self.y.



import random, time, datetime, calendar

class Date:
def __init__(self):
self.c = random.randint(16,30)
self.y = random.randint(0,99)
self.month = random.randint(1,12)
self.year = self.c*100 + self.y

apr = [4,6,9,11]
feb = [2]
notleap = [1700, 1800, 1900, 3000]

if self.month in feb:
if self.year%4 == 0:
if self.year in notleap:
self.k = random.randint(1,28)
else:
self.k = random.randint(1,29)
else:
self.k = random.randint(1,28)
elif self.month in apr:
self.k = random.randint(1,30)
else:
self.k = random.randint(1,31)

if self.month in [1,2]:
d = self.y - 1
m = self.month + 10
else:
d = self.y
m = self.month - 2

z = self.k + (13*m-1)/5 + d + d/4 + self.c/4 - 2*self.c

if z  0:
r = (abs(z)/7)*7 + z + 7
else:
r = z%7

dict = { 0: 'Sunday', 1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4:
'Thursday', 5: 'Friday', 6: 'Saturday' }
self.day = dict[r]

t1m = time.localtime().tm_min
t1s = time.localtime().tm_sec
t1 = t1m + t1s/100.0
n = 0
x = 0

while n  10:
newdate = Date()

print '\n',calendar.month_name[newdate.month], newdate.k,',',
newdate.year,'=',
answer = raw_input()
if answer.capitalize() == newdate.day:
pass
else:
x += 1
n += 1

t2m = time.localtime().tm_min
t2s = time.localtime().tm_sec
t2 = t2m + t2s/100.0
td = t2 - t1

print '\n',x,'out of 10 wrong\nAvg time/question:',td/10,'\nTotal time:',td


On Mon, Sep 27, 2010 at 10:21 PM, Dave Angel da...@ieee.org wrote:



 On 2:59 PM, Steven D'Aprano wrote:

 On Tue, 28 Sep 2010 08:55:36 am Carter Danforth wrote:


  class Date:
 c = random.randint(16,30)
 y = random.randint(0,99)
 month = random.randint(1,12)

  Here's your problem: you are creating a class where all the attributes
 (called members in some other languages) belong to the class and are
 shared by all instances.

 Python classes are themselves objects, and the code inside the class
 body gets executed *once*, when the class is created. So in this case,
 the Date class chooses a single random month, *once*, and all instances
 share this attribute Date.month.

 To get the behaviour you are after, you need to use instance attributes,
 which means referring to self. The usual place to do this is in the
 __init__ method, which is called when the instance is being
 initialised:

 class Date:
 def __init__(self):
 self.month = random.randint(1,12)
 # etc.



 By the way, why do you calculate a century and year separately, then add
 c+y to get the year? It would be easier to just say:

 year = random.randint(1600, 3099)




  That's the big problem, although it's also worth pointing out that you'll
 need a new instance each time through the loop.  It's not enough to call
 Date(), you also have to bind it to a name, and use that name for attribute
 lookup.So something like
 mydate = Date()
 year = mydate.y + 

 But there are at least a few subtle problems left.  One is that many of the
 years are divisible by four but do not have 29 days in February.  For
 example, 1800, 1900, 2100 are not leap years.

 Next problem is that the dates are not evenly distributed over the entire
 range of years.  The 14th of February will be more likely to be chosen than
 the sixth of July.  You can decide that this is deliberate, but it is a
 consideration.

 Third, the program doesn't do anything to check the user's answer.  For
 that matter, there's no timing going on either.

 Depending on the learning goals of this project, I'd consider using the
 datetime module, and method:

 mydate = date.fromordinal(*ordinal*)

 Now you can make a single randint() call, once you precalculate the
 starting and ending dates desired.   And this module also gives you other
 things you need, such as the weekday() method.

 DaveA


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:

Re: [Tutor] Operating in Place

2010-09-28 Thread Steven D'Aprano
On Wed, 29 Sep 2010 06:03:21 am Corey Richardson wrote:
   Hello tutors.

 I hate doing this:
  string = string.lower()

 Is there a way to do it without the string = part? Thanks.

No, strings are immutable. Once they're created, they cannot be changed.

This is no different from:

x = 42
x = x/2  # or x /= 2 if you prefer

instead of:

x = 42
x/2


As an alternative you could look at the UserString module, and the 
MutableString class it includes, but MutableString has some serious 
limitations and is not really meant for serious work. But it might do 
the job you want.



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing a txt from dbf

2010-09-28 Thread Steven D'Aprano
On Wed, 29 Sep 2010 04:33:51 am Susana Iraiis Delgado Rodriguez wrote:
 Hello dear pythonists:

 I'm developing an application in python, I'm new using this
 programming language I used to work with Java, but in my job my
 superiors suggested me to develop in this language.
 I'm trying to read a dbf file, I already done it but my code shows me
 all the lines without spaces, I want it toshow line per line and then
 write the lines into a plain txt file.

I am not sure what you mean. My guess is that you want something like:

alpha
beta
gamma
delta

in the file, but instead you get:

alphabetagammadelta


Am I right?



 My code is: 

 from dbf import *
 from string import strip

There is no need for this any more, as the functions in the string 
module are now also available as string methods. So instead of:

import string
print string.lower(my_string)


you can write:

my_string.lower()



 import sys
 def demo1():
  a = open (archivo.txt,w)
  dbf = Dbf('tapalpa_05_plani_point.dbf',new=False)

As a matter of style, it is normal to use 4 spaces for indents, not 1. 
You are welcome to use whatever you like in your own code, but many 
people find 1 space indents hard to see and so when writing for others 
(such as when asking a question here) you should use at least 2 spaces.


  for k in dbf:
   print '%s'%(strip(k[2]))

The print command automatically adds a newline after the string, so each 
printed string should be on its own line. But later, when you write the 
string to the file, you must add the newline yourself.

   l=()
   l=(strip(k[2]))
   a.write(l)

There's no need to clear l with the line l=() first. Just write:

l = k[2].strip()
a.write(l + '\n')




-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Operating in Place

2010-09-28 Thread Steven D'Aprano
On Wed, 29 Sep 2010 06:12:20 am Shashwat Anand wrote:
 On Wed, Sep 29, 2010 at 1:33 AM, Corey Richardson kb1...@aim.com 
wrote:
   Hello tutors.
 
  I hate doing this:
 string = string.lower()
 
  Is there a way to do it without the string = part? Thanks.

 1. string is a module which is deprecated. You should probably use
 str or s in your example.

Actually, in this case Corey is not using the string module, but is 
using string as the name of a variable.



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using in with a dictionary

2010-09-28 Thread Alex Hall
Hi all, yet again:
I have a dictionary that will look something like:
d={
 (1,2):a,
 (3,4):b
}

How can I say:
if (1,2) in d: print d[(1,2)]
This is false, so I expect to have to use d.keys, but I am not quite sure how.
I will be using this in a loop, and I have to know if there is a key
in the dictionary called (i,j) and, if there is, I have to grab the
value at that slot. If not I have to print something else. When I
tried in in the interpreter, I got something about builtin function
not being iterable. TIA for any suggestions.

-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using in with a dictionary

2010-09-28 Thread Wayne Werner
On Tue, Sep 28, 2010 at 4:58 PM, Alex Hall mehg...@gmail.com wrote:

 Hi all, yet again:
 I have a dictionary that will look something like:
 d={
  (1,2):a,
  (3,4):b
 }

 How can I say:
 if (1,2) in d: print d[(1,2)]
 This is false, so I expect to have to use d.keys, but I am not quite sure
 how.
 I will be using this in a loop, and I have to know if there is a key
 in the dictionary called (i,j) and, if there is, I have to grab the
 value at that slot. If not I have to print something else. When I
 tried in in the interpreter, I got something about builtin function
 not being iterable. TIA for any suggestions.


  d = {(1,2):a}
 if (1,2) in d:
... print d[(1,2)]
...
a

you tried that?

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using in with a dictionary

2010-09-28 Thread Steve Willoughby

On 28-Sep-10 14:58, Alex Hall wrote:

Hi all, yet again:
I have a dictionary that will look something like:
d={
  (1,2):a,
  (3,4):b
}

How can I say:
if (1,2) in d: print d[(1,2)]


Did you try this?  It looks fine to me as it is.
(1,2) is an immutable value (a tuple), so it is able to be used as a 
dictionary key.


if (1,2) in d

is perfectly valid, and would yield the True value as a result

if (1,2) in d: print d[(1,2)]

also is fine.  What specifically happens when you try this?



This is false, so I expect to have to use d.keys, but I am not quite sure how.
I will be using this in a loop, and I have to know if there is a key
in the dictionary called (i,j) and, if there is, I have to grab the
value at that slot. If not I have to print something else. When I
tried in in the interpreter, I got something about builtin function
not being iterable. TIA for any suggestions.



Sounds like there's more in your code than in your question.  If you 
give us a more complete picture of what you're doing, we can likely be 
more helpful to you.


if i=1 and j=2, then:

if (i,j) in d

would also be true.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using in with a dictionary

2010-09-28 Thread Steven D'Aprano
On Wed, 29 Sep 2010 07:58:28 am Alex Hall wrote:
 Hi all, yet again:
 I have a dictionary that will look something like:
 d={
  (1,2):a,
  (3,4):b
 }

 How can I say:
 if (1,2) in d: print d[(1,2)]

Exactly like that:


 d = {(1,2): 'a', (3,4): 'b'}
 if (1,2) in d: print d[(1,2)]
...
a


 This is false, so I expect to have to use d.keys, but I am not quite
 sure how. I will be using this in a loop, and I have to know if there
 is a key in the dictionary called (i,j) and, if there is, I have to
 grab the value at that slot. If not I have to print something else.
 When I tried in in the interpreter, I got something about builtin
 function not being iterable. TIA for any suggestions.

Without knowing exactly what you wrote, and what error you got, I have 
no clue why you got that.



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using in with a dictionary

2010-09-28 Thread Sander Sweers
On 28 September 2010 23:58, Alex Hall mehg...@gmail.com wrote:
 Hi all, yet again:
 I have a dictionary that will look something like:
 d={
  (1,2):a,
  (3,4):b
 }

 How can I say:
 if (1,2) in d: print d[(1,2)]

This will work fine.

 This is false

Not it is not..
 d = {(1,2):a,(3,4):b}
 (1,2) in d
True

, so I expect to have to use d.keys, but I am not quite sure how.
 I will be using this in a loop, and I have to know if there is a key
 in the dictionary called (i,j) and, if there is, I have to grab the
 value at that slot. If not I have to print something else.

 d = {1:a,2:b}
 for x in range(1,4):
if x in d:
print Found %s in dict d and has value %s % (x, d[x])
else:
print Value %s is not in dict d % x


Found 1 in dict d and has value a
Found 2 in dict d and has value b
Value 3 is not in dict d

 When I tried in in the interpreter, I got something about builtin function
 not being iterable. TIA for any suggestions.

What was the code you tried out? Please do provide this as it helps
figure out what was going on.

Greets
Sander
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who never programmed before or have no experience in programming

2010-09-28 Thread Rodney Lewis
making games is the best way to learn programming, and the book is free

http://programming.gather.com/viewArticle.action?articleId=281474978440241
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am looking for a book on Beginners who neverprogrammed before or have no experience in programming

2010-09-28 Thread Alan Gauld

Steven D'Aprano st...@pearwood.info wrote


I've never heard of Head First Programming -- how are they
unconventional?


They are a bit too cutesy for my liking, slow to get to any depth
but engaging for the sound-byte generation. Lots of cartoons and
jokes. I'd say its a bit like O'Reilly's take on the Dummies books.

I was briefly involved in reviewing an early HF Python book but it was 
so
badly done the project was scrapped while they found a new writing 
team.

They obviously have done this and I hope its now a good book because
I could see the merit in the style. But cute style still needs 
accurate
content! I will be looking out for it in my local bookshop, the 
editorial

team were very keen to see that the end product should be good.

Alan G.



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] generating independent random numbers

2010-09-28 Thread Dave Angel

 On 9/28/2010 5:11 PM, Carter Danforth wrote:

Thanks for the replies, Dave and Joel. The reason I'm not just using the
time or datetime modules for a random date is because it's restricted to
1970-2038; I'm pulling dates from 1600-3099. Thanks a lot for the pointer
about the leap years, Dave, as well the class instances; just updated it and
it's all working now, and also included the rest of the code too w/ answer
verification and time tracking.

I want to start using this program to test myself for speed calculation
using Zeller's formula, it's pretty cool for determining the days of dates -
http://mathforum.org/dr/math/faq/faq.calendar.html

Because of the way variables C and D are split up from the year in the
formula, I split up the year for self.c and self.y.



import random, time, datetime, calendar

class Date:
 def __init__(self):
 self.c = random.randint(16,30)
 self.y = random.randint(0,99)
 self.month = random.randint(1,12)
 self.year = self.c*100 + self.y

 apr = [4,6,9,11]
 feb = [2]
 notleap = [1700, 1800, 1900, 3000]

 if self.month in feb:
 if self.year%4 == 0:
 if self.year in notleap:
 self.k = random.randint(1,28)
 else:
 self.k = random.randint(1,29)
 else:
 self.k = random.randint(1,28)
 elif self.month in apr:
 self.k = random.randint(1,30)
 else:
 self.k = random.randint(1,31)

 if self.month in [1,2]:
 d = self.y - 1
 m = self.month + 10
 else:
 d = self.y
 m = self.month - 2

 z = self.k + (13*m-1)/5 + d + d/4 + self.c/4 - 2*self.c

 if z  0:
 r = (abs(z)/7)*7 + z + 7
 else:
 r = z%7

 dict = { 0: 'Sunday', 1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4:
'Thursday', 5: 'Friday', 6: 'Saturday' }
 self.day = dict[r]

t1m = time.localtime().tm_min
t1s = time.localtime().tm_sec
t1 = t1m + t1s/100.0
n = 0
x = 0

while n  10:
 newdate = Date()

 print '\n',calendar.month_name[newdate.month], newdate.k,',',
newdate.year,'=',
 answer = raw_input()
 if answer.capitalize() == newdate.day:
 pass
 else:
 x += 1
 n += 1

t2m = time.localtime().tm_min
t2s = time.localtime().tm_sec
t2 = t2m + t2s/100.0
td = t2 - t1

print '\n',x,'out of 10 wrong\nAvg time/question:',td/10,'\nTotal time:',td


snip


(You top-posted your response, so your message is out of order)

I haven't tried to run your code, but there is at least one problem.

Your notleap list is very incomplete.

notleap = [1700, 1800, 1900, 2100, 2200, 2300, 2500, 2600, 2700, 2900, 3000]

I'm a little suspicious of your version of Zeller.  I wouldn't think 
that last term should have a 2* in it.


I'm not sure why you use a dictionary to calculate self.day.  A list 
would work just as well.


DaveA


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor