Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old October 6th, 2003, 01:08 PM
cvchen cvchen is offline
Hi, I'm Calvin
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: LosAngeles, SanDiego, Houston
Posts: 50 cvchen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 7 sec
Reputation Power: 5
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?

Reply With Quote
  #2  
Old October 6th, 2003, 03:26 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #3  
Old October 6th, 2003, 03:50 PM
cvchen cvchen is offline
Hi, I'm Calvin
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: LosAngeles, SanDiego, Houston
Posts: 50 cvchen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 7 sec
Reputation Power: 5
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...

Reply With Quote
  #4  
Old October 6th, 2003, 05:57 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #5  
Old October 6th, 2003, 07:16 PM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
  #6  
Old October 7th, 2003, 08:22 AM
cvchen cvchen is offline
Hi, I'm Calvin
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: LosAngeles, SanDiego, Houston
Posts: 50 cvchen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 7 sec
Reputation Power: 5
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.

Reply With Quote
  #7  
Old October 7th, 2003, 09:27 AM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > giving 2.2 some 2.3 modules


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway