Gentoo Archives: gentoo-dev

From: Arfrever Frehtes Taifersar Arahesis <Arfrever@g.o>
To: Gentoo Development <gentoo-dev@l.g.o>
Subject: Re: [gentoo-dev] Stabilization of Python 3.1
Date: Sun, 20 Sep 2009 17:55:05
Message-Id: 200909201957.05957.Arfrever@gentoo.org
In Reply to: Re: [gentoo-dev] Stabilization of Python 3.1 by Nirbheek Chauhan
1 2009-09-20 19:30:54 Nirbheek Chauhan napisał(a):
2 > On Sun, Sep 20, 2009 at 8:54 PM, Arfrever Frehtes Taifersar Arahesis
3 > <Arfrever@g.o> wrote:
4 > > 2009-09-20 16:53:37 Jesús Guerrero napisał(a):
5 > >> # eselect python set 2
6 > >> # emerge -s foo
7 > >> File "/usr/bin/emerge", line 41
8 > >> except PermissionDenied, e:
9 > >> ^
10 > >> SyntaxError: invalid syntax
11 > >>
12 > >>
13 > >> Ummm, yes, it works *beautifully*, you see. Nothing else to add.
14 > >
15 > > I have fixed it today :) .
16 > > http://sources.gentoo.org/viewcvs.py/portage?rev=14289&view=rev
17 >
18 > This is silly. portage itself was broken with python-3.1 and you want
19 > to stabilize it?
20
21 You should distinguish between Python version used by Portage and
22 Python version used by packages which can be installed by Portage.
23
24 > Actually, how did you make portage work with both 2.x and 3.x at the
25 > same time?
26
27 Portage doesn't yet work with Python 3, but it hopefully change soon.
28
29 > I would be very interested to know this since afaik no useful program
30 > can work with both python-3 and python-2 with the same code.
31
32 It isn't hard to write code which works with both Python 2.6 and 3.*.
33
34 Example:
35
36 $ cat get_protocol.py
37 #!/usr/bin/env python
38
39 # It allows to use print() function in 2.6.
40 from __future__ import print_function
41
42 import sys
43
44 try:
45 # Python 3
46 from urllib.parse import urlparse as urllib_parse_urlparse
47 except ImportError:
48 # Python 2
49 from urlparse import urlparse as urllib_parse_urlparse
50
51 if len(sys.argv) != 2:
52 sys.stderr.write("This script requires 1 argument: URL\n")
53
54 def get_protocol(url):
55 return urllib_parse_urlparse(url)[0]
56
57 print("Protocol:", get_protocol(sys.argv[1]))
58 $ ./get_protocol.py http://www.example.com
59 Protocol: http
60
61 --
62 Arfrever Frehtes Taifersar Arahesis

Attachments

File name MIME type
signature.asc application/pgp-signature