Re: Python 2 or 3

2011-12-03 Thread jmfauth
On 3 déc, 04:54, Antti J Ylikoski  wrote:

> Helsinki, Finland, the EU   <<<


>>> sys.version
'2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'
>>> 'éléphant'
'\xe9l\xe9phant'
>>>



>>> sys.version
'3.2.2 (default, Sep  4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)]'
>>> 'éléphant'
'éléphant'
>>>


jmf



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


Re: Multiprocessing: killing children when parent dies

2011-12-03 Thread Jack Keegan
I think the OP meant when the parent gets killed (by ctrl+c or similar),
not deleted. At least that's what I think when I think of a program being
killed. Is it even possible to send a signal in such a case?

Cheers,

Jack

On Fri, Dec 2, 2011 at 4:27 PM, 8 Dihedral  wrote:

> Please check Erlang that spawn so easily. And there are Python packages
> can do the same task.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
The earth is a very small stage in a vast cosmic arena. Think of the rivers
of blood spilled by all those generals and emperors so that in glory and in
triumph they could become the momentary masters of a fraction of a dot.
- Carl Sagan [Pale Blue Dot]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2 or 3

2011-12-03 Thread Steven D'Aprano
On Sat, 03 Dec 2011 05:54:19 +0200, Antti J Ylikoski wrote:

> The O'Reilly book has some 1200 pages.  I would not want to invest such
> an amount of work and time to an obsolete language (i. e. Python 2).

Python 2 is not an obsolete language. The differences between Python 2 
and Python 3 are minor, more like different dialects of one language than 
two languages. I learned Python 1.5 and watched the extended transition 
between 1.5 -> 2.2, and in my opinion, the 2.5 -> 3.2 transition is not 
that much more difficult.

An experienced programmer won't have any difficulty learning both, and 
swapping between them. Newbies who have never programmed before often 
have trouble with the differences between 2.x and 3.x, but if you are an 
experienced programmer, you shouldn't have any trouble at all. The 
biggest difference to the language is that strings are now Unicode 
instead of byte strings; this has forced a lot of English speakers to 
learn about Unicode and bytes instead of assuming that the universe is 
ASCII. Apart from that, the differences are, in my opinion, trivial.

However, there are a lot of them:

http://docs.python.org/release/3.0.1/whatsnew/3.0.html


But the most important ones in my opinion are:

* unicode text, as mentioned above, and the consequences of this;

* some of the modules in the standard library have been renamed;

* various new modules have been added;

* some built-in functions and methods which used to return lists now 
return lazy iterators or views; 

* print is now a function instead of a statement;

* a small number of syntax changes, some of which are also supported by 
Python 2.6 and 2.7;

* "classic classes" no longer exist, so there is now only one class 
mechanism, not two.

If you can deal with the difference between these two lines without 
getting confused:

print md5.md5("spam").hexdigest()  # Python 2.x
print(hashlib.md5("spam").hexdigest())  # Python 3.x

you're half way there.



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


Re: Python 2 or 3

2011-12-03 Thread Chris Angelico
On Sat, Dec 3, 2011 at 9:04 PM, Steven D'Aprano
 wrote:
> If you can deal with the difference between these two lines without
> getting confused:
>
> print md5.md5("spam").hexdigest()  # Python 2.x
> print(hashlib.md5("spam").hexdigest())  # Python 3.x

The second line needs to be:
print(hashlib.md5("spam".encode()).hexdigest())

Relatively insignificant differences, since Python 2 and Python 3 both
support both bytes and unicode strings. The only difference is that
Py3 makes Unicode the default, forcing you to be explicit when you
want bytes.

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


Re: Referencing module.instance

2011-12-03 Thread Gnarlodious
HA! After much experimenting I hit upon getattr(__import__(page), page):

for page in self.allowedPages:
   scriptPath = '{}/{}.py'.format(os.path.dirname(__file__), page)
   if os.path.exists(scriptPath):
  self.modules[page] = getattr(__import__(page), page)


Then in __call_ I just say:

target = incoming CGI variable
self.modules[target](qList, environ)

and it works!

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


Re: Python 2 or 3

2011-12-03 Thread Arnaud Delobelle
On 3 December 2011 03:54, Antti J Ylikoski  wrote:
>
> I'm in the process of learning Python.  I already can code
> objet-oriented programs with the language.  I have in my hands the
> O'Reilly book by Mark Lutz, Programming Python, in two versions: the
> 2nd Edition, which covers Python 2, and the 4th edition, which covers
> Python 3.
>
> In the "official Python site" so to speak, http://www.python.org, it
> is mentioned that the authors recommend the visitor, who is a novice,
> to learn Python 2 rather than Python 3, because most of existing
> software has been writen with Python 2.
>
> The O'Reilly book has some 1200 pages.  I would not want to invest
> such an amount of work and time to an obsolete language (i. e. Python
> 2).

Python 2 and Python 3 are mostly the same language.  Learning either
will be equally valuable IMHO.  There are some significant differences
but if you have a good understanding of one, you will have no problem
adapting very quickly to the other.

And Python 2 is definitely not obsolete :)

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


Re: Install Python on Windows without Start Menu icons?

2011-12-03 Thread Pedro Henrique G. Souto

On 02/12/2011 16:34, snorble wrote:

Is it possible to automate the Python installation on Windows using
the MSI file so it does not add a Start Menu folder? I would like to
push out Python to all of my office workstations, but I'd like for it
to be relatively silent from the user's point of view.


If you just want to run python scripts in those machines (not developing 
in it), you can use something like py2exe [http://www.py2exe.org/].


It converts a python script to a standalone executable.

Good luck!
--
Att;
Pedro Henrique G. Souto

╔═╗
║ ²²²d○_○b²²² ║
╚═╝
--
http://mail.python.org/mailman/listinfo/python-list


Re: Django ported to Python3!

2011-12-03 Thread Ron
Thanks Stefan for clarifying that. I guess Martin deserves most of the
credit.

But I still admire how Sajip jumped in, and I especially admire how
the core team accepted his work without taking a "Not Invented Here"
attitude.

I sure hope the port is accepted into the main trunk soon. There is
just such a huge difference bewtween "90% done" and actually released.
Often code is 90% done but is never finished. And Django has such
enormous psychological significance for Python 3. Many important
projects will never begin serious porting until after Django
officially supports Python 3. And many Python folks will finally start
to take Python 3 seriously only when Django does announce official
support.

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


Re: order independent hash?

2011-12-03 Thread 88888 Dihedral
On Saturday, December 3, 2011 9:04:49 AM UTC+8, Steven D'Aprano wrote:
> On Fri, 02 Dec 2011 10:18:12 -0800, 8 Dihedral wrote:
> [...]
> 
> 
> Dihedral, EVERY SINGLE ONE of your messages is double posted. You are 
> sending to the newsgroup and the mailing list, but they are aliases for 
> each other. Please stop double posting.
> 
> 
> -- 
> Steven

A list  can replace a hash. I knew that in lisp. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: order independent hash?

2011-12-03 Thread Gelonida N
On 12/02/2011 07:39 PM, Dave Angel wrote:
> On 12/01/2011 08:55 AM, Neal Becker wrote:
>> Gelonida N wrote:
>>
>>> On 11/30/2011 01:32 PM, Neal Becker wrote:
 I like to hash a list of words (actually, the command line args of my
 program) in such a way that different words will create different
 hash, but
 not sensitive
 to the order of the words.  Any ideas?

>>> Do youmean hash like digest like md5sum / sha1 ?
>>>
>>>
>>> You should sort the words alphabetically, concatenate them with a space
>>> or any character, that will NEVER be part of a word and calulate the
>>> hash.
>>>
>>> If words can exist multiple times, then youhad tu uniqufy them (u using
>>> a python dict / set) first.
>> Yes that sounds just like what I wanted - thanks!
>>
You're welcome.

is it working as expected?

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


Re: Python 2 or 3

2011-12-03 Thread Gelonida N
On 12/03/2011 04:54 AM, Antti J Ylikoski wrote:
> 
> I'm in the process of learning Python.  I already can code
> objet-oriented programs with the language.  I have in my hands the
> O'Reilly book by Mark Lutz, Programming Python, in two versions: the
> 2nd Edition, which covers Python 2, and the 4th edition, which covers
> Python 3.
> 
> In the "official Python site" so to speak, http://www.python.org, it
> is mentioned that the authors recommend the visitor, who is a novice,
> to learn Python 2 rather than Python 3, because most of existing
> software has been writen with Python 2.
> 
> The O'Reilly book has some 1200 pages.  I would not want to invest
> such an amount of work and time to an obsolete language (i. e. Python
> 2).
> 
> What is the opinion of the wizards here, shall I learm Python 2 or
> Python 3?  I'm posting this here because I feel that this point is
> interesting to other students of Python.
> 
> 
> Cheers, Antti "Andy" Ylikoski
> Helsinki, Finland, the EU

I would still stick with python 2.

In my opinion there is no reason to rush to the most recent version.

Especially when working in a corporate environment or when being obliged
to use certain web servers / servers  you will notice, that
you will still encounter quite some hosts with python 2.5 and even some
with python2.4.

Most machines, that I have to use,  run python 2.6  (and some python
2.5) I personally try to write most of my code such that it could still
run with python 2.5  I decided that python2.4 is my cut-off point,
though I still have one machines and some embedded devices, which just
run 2.4


Other considerations

- there are still more libraries / packages available for python
   2 than for python 3, though this is changing.

- if you write code nicely enough in python 2, then you can translate it
  to python 3. autmatically. However up to my knowledge you
cannot automatically translate python 3 code to python 2 code.

With that strategy your code will be able to run on most web servers and
your own machines.



If you want to write your own code which does not have to run on other
machines and / or if you want to heavily use unicode, then it might be
better to start with Python 3.

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


How to generate java .properties files in python

2011-12-03 Thread Arnaud Delobelle
Hi all,

I need to generate some java .properties files in Python (2.6 / 2.7).
It's a simple format to store key/value pairs e.g.

blue=bleu
green=vert
red=rouge

The key/value are unicode strings.  The annoying thing is that the
file is encoded in ISO 8859-1, with all non Latin1 characters escaped
in the form \u (same as how unicode characters are escaped in
Python).

I thought I could use the "unicode_escape" codec.  But it doesn't work
because it escapes Latin1 characters with escape sequences of the form
\xHH, which is not valid in a java .properties file.

Is there a simple way to achieve this? I could do something like this:

def encode(u):
"""encode a unicode string in .properties format"""
return u"".join(u"\\u%04x" % ord(c) if ord(c) > 0xFF else c for c
in u).encode("latin_1")

but it would be quite inefficient as I have many to generate.

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


Re: Django ported to Python3!

2011-12-03 Thread Roy Smith
In article 
,
 Ron  wrote:

> Django has such
> enormous psychological significance for Python 3. Many important
> projects will never begin serious porting until after Django
> officially supports Python 3. And many Python folks will finally start
> to take Python 3 seriously only when Django does announce official
> support.

In a somewhat related topic, it looks like Mongodb will also be 
supporting Python 3 soon.  It's on the roadmap for their 2.2 release 
(https://jira.mongodb.org/browse/PYTHON-84).  There's no date announced 
yet, but extrapolating from past release schedules, I'd guess mid 2012.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to generate java .properties files in python

2011-12-03 Thread Peter Otten
Arnaud Delobelle wrote:

> I need to generate some java .properties files in Python (2.6 / 2.7).
> It's a simple format to store key/value pairs e.g.
> 
> blue=bleu
> green=vert
> red=rouge
> 
> The key/value are unicode strings.  The annoying thing is that the
> file is encoded in ISO 8859-1, with all non Latin1 characters escaped
> in the form \u (same as how unicode characters are escaped in
> Python).
> 
> I thought I could use the "unicode_escape" codec.  But it doesn't work
> because it escapes Latin1 characters with escape sequences of the form
> \xHH, which is not valid in a java .properties file.
> 
> Is there a simple way to achieve this? I could do something like this:
> 
> def encode(u):
> """encode a unicode string in .properties format"""
> return u"".join(u"\\u%04x" % ord(c) if ord(c) > 0xFF else c for c
> in u).encode("latin_1")
> 
> but it would be quite inefficient as I have many to generate.

>>> class D(dict):
... def __missing__(self, key):
... result = self[key] = u"\\u%04x" % key
... return result
...
>>> d = D(enumerate(map(unichr, range(256
>>> u"ähnlich üblich nötig ΦΧΨ"
u'\xe4hnlich \xfcblich n\xf6tig \u03a6\u03a7\u03a8'
>>> u"ähnlich üblich nötig ΦΧΨ".translate(d)
u'\xe4hnlich \xfcblich n\xf6tig \\u03a6\\u03a7\\u03a8'
>>> u"ähnlich üblich nötig ΦΧΨ".translate(d).encode("latin1")
'\xe4hnlich \xfcblich n\xf6tig \\u03a6\\u03a7\\u03a8'


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


Re: Python 2 or 3

2011-12-03 Thread Chris Angelico
On Sun, Dec 4, 2011 at 7:59 AM, Gelonida N  wrote:
> if you write code nicely enough in python 2, then you can translate it
>  to python 3. autmatically.

It's entirely possible to write code that can run on both Python 2 and
Python 3  - at least, if you can target 2.6/2.7 and get the
appropriate future directives. Add in a few exception-guarded imports
for the renamed modules, and then all you're left with is a few things
where you can take a little care while coding, run it through both
versions to test, and have it all work.

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


Re: Python 2 or 3

2011-12-03 Thread Terry Reedy

On 12/3/2011 3:59 PM, Gelonida N wrote:


I would still stick with python 2.

In my opinion there is no reason to rush to the most recent version.


Python 3 is 3 years old. Starting with it now is hardly rushing.
There are several reasons someone 'in the process of learning Python' 
might want to start with it. The removal of old stuff makes it more 
steamlined and easier to learn. There is only one class system instead 
of two, one meaning of '/' instead of two, and one version of the input, 
range, map, and filter functions instead of two. For anyone working with 
unicode instead of ascii, Python 3 is much better, and 3.3 will be 
better yet. There are numerous improvements to the standard library. 
Most but not all bugfixes have been backported; changes and new features 
have not.


What's New in 3.0/1/2 is a long list of possible reasons.

--
Terry Jan Reedy

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


Re: Python 2 or 3

2011-12-03 Thread Chris Angelico
On Sun, Dec 4, 2011 at 1:52 PM, Terry Reedy  wrote:
> For anyone working with unicode instead of ascii...

Which, frankly, should be everyone. You can't get away with assuming
that a character is a byte any more; even if you stick to the US,
you're going to run into some non-ASCII symbols sooner or later. Of
course, you can work with UTF-8, which means that anything that fits
into 7-bit ASCII will be represented as itself; but you still need to
be aware of the difference between 'bytes' and 'str' (or between 'str'
and 'unicode').

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