#1
  1. No Profile Picture
    Hi, I'm Calvin
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    LosAngeles, SanDiego, Houston
    Posts
    50
    Rep Power
    11

    giving 2.2 some 2.3 modules


    Howdy,
    Well, I thought that this would be pretty easy (and I'm sure it still is, I just don't know where to start now)... I've downloaded and googled a bug fix in ActiveState's ActivePython release. I'm using that for asp. This release is Python in version 2.2, but the code that I already have written is based on 2.3 (wouldn't make much difference except I use the 2.3-introduced module 'sets').
    I thought I could simply take sets.py and sets.pyc from the 2.3 'Lib' folder and place that into the 'lib' folder for 2.2, in order to make 2.2 support the sets module. However I noticed that sets.py contains an import statement for itertools. I searched through the entire 2.3 folder looking for a file named 'itertools.py' or 'itertools.pyc', but the closest I was able to come was 'test_itertools.py'. I opened up the 2.3 version of IDLE and imported itertools and called itertools... this is the return statement:

    <module 'itertools' (built-in)>

    So, I'm pretty sure that tells me that itertools is a built-in module. I don't know how to extract the itertools module from 2.3, so... is there any way that I can still give 2.2 the functionality of the sets module?
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Oh god, let me start of by saying that if they ever make Set's a built-in type (in the way they plan to do it now) i am going too cry! It's just soooo ugly.. Anyway, you can do basically the same thing using dictionaries, just forget about the keys, since a set is an unordered list (a dictionary without the keys).

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Hi, I'm Calvin
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    LosAngeles, SanDiego, Houston
    Posts
    50
    Rep Power
    11
    you mean forget about the values?

    ...i think it's the values that you forget about...

    what's so ugly about the sets module? man, when i found out about that i was SO incredibly happy. except... well, i thought that calling 'ImmutableSet' was a bit annoying because it's just a lot of typing, and it's probably going to be used more than 'Set'... argh. but oh well, you could just say something like

    from sets import ImmutableSet as set

    or something.

    but yeah... i asked because I'd rather screw around with moving files around because I'd rather learn how python is configured (well, it wouldn't tell me much... but a little?) than to do it the dictionary way (it's easy, but not as fun).

    eh... thanks anyhow Mark. do you get paid for this? haha stacking shelves and mod'ing devshed's python forum... interesting...
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Don't get me wrong CV, the set type/module is very cool and a nice addition to Python's library! Well worthy of becomming a builtin type someday..

    But if they make built-in that's looks like {-} when its empty then i sware i am gonna barf whenever i use it lol.

    On the subject of moving files around, if your confident with a C/C++ compiler you could download Python's source code and try figure out which parts you need to impliment itertools but i think it would be far easier to just get Python 2.3 and wack it on when they ain't looking

    Paid for stacking shelves, it's simple and it gives me plenty of free time and all the money i need so can't complain.. mod'ing devshed, I wish! Naw, just do this for fun and to ya know, help yall out

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    11
    You shouldn't have a problem with the sets module, since the sets module contains code to work around that Python 2.2 lacks the itertools module, like it says in the source in sets.py.

    Try again

    If your sets module looks different from mine, here's the part you'd need:
    Code:
    from __future__ import generators
    try:
        from itertools import ifilter, ifilterfalse
    except ImportError:
        # Code to make the module run under Py2.2
        def ifilter(predicate, iterable):
            if predicate is None:
                def predicate(x):
                    return x
            for x in iterable:
                if predicate(x):
                    yield x
        def ifilterfalse(predicate, iterable):
            if predicate is None:
                def predicate(x):
                    return x
            for x in iterable:
                if not predicate(x):
                    yield x
    Last edited by percivall; October 6th, 2003 at 07:19 PM.
  10. #6
  11. No Profile Picture
    Hi, I'm Calvin
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    LosAngeles, SanDiego, Houston
    Posts
    50
    Rep Power
    11
    what... the...

    hey! that's really cool... thanks very much, percival! i'm looking through my sets.py file right now and i really don't see that code that you posted. these are the couple of lines that i have in my sets.py file:

    Code:
    __all__ = ['BaseSet', 'Set', 'ImmutableSet']
    from itertools import ifilter, ifilterfalse
    
    class BaseSet(object):
        """Common base class for mutable and immutable sets."""
    
        __slots__ = ['_data']
    ...etc...
    just out of curiosity, which python version do you have? i'm running 2.3, the July/29/2003 release. in any case, thanks a million.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    11
    The code I posted was from the Python 2.3.1 release.

    Looking through the CVS, I see this:
    Code:
    Revision 1.45 -  (download), view (text) (markup)  (annotate)    - [select for diffs]    
      Fri Aug 15 21:17:04 2003 UTC (7 weeks, 3 days ago) by rhettinger       
    Changes since 1.44: +19 -1 lines       
    Diff to previous 1.44        
    Make sets.py compatible with Py2.2
    
    Revision 1.44.8.1 -  (download), view (text) (markup)  (annotate)    - [select for diffs]    
      Fri Aug 15 21:14:51 2003 UTC (7 weeks, 3 days ago) by rhettinger  
    Branch:  release23-maint        
    Changes since 1.44: +19 -1 lines       
    Diff to previous 1.44        
    Make sets.py compatible with Py2.2
    So I guess you really didn't have that code. Well, now you do.

IMN logo majestic logo threadwatch logo seochat tools logo