Re: Clever hack or code abomination?

2011-12-02 Thread Steven D'Aprano
On Fri, 02 Dec 2011 17:02:01 +1100, Chris Angelico wrote:

> On Fri, Dec 2, 2011 at 4:34 PM, Steven D'Aprano
>  wrote:
>> On Fri, 02 Dec 2011 13:07:57 +1100, Chris Angelico wrote:
>>> I would consider integer representations of ASCII to be code smell.
>>> It's not instantly obvious that 45 means '-', even if you happen to
>>> know the ASCII table by heart (which most people won't).
> 
> Note, I'm not saying that C's way is perfect; merely that using the
> integer 45 to represent a hyphen is worse.

Dude, it was deliberately obfuscated code. I even named the function 
"obfuscated_prefixes". I thought that would have been a hint 

It's kinda scary that of all the sins against readability committed in my 
function, including isinstance(type(c), type(type)) which I was 
particularly proud of, the only criticism you came up with was that 
chr(45) is hard to read. I'm impressed 

[...]
>> Note that this still doesn't work the way we might like in EBCDIC, but
>> the very fact that you are forced to think about explicit conversion
>> steps means you are less likely to make unwarranted assumptions about
>> what characters convert to.
> 
> I don't know about that. Anyone brought up on ASCII and moving to EBCDIC
> will likely have trouble with this, no matter how many function calls it
> takes.

Of course you will, because EBCDIC is a pile of festering garbage :)

But IMAO you're less likely to have trouble with with Unicode if you 
haven't been trained to treat characters as synonymous with integers.

And besides, given how rare such byte-manipulations on ASCII characters 
are in Python, it would be a shame to lose the ability to use '' and "" 
for strings just to avoid calling ord and chr functions.


>> Better than both, I would say, would be for string objects to have
>> successor and predecessor methods, that skip ahead (or back) the
>> specified number of code points (defaulting to 1):
>>
>> 'A'.succ()  => 'B'
>> 'A'.succ(5)  => 'F'
>>
>> with appropriate exceptions if you try to go below 0 or above the
>> largest code point.
> 
> ... and this still has that same issue. Arithmetic on codepoints depends
> on that.

We shouldn't be doing arithmetic on code points. Or at least we shouldn't 
unless we are writing a Unicode library that *needs* to care about the 
implementation. We should only care about the interface, that the 
character after 'A' is 'B'. Implementation-wise, we shouldn't care 
whether A and B are represented in memory by 0x0041 and 0x0042, or by 
0x14AF and 0x9B30. All we really need to know is that B comes immediately 
after A. Everything else is implementation.

But I fear that the idea of working with chr and ord is far to ingrained 
now to get rid of it.



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


Re: Reading twice from STDIN

2011-12-02 Thread janedenone
On Dec 2, 8:53 am, Hans Mulder  wrote:
> On 2/12/11 03:46:10, Dan Stromberg wrote:
>
> > You can read piped data from sys.stdin normally.  Then if you want
> > something from the user, at least on most *ix's, you would open
> > /dev/tty and get user input from there.  'Not sure about OS/X.
>
> Reading from /dev/tty works fine on OS/X.
>
> -- HansM

Many thanks for the pointers – I had tried

sys.stdin = open('/dev/tty', 'r')

but the actual solution is slightly more complicated. With your help
(and another round of Google searches), I found exactly what I was
looking for:

http://turambar.org/jarkko/stdin_input.php

Because raw_input() (input() in Python 3) reads from file descriptor
0, the solution is to copy this file descriptor elsewhere, and use a
file descriptor pointing to /dev/tty for the user input.

Thanks again - Jan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clever hack or code abomination?

2011-12-02 Thread Chris Angelico
On Fri, Dec 2, 2011 at 7:54 PM, Steven D'Aprano
 wrote:
> Dude, it was deliberately obfuscated code. I even named the function
> "obfuscated_prefixes". I thought that would have been a hint 
>
> It's kinda scary that of all the sins against readability committed in my
> function, including isinstance(type(c), type(type)) which I was
> particularly proud of, the only criticism you came up with was that
> chr(45) is hard to read. I'm impressed 

Heh! I know it was obfuscated, and that's why I didn't bother
mentioning the obvious.

> And besides, given how rare such byte-manipulations on ASCII characters
> are in Python, it would be a shame to lose the ability to use '' and ""
> for strings just to avoid calling ord and chr functions.

Agreed. That flexibility is a _huge_ advantage. Definitely not worth
changing anything.

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


Re: order independent hash?

2011-12-02 Thread Hrvoje Niksic
Chris Angelico  writes:

>> The hash can grow with (k,v) pairs accumulated in the run time.
>> An auto memory management mechanism is required for a hash of a non-fixed 
>> size of (k,v) pairs.
>
> That's a hash table

In many contexts "hash table" is shortened to "hash" when there is no
ambiguity.  This is especially popular among Perl programmers where the
equivalent of dict is called a hash.

> Although strictly speaking, isn't that "Python dicts are implemented
> as hash tables in CPython"? Or is the hashtable implementation
> mandated?

It's pretty much mandated because of the __hash__ protocol.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 - xml - crlf handling problem

2011-12-02 Thread durumdara
Dear Stefan!


So: may I don't understand the things well, but I thought that parser
drop the "nondata" CRLF-s + other characters (not preserve them).

Then don't matters that I read the XML from a file, or I create it
from code, because all of them generating SAME RESULT.
But Python don't do that.
If I make xml from code, the code is without plus characters.
But Python preserves parsed CRLF characters somewhere, and they are
also flushing into the result.

Example:

original='''



AnyText


'''

If I parse this, and write with toxml, the CRLF-s remaining in the
code, but if I create this document line by line, there is no CRLF,
the toxml write "only lined" xml.

This also meaning that if I use prettyxml call, to prettying the xml,
the file size is growing.

If there is a multiple processing queue - if two pythons communicating
in xml files, the size can growing every time.

Py1 - read the Py2's file, process it, and write to a result file
Py2 - read the Py1's result file, process it, and pass back to Py1
this can grow the file with each call, because "pretty" CRLF-s not
normalized out from the code.

original='''



AnyText


'''

def main():
f = open('test.0.xml','w')
f.write(original.strip())
f.close()

for i in range(1, 10 + 1):
xo = parse('test.%d.xml' % (i - 1))
de = xo.documentElement
de.setAttribute('c', str(i))
t = de.getElementsByTagName('element')[0]
tn = t.childNodes[0]
print (dir(t))
print (tn)
print (tn.nodeValue)
tn.nodeValue = str(i) + '\t' + '\n'
#s = xo.toxml()
s = xo.toprettyxml()
f = open('test.%d.xml' % i,'w')
f.write(s)
f.close()

sys.exit()

And: because Python is not converting CRLF to &013; I cannot make
different from "prettied source's CRLF" (loaded from template file),
"my own pretty's CRLF" (my own topretty), and really contained CRLF
(for example a memo field's value).

My case is that the processor application (for whom I pass the XML
from Python) is sensitive to "plus CRLF"-s in text nodes, I must do
something these "plus" items to avoid external's program errors.

I got these templates and input files from prettied format (with
CRLFS), but I must "eat" them to make an XML that one lined if
possible.

I hope you understand my problem with it.

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


Re: suppressing bad characters in output PCDATA (converting JSON to XML)

2011-12-02 Thread Adam Funk
On 2011-11-29, Stefan Behnel wrote:

> Adam Funk, 29.11.2011 13:57:
>> On 2011-11-28, Stefan Behnel wrote:

>>> If the name "big_json" is supposed to hint at a large set of data, you may
>>> want to use something other than minidom. Take a look at the
>>> xml.etree.cElementTree module instead, which is substantially more memory
>>> efficient.
>>
>> Well, the input file in this case contains one big JSON list of
>> reasonably sized elements, each of which I'm turning into a separate
>> XML file.  The output files range from 600 to 6000 bytes.
>
> It's also substantially easier to use, but if your XML writing code works 
> already, why change it.

That module looks useful --- thanks for the tip.  (TBH, I'm using
minidom mainly because I've used it before and the API is similar to
the DOM APIs I've used in other languages.)


> You should read up on Unicode a bit.

It wouldn't do me any harm.  :-)


 I thought this would force all the output to be valid, but xmlstarlet
 gives some errors like these on a few documents:

 PCDATA invalid Char value 7
 PCDATA invalid Char value 31
>>>
>>> This strongly hints at a broken encoding, which can easily be triggered by
>>> your erroneous encode-and-encode cycles above.
>>
>> No, I've checked the JSON input and those exact control characters are
>> there too.
>
> Ah, right, I didn't look closely enough. Those are forbidden in XML:
>
> http://www.w3.org/TR/REC-xml/#charsets
>
> It's sad that minidom (apparently) lets them pass through without even a 
> warning.

Yes, it is!  I've now found this, which seems to fix the problem:

http://bitkickers.blogspot.com/2011/05/stripping-control-characters-in-python.html


-- 
The internet is quite simply a glorious place. Where else can you find
bootlegged music and films, questionable women, deep seated xenophobia
and amusing cats all together in the same place? [Tom Belshaw]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 - xml - crlf handling problem

2011-12-02 Thread Stefan Behnel

durumdara, 02.12.2011 09:13:

So: may I don't understand the things well, but I thought that parser
drop the "nondata" CRLF-s + other characters (not preserve them).


Well, it does that, at least on my side (which is not under Windows):

===
original='''



AnyText


'''

from xml.dom.minidom import parse

def main():
f = open('test.0.xml', 'wb')
f.write(original.strip().replace('\n', '\r\n').encode('utf8'))
f.close()

xo = parse('test.0.xml')
de = xo.documentElement
print(repr(de.childNodes[0].nodeValue))
print(repr(de.childNodes[1].childNodes[0].nodeValue))

if __name__ == '__main__':
main()
===

This prints '\n' and '\nAnyText\n' on my side, so the 
whitespace normalisation in the parser properly did its work.




Then don't matters that I read the XML from a file, or I create it
from code, because all of them generating SAME RESULT.
But Python don't do that.
If I make xml from code, the code is without plus characters.


What do you mean by "plus characters"? It's not the "+" character that you 
are referring to, right? Do you mean additional characters? Such as the 
additional '\r'?




But Python preserves parsed CRLF characters somewhere, and they are
also flushing into the result.

Example:

original='''


 
 AnyText
 

'''

If I parse this, and write with toxml, the CRLF-s remaining in the
code, but if I create this document line by line, there is no CRLF,
the toxml write "only lined" xml.

This also meaning that if I use prettyxml call, to prettying the xml,
the file size is growing.

If there is a multiple processing queue - if two pythons communicating
in xml files, the size can growing every time.

Py1 - read the Py2's file, process it, and write to a result file
Py2 - read the Py1's result file, process it, and pass back to Py1
this can grow the file with each call, because "pretty" CRLF-s not
normalized out from the code.

original='''


 
 AnyText
 

'''

def main():
 f = open('test.0.xml','w')
 f.write(original.strip())
 f.close()

 for i in range(1, 10 + 1):
 xo = parse('test.%d.xml' % (i - 1))
 de = xo.documentElement
 de.setAttribute('c', str(i))
 t = de.getElementsByTagName('element')[0]
 tn = t.childNodes[0]
 print (dir(t))
 print (tn)
 print (tn.nodeValue)
 tn.nodeValue = str(i) + '\t' + '\n'
 #s = xo.toxml()
 s = xo.toprettyxml()
 f = open('test.%d.xml' % i,'w')
 f.write(s)
 f.close()

 sys.exit()

And: because Python is not converting CRLF to&013; I cannot make
different from "prettied source's CRLF" (loaded from template file),
"my own pretty's CRLF" (my own topretty), and really contained CRLF
(for example a memo field's value).

My case is that the processor application (for whom I pass the XML
from Python) is sensitive to "plus CRLF"-s in text nodes, I must do
something these "plus" items to avoid external's program errors.

I got these templates and input files from prettied format (with
CRLFS), but I must "eat" them to make an XML that one lined if
possible.

I hope you understand my problem with it.


Still not quite, but never mind. May or may not be a problem in minidom or 
your code. For example, you shouldn't open the output file in text mode but 
in binary mode (i.e. "wb") because you are writing bytes into it.


Here's what I tried with ElementTree, and it seems to do what your code 
above wants. The indent() function is taken from Fredrik's element lib page:


http://effbot.org/zone/element-lib.htm


original='''



AnyText


'''

def indent(elem, level=0):
i = "\n" + level*"  "
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + "  "
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
indent(elem, level+1)
if not elem.tail or not elem.tail.strip():
elem.tail = i
else:
if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i

def main():
f = open('test.0.xml','w', encoding='utf8')
f.write(original.strip())
f.close()

from xml.etree.cElementTree import parse

for i in range(10):
tree = parse('test.%d.xml' % i)
root = tree.getroot()
root.set('c', str(i+1))
t = root.find('.//element')
t.text = '%d\t\n' % (i+1)
indent(root)
tree.write('test.%d.xml' % (i+1), encoding='utf8')

if __name__ == '__main__':
main()


Hope that helps,

Stefan

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


Re: order independent hash?

2011-12-02 Thread 88888 Dihedral
On Friday, December 2, 2011 5:53:47 PM UTC+8, Hrvoje Niksic wrote:
> Chris Angelico  writes:
> 
> >> The hash can grow with (k,v) pairs accumulated in the run time.
> >> An auto memory management mechanism is required for a hash of a non-fixed 
> >> size of (k,v) pairs.
> >
> > That's a hash table
> 
> In many contexts "hash table" is shortened to "hash" when there is no
> ambiguity.  This is especially popular among Perl programmers where the
> equivalent of dict is called a hash.
> 
> > Although strictly speaking, isn't that "Python dicts are implemented
> > as hash tables in CPython"? Or is the hashtable implementation
> > mandated?
> 
> It's pretty much mandated because of the __hash__ protocol.

A hash table  definitely can replace a bi-directional list. 
But this is for applications or languages like C. 
In python hash is a build in type. Perl's lazy way of programming is famous. 


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


Re: Reading twice from STDIN

2011-12-02 Thread Hans Mulder

On 2/12/11 10:09:17, janedenone wrote:

I had tried

sys.stdin = open('/dev/tty', 'r')


That seems to work for me.  This code:

import sys

if sys.version_info.major == 2:
input = raw_input

for tp in enumerate(sys.stdin):
print("%d: %s" % tp)

sys.stdin = open('/dev/tty', 'r')
answer = input('What is the carrying capacity of a swallow? ')
print("You answered: %s" % answer)
print("File descriptor is %d" % sys.stdin.fileno())

... does what I expect it to do in both Python 2.7 and Python 3.2.


but the actual solution is slightly more complicated. With your help
(and another round of Google searches), I found exactly what I was
looking for:

http://turambar.org/jarkko/stdin_input.php

Because raw_input() (input() in Python 3) reads from file descriptor
0, the solution is to copy this file descriptor elsewhere, and use a
file descriptor pointing to /dev/tty for the user input.


That's odd.  For some reason, I can get away with a simple

sys.stdin = open('/dev/tty')

and raw_input will merrily read from file descriptor 3.

I'm using Pyhton 2.7.1 and 3.2 on MacOS/X 10.5.0.

What version are you using?

-- HansM




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


Re: Passing along cmd.Cmd completion to contained class

2011-12-02 Thread Miki Tebeka
This is not tested, but maybe it'll work :)

def complete(self, text, state):
if text.startswith('config):
return self.config.complete(text, state)
return Cmd.complete(self, text, state)
-- 
http://mail.python.org/mailman/listinfo/python-list


Multiprocessing: killing children when parent dies

2011-12-02 Thread Mihai Badoiu
In the multiprocessing module, on a Process p, by just doing p.daemon=1
before p.start(), we can make the child die when the parent exits.
 However, the child does not die if the parent gets killed.

How can I make sure the child die when the parent gets killed?

thanks,

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


Re: Multiprocessing: killing children when parent dies

2011-12-02 Thread Chris Angelico
On Sat, Dec 3, 2011 at 2:05 AM, Mihai Badoiu  wrote:
> In the multiprocessing module, on a Process p, by just doing p.daemon=1
> before p.start(), we can make the child die when the parent exits.  However,
> the child does not die if the parent gets killed.
> How can I make sure the child die when the parent gets killed?

Are you in control of the killing of the parent? One easy way would be
to catch the signal (say SIGINT) and initiate an orderly shutdown,
signalling the children first.

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


Re: python 2.5 and ast

2011-12-02 Thread DevPlayer
On Nov 30, 1:03 pm, Andrea Crotti  wrote:
> Another thing about the AST, I am having fun trying to for example list
> out all
> the unused imports.
>
> I have already a visitor which works quite nicely I think, but now I
> would like
> to get a way to find all the unused imports, so I need more visitors that
> find out all the used names.
>
> I didn't find too much documentation about these kind of things, so any
> suggestions on how to approach?
>
> Pylint and snakefood have similar code, but they use the old "compiler"
> module,
> so it's not really helpful.

There was another topic in these forums recently about "un-importing"
modules (and how you can not do that reliably without restarting
python). There was various ways mentioned of keeping track of what was
imported. And there was mentioned reasonable ways of finding all
possible imports on a computer.

By "unused imports" I assume you mean "all unused imports in the
application's source code" as opposed to meaning "all unused modules/
packages/libraries on that computer."

Personally I'd love to see more tutorials on the AST module; An AST
for Dummies. Pretty much the tutorials talk about parsing an
expression like "1+2=3". But I'd like to see how blocks are compiled/
managed by the indent/dedent tokens and how the complete algorithm for
finding qouted strings is implimented (using really simple
explanations).

Some google buzzwords to help with your search for your question:  sys
import cache, import hook, pydoc walkpackages().

And I just found this little tool; never knew about it: C:\PythonXX
\Tools\Scripts\pydocui.pyw

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


Why are Sphinx docs incompatible with Safari Reader?

2011-12-02 Thread K . -Michael Aye

Anybody knows?

Have a nice weekend!

Michael



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


Re: Reading twice from STDIN

2011-12-02 Thread janedenone
On Dec 2, 2:04 pm, Hans Mulder  wrote:

> That's odd.  For some reason, I can get away with a simple
>
>      sys.stdin = open('/dev/tty')
>
> and raw_input will merrily read from file descriptor 3.
>
> I'm using Pyhton 2.7.1 and 3.2 on MacOS/X 10.5.0.
>
> What version are you using?
>
> -- HansM

Python 2.7.1 and 3.2.2 on Mac OS X 10.7.2.

But what's really strange – you're right. It works now. I have no idea
what I did before, but I can confirm that the following code executes
flawlessly:

message = sys.stdin.read()
urls = re.findall(r'(?:http|www)\S+', message)

sys.stdin = open('/dev/tty')
# Asks user to select a URL only if more than one URL is present
if len(urls) > 1:
for index, url in enumerate(urls):
print '{0}: {1}\n'.format(index, url)

selected_index = raw_input('Which URL to open? ')
selected_index = int(selected_index)
else:
selected_index = 0
selected_url = urls[selected_index]

Quite embarrassing. In any case, I am happy to have found the simplest
solution.

Thanks again,
Jan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing: killing children when parent dies

2011-12-02 Thread Alec Taylor
I've been in philosophical discussions all day.

This topic title makes me cringe

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


Re: Multiprocessing: killing children when parent dies

2011-12-02 Thread 88888 Dihedral
On Friday, December 2, 2011 11:13:34 PM UTC+8, Chris Angelico wrote:
> On Sat, Dec 3, 2011 at 2:05 AM, Mihai Badoiu  wrote:
> > In the multiprocessing module, on a Process p, by just doing p.daemon=1
> > before p.start(), we can make the child die when the parent exits.  However,
> > the child does not die if the parent gets killed.
> > How can I make sure the child die when the parent gets killed?
> 
> Are you in control of the killing of the parent? One easy way would be
> to catch the signal (say SIGINT) and initiate an orderly shutdown,
> signalling the children first.
> 
> ChrisA

Multiple thread supporting programming languages  in true OOP as Erlang and 
Python do not talk about POSIX signals.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiprocessing: killing children when parent dies

2011-12-02 Thread Chris Angelico
On Sat, Dec 3, 2011 at 2:57 AM, 8 Dihedral
 wrote:
> Multiple thread supporting programming languages  in true OOP as Erlang and 
> Python do not talk about POSIX signals.

The OP talked about multiprocessing. Each thread of execution is a
separate context, and can receive signals.

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


Re: Multiprocessing: killing children when parent dies

2011-12-02 Thread 88888 Dihedral
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


Re: unpack('>f', b'\x00\x01\x00\x00')

2011-12-02 Thread Mark Dickinson
On Dec 1, 10:21 am, Hrvoje Niksic  wrote:
> Chris Rebert  writes:
> > C does not have a built-in fixed-point datatype, so the `struct`
> > module doesn't handle fixed-point numbers directly.
>
> The built-in decimal module supports fixed-point arithmetic, but the
> struct module doesn't know about it.  A bug report (or patch) by someone
> who works with binary representations of fixed-point would be a good
> start to improve it.

Not really:  the decimal module is for floating-point, not fixed-
point, though its semantics for significant trailing zeros can help
give the appearance of fixed-point arithmetic for simple operations
(addition, subtraction) that stay within suitable bounds.  And decimal
fixed-point isn't so much use for a binary fixed-point format, anyway.

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


Re: python 2.5 and ast

2011-12-02 Thread Andrea Crotti

On 12/02/2011 03:18 PM, DevPlayer wrote:

There was another topic in these forums recently about "un-importing"
modules (and how you can not do that reliably without restarting
python). There was various ways mentioned of keeping track of what was
imported. And there was mentioned reasonable ways of finding all
possible imports on a computer.

By "unused imports" I assume you mean "all unused imports in the
application's source code" as opposed to meaning "all unused modules/
packages/libraries on that computer."

Personally I'd love to see more tutorials on the AST module; An AST
for Dummies. Pretty much the tutorials talk about parsing an
expression like "1+2=3". But I'd like to see how blocks are compiled/
managed by the indent/dedent tokens and how the complete algorithm for
finding qouted strings is implimented (using really simple
explanations).

Some google buzzwords to help with your search for your question:  sys
import cache, import hook, pydoc walkpackages().

And I just found this little tool; never knew about it: C:\PythonXX
\Tools\Scripts\pydocui.pyw



Yes I meant unused imports in each of the modules actually...
The problem for me is to actually understand what are all the possible
AST node that can involve the use of an actual import, and I didn't
find anything helpful aboupt that.

The ASDL definition says everything in theory but without some examples
is a bit hard.

I got something nice however:
http://stackoverflow.com/questions/8340567/python-ast-to-dot-graph/8342383#8342383

But on windows and Python 2.5 nothing is working :/, even if I blandly 
copied the

ast.py from the python 2.7 code file..

  File "h:\long\path\devsonly\ast.py", line 166, in iter_fields
for field in node._fields:
TypeError: 'NoneType' object is not iterable
--
http://mail.python.org/mailman/listinfo/python-list


Re: python 2.5 and ast

2011-12-02 Thread Andrea Crotti
And on a related topic, how can I actually detect other types of 
imports, for example

__import__

Doing a dump I get this:

In [113]: ast.dump(ast.parse('__import__("module")'))
Out[113]: "Module(body=[Expr(value=Call(func=Name(id='__import__', 
ctx=Load()), args=[Str(s='module')], keywords=[], starargs=None, 
kwargs=None))])"


So the visitor should be quite smart, and the string passed can't be 
always be done.
I think the easiest way is just to use regexp and look for them warning 
the user that there might be other
stupid imports, the harder way is to try to detect it and if the string 
passed is actually known at compile-time

use it, otherwise warn the user.
--
http://mail.python.org/mailman/listinfo/python-list


Re: order independent hash?

2011-12-02 Thread 88888 Dihedral
On Friday, December 2, 2011 5:53:47 PM UTC+8, Hrvoje Niksic wrote:
> Chris Angelico  writes:
> 
> >> The hash can grow with (k,v) pairs accumulated in the run time.
> >> An auto memory management mechanism is required for a hash of a non-fixed 
> >> size of (k,v) pairs.
> >
> > That's a hash table
> 
> In many contexts "hash table" is shortened to "hash" when there is no
> ambiguity.  This is especially popular among Perl programmers where the
> equivalent of dict is called a hash.
> 
> > Although strictly speaking, isn't that "Python dicts are implemented
> > as hash tables in CPython"? Or is the hashtable implementation
> > mandated?
> 
> It's pretty much mandated because of the __hash__ protocol.

I agree with you. When a hash is inserted with (k,v1) and then (k,v2) 
such that  v1!=v2, there are several possibilities to handle this situation 
in programming:

1. v2 just replaces v1 with or without a message
2. the programmer can delete the (k,v1) entry and then insert a (k, (v1,v2))
entry.
3. the programmer initializes a tuple of (v1,v2), and then delete the (k,v1)
entry to be replaced by a (k,(v1,v2)) entry.

Hashes of hashes are really powerful in Python to be used to build a relational
DB of thousands of thousands of objects or records in a piece of cake.

A similar hash library in C is to be used everywhere is not difficult at all.


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


Re: Clever hack or code abomination?

2011-12-02 Thread Chris Hulan
I'd just look a the unit tests for clarification/examples
-- 
http://mail.python.org/mailman/listinfo/python-list


Referencing module.instance

2011-12-02 Thread Gnarlodious
What I am doing is importing modules that have an identical instance
name. So I say:

import Grid

Grid has its instance:

Grid.Grid()

and this is the same for all modules of my webapp.
allowedPages is a list of modules to import, so they are quoted
strings:

for page in self.allowedPages:
   setattr(self, page, __import__(page))

The problem is that the attribute name needs to reference the
Grid.Grid instance and not the Grid module. How would I do this?
I can do it literally:
setattr(self, 'Grid', Grid.Grid)

however doing it as a reference eludes me.

Or is there some nifty Pythonic way of bulk importing modules?

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


Re: order independent hash?

2011-12-02 Thread 88888 Dihedral
On Wednesday, November 30, 2011 8:32:39 PM UTC+8, 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?

For each word of your list as the key, an object of a hash can be used further 
is stored as the value in the hash of the list of words.

Assume that word 1 is the key and the hash stored is a sentence that uses 
the key word 1.

This is very useful to learn vocabularies and writing sentences. 

 

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


Re: python 2.5 and ast

2011-12-02 Thread 88888 Dihedral
On Monday, November 28, 2011 7:45:57 PM UTC+8, Andrea Crotti wrote:
> I'm happily using the ast module to analyze some code,
> but my scripts need also to run unfortunately on python 2.5
> 
> The _ast was there already, but the ast helpers not yet.
> Is it ok if I just copy over the source from the ast helpers in my code base
> or is there a smarter way?
> (I don't even need all of them, just "parse" and NodeVisitor at the moment)

Sounds like a hash for nodes and a hash for a tree. 
A hash can replace a tree of finite number of nodes. 
An array or list is enough to replace a tree of finite number of nodes.

The heap sort ordering is simple but illustrative . 

After all the tasks  of the tree are done, the hash of the tree 
will be deleted by Python's garbage collection mechanism. 

A hash can replace an indexed array with (k,v) pairs for k=0,1,2,3...n in 
a trivial way.


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


Re: order independent hash?

2011-12-02 Thread Ian Kelly
On Fri, Dec 2, 2011 at 11:18 AM, 8 Dihedral
 wrote:
> On Wednesday, November 30, 2011 8:32:39 PM UTC+8, 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?
>
> For each word of your list as the key, an object of a hash can be used further
> is stored as the value in the hash of the list of words.
>
> Assume that word 1 is the key and the hash stored is a sentence that uses
> the key word 1.
>
> This is very useful to learn vocabularies and writing sentences.

The OP is talking about hash functions, not hash tables, and
furthermore he is talking about hashing the entire unordered
collection of words, not hashing individual words or ordered
sentences.
-- 
http://mail.python.org/mailman/listinfo/python-list


Install Python on Windows without Start Menu icons?

2011-12-02 Thread snorble
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.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: order independent hash?

2011-12-02 Thread Dave Angel

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!



"different words will create different hash, but not sensitive to the order of the 
words"


Just note that you can only say that "probably create" a different 
hash.  If the hash number is constrained in size (eg. 32 bits), then a 
collision is possible.  (Unless of course you also constrain the 
alphabet and/or length of the words involved)


--

DaveA

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


Re: python 2.5 and ast

2011-12-02 Thread Ian Kelly
On Fri, Dec 2, 2011 at 11:28 AM, 8 Dihedral
 wrote:
> On Monday, November 28, 2011 7:45:57 PM UTC+8, Andrea Crotti wrote:
>> I'm happily using the ast module to analyze some code,
>> but my scripts need also to run unfortunately on python 2.5
>>
>> The _ast was there already, but the ast helpers not yet.
>> Is it ok if I just copy over the source from the ast helpers in my code base
>> or is there a smarter way?
>> (I don't even need all of them, just "parse" and NodeVisitor at the moment)
>
> Sounds like a hash for nodes and a hash for a tree.
> A hash can replace a tree of finite number of nodes.
> An array or list is enough to replace a tree of finite number of nodes.
>
> The heap sort ordering is simple but illustrative .
>
> After all the tasks  of the tree are done, the hash of the tree
> will be deleted by Python's garbage collection mechanism.
>
> A hash can replace an indexed array with (k,v) pairs for k=0,1,2,3...n in
> a trivial way.

What in the world does any of this have to do with using the ast
module in Python 2.5?  I am starting to suspect that "8 Dihedral"
may be a bot.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need some IPC pointers

2011-12-02 Thread bobicanprogram
On Nov 30, 4:03 pm, Andrew Berg  wrote:
> I've done some research, but I'm not sure what's most appropriate for my
> situation. What I want to do is have a long running process that spawns
> processes (that aren't necessarily written in Python) and communicates
> with them. The children can be spawned at any time and communicate at
> any time. Being able to communicate with non-local processes would be
> nice, but is not necessary. The implementation needs to be
> cross-platform, but child processes will use the same OS as the parent
> during runtime.
> I don't think I'll ever need to transfer anything complicated or large -
> just strings or possibly tuples/lists. I'd rather not go outside the
> standard library (but I'd consider it). I don't need to worry about
> compatibility with older Python versions; if it only works with Python
> 3.2, that's not a problem.
> I'm thinking sockets, but perhaps there's something simpler/easier.
>
> --
> CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0


You might want to take a look at the SIMPL toolkit.
http://www.icanprogram.com/06py/lesson1/lesson1.html

SIMPL modules can be written (and mixed) in any number of supported
languages including Python, C, C++, JAVA, Tcl/Tk or PHP.   Non local
communication is handled by generic surrogates.  Because of this
surrogate architecture SIMPL modules can often be tested locally and
then deployed into the cloud without any changes.

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


RE: Using the Python Interpreter as a Reference

2011-12-02 Thread Sells, Fred
Steven, that's probably the most elegant explanation of the "pythonic"
way I've ever seen.  I'm saving it for the next time upper management
want to use Java again.

-Original Message-
From: [email protected]
[mailto:[email protected]] On
Behalf Of Steven D'Aprano
Sent: Thursday, December 01, 2011 7:43 PM
To: [email protected]
Subject: Re: Using the Python Interpreter as a Reference

On Thu, 01 Dec 2011 10:03:53 -0800, DevPlayer wrote:

[...]
> Well, that may be a little hyperbolic. But with 2 spaces you can
> encourage coders to get very deep, indentially, and still fit 80
chars.

Why would you want to encourage coders to write deeply indented code?

In my opinion, if your code is indented four or more levels, you should 
start to think about refactorising your code; if you reach six levels, 
your code is probably a mess.

class K:
def spam():
if x:
for a in b:
# This is about as deep as comfortable
while y:
# Code is starting to smell
try:
# Code smell is now beginning to reek
with z as c:
# And now more of a stench
try:
# A burning, painful stench
if d:
# Help! I can't breathe!!!
for e in f:
# WTF are you thinking?
try:
# DIE YOU M***ER!!!
while g:
# gibbers quietly
...


The beauty of languages like Python where indentation is significant is 
that you can't hide from the ugliness of this code. 

class K: {
  # Code looks okay to a casual glance.
  def spam():{
   if x: { for a in b:{
 while y:{ try:{ with z as c:{
   try:{ if d:{ for e in f:{ try:{
 while g:{ ... 
   
 

Deeply indented code *is* painful, it should *look* painful.


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

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


Re: Using the Python Interpreter as a Reference

2011-12-02 Thread Devin Jeanpierre
> In my opinion, if your code is indented four or more levels, you should
> start to think about refactorising your code; if you reach six levels,
> your code is probably a mess.

Here's some code I encountered while grading assignments from
first-year CS students:

if 'not' in temp_holder:
for item in (range(len(ial))):
for key in (range(len(ial[item]))):
if type(ial[item][key]) == str:
   if temp[term].find(ial[item][key]) > 0:
  for value in range(len(ial[item][1])):
  if ial[item][1][value] in images:
 while ial[item][1][value] in images:
   images.remove(ial[item][1][value])

I think after some point of nesting, not only can we conclude that the
code is difficult to read, we can probably conclude the author wasn't
thinking very clearly about what he or she was doing.

Devin

On Thu, Dec 1, 2011 at 7:43 PM, Steven D'Aprano
 wrote:
> On Thu, 01 Dec 2011 10:03:53 -0800, DevPlayer wrote:
>
> [...]
>> Well, that may be a little hyperbolic. But with 2 spaces you can
>> encourage coders to get very deep, indentially, and still fit 80 chars.
>
> Why would you want to encourage coders to write deeply indented code?
>
> In my opinion, if your code is indented four or more levels, you should
> start to think about refactorising your code; if you reach six levels,
> your code is probably a mess.
>
> class K:
>    def spam():
>        if x:
>            for a in b:
>                # This is about as deep as comfortable
>                while y:
>                    # Code is starting to smell
>                    try:
>                        # Code smell is now beginning to reek
>                        with z as c:
>                            # And now more of a stench
>                            try:
>                                # A burning, painful stench
>                                if d:
>                                    # Help! I can't breathe!!!
>                                    for e in f:
>                                        # WTF are you thinking?
>                                        try:
>                                            # DIE YOU M***ER!!!
>                                            while g:
>                                                # gibbers quietly
>                                                ...
>
>
> The beauty of languages like Python where indentation is significant is
> that you can't hide from the ugliness of this code.
>
> class K: {
>  # Code looks okay to a casual glance.
>  def spam():{
>   if x: { for a in b:{
>     while y:{ try:{ with z as c:{
>       try:{ if d:{ for e in f:{ try:{
>         while g:{ ... 
>       
>     
>
> Deeply indented code *is* painful, it should *look* painful.
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Referencing module.instance

2011-12-02 Thread Ben Finney
Gnarlodious  writes:

> What I am doing is importing modules that have an identical instance
> name.

Best to fix that, then.

> import Grid

That's a poorly-named module. PEP 8 recommends module names be all
lowercase.

> Grid has its instance:
>
> Grid.Grid()

And this is the reason: PEP 8 recommends class names be named with
TitleCase, so they're distinguishable from module names.

So the above should be:

import grid
grid.Grid()

> for page in self.allowedPages:
>setattr(self, page, __import__(page))

For completeness, I'll note that the function name would be PEP 8
compatible as ‘allowed_pages’.

> The problem is that the attribute name needs to reference the
> Grid.Grid instance and not the Grid module. How would I do this?
> I can do it literally:
> setattr(self, 'Grid', Grid.Grid)

Why do you shy away from this? You're already using ‘__import__’, and I
don't know why that is since you already showed that you're importing
the module explicitly anyway.

-- 
 \ “Don't be afraid of missing opportunities. Behind every failure |
  `\ is an opportunity somebody wishes they had missed.” —Jane |
_o__)  Wagner, via Lily Tomlin |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: order independent hash?

2011-12-02 Thread Terry Reedy

On 12/2/2011 4:53 AM, Hrvoje Niksic wrote:

Chris Angelico  writes:


The hash can grow with (k,v) pairs accumulated in the run time.
An auto memory management mechanism is required for a hash of a non-fixed size 
of (k,v) pairs.


That's a hash table


In many contexts "hash table" is shortened to "hash" when there is no
ambiguity.  This is especially popular among Perl programmers where the
equivalent of dict is called a hash.


Although strictly speaking, isn't that "Python dicts are implemented
as hash tables in CPython"? Or is the hashtable implementation
mandated?


It's pretty much mandated because of the __hash__ protocol.


Lib Ref 4.8. Mapping Types — dict
"A mapping object maps hashable values to arbitrary objects."

This does not say that the mapping has to *use* the hash value ;-).
Even if it does, it could use a tree structure instead of a hash table. 
But hash tables seem to work well for general purposes,


"Mappings are mutable objects."
(This would change if a frozendict were added.)

especially when additions and deletions are needed.

--
Terry Jan Reedy


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


Django ported to Python3!

2011-12-02 Thread Ron
It looks like Vinay Sajip has succeeded in porting Django to Python3
(in a shared code base for Python 3.2 and Python 2.7). This is an
astoundingly good job, done very fast and is big news.
See https://groups.google.com/forum/#!topic/django-developers/XjrX3FIPT-U
and the actual code is at Bitbucket https://bitbucket.org/vinay.sajip/django

With NumPy and SciPy already ported, and with Matplotlib almost there,
maybe PIL and others will follow shortly. This could be a turning
point, or a milestone, or whatever you want to call it. Vinay is  a
hero who should be thanked and congratulated!

In an infinitely less important note, Python411 podcasts are finally
back online after  a three month occultation due to a prolonged and
ugly  billing dispute with Libsyn. Maybe I can interview Vinay and
have him tell us about the porting effort!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: order independent hash?

2011-12-02 Thread Steven D'Aprano
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

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


Re: Referencing module.instance

2011-12-02 Thread Steven D'Aprano
On Fri, 02 Dec 2011 09:49:25 -0800, Gnarlodious wrote:

> What I am doing is importing modules that have an identical instance
> name. So I say:
> 
> import Grid
> 
> Grid has its instance:
> 
> Grid.Grid()
> 
> and this is the same for all modules of my webapp. allowedPages is a
> list of modules to import, so they are quoted strings:
> 
> for page in self.allowedPages:
>setattr(self, page, __import__(page))

So if allowedPages looks like this: ['Grid', 'Spam', 'Ham', 'Cheese'] you 
expect your instance to look like this:

self.Grid  # has the value Grid.Grid
self.Spam  # has the value Spam.Grid etc.
self.Ham
self.Cheese

Correct?

I'm not sure I like that design, it feels wrong, but perhaps I don't 
understand the reason for it. Moving along...

> The problem is that the attribute name needs to reference the Grid.Grid
> instance and not the Grid module. How would I do this? I can do it
> literally:
> setattr(self, 'Grid', Grid.Grid)
> 
> however doing it as a reference eludes me.

__import__(page) returns a module, so just grab that attribute from the 
module.

for page in self.allowedPages:
setattr(self, page, __import__(page).Grid)


But note that this is an binding operation, like an assignment. If you 
rebind module.Grid, your instance self will not see the change:

Spam.Grid = 42  # some value
instance.read_pages()  # whatever you call the method
assert instance.Spam == 42
Spam.Grid = 23  # rebind the original
assert instance.Spam == 23  # THIS WILL FAIL!!!


If you need these attributes to be aliases to the module attribute, 
rather than independent bindings, you need to use computed properties 
rather than plain attributes. I leave that as an exercise, mainly because 
I suspect it will be very difficult.

Wait... no, I think it's easy! (Famous last words...) Try this untested 
code:

class MyClass(object):
allowedPages = ('Grid', 'Spam', 'Ham', 'Cheese')
def __init__(self):
self.modules = {}
for name in allowedPages:
self.modules[name] = __import__(name)
def __getattribute__(self, name):
if name in self.allowedPages:
return self.modules[name].Grid
return super(MyClass, self).__getattribute__(name)


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


Python 2 or 3

2011-12-02 Thread Antti J Ylikoski


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
--
http://mail.python.org/mailman/listinfo/python-list


Re: Referencing module.instance

2011-12-02 Thread Gnarlodious
To explain my reasoning, this scheme will allow me to run the script three 
ways, as shell, as one-shot CGI or as a persistent mod_wsgi module.

So to be more exhaustive:

In __init__ I can say:

import Grid
self.Grid = Grid.Grid

self.Grid is now the instance of Grid inside the module Grid.

then later on I __call__ with the input data:

html=self.Grid(queryString, environ)

and this works great for one module, a default output which is now running on 
my server.


But now I want to use the query string to load the instance, which means it 
comes in as text. Say I load a list of modules:
allowedPages=['Gnomon', 'Grid', 'Lexicon', 'Harmonics']

I need to import them all at __init__, and set the instance for each like this:
self.Gnomon=Gnomon.Gnomon
self.Grid=Grid.Grid
self.Lexicon=Lexicon.Lexicon
self.Harmonics=Harmonics.Harmonics

Then dynamically, in __call_, I just use the CGI string to invoke my target 
object.

What I have now is:

self.modules = {} 
page = 'Gnomon'
self.modules[page] = __import__(page)

which gives me



A solution is to set self.modules[page] to the Gnomon instance of the Gnomon 
module. How to?

-- Gnarlie
http://Sectrum.com

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


Re: Python 2 or 3

2011-12-02 Thread Gnarlodious
If you are writing your own scripts, I would recommend Py3 for learning. But if 
you are studying existing scripts to learn, Py2 might be better.

I have been doing Python for about 2 years and started learning Py3 with no 
regrets. Py2 is not going to be "obsolete" for quite a while. It is almost all 
the same as Py3, just a few updates mostly of concern to those who maintain 
existing code. And actually, Python has been incrementally improved upon all 
along, just that Py3 was the cutoff point for stuff that HAD to change.

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


Re: Python 2 or 3

2011-12-02 Thread Andrew Berg
On 12/2/2011 9:54 PM, Antti J Ylikoski wrote:
> 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.
Unless you are tied to Python 2 in some way, go for Python 3 and don't
look back. There are a few major software projects that still do not
support Python 3 (more and more are getting ported or replaced as time
goes on), and many production systems are still using Python 2, but
don't let /potential/ roadblocks keep you away from Python 3. Another
thing to note is that, at least AFAICT, Jython, IronPython and PyPy are
not going to support Python 3 any time soon, so if you need to use one
of them, Python 2 is the way to go.

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2 or 3

2011-12-02 Thread Roy Smith
In article ,
 Antti J Ylikoski  wrote:

> 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.

The engineer in me really has to wonder what the 3rd edition might have 
covered :-)

> I would not want to invest such an amount of work and time to an 
> obsolete language (i. e. Python 2).

I think the best that can be said for Python 2 is, "It's not dead yet!".  
The vast majority of production Python code written today is for 2.x, 
for x in {5, 6, 7}.  The biggest thing that's holding back adoption of 3 
is that most of the major packages don't support 3 yet (but I saw an 
announcement just this morning that django has been ported to 3).

I predict that 2012 will be the year of Python-3.  I expect we're at the 
point now that all major packages will either get ported to 3 in the 
next year or two, or become abandonware.  Also, people building new 
packages will come out with versions for both 2 and 3 if they want their 
stuff to get widely adopted.

> 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.

The difficult thing here is that you are living on the cusp.  If you 
came back and asked that question in a couple of years, I strongly 
suspect the answer would be, "Don't bother with 2; 3 is what everybody 
uses today".  But, we're not there quite yet.  Learn 2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2 or 3

2011-12-02 Thread Dan Stromberg
On 12/2/11, 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).

It mostly depends on what sort of thing you're learning Python for.

If you have a project in mind that has large dependencies that still
require Python 2.x, then you're probably best off with 2.x for now.

Otherwise, go with 3.x.

Or do what I've been enjoying: Install 2.x and 3.x, and test with
both, each step of the way.  In this manner, you can pretty easily
write new code that runs on either equally well.  But again, there's
the matter of dependencies.

> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2 or 3

2011-12-02 Thread Terry Reedy

On 12/2/2011 11:20 PM, Andrew Berg wrote:


thing to note is that, at least AFAICT, Jython, IronPython and PyPy are
not going to support Python 3 any time soon,


PyPy has a roadmap for 3.2
http://pypy.org/py3donate.html
They definitely plan to do it one way or another.

--
Terry Jan Reedy

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


Re: Python 2 or 3

2011-12-02 Thread Andrew Berg
On 12/3/2011 12:23 AM, Terry Reedy wrote:
> PyPy has a roadmap for 3.2
> http://pypy.org/py3donate.html
> They definitely plan to do it one way or another.
I never said there were no plans, but at $2567 out of $60k, I don't see
it happening soon. Unless someone decides to donate a huge sum of money
or a large amount of code in the next couple months, I don't see a
release happening until at least the middle of next year. It would
definitely not be practical to learn Python 3 at this point if your
primary implementation is PyPy.

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2 or 3

2011-12-02 Thread Andrew Berg
I accidentally quoted the wrong figure. I meant $4369 of $105000.

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Django ported to Python3!

2011-12-02 Thread Stefan Behnel

Ron, 02.12.2011 22:47:

It looks like Vinay Sajip has succeeded in porting Django to Python3
(in a shared code base for Python 3.2 and Python 2.7). This is an
astoundingly good job, done very fast and is big news.
See https://groups.google.com/forum/#!topic/django-developers/XjrX3FIPT-U
and the actual code is at Bitbucket https://bitbucket.org/vinay.sajip/django

With NumPy and SciPy already ported, and with Matplotlib almost there,
maybe PIL and others will follow shortly. This could be a turning
point, or a milestone, or whatever you want to call it. Vinay is  a
hero who should be thanked and congratulated!


Note that most of the work was done by Martin von Löwis, quite a while back 
in the early days of Python 3.x.


http://wiki.python.org/moin/PortingDjangoTo3k

He also did a huge amount of lobbying to get the changes accepted before 
the time that the project originally envisioned. The original plans of the 
Django project were to only *start* the porting after dropping support for 
Python 2.5 somewhere in the future. Martin made it rather clear with his 
patch (and keeps reiterating it wherever he can) that you can support both 
in one code base, even in a project as large as Django.


Stefan

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


Re: Django ported to Python3!

2011-12-02 Thread Matt Joiner
As long as we can dump python 2, a big congrats to anyone who makes this
possible. Thanks martin
On Dec 3, 2011 5:51 PM, "Stefan Behnel"  wrote:

> Ron, 02.12.2011 22:47:
>
>> It looks like Vinay Sajip has succeeded in porting Django to Python3
>> (in a shared code base for Python 3.2 and Python 2.7). This is an
>> astoundingly good job, done very fast and is big news.
>> See https://groups.google.com/**forum/#!topic/django-**
>> developers/XjrX3FIPT-U
>> and the actual code is at Bitbucket https://bitbucket.org/vinay.**
>> sajip/django 
>>
>> With NumPy and SciPy already ported, and with Matplotlib almost there,
>> maybe PIL and others will follow shortly. This could be a turning
>> point, or a milestone, or whatever you want to call it. Vinay is  a
>> hero who should be thanked and congratulated!
>>
>
> Note that most of the work was done by Martin von Löwis, quite a while
> back in the early days of Python 3.x.
>
> http://wiki.python.org/moin/**PortingDjangoTo3k
>
> He also did a huge amount of lobbying to get the changes accepted before
> the time that the project originally envisioned. The original plans of the
> Django project were to only *start* the porting after dropping support for
> Python 2.5 somewhere in the future. Martin made it rather clear with his
> patch (and keeps reiterating it wherever he can) that you can support both
> in one code base, even in a project as large as Django.
>
> Stefan
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2 or 3

2011-12-02 Thread Matt Joiner
2 without a doubt.
On Dec 3, 2011 5:40 PM, "Andrew Berg"  wrote:

> On 12/3/2011 12:23 AM, Terry Reedy wrote:
> > PyPy has a roadmap for 3.2
> > http://pypy.org/py3donate.html
> > They definitely plan to do it one way or another.
> I never said there were no plans, but at $2567 out of $60k, I don't see
> it happening soon. Unless someone decides to donate a huge sum of money
> or a large amount of code in the next couple months, I don't see a
> release happening until at least the middle of next year. It would
> definitely not be practical to learn Python 3 at this point if your
> primary implementation is PyPy.
>
> --
> CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list