Re: simple games w/o pygame

2010-12-22 Thread Andre Alexander Bell
On 22.12.2010 17:40, William Gill wrote: > I am teaching an 11 year old who wants to learn programming. I chose > Python, and it is working well. I seem to remember lots of simple > script games, like quizzes, number games etc. that would be good for his > tutorial. However, now all I can find i

Re: Dynamic list name from a string

2010-12-20 Thread Andre Alexander Bell
Hello, On 12/20/2010 11:08 AM, MarcoS wrote: > Hi, I need to create a list with a dynamic name, something like this: > > '%s_list' %my_dynamic list = [] > > It's this possible? I would suggest you use a dictionary to store your lists like this: lists = {} lists[my_dynamic_list] = [] Maybe yo

Re: is list comprehension necessary?

2010-10-26 Thread Andre Alexander Bell
On 10/26/2010 07:22 PM, Ian Kelly wrote: > >>> i = 5 > >>> l = [i**2 for i in range(3)] > >>> i > 2 > > > This has been corrected in Python 3. Sorry. You're right. I forgot to mention that... Andre -- http://mail.python.org/mailman/listinfo/python-list

Re: is list comprehension necessary?

2010-10-26 Thread Andre Alexander Bell
Hello, I occasionally use LCs, if they seem useful. However, what I don't like about LCs is that they 'look-like' being a closed scope, while actually they are in the scope of there call. Example: >>> i = 5 >>> l = [i**2 for i in range(3)] >>> i 2 Regards Andre -- http://mail.python.org/mailm

Re: isnan

2010-10-12 Thread Andre Alexander Bell
On 10/12/2010 06:22 PM, Ian Kelly wrote: > That's the inverse of what the OP wanted. The full solution: > A[~isnan(B)] > array([2, 3]) Indeed, you are right Ian. Thanks for pointing that out. :) Sorry for the mistake. Regards Andre -- http://mail.python.org/mailman/listinfo/python-list

Re: isnan

2010-10-11 Thread Andre Alexander Bell
Hi Kenny, On 10/12/2010 05:58 AM, Kenny wrote: > I have an array A, and another one B with same dimention and size. Now I > want to change the delete the elements in A where the same position in B > is nan. How can I do. > > Similar to the matlab code A(find(isnan(B)) = [] How about this: >>> f

Re: Numpy: Multiplying arrays of matrices

2010-09-15 Thread Andre Alexander Bell
On 09/16/2010 08:24 AM, Andre Alexander Bell wrote: or you could write the loop >>> m1m2 = np.empty_like(m1) >>> for i in range(m1m2.shape[0]): ... m1m2[i] = np.dot(m1, m2) This should have been ... m1m2[i] = np.dot(m1[i], m2[i]) Sorry for the typo. Andre -- http

Re: Numpy: Multiplying arrays of matrices

2010-09-15 Thread Andre Alexander Bell
Hi, I assume you have arrays like these: >>> import numpy as np >>> m1 = np.random.rand(size=(4,3,3)) >>> m2 = np.random.rand(size=(4,3,3)) So that m1[0] is a 3x3 Matrix and m1[1] is another one, i.e. you have four matrices. On 09/15/2010 01:54 AM, Gregory Ewing wrote: I had thought that do

Re: String formatting with the format string syntax

2010-09-15 Thread Andre Alexander Bell
On 09/15/2010 10:48 AM, Peter Otten wrote: I personally would not be too concerned about the leading underscore, but you can use string.Formatter().parse(template) instead. Thanks for this pointer. I like it this way. So if I now combine your generator with your suggestion, I end up with som

Re: String formatting with the format string syntax

2010-09-15 Thread Andre Alexander Bell
On 09/15/2010 10:00 AM, Peter Otten wrote: def extract_names(t, recurse=1): for _, name, fmt, _ in t._formatter_parser(): if name is not None: yield name if recurse and fmt is not None: for name in extract_names(fmt, recurse-1): yi

Re: String formatting with the format string syntax

2010-09-14 Thread Andre Alexander Bell
On 09/14/2010 08:20 PM, Miki wrote: You can use ** syntax: english = {'hello':'hello'} s.format(**english) Thanks for your answer. Actually your answer tells me that my example was misleading. Consider the template s = 'A template with {variable1} and {variable2} placeholders.' I'm seeking

String formatting with the format string syntax

2010-09-14 Thread Andre Alexander Bell
Hello, I'm used to write in Python something like >>> s = 'some text that says: %(hello)s' and then have a dictionary like >>> english = { 'hello': 'hello' } and get the formatted output like this: >>> s % english Occasionally I want to extract the field names from the template string. I w

Re: Accumulate function in python

2010-07-19 Thread Andre Alexander Bell
On 07/19/2010 01:18 PM, dhruvbird wrote: > Hello, > I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ] > And would like to compute the cumulative sum of all the integers > from index zero into another array. So for the array above, I should > get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ] > Wh

Re: create dynamic instance

2010-07-16 Thread Andre Alexander Bell
On 07/16/2010 06:01 PM, Ray wrote: > if __name__=='__main__': > for x in range(10): > x=Test() > """ > the question is how do i call x.value outside of that for loop? > something like > print x.value ? > """ You would have to keep references to your Test objects (untested code):

Re: Naming Conventions, Where's the Convention Waldo?

2010-07-11 Thread Andre Alexander Bell
On 07/11/2010 10:30 AM, rantingrick wrote: > On Jul 11, 3:03 am, "Günther Dietrich" > wrote: > >> So, it is not a disadvantage that the functions you listed above are >> named in this way. In the contrary, it is an advantage, as it keeps >> newcomers from using stupid variable names. > > "int" f

Re: python app development

2010-07-03 Thread Andre Alexander Bell
On 07/03/2010 07:48 PM, mo reina wrote: > an anyone recommend a resource (book,tutorial,etc.) that focuses on > application development in python? something similar to Practical > Django Projects, but for stand alone applications instead of web apps > (for now). I think you are referring to GUI ap

Re: Python dynamic attribute creation

2010-06-30 Thread Andre Alexander Bell
On 06/29/2010 06:46 PM, WANG Cong wrote: > On 06/29/10 17:48, Andre Alexander Bell wrote: >>>>> var a >>>>> a >> -> should raise an variable 'unset' exception >> >> Keep in mind that the module you are writing in is just an object a

Re: Python dynamic attribute creation

2010-06-29 Thread Andre Alexander Bell
On 06/25/2010 03:15 PM, WANG Cong wrote: > 1) Modifying a class attribute is metaprogramming, and this is modifying > a class, i.e. adding a new attribute to it, thus this should belong > to metaprogramming. (I know, strictly speaking, maybe my definition of > "metaprogramming" here is incorrect, I

Re: Second attempt WAS: From Dict to Classes yes or no and how

2010-06-22 Thread Andre Alexander Bell
On 06/22/2010 02:03 PM, Jerry Rocteur wrote: >> On Tue, Jun 22, 2010 at 9:32 PM, Jerry Rocteur wrote: >> If you were able to ask us perhaps a more specific question >> and describe your problem a little more concisely perhaps >> I (and we) might have a bit more to offer you. > > I have a dictiona

Re: From Dict to Classes yes or no and how

2010-06-22 Thread Andre Alexander Bell
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 06/22/2010 01:32 PM, Jerry Rocteur wrote: > My input is NOT CSV, I used this format to try and make the question shorter. > Although I could create a CSV file, I'd > like to learn how to code a class to work the way I described in the question. So

Re: From Dict to Classes yes or no and how

2010-06-22 Thread Andre Alexander Bell
On 06/22/2010 12:05 PM, Jerry Rocteur wrote: > Sorry for the long mail but I've been searching the web for days for how to > do this.. I see that possibilities using > shelve or pickle but I don't want to do this (The source of the data changes > constantly) You might be interested in the csv mo

Re: plac 0.5 is out!

2010-06-21 Thread Andre Alexander Bell
On 06/21/2010 05:38 AM, Michele Simionato wrote: >>> A few weeks ago I presented on this list my most recent effort, plac. >>> http://micheles.googlecode.com/hg/plac/doc/plac_ext.html >> >> But this one is broken. :( > > Aagh! The good one is > http://micheles.googlecode.com/hg/plac/doc/plac_adv

Re: plac 0.5 is out!

2010-06-20 Thread Andre Alexander Bell
On 06/20/2010 11:22 AM, Michele Simionato wrote: > A few weeks ago I presented on this list my most recent effort, plac. > Now there is a *huge* new release: > the size of plac and of its documentation doubled. > [...] > > http://micheles.googlecode.com/hg/plac/doc/plac.html I've read this one..

Re: plac 0.5 is out!

2010-06-20 Thread Andre Alexander Bell
On 06/20/2010 11:22 AM, Michele Simionato wrote: > A few weeks ago I presented on this list my most recent effort, plac. > Now there is a *huge* new release: > the size of plac and of its documentation doubled. How about adding some support for internationalization of the generated usage output?

Re: pythonize this!

2010-06-19 Thread Andre Alexander Bell
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 06/18/2010 05:53 PM, Mark Lawrence wrote: > Andre, looks like a really bad day for you then, *TWO* nights out with > me *AND* (looking at your email address) Germany loosing in the world > cup. :( There are days one looses and there are days the ot

Re: pythonize this!

2010-06-18 Thread Andre Alexander Bell
On 06/18/2010 03:32 PM, Mark Lawrence wrote: > The good news is that this is easily the fastest piece of code that I've > seen yet. The bad news is that first prize in the speed competition is > a night out with me. :) Well, that actually means that Stefan Behnel will run my solution through cyth

Re: pythonize this!

2010-06-18 Thread Andre Alexander Bell
On 06/16/2010 12:47 PM, Lie Ryan wrote: > Probably bending the rules a little bit: > sum(x**2 - 8*x - 20 for x in range(1, 2010, 5)) > 536926141 Bending them even further, the sum of the squares from 1 to N is given by (1) N*(N+1)*(2*N+1)/6. The given problem can be divided into five sums

Re: pythonize this!

2010-06-15 Thread Andre Alexander Bell
On 06/15/2010 01:49 PM, superpollo wrote: > my solution: > > [...] > >>> print s > 536926141 Or, if you would like to use numpy: >>> import numpy >>> squares = numpy.arange(1, 2011, dtype=numpy.int)**2 >>> signs = numpy.ones(len(squares), dtype=numpy.int) >>> signs[3::5] = -1 >>> signs[4::5] = -1