[Tutor] 2.7.3 documentation gripe (feel free to ignore)

2012-09-14 Thread Ray Jones
6.5. The del statement *del_stmt* ::= "del" target_list Deletion is recursively defined very similar to the way assignment is defined. Rather than spe

Re: [Tutor] index of elements in numpy array

2012-09-14 Thread Bala subramanian
Thank you all for the answer. Below, i have pasted a sample code that shows what i am intending to do. The code fails at line 13 as numpy array dnt have a index attribute. 1 #!/usr/bin/env python 2 import numpy as np 3 4 a=np.array([1,2,3,4,5,6,7,8,9,10,11,12]) 5 6 b=np.reshape(a,(3,4)

[Tutor] (2.7.3) Inexplicable change of type

2012-09-14 Thread Ray Jones
The code: def split_string(source,splitlist): idx = 0 while idx < len(splitlist): if splitlist[idx] in source: source = ' '.join(source.split(splitlist[idx])) idx += 1 source = source.split(' ') print "source is", source,

Re: [Tutor] index of elements in numpy array

2012-09-14 Thread Peter Otten
Bala subramanian wrote: > Thank you all for the answer. Below, i have pasted a sample code that > shows what i am intending to do. The code fails at line 13 as numpy > array dnt have a index attribute. > > 1 #!/usr/bin/env python > 2 import numpy as np > 3 > 4 a=np.array([1,2,3,4,5,6,7,8,

Re: [Tutor] (2.7.3) Inexplicable change of type

2012-09-14 Thread Steven D'Aprano
On 14/09/12 18:43, Ray Jones wrote: Between the two arrows, 'source' inexplicably switches from to. Why? source.remove('') does not do what you think it does. Checking the Fine Manual is always a good idea, or experimentation at the interactive interpreter: py> source = list('abcd') py> resu

Re: [Tutor] (2.7.3) Inexplicable change of type

2012-09-14 Thread Peter Otten
Ray Jones wrote: > source = source.remove('') list.remove() modifies the list in-place and therefore by convention returns None: >>> source = ["one", "", "three"] >>> source.remove("") >>> source ['one', 'three'] ___ Tutor maillist - Tutor

Re: [Tutor] (2.7.3) Inexplicable change of type

2012-09-14 Thread eryksun
On Fri, Sep 14, 2012 at 4:43 AM, Ray Jones wrote: > > source = source.remove('') > > Between the two arrows, 'source' inexplicably switches from > to . Why? >>> x = [1,2,3] >>> result = x.remove(1) >>> type(result) >>> x [2, 3] Methods that mutate an object typi

Re: [Tutor] (2.7.3) Inexplicable change of type

2012-09-14 Thread Ray Jones
On 09/14/2012 02:07 AM, Steven D'Aprano wrote: > On 14/09/12 18:43, Ray Jones wrote: > >> Between the two arrows, 'source' inexplicably switches from >> to. Why? > > source.remove('') does not do what you think it does. Checking the > Fine Manual is always a good idea, or experimentation at the int

Re: [Tutor] (2.7.3) Inexplicable change of type

2012-09-14 Thread Ray Jones
Thanks for the responses. I knew it had to be something stupid ;)). Ray ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] 2.7.3 documentation gripe (feel free to ignore)

2012-09-14 Thread Steven D'Aprano
On 14/09/12 17:29, Ray Jones wrote: 6.5. The del statement [...] They call this DOCUMENTATION??? "it's similar to such and such - you figure it outhere are the hints"! Bah! I hope their code is better than the documentati

Re: [Tutor] 2.7.3 documentation gripe (feel free to ignore)

2012-09-14 Thread Ray Jones
On 09/14/2012 02:32 AM, Steven D'Aprano wrote: > On 14/09/12 17:29, Ray Jones wrote: >> >> 6.5. The del >> statement > [...] >> They call this DOCUMENTATION??? "it's similar to such and such - you >> figure it outhere are the h

Re: [Tutor] index of elements in numpy array

2012-09-14 Thread eryksun
On Fri, Sep 14, 2012 at 4:36 AM, Bala subramanian wrote: > > 10 # loop over each row > 11 for i1, d1 in enumerate(b): > 12 # each x in d1 - value in z corresponding to index of x in d1 > 13 d1=[x-z[d1.index(x)] for x in d1] > > If d1 is a simple list, i can fetch the index of its eleme

Re: [Tutor] Musical note on python

2012-09-14 Thread eryksun
On Thu, Sep 13, 2012 at 8:37 PM, D.V.N.Sarma డి.వి.ఎన్.శర్మ wrote: > > Error: "name data undefined" > >> import wave >> import winsound >> from cStringIO import StringIO >> >> def get_wave(data): >> f = StringIO() >> w = wave.open(f, 'w') >> w.setnchannels(1

[Tutor] is this use or abuse of __getitem__ ?

2012-09-14 Thread Albert-Jan Roskam
Hi, I defined a __getitem__ special method in a class that reads a binary data file using a C library. The docstring should clarify the purpose of the method. This works exactly as I intended it, however, the "key" argument is actually used as an index (it also raises an IndexError when is grea

Re: [Tutor] index of elements in numpy array

2012-09-14 Thread Oscar Benjamin
On 14 September 2012 11:05, eryksun wrote: > On Fri, Sep 14, 2012 at 4:36 AM, Bala subramanian > wrote: > > > > 10 # loop over each row > > 11 for i1, d1 in enumerate(b): > > 12 # each x in d1 - value in z corresponding to index of x in d1 > > 13 d1=[x-z[d1.index(x)] for x in d1] > >

Re: [Tutor] (2.7.3) Inexplicable change of type

2012-09-14 Thread Emile van Sebille
On 9/14/2012 1:43 AM Ray Jones said... The code: source = source.remove('') return source To round things out, here's one way to do what I expect you're expecting: >>> r=range(10) >>> a = r.pop(r.index(4)) >>> a 4 >>> r [0, 1, 2, 3, 5, 6, 7, 8, 9] Emile ___

Re: [Tutor] is this use or abuse of __getitem__ ?

2012-09-14 Thread eryksun
On Fri, Sep 14, 2012 at 8:16 AM, Albert-Jan Roskam wrote: > > Am I abusing the __getitem__ method, or is this just a creative way of using > it? No, you're using it the normal way. The item to get can be an index, a key, or even a slice. http://docs.python.org/reference/datamodel.html#object.__

Re: [Tutor] (2.7.3) Inexplicable change of type

2012-09-14 Thread eryksun
On Fri, Sep 14, 2012 at 8:37 AM, Emile van Sebille wrote: > >> source = source.remove('') > > To round things out, here's one way to do what I expect you're expecting: > >>>> r=range(10) >>>> a = r.pop(r.index(4)) >>>> a >4 >>>> r >[0, 1, 2, 3, 5, 6, 7, 8, 9] Ray

Re: [Tutor] is this use or abuse of __getitem__ ?

2012-09-14 Thread Steven D'Aprano
On 14/09/12 22:16, Albert-Jan Roskam wrote: Hi, I defined a __getitem__ special method in a class that reads a binary data file using a C library. The docstring should clarify the purpose of the method. This works exactly as I intended it, however, the "key" argument is actually used as an index

Re: [Tutor] simon game issues

2012-09-14 Thread Matthew Ngaha
> It would appear you're running some form of event loop, such as > wxpython, tkinter, pygame, or whatever. If so, you have to do your > delays using the mechanism that system defines, not using sleep(). As > you've discovered, sleep() stops the whole thread, and that's not what > you want. What

Re: [Tutor] is this use or abuse of __getitem__ ?

2012-09-14 Thread Albert-Jan Roskam
> On 14/09/12 22:16, Albert-Jan Roskam wrote: >>  Hi, >> >>  I defined a __getitem__ special method in a class that reads a binary data >>  file using a C library. The docstring should clarify the purpose of the >> method. This works exactly as I intended it, however, the "key" > argument is >> 

[Tutor] (no subject)

2012-09-14 Thread Johny Rei
hi  to all readers, i 'm a newbie and i'm interested to learn python programming, can anybody please guide me out to learn basic to advance python programming, be actually can anyone out there should suggest a free book that i can read it on just to learn from as a newbie to python programming?

Re: [Tutor] (no subject)

2012-09-14 Thread Stephen Haywood
http://learnpythonthehardway.org/book/ http://docs.python.org/tutorial/ http://www.readwriteweb.com/hack/2011/03/python-is-an-increasingly-popu.php That should keep you busy for a while. -- Stephen Haywood Information Security Consultant CISSP, GPEN, OSCP T: @averagesecguy W: averagesecurityguy