Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pyrhon2.5 to 2.4 conversion

2 views
Skip to first unread message

tare...@gmail.com

unread,
Feb 27, 2010, 8:41:09 PM2/27/10
to
Hi,

I am currently using oauth2.py library, and it works fine on one of my
PC's (python2.5), but later on when I tried to use it with python2.4
the following line (line 332 in http://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py)
showed a syntax error

items = [(k, v if type(v) != ListType else sorted(v)) for k,v in
sorted(self.items()) if k != 'oauth_signature']

So it there a way to convert this line to a python2.4 compliant
syntax.

Thanks a lot,
Tarek

Message has been deleted

Chris Rebert

unread,
Feb 27, 2010, 8:58:34 PM2/27/10
to tare...@gmail.com, pytho...@python.org

This part is your problem:


(k, v if type(v) != ListType else sorted(v))

Conditional expressions like that were added in v2.5:
http://docs.python.org/whatsnew/2.5.html#pep-308-conditional-expressions

Here's an untested substitute:

def sort_or_tuple(k, v):
if type(v) != ListType:
return k, v
else:
return sorted(v)

items = [sort_or_tuple(k,v) for k,v in sorted(self.items()) if k !=
'oauth_signature']

Of course, the more obvious solution is just to upgrade your Python;
it's well worth it!

Cheers,
Chris
--
http://blog.rebertia.com

Steven D'Aprano

unread,
Feb 27, 2010, 9:02:58 PM2/27/10
to

You would be better off installing Python2.5 on the PC rather than trying
to backport the library to 2.4. There could be thousands of changes
needed to backport the library.

--
Steven

MRAB

unread,
Feb 27, 2010, 9:12:12 PM2/27/10
to pytho...@python.org
I think the clearest is:

items = []
for k, v in sorted(self.items()):
if k != 'oauth_signature':
if type(v) == ListType:
v = sorted(v)
items.append((k, v))

Message has been deleted

tare...@gmail.com

unread,
Mar 9, 2010, 3:31:15 PM3/9/10
to
Thanks a lot everybody for your help, it worked now :)

On Feb 28, 4:12 am, MRAB <pyt...@mrabarnett.plus.com> wrote:


> tarek...@gmail.com wrote:
> > Hi,
>
> > I am currently using oauth2.py library, and it works fine on one of my
> > PC's (python2.5), but later on when I tried to use it with python2.4

> > the following line (line 332 inhttp://github.com/simplegeo/python-oauth2/blob/master/oauth2/__init__.py)

0 new messages