Re: non-copy slices

2009-11-19 Thread Themis Bourdenas
On Thu, Nov 19, 2009 at 2:44 PM, Ethan Furman et...@stoneleaf.us wrote:

 Please don't top post.  :)

 So shallow copy == new label created for existing object.

 So is your desired behavior to write back to the original list if your
 sub-list is modified?  In other words, you are creating a window onto an
 existing list?  If not, what would happen when a sublist element was
 modified (or deleted, or appended, or ...)?

 ~Ethan~
 --
 http://mail.python.org/mailman/listinfo/python-list


Yes a window / view on the existing list describes it best. So every
modification you make in this view is actually modifying the original list
accordingly. Blist that was suggested in a previous email in the thread
seems lightweight but it does create a new list when a modification is made.
In any case, I've already implemented the object myself and I can post it if
you care to have a look, but I was just wondering if there was already
something in the standard library.

Themis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: non-copy slices

2009-11-18 Thread Themis Bourdenas
Sth else that I noticed as I started using islice. The name is somewhat
misleading. Having the slice part in the name I would expect it to imitate
the functionality of normal slices. Random access, sub-slicing etc. However,
it is only iteratable. Any particular reasons for that? My guess is that
it's inside the itertools so it's meant only for iteration and not random
access. However, as I told before the name implies the same functionality
while the only thing they share is iteration. It's nothing in the library
that completely imitates the slice without the copies, right?

Cheers,
Themis


On Wed, Nov 18, 2009 at 6:49 PM, Terry Reedy tjre...@udel.edu wrote:

 tbour...@doc.ic.ac.uk wrote:
  Hi,
 
  I was looking for a facility similar to slices in python library that
  would avoid the implicit creation of a new list and copy of elements
  that is the default behaviour. Instead I'd rather have a lazy iteratable
  object on the original sequence. Well, in the end I wrote it myself but
  I was wondering if I missed sth in the library  If I didn't is there a
  particular reason there isn't sth like that? I find it hard to believe
  that all slice needs have strictly copy semantics.

 It is a strict *shallow* copy. There is no copying of contents.
 That aside, you are right, hence itertools.islice as already mentioned.
 In the design of 3.0, I believe the idea was raised of making slices
 iterables in 3.0, just as was done for map, filter, and range. However,
 it would have been highly disruptive, and not save much space. Map and
 range create an unbounded number of new objects, rather than just a
 sequence of references to existing objects (or bytes or words for bytes
 and str slices). There is also the problem of virtual slices preventing
 garbage collection of the source sequence when it is not otherwise needed.

 Terry Jan Reedy

 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: method decorators and more on decorators

2008-07-29 Thread Themis Bourdenas
On Mon, Jul 28, 2008 at 11:12 AM, Gabriel Genellina
[EMAIL PROTECTED]wrote:

 En Sun, 27 Jul 2008 15:26:39 -0300, Themistoklis Bourdenas 
 [EMAIL PROTECTED] escribió:

  On a related note, as the actual instance method of myclass is not foo
 but
  decorate(foo), why are they called method decorators? This does not
 decorate
  methods, they decorate functions and eventually the decorated functions
  become methods. The name method decorator sounds a bit misleading to me.

 Where have you found it? I've always seen the expression function
 decorator or just decorator, not method decorator.


well a few occurrences of it can be found in PEP 318



  So returning to my original question is there any way I can get the class
  inside decorate()? I guess there is not, but just asking to make sure.

 the class inside decorate? What do you mean? The type of the x instance
 in an x.foo() call? That should be determined inside the wrapped function
 -when it is actually called-.

 Yes, what I was hoping is that it might be possible to get the name of the
class the function is eventually is going to be bound to, but I guess that's
not very likely to be possible. I wanted the name well before the function
is called, actually even before an instance of the class is created. Anyway,
I 've solved my problem with other means. Just out curiosity though, has
there been any talk about actual method decorators? I guess you can work
around them with the introduction of class decorators or even now with
meta-classes, but you have to wrap methods manually with no syntactic sugar.

Cheers,
Themis
--
http://mail.python.org/mailman/listinfo/python-list

Re: Module clarification

2008-07-28 Thread Themis Bourdenas
I would recommend dive into python. Its available free online (just google
it) and it tries to teach you python, not programming which unfortunately
many books try to do. It assumes that you already have some experience with
C++ or Java and contradicts python syntax/semantics to those languages. Very
useful and fast if you already know how to program.

Cheers,
Themis

On Mon, Jul 28, 2008 at 6:57 PM, Marcus.CM [EMAIL PROTECTED]wrote:

 Hi Hussein,

 Basically a module is a FILE and is considered as a singleton model. Yes ur
 wow.py assumption is correct.
 I recommend getting Mark Lutz Learning Python book to get you started.

 Marcus.CM


 Hussein B wrote:

 Hi.
 I'm a Java guy and I'm playing around Python these days...
 In Java, we organize our classes into packages and then jarring the
 packages into JAR files.
 What are modules in Python?
 What is the equivalent of modules in Java?
 Please correct me if I'm wrong:
 I saved my Python code under the file   Wow.py
 Wow.py is now a module and I can use it in other Python code:
 import Wow

 Thanks.
 --
 http://mail.python.org/mailman/listinfo/python-list





 --
 http://mail.python.org/mailman/listinfo/python-list

--
http://mail.python.org/mailman/listinfo/python-list