The book Learn Python Quickly is FREE today March 18th

2013-03-18 Thread John Rowland
It's free today (only) to download from Amazon.
Please go to www.learnpythonquickly.com for more info.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: How to add the current dir to sys.path when calling a python file?

2013-03-18 Thread Steven D'Aprano
On Sun, 17 Mar 2013 22:56:07 -0500, Peng Yu wrote:

 Hi,
 
 man python says If a script  argument  is  given,  the directory
 containing the script is inserted in the path in front of $PYTHONPATH.
 The search path can be manipulated from  within a Python program as the
 variable sys.path. Instead I want to have the current directory
 inserted to the front of $PYTHONPATH without changing anything the
 script. Is there a way to do so?

No. If you want to manipulate the path, you have to write code to do so, 
and put it in your script. That's very simple:

import os, sys
sys.path.insert(0, os.getcwd())



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


Re: Message passing syntax for objects

2013-03-18 Thread Tim Harig
On 2013-03-18, Mark Janssen dreamingforw...@gmail.com wrote:
 Alan Kay's idea of message-passing in Smalltalk are interesting, and
 like the questioner says, never took off.  My answer was that Alan
 Kay's abstraction of Everything is an object fails because you can't
 have message-passing, an I/O task, working in the same space as your
 objects -- they are two very different functionalities and they have
 to be preserved **for the programmer**.

Without concurrency, message passing and interacting through functions
are semantically similar.  You have operating for sending and receiving
messages.  Python does this through methods which potentially have inputs
and outputs.  Function syntax does have two slight advantages over pure
message passing.

1. A command is sent with the message as opposed to requiring requests to
be parsed from the message separately from the data.

2. Functions constrain what actions are available and what inputs they can
legal accept.  This is doubly true

With concurrency, CSP has shown us that message passing is valuable for
syncronization.  Most CSP languages retain the idea of passing messages.
This need not be the case.  The same semantics could be acheived through
function call syntax, although it would likely be less intuitive.

If you want to pursue your ideas further, and you have not already,
I suggest that you investigate Erlang and its CSP based concurrent
oriented programming.  Alan Kay, himself, commented that he felt it
matched his ideas of message based OOP.  When you return, there is a
Candygram package providing similar constructs (last I knew, it did not
yet impliment light weight processes) for Python.

You might also look at using Go which has CSP based channel and coroutine
semantics.  It has many things in common with Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Just curious - I thought dict keys would maintain sequence

2013-03-18 Thread Frank Millman

Hi all

I know that you cannot rely on the order of keys in a dictionary, and I 
am not attempting to do so.


Nevertheless, the following surprised me. A program creates a dictionary 
with a known set of keys. I would have thought that multiple runs of the 
program would return the keys in the same sequence. As you can see, the 
results appear to be totally random.


Just out of interest, I would appreciate an explanation.

Thanks

Frank Millman


F:\type test.py
test_list = [
'ert', 'jhg', 'yer', 'nli', 'vrg',
'qnh', 'kyh', 'cgj', 'lys', 'vyk',
'dws', 'fuj', 'ghj', 'puy', 'brc',
'dhy', 'jkl', 'gfd', 'jtf', 'dfp']
test_dict = dict([(x, None) for x in test_list])
print(test_dict.keys())

F:\test.py
dict_keys(['ghj', 'qnh', 'lys', 'ert', 'jhg', 'dfp', 'vrg', 'dws', 
'jtf', 'puy',

 'yer', 'brc', 'kyh', 'jkl', 'gfd', 'nli', 'fuj', 'dhy', 'cgj', 'vyk'])

F:\test.py
dict_keys(['vrg', 'dfp', 'brc', 'yer', 'nli', 'jhg', 'cgj', 'ert', 
'dws', 'gfd',

 'puy', 'vyk', 'ghj', 'jkl', 'jtf', 'kyh', 'qnh', 'fuj', 'dhy', 'lys'])

F:\test.py
dict_keys(['yer', 'nli', 'brc', 'fuj', 'cgj', 'dfp', 'dhy', 'vrg', 
'jkl', 'jtf',

 'vyk', 'ghj', 'qnh', 'kyh', 'gfd', 'ert', 'dws', 'jhg', 'lys', 'puy'])

Python version is 3.3.0, win32.

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


Re: Just curious - I thought dict keys would maintain sequence

2013-03-18 Thread Chris Angelico
On Mon, Mar 18, 2013 at 6:26 PM, Frank Millman fr...@chagford.com wrote:
 Hi all

 I know that you cannot rely on the order of keys in a dictionary, and I am
 not attempting to do so.

 Nevertheless, the following surprised me. A program creates a dictionary
 with a known set of keys. I would have thought that multiple runs of the
 program would return the keys in the same sequence. As you can see, the
 results appear to be totally random.

 Just out of interest, I would appreciate an explanation.

Mainly, it's just something you utterly cannot depend on, so it's
allowed to vary based on the phase of the moon, the position of your
hard drive platters, or anything else it likes. The hashing is
actually randomized in recent versions of Python as a defense against
a denial of service attack by generating hash collisions; that's most
likely what you're seeing there. The dictionary object is not
deterministic to that extent. :)

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


Re: How to add the current dir to sys.path when calling a python file?

2013-03-18 Thread rusi
On Mar 18, 8:56 am, Peng Yu pengyu...@gmail.com wrote:
 Hi,

 man python says If a script  argument  is  given,  the directory
 containing the script is inserted in the path in front of $PYTHONPATH.
 The search path can be manipulated from  within a Python program as
 the variable sys.path. Instead I want to have the current directory
 inserted to the front of $PYTHONPATH without changing anything the
 script. Is there a way to do so?

 --
 Regards,
 Peng

Have you seen http://docs.python.org/2/library/site.html ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Just curious - I thought dict keys would maintain sequence

2013-03-18 Thread Frank Millman

On 18/03/2013 09:31, Chris Angelico wrote:

On Mon, Mar 18, 2013 at 6:26 PM, Frank Millman fr...@chagford.com wrote:

Hi all

I know that you cannot rely on the order of keys in a dictionary, and I am
not attempting to do so.

Nevertheless, the following surprised me. A program creates a dictionary
with a known set of keys. I would have thought that multiple runs of the
program would return the keys in the same sequence. As you can see, the
results appear to be totally random.

Just out of interest, I would appreciate an explanation.


Mainly, it's just something you utterly cannot depend on, so it's
allowed to vary based on the phase of the moon, the position of your
hard drive platters, or anything else it likes. The hashing is
actually randomized in recent versions of Python as a defense against
a denial of service attack by generating hash collisions; that's most
likely what you're seeing there. The dictionary object is not
deterministic to that extent. :)



Now that you mention it, I do remember reading about the recent addition 
of a random element to the hashing mechanism. I am sure that is the 
explanation.


Thanks, Chris

Frank


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


Re: Just curious - I thought dict keys would maintain sequence

2013-03-18 Thread Peter Otten
Chris Angelico wrote:

 On Mon, Mar 18, 2013 at 6:26 PM, Frank Millman fr...@chagford.com wrote:
 Hi all

 I know that you cannot rely on the order of keys in a dictionary, and I
 am not attempting to do so.

 Nevertheless, the following surprised me. A program creates a dictionary
 with a known set of keys. I would have thought that multiple runs of the
 program would return the keys in the same sequence. As you can see, the
 results appear to be totally random.

 Just out of interest, I would appreciate an explanation.
 
 Mainly, it's just something you utterly cannot depend on, so it's
 allowed to vary based on the phase of the moon, the position of your
 hard drive platters, or anything else it likes. The hashing is
 actually randomized in recent versions of Python as a defense against
 a denial of service attack by generating hash collisions; that's most
 likely what you're seeing there. The dictionary object is not
 deterministic to that extent. :)

If you set the PYTHONHASHSEED environment variable you will see the same 
order for every invocation. Anecdotal evidence:

$ python3.3 -c'print(dict.fromkeys(abcde, ))'
{'c': '', 'b': '', 'a': '', 'e': '', 'd': ''}
$ python3.3 -c'print(dict.fromkeys(abcde, ))'
{'a': '', 'c': '', 'b': '', 'e': '', 'd': ''}
$ python3.3 -c'print(dict.fromkeys(abcde, ))'
{'b': '', 'c': '', 'a': '', 'd': '', 'e': ''}

$ PYTHONHASHSEED=42 python3.3 -c'print(dict.fromkeys(abcde, ))'
{'e': '', 'd': '', 'a': '', 'c': '', 'b': ''}
$ PYTHONHASHSEED=42 python3.3 -c'print(dict.fromkeys(abcde, ))'
{'e': '', 'd': '', 'a': '', 'c': '', 'b': ''}
$ PYTHONHASHSEED=42 python3.3 -c'print(dict.fromkeys(abcde, ))'
{'e': '', 'd': '', 'a': '', 'c': '', 'b': ''}

Only str, byte and datetime keys are affected. See

http://docs.python.org/dev/reference/datamodel.html#object.__hash__
http://docs.python.org/dev/using/cmdline.html#envvar-PYTHONHASHSEED


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


Re: Just curious - I thought dict keys would maintain sequence

2013-03-18 Thread Steven D'Aprano
On Mon, 18 Mar 2013 18:31:33 +1100, Chris Angelico wrote:

 On Mon, Mar 18, 2013 at 6:26 PM, Frank Millman fr...@chagford.com
 wrote:
 Hi all

 I know that you cannot rely on the order of keys in a dictionary, and I
 am not attempting to do so.

 Nevertheless, the following surprised me. A program creates a
 dictionary with a known set of keys. I would have thought that multiple
 runs of the program would return the keys in the same sequence. As you
 can see, the results appear to be totally random.

 Just out of interest, I would appreciate an explanation.
 
 Mainly, it's just something you utterly cannot depend on, so it's
 allowed to vary based on the phase of the moon, the position of your
 hard drive platters, or anything else it likes. The hashing is actually
 randomized in recent versions of Python as a defense against a denial of
 service attack by generating hash collisions; that's most likely what
 you're seeing there. The dictionary object is not deterministic to that
 extent. :)

Correct. If you try the same in Python 3.2 instead of 3.3, you will get 
the same order each time.

You can read more about the dictionary hashing attack here:


http://mail.python.org/pipermail/python-dev/2011-December/115116.html
http://bugs.python.org/issue13703
http://bugs.python.org/issue14621

The current status is that Python's dict hashes are improved, but still 
leak enough information that attackers can cause a Denial Of Service 
attack with just a bit more effort than before, but work is ongoing to 
solve this issue.



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


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Shane Green
So, by introducing this collaboration mechanism with a syntax that defines it 
as sending and receiving things that are *not* arbitrary objects, the language 
would naturally reinforce a more thoroughly decoupled architecture?  

Sent from my iPad

On Mar 17, 2013, at 8:53 PM, Mark Janssen dreamingforw...@gmail.com wrote:

 Hello,
 
 I just posted an answers on quora.com about OOP (http://qr.ae/TM1Vb)
 and wanted to engage the python community on the subject.
 
 Alan Kay's idea of message-passing in Smalltalk are interesting, and
 like the questioner says, never took off.  My answer was that Alan
 Kay's abstraction of Everything is an object fails because you can't
 have message-passing, an I/O task, working in the same space as your
 objects -- they are two very different functionalities and they have
 to be preserved **for the programmer**.
 
 This functional separation made me think that Python could benefit
 from a syntactical, language-given separation between Classes and the
 messages between them, to encourage loosely-coupled, modular OOP.
 Something that OOP has always promised but never delivered.
 
 I think we should co-opt C++'s poorly used  and  I/O operators
 (for files) and re-purpose them for objects/classes.  One could then
 have within interpreter space, the ability to pass in a message to an
 object.
 
 42  MyObject  #sends 42 as a message into MyObject
 
 The Object definition would then have special methods __in__ to
 receive data and a special way of outputing data that can be caught
 __str__(?).
 
 I'm hoping the community can comment on the matter
 
 Thanks,
 
 Mark
 Tacoma, Washington
 ___
 Python-ideas mailing list
 python-id...@python.org
 http://mail.python.org/mailman/listinfo/python-ideas
-- 
http://mail.python.org/mailman/listinfo/python-list


Read utf-8 file

2013-03-18 Thread moonhkt
File have China Made
中國 製

http://www.fileformat.info/info/unicode/char/4e2d/index.htm
UTF-16 (hex)0x4E2D (4e2d)
UTF-8 (hex) 0xE4 0xB8 0xAD (e4b8ad)


Read by od -cx utf_a.text
000   中  **  **  國  **  **  製  **  **  \n
e4b8ade59c8be8a3bd0a
012

Read by python, why python display as beow ?

中國製

u'\u4e2d\u570b\u88fd\n'  --- Value 中國製
-- UTF-8 value
u'\u4e2d' 中  CJK UNIFIED IDEOGRAPH-4E2D
u'\u570b' 國  CJK UNIFIED IDEOGRAPH-570B
u'\u88fd' 製  CJK UNIFIED IDEOGRAPH-88FD

import unicodedata
import codecs # UNICODE


file = codecs.open(options.filename, 'r','utf-8' )
try:
  for line in file:
 #print repr(line)
 #print =
 print line.encode(utf)
 for keys in line.split(,):

   print repr(keys)  , --- Value ,  keys.encode(utf) ,--
UTF-8 value
   for key in keys:
 try:
name = unicodedata.name(unicode(key))
print %-9s %-8s %-30s % ( (repr(key)),
key.encode(utf) , name )


How to display
e4b8ad for 中 in python ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read utf-8 file

2013-03-18 Thread Peter Otten
moonhkt wrote:

 How to display
 e4b8ad for 中 in python ?

Python 2

 print u中.encode(utf-8).encode(hex)
e4b8ad


Python 3

 print(binascii.b2a_hex(中.encode(utf-8)).decode(ascii))
e4b8ad


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


Re: How to add the current dir to sys.path when calling a python file?

2013-03-18 Thread Dave Angel

On 03/17/2013 11:56 PM, Peng Yu wrote:

Hi,

man python says If a script  argument  is  given,  the directory
containing the script is inserted in the path in front of $PYTHONPATH.
The search path can be manipulated from  within a Python program as
the variable sys.path. Instead I want to have the current directory
inserted to the front of $PYTHONPATH without changing anything the
script. Is there a way to do so?



if the script you're running is in the current directory, it'll just 
already do what you seem to be asking.


cd /home/davea/temppython
cat  peng.;py
import sys
print sys.path is, sys.path

python peng.py
sys.path is ['/home/davea/temppython', '/usr/lib/python2.7', 
'/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', 
'/usr/lib/python2.7/lib-old', '/usr/l .


The text you quoted is trying to say that there are 3 different ways you 
can modify the search path.  The script name's location, the $PYTHONPATH 
environment variable, and the sys.path Python variable.


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


Re: [Python 2.7.3] What's the difference between these two uses of for?

2013-03-18 Thread Dave Angel

On 03/17/2013 10:14 PM, Yves S. Garret wrote:

I don't get why it's posting what I said twice...



Because you're using googlegroups, and haven't unchecked some poorly 
defined default setting.  You're posting both to python-list and to 
comp.lang.python, each of which is mirrored to the other.


That's one of at least two problems with posting via googlegroups.  The 
other is the stupid double-spacing of quotes, which is very annoying to 
others.



See:
  http://wiki.python.org/moin/GoogleGroupsPython


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


Learn Python Quickly is FREE today March 18th

2013-03-18 Thread John Rowland
For just today, the book Learn Python Quickly is free to download from Amazon.
Also, go to www.learnpythonquickly.com for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


eval vs operator.methodcaller - which is better?

2013-03-18 Thread Laxmikant Chitare
Hi,

I have a program that picks module and method name from a
configuration file and executes the method. I have found two ways to
achieve this.

Apporach 1:
---
moduleName = 'mymodule'#These two variables are read from conf file.
methodName = 'mymethod'

import operator
myModule = __import__('mymodule')
myMethod = operator.methodcaller('mymethod')
val = myMethod(myModule)
print val
---

Apporach 2:
---
moduleName = 'mymodule'#These two variables are read from conf file.
methodName = 'mymethod'

val = eval('myModule.' + methodName + '()')
print val
---

Question: Which approach is better and why. Is there any other better
way to do this?

Regards,
Laxmikant
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: eval vs operator.methodcaller - which is better?

2013-03-18 Thread Chris Angelico
On Tue, Mar 19, 2013 at 12:30 AM, Laxmikant Chitare
laxmikant.gene...@gmail.com wrote:
 moduleName = 'mymodule'#These two variables are read from conf file.
 methodName = 'mymethod'

 import operator
 myModule = __import__('mymodule')
 myMethod = operator.methodcaller('mymethod')
 val = myMethod(myModule)
 print val

Is there any reason not to do the obvious?

val = myModule.__getattribute__(methodName)(... args ...)

Works in 2.6 and 3.3, at least on the trivial example I tried.

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


Re: How to add the current dir to sys.path when calling a python file?

2013-03-18 Thread Peng Yu
On Mon, Mar 18, 2013 at 1:54 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 On Sun, 17 Mar 2013 22:56:07 -0500, Peng Yu wrote:

 Hi,

 man python says If a script  argument  is  given,  the directory
 containing the script is inserted in the path in front of $PYTHONPATH.
 The search path can be manipulated from  within a Python program as the
 variable sys.path. Instead I want to have the current directory
 inserted to the front of $PYTHONPATH without changing anything the
 script. Is there a way to do so?

 No. If you want to manipulate the path, you have to write code to do so,
 and put it in your script. That's very simple:

 import os, sys
 sys.path.insert(0, os.getcwd())

Actually, it is quite simple. Just use stdin to take the python file.

~/linux/test/python/man/library/sys/path$ cat.sh main.py subdir/main.py
== main.py ==
#!/usr/bin/env python

import sys

print sys.path

== subdir/main.py ==
#!/usr/bin/env python

import sys

print sys.path
~/linux/test/python/man/library/sys/path$ diff (python -  main.py)
(python -  subdir/main.py)



-- 
Regards,
Peng
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: eval vs operator.methodcaller - which is better?

2013-03-18 Thread Laxmikant Chitare
Aha, that was smart Chris. Thank you.

But this raises another question in my mind. What is the use case for
operator.methodcaller ?

On 3/18/13, Chris Angelico ros...@gmail.com wrote:
 On Tue, Mar 19, 2013 at 12:30 AM, Laxmikant Chitare
 laxmikant.gene...@gmail.com wrote:
 moduleName = 'mymodule'#These two variables are read from conf file.
 methodName = 'mymethod'

 import operator
 myModule = __import__('mymodule')
 myMethod = operator.methodcaller('mymethod')
 val = myMethod(myModule)
 print val

 Is there any reason not to do the obvious?

 val = myModule.__getattribute__(methodName)(... args ...)

 Works in 2.6 and 3.3, at least on the trivial example I tried.

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

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


Re: eval vs operator.methodcaller - which is better?

2013-03-18 Thread Jean-Michel Pichavant
- Original Message -
 Hi,
 
 I have a program that picks module and method name from a
 configuration file and executes the method. I have found two ways to
 achieve this.
 
 Apporach 1:
 ---
 moduleName = 'mymodule'#These two variables are read from conf
 file.
 methodName = 'mymethod'
 
 import operator
 myModule = __import__('mymodule')
 myMethod = operator.methodcaller('mymethod')
 val = myMethod(myModule)
 print val
 ---
 
 Apporach 2:
 ---
 moduleName = 'mymodule'#These two variables are read from conf
 file.
 methodName = 'mymethod'
 
 val = eval('myModule.' + methodName + '()')
 print val
 ---
 
 Question: Which approach is better and why. Is there any other better
 way to do this?
 
 Regards,
 Laxmikant
 --
 http://mail.python.org/mailman/listinfo/python-list
 

Hi,

Any alternative to eval is always better than eval (aka eval is evil). 
Your code is not working in my python 2.5 env (operator has no methodcaller).

try something like

moduleName = 'mymodule'#These two variables are read from conf file.
methodName = 'mymethod'
myModule = __import__(moduleName)
myFunc = getattr(myModule, methodName)
myFunc()


JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: eval vs operator.methodcaller - which is better?

2013-03-18 Thread Chris Angelico
On Tue, Mar 19, 2013 at 12:58 AM, Jean-Michel Pichavant
jeanmic...@sequans.com wrote:
 myFunc = getattr(myModule, methodName)

Doh! Thanks. I knew there was a shorter way of spelling it, rather
than digging with dunder methods. That's the way I would recommend -
slight tweak from the __getattribute__ version.

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


Re: eval vs operator.methodcaller - which is better?

2013-03-18 Thread Chris Angelico
On Tue, Mar 19, 2013 at 12:58 AM, Laxmikant Chitare
laxmikant.gene...@gmail.com wrote:
 Aha, that was smart Chris. Thank you.

 But this raises another question in my mind. What is the use case for
 operator.methodcaller ?

Most of the operator module is functional versions of what can be done
elsewhere with operators. They're not generally needed unless you
specifically need a function, such as for a map() call:

 a=[1,2,3,4,5]
 b=[50,40,30,20,10]
 list(map(operator.add,a,b))
[51, 42, 33, 24, 15]

(The list() call is unnecessary in Python 2, but means this will also
work in Python 3.)

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


Re: What's the easiest Python datagrid GUI (preferably with easy database hooks as well)?

2013-03-18 Thread Sibylle Koczian

Am 17.03.2013 16:50, schrieb rusi:

About your python I cant say, but your English looks/sounds as good as
a native's.
So dont waste your time getting that right; its good enough!


Thank you. Flowers go to Dorothy L. Sayers, most of them. As far as Dabo 
is concerned, at the moment I just have to know how to spell crash ...


Sibylle

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


Re: What are some other way to rewrite this if block?

2013-03-18 Thread Jussi Piitulainen
Santosh Kumar sntshkm...@gmail.com writes:

 This simple script is about a public transport, here is the code:
 
 def report_status(should_be_on, came_on):
 if should_be_on  0.0 or should_be_on  24.0 or came_on  0.0 or
 came_on  24.0:
 return 'time not in range'
 elif should_be_on == came_on:
 return 'on time'
 elif should_be_on  came_on:
 return 'early'
 elif should_be_on  came_on:
 return 'delayed'
 else:
 return 'something might be wrong'
 
 print(report_status(123, 12.0))
 
 I am looking forward of make the line starting with `if` short.
 
 Any tips are welcome.

A double tip:

if (not (0.0 = should_be_on = 24.0) or
not (0.0 = came_on = 24.0)):
   ...

You might want to raise an exception from the range-check branch
instead of returning a value. And raise an exception from the
else-branch, because that branch should never be reached.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are some other way to rewrite this if block?

2013-03-18 Thread Chris Angelico
On Tue, Mar 19, 2013 at 12:56 AM, Santosh Kumar sntshkm...@gmail.com wrote:
 This simple script is about a public transport, here is the code:

 def report_status(should_be_on, came_on):
 if should_be_on  0.0 or should_be_on  24.0 or came_on  0.0 or
 came_on  24.0:
 return 'time not in range'
 elif should_be_on == came_on:
 return 'on time'
 elif should_be_on  came_on:
 return 'early'
 elif should_be_on  came_on:
 return 'delayed'
 else:
 return 'something might be wrong'

 print(report_status(123, 12.0))

Well, for a start, I wouldn't compare for equality there. What's your
definition of on time? In Melbourne, for instance, a service is
deemed on time if it's less than 1 minute early and less than 5
minutes late. This is probably too broad, but I would guess that up to
1 minute (or at least half a minute) either side should be considered
on time.

Are you catering here for custom objects or NaNs that might not be
equal, less, or greater? If not, drop the else and just have three
branches - for instance:

if should_be_on = came_on + 0.5: # Up to half a minute early is okay
return 'early'
elif should_be_on = came_on - 1.0: # Up to one minute late is okay
return 'delayed'
else:
return 'on time'

As a matter of readability, incidentally, I'd be inclined to invert
the conditions and check the time of arrival against the expected
time:

if came_on  should_be_on - 0.5: # Up to half a minute early is okay
return 'early'
elif came_on  should_be_on + 1.0: # Up to one minute late is okay
return 'delayed'
else:
return 'on time'

I don't understand your bounds check, though. Are you working with
floating point hours in the day? (If so, it's still not necessarily
right - it's not uncommon to refer to the hours post-midnight as
24:00, 25:00, etc. But for a toy and a PoC, that would work.) But you
then pass the integer 123 as the first arg, which will fail that
check. What _is_ your data type?

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


Re: What are some other way to rewrite this if block?

2013-03-18 Thread Laxmikant Chitare
What about this one:
if 0.0  should_be_on  24.0 or 0.0  came_on  24.0:

Regards,
Laxmikant

On 3/18/13, Santosh Kumar sntshkm...@gmail.com wrote:
 This simple script is about a public transport, here is the code:

 def report_status(should_be_on, came_on):
 if should_be_on  0.0 or should_be_on  24.0 or came_on  0.0 or
 came_on  24.0:
 return 'time not in range'
 elif should_be_on == came_on:
 return 'on time'
 elif should_be_on  came_on:
 return 'early'
 elif should_be_on  came_on:
 return 'delayed'
 else:
 return 'something might be wrong'

 print(report_status(123, 12.0))

 I am looking forward of make the line starting with `if` short.

 Any tips are welcome.
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: eval vs operator.methodcaller - which is better?

2013-03-18 Thread Steven D'Aprano
On Mon, 18 Mar 2013 19:28:37 +0530, Laxmikant Chitare wrote:

 Aha, that was smart Chris. Thank you.
 
 But this raises another question in my mind. What is the use case for
 operator.methodcaller ?


The use-case is mostly to allow people to write code in a functional 
style, if they so choose.

import operator
func = operator.methodcaller(spam)
items = map(func, [a, b, c, d])

is the functional-style equivalent of:

items = [obj.spam() for obj in [a, b, c, d]]

methodcaller makes a little more sense if you provide arguments:


func = operator.methodcaller(spam, 1, 2, None, ham)
items = map(func, [a, b, c, d])

compared to:

items = [obj.spam(1, 2, None, ham) for obj in [a, b, c, d]]


I expect that the methodcaller version will be very slightly faster in 
this case, since it doesn't have to parse the arguments every time the 
method is called.



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


Re: eval vs operator.methodcaller - which is better?

2013-03-18 Thread Steven D'Aprano
On Mon, 18 Mar 2013 19:00:15 +0530, Laxmikant Chitare wrote:

 Hi,
 
 I have a program that picks module and method name from a configuration
 file and executes the method. I have found two ways to achieve this.
 
 Apporach 1:
 ---
 moduleName = 'mymodule'#These two variables are read from conf file.
 methodName = 'mymethod'
 
 import operator
 myModule = __import__('mymodule')
 myMethod = operator.methodcaller('mymethod')
 val = myMethod(myModule)
 print val

Since your example code only uses string literals, the best way to write 
this would be:

import mymodule
mymodule.mymethod()

But I expect that your example was faulty, and you intended to use 
variables:

myModule = __import__(moduleName)
myMethod = operator.methodcaller(methodName)
val = myMethod(myModule)


This would be simpler, and probably faster too:

myModule = __import__(moduleName)
val = getattr(myModule, methodName)()


It's certainly easier to read.


 ---
 
 Apporach 2:
 ---
 moduleName = 'mymodule'#These two variables are read from conf file.
 methodName = 'mymethod'
 
 val = eval('myModule.' + methodName + '()')
 print val

This example also fails, since you don't have anything called myModule.

I suspect you left out a line, myModule = __import__(moduleName).


 ---
 
 Question: Which approach is better and why. Is there any other better
 way to do this?


You should avoid eval, it is a massive security risk unless you are an 
expert, and even then it is still a big security risk. It's also slower 
than the alternatives.


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


Re: What are some other way to rewrite this if block?

2013-03-18 Thread Jean-Michel Pichavant
- Original Message -
 This simple script is about a public transport, here is the code:
 
 def report_status(should_be_on, came_on):
 if should_be_on  0.0 or should_be_on  24.0 or came_on  0.0 or
 came_on  24.0:
 return 'time not in range'
 elif should_be_on == came_on:
 return 'on time'
 elif should_be_on  came_on:
 return 'early'
 elif should_be_on  came_on:
 return 'delayed'
 else:
 return 'something might be wrong'
 
 print(report_status(123, 12.0))
 
 I am looking forward of make the line starting with `if` short.
 
 Any tips are welcome.
 --
 http://mail.python.org/mailman/listinfo/python-list

You can remove the 'if' line, report_status asks for hours, the caller is 
supposed to provide valid hours. What if the caller gives you strings, integer, 
floats ?  This is a never ending story.


def report_status(should_be_on, came_on):

# well if you really really want to test it
assert(all([int(arg) in range(0,24) for arg in (should_be_on, came_on)])) 

return { 0 : 'on time', -1 : 'delayed', 1 : 'early'}[cmp(should_be_on, 
came_on)]


JM

Note : in my example, 24.0 is excluded from the valid durations but I think 
this is the correct behavior.


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are some other way to rewrite this if block?

2013-03-18 Thread Yves S. Garret
On Monday, March 18, 2013 9:56:16 AM UTC-4, Santosh Kumar wrote:
 This simple script is about a public transport, here is the code:
 
 
 
 def report_status(should_be_on, came_on):
 
 if should_be_on  0.0 or should_be_on  24.0 or came_on  0.0 or
 
 came_on  24.0:
 
 return 'time not in range'
 
 elif should_be_on == came_on:
 
 return 'on time'
 
 elif should_be_on  came_on:
 
 return 'early'
 
 elif should_be_on  came_on:
 
 return 'delayed'
 
 else:
 
 return 'something might be wrong'
 
 
 
 print(report_status(123, 12.0))
 
 
 
 I am looking forward of make the line starting with `if` short.
 
 
 
 Any tips are welcome.

If you have a lot of conditions to check, you can't really get around it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: eval vs operator.methodcaller - which is better?

2013-03-18 Thread Laxmikant Chitare
Thank you Chris, Michel and Steven for your feedback.

Steven, yes I realised that the examples are faulty. I intended to use
variables instead of string literals. I will be careful next time.

On 3/18/13, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 On Mon, 18 Mar 2013 19:00:15 +0530, Laxmikant Chitare wrote:

 Hi,

 I have a program that picks module and method name from a configuration
 file and executes the method. I have found two ways to achieve this.

 Apporach 1:
 ---
 moduleName = 'mymodule'#These two variables are read from conf file.
 methodName = 'mymethod'

 import operator
 myModule = __import__('mymodule')
 myMethod = operator.methodcaller('mymethod')
 val = myMethod(myModule)
 print val

 Since your example code only uses string literals, the best way to write
 this would be:

 import mymodule
 mymodule.mymethod()

 But I expect that your example was faulty, and you intended to use
 variables:

 myModule = __import__(moduleName)
 myMethod = operator.methodcaller(methodName)
 val = myMethod(myModule)


 This would be simpler, and probably faster too:

 myModule = __import__(moduleName)
 val = getattr(myModule, methodName)()


 It's certainly easier to read.


 ---

 Apporach 2:
 ---
 moduleName = 'mymodule'#These two variables are read from conf file.
 methodName = 'mymethod'

 val = eval('myModule.' + methodName + '()')
 print val

 This example also fails, since you don't have anything called myModule.

 I suspect you left out a line, myModule = __import__(moduleName).


 ---

 Question: Which approach is better and why. Is there any other better
 way to do this?


 You should avoid eval, it is a massive security risk unless you are an
 expert, and even then it is still a big security risk. It's also slower
 than the alternatives.


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

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


Re: What are some other way to rewrite this if block?

2013-03-18 Thread Duncan Booth
Jussi Piitulainen jpiit...@ling.helsinki.fi wrote:

 Any tips are welcome.
 
 A double tip:
 
 if (not (0.0 = should_be_on = 24.0) or
 not (0.0 = came_on = 24.0)):
...
 
Or even:

if not (0.0 = should_be_on = 24.0 and 0.0 = came_on = 24.0):
...

 You might want to raise an exception from the range-check branch
 instead of returning a value. And raise an exception from the
 else-branch, because that branch should never be reached.

Or even lose the else branch entirely. If the code can never be reached 
then don't write it. Also you don't need 'elif' when the individual 
branches all return.

Putting that together and allowing some flexibility in the definition of 
'on time':

EARLY_DELTA = 1.0/60
LATE_DELTA = 5.0/60

def report_status(should_be_on, came_on):
if not (0.0 = should_be_on = 24.0 and 0.0 = came_on = 24.0):
raise ValueError('time not in range')

if should_be_on - EARLY_DELTA = came_on = should_be_on + LATE_DELTA:
return 'on time'

if came_on  should_be_on:
return 'delayed'

return 'early'

Note that none of this will hande situations around midnight such as: 
should_be_on==23.5, came_on=0.5

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to automatically get the indent level from code?

2013-03-18 Thread Peng Yu
On Sun, Mar 17, 2013 at 1:23 AM, Mark Shroyer mshro...@awaredigital.com wrote:
 I realize this isn't yet precisely what you're asking for, but look at the 
 inspect and ast modules:

 import ast, inspect

 def indent_level():
 lineno = inspect.currentframe().f_back.f_lineno

 with open(__file__) as source_file:
 tree = ast.parse(source_file.read(), filename=__file__)

 for node in ast.walk(tree):
 if hasattr(node, 'lineno') and node.lineno == lineno:
 return node.col_offset

 def example_usage():
 print(first indent_level() = {0}.format(indent_level()))
 if True:
 print(second indent_level() = {0}.format(indent_level()))

 if __name__ == '__main__':
 example_usage()

 The indent_level function above returns the textual column offset rather than 
 the logical block level you're asking for, e.g.:

 first indent_level() = 4
 second indent_level() = 8

 But hopefully it's a start.

Thanks. I try to run it from stdin. Obviously, it does not work. The
problem is the stdin can not be read again. Is there a way to extend
the code that indentation can be computed even the code is from stdin?

~/linux/test/python/tricks/indent_level$ python -  main.py
Traceback (most recent call last):
  File stdin, line 23, in module
  File stdin, line 16, in example_usage
  File stdin, line 8, in indent_level
IOError: [Errno 2] No such file or directory: 'stdin'
~/linux/test/python/tricks/indent_level$ cat main.py
#!/usr/bin/env python

import ast, inspect

def indent_level():
  lineno = inspect.currentframe().f_back.f_lineno

  with open(__file__) as source_file:
tree = ast.parse(source_file.read(), filename=__file__)

  for node in ast.walk(tree):
if hasattr(node, 'lineno') and node.lineno == lineno:
  return node.col_offset

def example_usage():
  print indent_level()
  #print(first indent_level() = {0}.format(indent_level()))
  if True:
print indent_level()
#print(second indent_level() = {0}.format(indent_level()))

if __name__ == '__main__':
  example_usage()

-- 
Regards,
Peng
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are some other way to rewrite this if block?

2013-03-18 Thread Jussi Piitulainen
Duncan Booth writes:
 Jussi Piitulainen wrote:
 
  Any tips are welcome.
  
  A double tip:
  
  if (not (0.0 = should_be_on = 24.0) or
  not (0.0 = came_on = 24.0)):
 ...
  
 Or even:
 
 if not (0.0 = should_be_on = 24.0 and 0.0 = came_on = 24.0):
 ...

I'd still prefer to split the line, especially considering the fact
that the request was to make the line shorter:

if not (0.0 = should_be_on = 24.0 and
0.0 = came_on = 24.0):
   ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are some other way to rewrite this if block?

2013-03-18 Thread Steven D'Aprano
On Mon, 18 Mar 2013 15:32:03 +0100, Jean-Michel Pichavant wrote:

 You can remove the 'if' line, report_status asks for hours, the caller
 is supposed to provide valid hours. What if the caller gives you
 strings, integer, floats ?  This is a never ending story.

I see you haven't been a programmer very long *wink*

Yes, error checking and data validation is a never ending story. Welcome 
to programming. That's what we do.



 def report_status(should_be_on, came_on):
 
 # well if you really really want to test it 
 assert(all([int(arg) in range(0,24) for arg in
   (should_be_on, came_on)]))

Please don't use assert for argument checking in public APIs. (And 
probably not in private APIs either.) assert is wrong for two reasons:

1) Invalid arguments should raise TypeError or ValueError. You wouldn't 
arbitrarily raise KeyError(expected 0  arg  24 but got arg = -1) or 
IOError(expected an int but got a string). That would be unprofessional 
and foolish. So why raise AssertionError?

2) assert is not guaranteed to run, and you have *no control over it*. If 
the user calls python with the -O flag, asserts are disabled and your 
error checking is never performed.


assert is designed to verify internal logic of your code, not caller-
facing argument validation.



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


Re: What are some other way to rewrite this if block?

2013-03-18 Thread Steven D'Aprano
On Mon, 18 Mar 2013 19:26:16 +0530, Santosh Kumar wrote:

 This simple script is about a public transport, here is the code:
 
 def report_status(should_be_on, came_on):
 if should_be_on  0.0 or should_be_on  24.0 or came_on  0.0 or
 came_on  24.0:
 return 'time not in range'
 elif should_be_on == came_on:
 return 'on time'
 elif should_be_on  came_on:
 return 'early'
 elif should_be_on  came_on:
 return 'delayed'
 else:
 return 'something might be wrong'


Untested, but something like this should work. It adjusts for the times 
which fall either side of midnight, it optionally allows for some slop 
in deciding whether an arrival was on time or not (defaults to 0).


def report(scheduled, actual, slop=0.0):
Report whether actual time of arrival is on time, late, early 
or cancelled.

Pass actual=None for cancelled services, otherwise both scheduled and 
actual must be given as float hours between 0 and 24. E.g. to indicate
a time of 06:30, pass 6.5.

Optional argument slop is a non-negative time in hours which services
are allowed to be late or early and still count as on time. E.g. if 
a service is allowed to arrive with two minutes either side of the
scheduled time and still count as on time, pass slop=2.0/60. The slop
defaults to 0.0.


if not 0 = scheduled  24:
raise ValueError('scheduled time out of range')
if not 0 = slop  24:
raise ValueError('slop out of range')
if actual is None:
return service cancelled
if not 0 = actual  24:
raise ValueError('actual arrival time out of range')
diff = actual - scheduled
# Adjust for discontinuity around midnight. We assume that arrivals
# are never more than 12 hours away from their scheduled times.
if diff  -12:
# For example, scheduled=23:55, actual=00:05 gives diff of -23:50
diff += 24
elif diff  12:
diff -= 24
if diff  -slop:
return early
elif diff  slop:
return late
else:
return on time


One disadvantage with the function as written is that you have to give 
times as floats between 0 and 24, instead of a more natural HH:MM syntax. 
For example, 11:07am would have to be given as 11.117. 

Another weakness is that any slop allowance is symmetrical (e.g. you 
can't allow trains to arrive up to one minute early or five minutes late 
to be counted as on time, the two figures have to be equal).

A third weakness is that you can't allow for arrivals more than 12 hours 
early or late.



 I am looking forward of make the line starting with `if` short.

:-)



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


Re: What are some other way to rewrite this if block?

2013-03-18 Thread Chris Angelico
On Tue, Mar 19, 2013 at 2:10 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 A third weakness is that you can't allow for arrivals more than 12 hours
 early or late.

Oh, but that'll NEVER happen.

Oh wait, I've been on a service that was 12 hours late.

Is there any chance that you could do your times of arrival and
expectation in, say, integer seconds since 1970?

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


Excel column 256 limit

2013-03-18 Thread Ana Dionísio
Is there some way to go around this limit? I need to import data from python to 
excel and I need 1440 columns for that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Excel column 256 limit

2013-03-18 Thread Dave Angel

On 03/18/2013 11:28 AM, Ana Dionísio wrote:

Is there some way to go around this limit? I need to import data from python to 
excel and I need 1440 columns for that.



Doesn't sound like a Python question.  But one answer is Libre Office 
Calc, which seems to have a 1024 column limit.



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


Re: Excel column 256 limit

2013-03-18 Thread Steven D'Aprano
On Mon, 18 Mar 2013 08:28:46 -0700, Ana Dionísio wrote:

 Is there some way to go around this limit? I need to import data from
 python to excel and I need 1440 columns for that.

That's an Excel question, it has nothing to do with Python.

Have you considered using something other than Excel? As I understand it, 
OpenOffice, LibreOffice, and Gnumeric do not have a 256 column limit. 
Gnumeric is Linux-only, but the other two are available for Windows and 
Mac, and they are all free, open source software, and they all will read 
and write Excel spreadsheets.


http://openoffice.org/
http://www.libreoffice.org/
http://projects.gnome.org/gnumeric/index.shtml



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


Re: Excel column 256 limit

2013-03-18 Thread Grant Edwards
On 2013-03-18, Dave Angel da...@davea.name wrote:
 On 03/18/2013 11:28 AM, Ana Dion?sio wrote:

 Is there some way to go around this limit? I need to import data from
 python to excel and I need 1440 columns for that.

 Doesn't sound like a Python question.  But one answer is Libre Office 
 Calc, which seems to have a 1024 column limit.

[I don't see how something with a 1024 column limit is one answer for
a requirement of 1440 columns.]

IMO, if 256 columns isn't enough, then a spreadsheet probably isn't
the right tool.  If you need 1440 columns then I can't even imagine a
case where a spreadsheet is the right tool.

I've seen people spend weeks trying to do something with excel that
would have taken a few hours using Numpy/Scipy/Scientific-Python.

-- 
Grant Edwards   grant.b.edwardsYow! I want to kill
  at   everyone here with a cute
  gmail.comcolorful Hydrogen Bomb!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Mark Janssen
On Sun, Mar 17, 2013 at 11:46 PM, Steven D'Aprano st...@pearwood.info wrote:
 I am very interested in this as a concept, although I must admit I'm not
 entirely sure what you mean by it. I've read your comment on the link above,
 and subsequent emails in this thread, and I'm afraid I don't understand what
 you mean here. I feel you are assuming that your readers are already experts
 on message-passing languages (Smalltalk?). I know what *I* mean by message
 passing, but that's not necessarily what you mean by it.

I'm sorry, I haven't been very clear.  I'm not even an expert on
message-passing languages, but I see that it's a profound concept that
hasn't been adequately integrated into the OOP model.  In any case, I
will try to do better.  And I apologize to everyone on the list for
the prior mail spam.  A part of me is a bit giddy with the idea.

By message passing, I mean all the ways we communicate to objects in
the OOP environment.  Usually we communicate to them through
method-invokation.  But this is the wrong way, I argue, to look at the
problem.

With function or method syntax, you're telling the computer to
execute something, but that is not the right concepts for OOP.  You
want the objects to interact with each other and in a high-level
language, the syntax should assist with that.

 By building it into the language, it would *enforce* a modular object
 style, rather than the current, very specialized and very programmer
 specific way there is now.  In fact, most people never really think in
 that paradigm, yet if the language supported/proposed such a syntax,
 programmers would start to re-arrange the whole object hierarchy in a
 new, more modular and universal way.
 [end quote]

 I don't understand this. In what way would message passing enforce a modular
 object style? In what way does Python not already have a modular object
 style?

Hopefully my paragraph clarifies that a bit.  But the key conceptual
shift is that by enforcing a syntax that moves away from invoking
methods and move to message passing between objects, you're
automatically enforcing a more modular approach.

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


[Python 3.3.0] Getting tkinter to work on Python 3

2013-03-18 Thread Yves S. Garret
Hi.  I'm having a problem trying to get this to work well.  Basically,
whenever I try to
import tkinter, this is the issue that I have:

 import tkinter
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/local/lib/python3.3/tkinter/__init__.py, line 40, in module
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'

I'm running Ubuntu.  If I need to provide any further info, please let me
know.
-- 
http://mail.python.org/mailman/listinfo/python-list


[Python-ideas] Message passing syntax for objects

2013-03-18 Thread Mark Janssen
 Ian Cordasco wrote:

 On Sun, Mar 17, 2013 at 11:53 PM, Mark Janssen
 dreamingforw...@gmail.com wrote:

 Hello,

 I just posted an answers on quora.com about OOP (http://qr.ae/TM1Vb)
 and wanted to engage the python community on the subject.


 My answer to that question would be that it *did*
 catch on, it's just that we changed the terminology.
 Instead of message passing, we talk about calling
 methods.

Yes, but this is where it breaks the OOP abstraction by 90 degrees.
By using function calls, you're telling the machine to do something.
But when you want to pass something to an object there should be a
natural way to do this for every object.  By using methods you pollute
the concept space with all sorts of semi-random (i.e. personal) names,
like append, add, enqueue, etc.

This proposal would not only make a consistent syntax across all
objects, but train the programmer to *think* modularly in the sense of
having a community of re-usable object.  I.e. What should I do if
another object passes me something?.  No one thinks this now, because
the programmer expects new developers to learn *their* interface!

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


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Benjamin Kaplan
On Mon, Mar 18, 2013 at 10:18 AM, Mark Janssen
dreamingforw...@gmail.com wrote:
 Ian Cordasco wrote:

 On Sun, Mar 17, 2013 at 11:53 PM, Mark Janssen
 dreamingforw...@gmail.com wrote:

 Hello,

 I just posted an answers on quora.com about OOP (http://qr.ae/TM1Vb)
 and wanted to engage the python community on the subject.


 My answer to that question would be that it *did*
 catch on, it's just that we changed the terminology.
 Instead of message passing, we talk about calling
 methods.

 Yes, but this is where it breaks the OOP abstraction by 90 degrees.
 By using function calls, you're telling the machine to do something.
 But when you want to pass something to an object there should be a
 natural way to do this for every object.  By using methods you pollute
 the concept space with all sorts of semi-random (i.e. personal) names,
 like append, add, enqueue, etc.

 This proposal would not only make a consistent syntax across all
 objects, but train the programmer to *think* modularly in the sense of
 having a community of re-usable object.  I.e. What should I do if
 another object passes me something?.  No one thinks this now, because
 the programmer expects new developers to learn *their* interface!

 Mark
 --

You're dreaming of a utopia where computers just read our minds and
know what we're thinking. So what if I can pass 42 into an object.
What do I intend to happen with that 42? Do I want to add the element
to a list? Access the 42nd element? Delete the 42nd element? Let the
object pick a behavior at random? Clearly there must be some sort of
behavior defined for passing a message into an object. And now we're
back to learning the interface that the programmer designed. Only now,
instead of having different types of behavior grouped together into
classes, we have to use a different object for each operation. So
what's the benefit of that over having the object implement the
__call__ method?

Also, why would we re-use the bit shift operators for message passing?
Just because C++ decided to overload the existing operators to mean
reading into and writing out of a stream doesn't mean it's a good
idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Excel column 256 limit

2013-03-18 Thread Michael Ross
On Mon, 18 Mar 2013 16:50:21 +0100, Steven D'Aprano  
steve+comp.lang.pyt...@pearwood.info wrote:



On Mon, 18 Mar 2013 08:28:46 -0700, Ana Dionísio wrote:


Is there some way to go around this limit? I need to import data from
python to excel and I need 1440 columns for that.


That's an Excel question, it has nothing to do with Python.

Have you considered using something other than Excel? As I understand it,
OpenOffice, LibreOffice, and Gnumeric do not have a 256 column limit.


Just for completeness:
Excel in it's Office 2010 version does not have a 256 column limit  
either.

I can use  2000 columns without problem.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 3.3.0] Getting tkinter to work on Python 3

2013-03-18 Thread Ritchie Flick
Seems tkinter is missing in standard installation in ubuntu. Try:
sudo apt-get install python3-tk


On Mon, Mar 18, 2013 at 6:17 PM, Yves S. Garret
yoursurrogate...@gmail.comwrote:

 Hi.  I'm having a problem trying to get this to work well.  Basically,
 whenever I try to
 import tkinter, this is the issue that I have:

  import tkinter
 Traceback (most recent call last):
   File stdin, line 1, in module
   File /usr/local/lib/python3.3/tkinter/__init__.py, line 40, in module
 import _tkinter # If this fails your Python may not be configured for
 Tk
 ImportError: No module named '_tkinter'

 I'm running Ubuntu.  If I need to provide any further info, please let me
 know.

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




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


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread 88888 Dihedral
zipher於 2013年3月19日星期二UTC+8上午1時04分36秒寫道:
 On Sun, Mar 17, 2013 at 11:46 PM, Steven D'Aprano st...@pearwood.info wrote:
 
  I am very interested in this as a concept, although I must admit I'm not
 
  entirely sure what you mean by it. I've read your comment on the link above,
 
  and subsequent emails in this thread, and I'm afraid I don't understand what
 
  you mean here. I feel you are assuming that your readers are already experts
 
  on message-passing languages (Smalltalk?). I know what *I* mean by message
 
  passing, but that's not necessarily what you mean by it.
 
 
 
 I'm sorry, I haven't been very clear.  I'm not even an expert on
 
 message-passing languages, but I see that it's a profound concept that
 
 hasn't been adequately integrated into the OOP model.  In any case, I
 
 will try to do better.  And I apologize to everyone on the list for
 
 the prior mail spam.  A part of me is a bit giddy with the idea.
 
 
 
 By message passing, I mean all the ways we communicate to objects in
 
 the OOP environment.  Usually we communicate to them through
 
 method-invokation.  But this is the wrong way, I argue, to look at the
 
 problem.
 
 
 
 With function or method syntax, you're telling the computer to
 
 execute something, but that is not the right concepts for OOP.  You
 
 want the objects to interact with each other and in a high-level
 
 language, the syntax should assist with that.
 
 
 
  By building it into the language, it would *enforce* a modular object
 
  style, rather than the current, very specialized and very programmer
 
  specific way there is now.  In fact, most people never really think in
 
  that paradigm, yet if the language supported/proposed such a syntax,
 
  programmers would start to re-arrange the whole object hierarchy in a
 
  new, more modular and universal way.
 
  [end quote]
 
 
 
  I don't understand this. In what way would message passing enforce a modular
 
  object style? In what way does Python not already have a modular object
 
  style?
 
 
 
 Hopefully my paragraph clarifies that a bit.  But the key conceptual
 
 shift is that by enforcing a syntax that moves away from invoking
 
 methods and move to message passing between objects, you're
 
 automatically enforcing a more modular approach.
 
 
 
 Mark

Please check object pascal and objective c and erlang for 
the message-action director model of what you want.

C is too low level to be suitable for everything.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Mark Janssen
 You're dreaming of a utopia where computers just read our minds and
 know what we're thinking. So what if I can pass 42 into an object.
 What do I intend to happen with that 42? Do I want to add the element
 to a list? Access the 42nd element? Delete the 42nd element? Let the
 object pick a behavior at random?

Huh?, No the programmer has to think of how data interacts with
his/her objects.  It's just that *now* the language is wise enough to
teach them to think about it.

 So
 what's the benefit of that over having the object implement the
 __call__ method?

You bring up an interesting subject.  I think you could get rid of the
__call__ special method on objects.  I think this is the wrong view
into the object universe or *data ecosystem*.

 Also, why would we re-use the bit shift operators for message passing?
 Just because C++ decided to overload the existing operators to mean
 reading into and writing out of a stream doesn't mean it's a good
 idea.

You're right, perhaps there's a better set of symbols that suggest
moving data.

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


Re: [Python 3.3.0] Getting tkinter to work on Python 3

2013-03-18 Thread Yves S. Garret
I have.  This is what I did and the result that I'm seeing.

$ sudo apt-get install python3-tk
[sudo] password for ysg:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-tk is already the newest version.
python3-tk set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
$ python3
Python 3.3.0 (default, Mar 11 2013, 15:04:13)
[GCC 4.5.2] on linux
Type help, copyright, credits or license for more information.
 import tkinter
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/local/lib/python3.3/tkinter/__init__.py, line 40, in module
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'


:-/

On Mon, Mar 18, 2013 at 2:22 PM, Ritchie Flick xenp...@gmail.com wrote:

 Seems tkinter is missing in standard installation in ubuntu. Try:
 sudo apt-get install python3-tk


 On Mon, Mar 18, 2013 at 6:17 PM, Yves S. Garret 
 yoursurrogate...@gmail.com wrote:

 Hi.  I'm having a problem trying to get this to work well.  Basically,
 whenever I try to
 import tkinter, this is the issue that I have:

  import tkinter
 Traceback (most recent call last):
   File stdin, line 1, in module
   File /usr/local/lib/python3.3/tkinter/__init__.py, line 40, in
 module
 import _tkinter # If this fails your Python may not be configured for
 Tk
 ImportError: No module named '_tkinter'

 I'm running Ubuntu.  If I need to provide any further info, please let me
 know.

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




 --
 Ritchie Flick

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


Re: [Python 3.3.0] Getting tkinter to work on Python 3

2013-03-18 Thread Lele Gaifax
Yves S. Garret yoursurrogate...@gmail.com writes:

 I have.  This is what I did and the result that I'm seeing.

 $ sudo apt-get install python3-tk

You installed a custom python 3.3, didn't you? So it does not help
installing Ubuntu's python3-tk: your python3.3 interpreter won't even
look into system packages.

Most probably, you need to install the proper development libraries and
*recompile* the Python 3.3 interpreter:

# apt-get install tk-dev

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Re: Excel column 256 limit

2013-03-18 Thread Ana Dionísio
But I still get the error and I use Excel 2010.

I'm trying to export data in a list to Excel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Excel column 256 limit

2013-03-18 Thread Dietmar Schwertberger

Am 18.03.2013 16:28, schrieb Ana Dionísio:

Is there some way to go around this limit? I need to import data from python to 
excel and I need 1440 columns for that.


There are many versions of Excel. The recent ones can handle more than
256 columns. If your version doesn't, then Python won't help you to
increase this limit...
There are many ways to get data from Python into Excel. If you have any
specific problems, you should provide more details.

Regards,

Dietmar




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


Re: Excel column 256 limit

2013-03-18 Thread Christian Gollwitzer

Am 18.03.13 20:00, schrieb Ana Dionísio:

But I still get the error and I use Excel 2010.

I'm trying to export data in a list to Excel

Unless you tell *how exactly* do you export the data into excel format, 
we probably can't help you. You could try to write a .csv ASCII file, 
for instance.


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


Re: What am I doing wrong in this simple tkinter example?

2013-03-18 Thread Chris Angelico
On Sun, Mar 17, 2013 at 2:34 AM, Yves S. Garret
yoursurrogate...@gmail.com wrote:
 *facepalm*

 Yep, I see it :) .  Thanks for your help.

Glad to be of service. Welcome to a life of programming, where the
palm meets the face on a regular basis... more frequently if you use
Microsoft Windows, tar, non-eight-bit-clean transmission methods, or
Adobe products, and extremely common as soon as you take over someone
else's code [1], but inevitable even without these stimuli. :)

Have fun!

[1] http://www.dilbert.com/strips/comic/2013-02-24/

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


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Lele Gaifax
8 Dihedral dihedral88...@googlemail.com writes:

 zipher於 2013年3月19日星期二UTC+8上午1時04分36秒寫道:
 the key conceptual shift is that by enforcing a syntax that moves
 away from invoking methods and move to message passing between
 objects, you're automatically enforcing a more modular approach.

 Please check object pascal and objective c and erlang for 
 the message-action director model of what you want.

I fail to see how syntax differences would change the modularity of your
product. 

The fact that (say) ObjC use the name message while Python calls the
same a method isn't actually changing the concrete fact that both are
executing some sort of function that accepts an instance object as one
of the arguments (in Python, the first parameter, usually called self,
in ObjC, and implicit self).

In other words, the following ObjC

  [someObj getItemAt: i]

is perfectly equivalent to the following Python

  someObj.getItemAt(i)

and to the following Smalltalk

  someObj getItemAt: i

How is the former syntax, where getItemAt: is called a message, more
modular from the second, where getItemAt() is called a method?

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Mark Janssen
On Mon, Mar 18, 2013 at 12:06 PM, Georg Brandl g.bra...@gmx.net wrote:
 Am 18.03.2013 05:26, schrieb Mark Janssen:
 Continuing on this thread, there would be a new bunch of behaviors to
 be defined.  Since everything is an object, there can now be a
 standard way to define the *next* common abstraction of every object
 interacts with other objects.

 The problem is that for most objects there isn't *the* interaction.  Sure,
 you could split up complicated objects into small pieces with a smaller
 functionality, but at some point you have to stop.

Yes.  But that is the point, if you look at the quora post -- to
invert the object model and create mashups of simple modular data
types and working *upwards*.

  Let's see how this
 concept fares with simple types such as integers or collections...

 42  MyNumberType #would add the integer to your integer type

 That's just random.  Why not multiply?  Why not exponentiate?

Well, as I noted in another post, that while these can be broken down
into their simpler component (addition and negative numbers), numbers
should probably be treated separately.

 42  MyCollectionType  #would add the object into your collection:
  *poof*: no more random syntaxiis for putting things in collections.\

 So you've replaced one method of a collections API by your magical operator,
 for all collections.

Yes -- for all collections.  That's a pretty big gain right?

 What about the other methods that are just as important,
 such as deleting items, indexing, and querying?  The syntaxitis would stay
 just the same, except if you introduce more operators, which means new syntax
 again.

 Also, how would this work for dictionaries or deques?

Well, now you get into the Work:  a unified data model.   Deques,
trees, lists, etc were all preliminary evolutionary explorations on
this giant computer science journey of knowledge (and data types)
which will have to be, can be, pruned and dropped.

 MyObject  # queries the object to output its state.

 What is its state?  A readable representation?  A serialized representation?
 A memory dump?

That's still for us to decide.  We're mastering the OOP paradigm here:
  What is the ideal object and what is in common across all objects?
  We are Zen, we want to master the notion of object.  What is the
simplest object model possible without sacrificing critical
functionality...

 http://www.cnn.com;  MyInternetObject  #outputs the HTML text from 
 CNN's home page.

 Each object has to figure out how it will receive things from outside
 of it.  Things it can't handle (a string sent to an int) just have to
 be dropped to some other space, much like stderr does within the O.S.

 There are probably many other very interesting examples, but the key
 idea I'm working on (as noted in other messages), is a sort-of
 universal language for the internet, a WebOS to be applied to a
 universal data model.

 It seems that you are reinventing pipes (such as UNIX shell pipes).

That is a very interesting comparison.  That is something like what
I'm trying to do.  In tandem with the Internet, I do see a kind of
synthesis of Web + O.S. integration -- ultimately, creating a data
ecosystem.

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


Re: Pygame mouse cursor load/unload

2013-03-18 Thread Alex Gardner
On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote:
 I am in the process of making a pong game in python using the pygame library. 
  My current problem is that when I move the mouse, it turns off as soon as 
 the mouse stops moving.  The way I am doing this is by making the default 
 cursor invisible and using .png files as replacements for the cursor.  
 Perhaps my code would best explain my problem.  I will take help in any way 
 that I can.  Here are the links that contain my code:
 
 
 
 Main class:  http://pastebin.com/HSQzX6h2
 
 Main file (where the problem lies):  http://pastebin.com/67p97RsJ
 
 
 
 If the links yield nothing, please let me know (agardner...@gmail.com)

All is okay save for one thing!  I joined the ball and the p1 paddle in the 
same program.  Both of the images flicker to some extent.  The paddle itself 
rarely shows up.  I am not quite sure where / when to flip the display :(

[ http://pastebin.com/xzMwa85X ]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Benjamin Kaplan
On Mon, Mar 18, 2013 at 1:24 PM, Mark Janssen dreamingforw...@gmail.com wrote:
 On Mon, Mar 18, 2013 at 12:06 PM, Georg Brandl g.bra...@gmx.net wrote:
 Am 18.03.2013 05:26, schrieb Mark Janssen:
 Continuing on this thread, there would be a new bunch of behaviors to
 be defined.  Since everything is an object, there can now be a
 standard way to define the *next* common abstraction of every object
 interacts with other objects.

 The problem is that for most objects there isn't *the* interaction.  Sure,
 you could split up complicated objects into small pieces with a smaller
 functionality, but at some point you have to stop.

 Yes.  But that is the point, if you look at the quora post -- to
 invert the object model and create mashups of simple modular data
 types and working *upwards*.

  Let's see how this
 concept fares with simple types such as integers or collections...

 42  MyNumberType #would add the integer to your integer type

 That's just random.  Why not multiply?  Why not exponentiate?

 Well, as I noted in another post, that while these can be broken down
 into their simpler component (addition and negative numbers), numbers
 should probably be treated separately.

 42  MyCollectionType  #would add the object into your collection:
  *poof*: no more random syntaxiis for putting things in collections.\

 So you've replaced one method of a collections API by your magical operator,
 for all collections.

 Yes -- for all collections.  That's a pretty big gain right?


Nope. No gain at all. Instead of learning the add() method, you learn
the  operator. You have not simplified anything.
 It seems that you are reinventing pipes (such as UNIX shell pipes).

 That is a very interesting comparison.  That is something like what
 I'm trying to do.  In tandem with the Internet, I do see a kind of
 synthesis of Web + O.S. integration -- ultimately, creating a data
 ecosystem.

 mark

Yes, having the whole program run by chaining functions together is a
neat idea. And it works great in functional languages- if you want
that as a feature, use OCaml or Haskell. It works less well in
imperative languages where you are manipulating data, not just passing
it around.

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


Writing Python framework for declarative checks?

2013-03-18 Thread Victor Hooi
HI,

NB: I've posted this question on Reddit as well (but didn't get many responses 
from Pythonistas) - hope it's ok if I post here as well.

We currently use a collection of custom Python scripts to validate various 
things in our production environment/configuration.

Many of these are simple XML checks (i.e. validate that the value of this XML 
tag here equals the value in that file over there). Others might be to check 
that a host is up, or that this application's crontab start time is within 20 
minutes of X, or that a logfile on a server contains a certain line.

The checks are executed automatically before every production push.

The scripts are written imperatively. E.g.:

SSH into a server
Open up a file
Parse the XML
Search for a XML tag
Store the value in a variable
Compare it to another value somewhere else.
I'd like to look at writing a framework to do these validation in a slightly 
more declarative way - i.e. instead of defining how the server should check 
something, we should just be able to say tagvalue/tag should equal foobar - 
and let the framework handle the how.

I was thinking we could then schedule the checks and shove the jobs onto a 
queue like Celery.

To stop me from re-inventing the wheel - are there any existing projects that 
do something like this already?

Or has anybody here done something similar, or would be able to offer any 
advice?

(I aware of things like Puppet or Chef - or even Salt Stack - however, these 
are for managing deployments, or actually pushing out configurations. These 
validation scripts are more to ensure that the configuration changes done by 
hand are sane, or don't violate certain basic rules).

Cheers,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


The usage of -m option of python

2013-03-18 Thread Peng Yu
Hi,

I don't quite understand how -m option is used. And it is difficult to
search for -m in google. Could anybody provide me with an example on
how to use this option? Thanks!

   -m module-name
  Searches sys.path for the named module and runs the
corresponding .py file as a script.

-- 
Regards,
Peng
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The usage of -m option of python

2013-03-18 Thread Chris Angelico
On Tue, Mar 19, 2013 at 8:17 AM, Peng Yu pengyu...@gmail.com wrote:
 Hi,

 I don't quite understand how -m option is used. And it is difficult to
 search for -m in google. Could anybody provide me with an example on
 how to use this option? Thanks!

-m module-name
   Searches sys.path for the named module and runs the
 corresponding .py file as a script.

Well, I just searched for 'python m module', but I agree it's not
easy. Anyway, Google read my mind and returned this:

http://www.python.org/dev/peps/pep-0338/

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


Re: The usage of -m option of python

2013-03-18 Thread Modulok
 Hi,

 I don't quite understand how -m option is used. And it is difficult to
 search for -m in google. Could anybody provide me with an example on
 how to use this option? Thanks!

-m module-name
   Searches sys.path for the named module and runs the
 corresponding .py file as a script.

 I don't quite understand how -m option is used. And it is difficult to
 search for -m in google. Could anybody provide me with an example on
 how to use this option? Thanks!


Forgive me if I'm too verbose:

When this module is imported via a regular python import statement, the
module's special property ``__name__`` is automatically set to the
name of the module, as a string. For example::

 import random
 random.__name__
 'random'

If a file is executed as a script from the operating system's command line, the
value of the ``__main__`` property is instead automatically set to the string
__main__. This is useful because many python modules have a line such as::


if __name__ == __main__:
# Do something different...
# Maybe run some unit tests or something.
# Or perhaps parse some command line arguments...

This means you can cd into the python modules directory on your system and
execute one of the built-in modules directly::

cd /usr/local/lib/python3.3

python3.3 random.py
# Tests the random number functions and spits out the result to the
# console.

We have one file with two behaviors, depending on how it gets executed. You can
use the same concept in your own scripts to have both a command line script
that does something useful, as well as an importable python module to use in
other scripts. Remember, if ``__name__ == __main__`` the file is being run as
a script. Otherwise it's being imported as a module.

So what about that ``-m`` option? Having to cd into the python module directory
every time you need to execute a module as a script is cumbersome. The ``-m``
flag is basically a shortcut. These are basically the same::

cd /usr/local/lib/python3.3
python3.3 random.py

Same as::

python3.3 -m random #-- I can do this from any directory.


The modules in the standard library have no obligation to do anything useful,
or even anything at all, if execute directly but you can use the same idea to
execute modules as scripts from packages you create.

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


Re: Pygame mouse cursor load/unload

2013-03-18 Thread Alex Gardner
On Monday, March 18, 2013 3:24:57 PM UTC-5, Alex Gardner wrote:
 On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote:
 
  I am in the process of making a pong game in python using the pygame 
  library.  My current problem is that when I move the mouse, it turns off as 
  soon as the mouse stops moving.  The way I am doing this is by making the 
  default cursor invisible and using .png files as replacements for the 
  cursor.  Perhaps my code would best explain my problem.  I will take help 
  in any way that I can.  Here are the links that contain my code:
 
  
 
  
 
  
 
  Main class:  http://pastebin.com/HSQzX6h2
 
  
 
  Main file (where the problem lies):  http://pastebin.com/67p97RsJ
 
  
 
  
 
  
 
  If the links yield nothing, please let me know (agardner...@gmail.com)
 
 
 
 All is okay save for one thing!  I joined the ball and the p1 paddle in the 
same program.  Both of the images flicker to some extent.  The paddle itself 
rarely shows up.  I am not quite sure where / when to flip the display :(
 
 
 
 [ http://pastebin.com/i1GbT6JB ]

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


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Mark Janssen
On Mon, Mar 18, 2013 at 2:51 PM, Andrew Barnert abarn...@yahoo.com wrote:
 Have you even looked at a message-passing language?

 A Smalltalk message is a selector and a sequence of arguments. That's what 
 you send around. Newer dynamic-typed message-passing OO and actor languages 
 are basically the same as Smalltalk.

Yes, but you have to understand that Alan Kays came with strange ideas
of some future computer-human symbiosis.  So his language design and
other similar attempts (like php) is rather skewed from that premise

And also, despite name-dropping, I'm not trying to create anything
like that idea of message-passing.  I'm talking about something very
simple, a basic and universal way for objects to communicate.

 With function or method syntax, you're telling the computer to
 execute something, but that is not the right concepts for OOP.  You
 want the objects to interact with each other and in a high-level
 language, the syntax should assist with that.

 And you have to tell the object _how_ to interact with each other.

This is a different paradigm that what I'm talking about.  In the OOP
of my world, Objects already embody the intelligence of how they are
going to interact with the outside world, because I put them there.

 Even with reasonably intelligent animals, you don't just tell two animals to 
 interact, except in the rare case where you don't care whether they become 
 friends or dinner.

You're model of computer programming is very alien to me.  So I don't
think it will be productive to try to convince you of what I'm
suggesting, but feel free to continue...

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


Re: Small program ideas

2013-03-18 Thread eli m
Any other ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Small program ideas

2013-03-18 Thread Mark Lawrence

On 18/03/2013 23:51, eli m wrote:

Any other ideas?



How about coming up with a new message passing syntax for objects?  I 
understand from recent postings that this should be fairly easy :)


--
Cheers.

Mark Lawrence

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


Re: What's the difference between these two uses of for?

2013-03-18 Thread alex23
On Mar 18, 12:33 pm, Roy Smith r...@panix.com wrote:
 Google's motto may be don't be evil, but they get to define what evil
 is.  Apparently working and playing well with mailing list technology
 which has worked just fine for literally decades isn't part of the
 definition.

Their decision to scrap Reader while ploughing forward with this
godawful new UI for Groups has pushed them into the evil basket for
me :(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 3.3.0] Getting tkinter to work on Python 3

2013-03-18 Thread Yves S. Garret
On Monday, March 18, 2013 2:39:57 PM UTC-4, Lele Gaifax wrote:
 Yves S. Garret yo@gmail.com writes:
 
  I have.  This is what I did and the result that I'm seeing.
 
  $ sudo apt-get install python3-tk
 
 You installed a custom python 3.3, didn't you? So it does not help
 installing Ubuntu's python3-tk: your python3.3 interpreter won't even
 look into system packages.
 
 Most probably, you need to install the proper development libraries and
 *recompile* the Python 3.3 interpreter:
 
 # apt-get install tk-dev
 
 ciao, lele.
 -- 
 nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
 real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
 l...@metapensiero.it  | -- Fortunato Depero, 1929.

Ok, it now seems to work.  Weird.  I had tk-dev installed (it seems) and then 
after I re-compiled my interpreter just now, it's working.

Thanks for your help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem this random seed()

2013-03-18 Thread NZach
Hello everyone,

i am using the MMK.py example from a SimPy tutorial, which can be found here: 
http://heather.cs.ucdavis.edu/~matloff/156/PLN/DESimIntro.pdf

I have made very little changes to the code and i have upload it here:
http://codeviewer.org/view/code:30d3

The problem is that i am executing  the main() function in lines 83 and 90, but 
i do not receive the  same result, although the random seed is used in the G 
class.

Any idea please, how can i solve it ?


Thanks,

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


Re: Problem this random seed()

2013-03-18 Thread eli m
On Monday, March 18, 2013 6:57:30 PM UTC-7, NZach wrote:
 Hello everyone,
 
 
 
 i am using the MMK.py example from a SimPy tutorial, which can be found here: 
 http://heather.cs.ucdavis.edu/~matloff/156/PLN/DESimIntro.pdf
 
 
 
 I have made very little changes to the code and i have upload it here:
 
 http://codeviewer.org/view/code:30d3
 
 
 
 The problem is that i am executing  the main() function in lines 83 and 90, 
 but 
 
 i do not receive the  same result, although the random seed is used in the G 
 
 class.
 
 
 
 Any idea please, how can i solve it ?
 
 
 
 
 
 Thanks,
 
 
 
 Nicholas.

What errors did it show?
-- 
http://mail.python.org/mailman/listinfo/python-list


How avoid installing directories match some pattern when using distutils.core setup?

2013-03-18 Thread Peng Yu
Hi,

By default, setup.py will install everything in the source directory.
I want mask some directories so that they will not be installed. Is
there a way to do so in setup.py?

-- 
Regards,
Peng
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem this random seed()

2013-03-18 Thread alex23
On Mar 19, 11:57 am, NZach nickzachara...@gmail.com wrote:
 The problem is that i am executing  the main() function in lines 83 and 90, 
 but
 i do not receive the  same result, although the random seed is used in the G
 class.

 Any idea please, how can i solve it ?

The seed is used to create a Random instance at the very start of the
module. This means it will have the same state for each run of the
module, but not for each execution of the main function. To have each
execution of main() return the same result, you will need to set the
seed _within_ the main function.

Try adding this as the first line in main:

 G.Rnd = Random(12345)

This should ensure that the state of your random generator is the same
for each execution of the main() function and any subsequent functions
it calls that rely on G.Rnd.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The usage of -m option of python

2013-03-18 Thread Terry Reedy

On 3/18/2013 5:17 PM, Peng Yu wrote:

Hi,

I don't quite understand how -m option is used. And it is difficult to
search for -m in google. Could anybody provide me with an example on
how to use this option?


python -m test
at a command line runs the regression tests in the test package
python -m test -v test_difflib
runs test.test_difflib in verbose mode.

These are alternatives to
python path-to-test ...
Python just searches for module itself, same as for import, but executes 
it as main module instead of importing.


This is really handy for developers running tests, where path-to-test is 
not only a nuisance to type, but different for development builds than 
for installations, and of course, different for each version. Let python 
find the /Lib corresponding to the executable.


I am not sure if it works for things outside /Lib

--
Terry Jan Reedy

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


Re: Learn Python Quickly is FREE today March 18th

2013-03-18 Thread Terry Reedy

On 3/18/2013 8:55 AM, John Rowland wrote:

For just today, the book Learn Python Quickly is free to download
from Amazon. Also, go to www.learnpythonquickly.com for more
information.


I just 'bought' this to see if it is something I would recommend. I 
turned first to the IDLE section. A couple of suggestions:


Click Run - Run Module F5 The following window will appear save box 
That soon gets to be a nuisance and can be turned off with Options / 
Configure IDLE / General / Autosave Preferences (x) No prompt. I think 
even beginners should learn about the configure dialog.


It is essential that you include the .py extension.
We fixed that nuisance last summer for 3.3. So: For python versions 
before 3.3, 




--
Terry Jan Reedy

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


Re: [Python-ideas] Message passing syntax for objects

2013-03-18 Thread Andrew Barnert
From: Mark Janssen dreamingforw...@gmail.com

Sent: Monday, March 18, 2013 4:41 PM


 On Mon, Mar 18, 2013 at 2:51 PM, Andrew Barnert abarn...@yahoo.com 
 wrote:
  Have you even looked at a message-passing language?
 
  A Smalltalk message is a selector and a sequence of arguments. 
 That's what you send around. Newer dynamic-typed message-passing OO and 
 actor languages are basically the same as Smalltalk.
 
 Yes, but you have to understand that Alan Kays came with strange ideas
 of some future computer-human symbiosis.  So his language design and
 other similar attempts (like php) is rather skewed from that premise

The idea that message passing is fundamentally different from method calling 
also turned out to be one of those strange ideas, since it only took a couple 
years to prove that they are theoretically completely isomorphic—and, for that 
matter, they're both isomorphic to closures.

 And also, despite name-dropping, I'm not trying to create anything
 like that idea of message-passing.  I'm talking about something very
 simple, a basic and universal way for objects to communicate.

Message passing is a simple, basic, and universal way for objects to 
communicate. Everything from dot-syntax method calls to JSON RPC protocols can 
be modeled as passing messages. But what you're talking about isn't message 
passing. The idea that messages have names, and reference objects as arguments, 
is fundamental, and by leaving that out, you're talking about something 
different. 

In effect, your objects are just single-parameter functions, and your 
messages are the call operator.

  With function or method syntax, you're telling the computer to
  execute something, but that is not the right concepts for 
 OOP.  You
  want the objects to interact with each other and in a high-level
  language, the syntax should assist with that.
 

  And you have to tell the object _how_ to interact with each other.
 
 This is a different paradigm that what I'm talking about.  In the OOP
 of my world, Objects already embody the intelligence of how they are
 going to interact with the outside world, because I put them there.

The paradigm you're talking about is useless. You have lists that know how to 
append, but don't know how to get/search/iterate. Almost every useful object 
needs the intelligence to interact with the world in two or more ways.

  Even with reasonably intelligent animals, you don't just tell two 
 animals to interact, except in the rare case where you don't care whether 
 they become friends or dinner.
 
 You're model of computer programming is very alien to me.  So I don't
 think it will be productive to try to convince you of what I'm
 suggesting, but feel free to continue...


My model of (object-oriented) computer programming is that programming objects 
model objects which have a variety of behaviors, each of which is triggered by 
sending a different message. This is pretty much the central definition that 
everyone who programs or theorizes about programming uses. If you read any 
textbook, wiki page, journal article, or tutorial, they're all talking about 
that, or something directly isomorphic to it. If that's alien to you, then 
object-oriented programming is alien to you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python 3.3.0] Getting tkinter to work on Python 3

2013-03-18 Thread Terry Reedy

On 3/18/2013 9:52 PM, Yves S. Garret wrote:


Ok, it now seems to work.  Weird.  I had tk-dev installed (it seems)
and then after I re-compiled my interpreter just now, it's working.


If your previous compilation was before tk-dev was installed, it will 
not have compiled _tkinter properly. On PC, one also has to re-compile 
after doing equivalent of downloading tk-dev.


--
Terry Jan Reedy

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


[issue17445] Return the type you accept

2013-03-18 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Changing behavior that already matches the docs is an enhancement, not a 
bugfix, and one that will almost certainly break code. It is therefore one that 
would normally require a deprecation period. I think the most you should ask 
for is to skip the deprecation period.

I believe the urllib and difflib problems are quite different. I am going to 
presume that urllib simply converts bytes input to str and goes on from there, 
returning the result as str rather than (possibly) converting back to bytes. 
That is an example for this issue.

Difflib.unified_diff, on the other hand, raises rather than returning an 
unexpected or undesired type. The 3 sections like the below have two problems 
given the toy input of two bytes objects.

if tag in {'replace', 'delete'}:
for line in a[i1:i2]:
yield '-' + line

First, iterating bytes or a slice of bytes returns ints, not 1-byte bytes. 
Hence the exception. Even if that were worked around, the mixed string constant 
+ bytes expression would raise a TypeError. One fix for both problems would be 
to change the expression to '-' + str(line).

Neither of these problems are bugs. The doc says Compare a and b (lists of 
strings). Actually, 'sequence of strings' is sufficient. For the operations of 
unified_diff, a string looks like a sequence of 1-char strings, which is why

 for l in difflib.unified_diff('ab', 'c'): print(l)

--- 

+++ 

@@ -1,2 +1 @@

-a
-b
+c

works.

The other lines yielded by unified_diff are produced with str.format, and % 
formatting does not seem to work with bytes either. So a dual string/bytes 
function would not be completely trivial.

Greg, can you convert bytes to strings, or strings to bytes, for your tests, or 
do you have non-ascii codes in your bytes? Otherwise, I think it might be 
better to write a new function 'unified_diff_bytes' that did exactly what you 
want than to try to make unified_diff accept sequences of bytes.

--
nosy: +terry.reedy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17445
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17452] ftplib raises exception if ssl module is not available

2013-03-18 Thread Russell Kackley

New submission from Russell Kackley:

On a system with no ssl module the following test failure occurs:

==
ERROR: test_dir (test.test_ftplib.TestFTPClass)
--
Traceback (most recent call last):
  File /home/rkackley/Code/cpython/Lib/test/test_ftplib.py, line 598, in 
test_dir
self.client.dir(lambda x: l.append(x))
  File /home/rkackley/Code/cpython/Lib/ftplib.py, line 565, in dir
self.retrlines(cmd, func)
  File /home/rkackley/Code/cpython/Lib/ftplib.py, line 476, in retrlines
if isinstance(conn, _SSLSocket):
TypeError: isinstance() arg 2 must be a type or tuple of types

--
components: Library (Lib)
files: ftplib.diff
keywords: patch
messages: 184429
nosy: giampaolo.rodola, rkackley
priority: normal
severity: normal
status: open
title: ftplib raises exception if ssl module is not available
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file29438/ftplib.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17452
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17206] Py_XDECREF() expands its argument multiple times

2013-03-18 Thread Illia Polosukhin

Illia Polosukhin added the comment:

I've worked on this with Dave Malcolm @PyCon2013 sprints.

This patch is work in progress to make Py_XDECREF() and Py_XINCREF() expands 
their arguments once instead of multiple times.

Because patch is work in progress, it contains old version for ease of 
benchmarking. To enable the old version - define OLD_17206.

Tested so far only with: Clang on Mac OS X 10.7 x64.

--
keywords: +patch
nosy: +ilblackdragon
Added file: http://bugs.python.org/file29439/17206.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17206
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17206] Py_XDECREF() expands its argument multiple times

2013-03-18 Thread Illia Polosukhin

Illia Polosukhin added the comment:

Additionally, in macros Py_XINCREF and Py_XDECREF we've took an opportunity to 
increase readability by changing expression:
 if (item == NULL) ; else action(item);
to more natural inverted condition:
 if (item != NULL) action(item);

There is a chance that there may be a reason for this form of expression, so 
let me know if this is an issue.

--
nosy: +larry

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17206
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17206] Py_XDECREF() expands its argument multiple times

2013-03-18 Thread Illia Polosukhin

Illia Polosukhin added the comment:

Benchmark run on Clang Mac OS X 10.7 attached of comparison with and without 
patch 17206.diff.

--
Added file: http://bugs.python.org/file29440/perf.log

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17206
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17206] Py_XDECREF() expands its argument multiple times

2013-03-18 Thread Illia Polosukhin

Illia Polosukhin added the comment:

Command used for benchmarking was:

python perf.py -b 2n3 -f ../cpython/baseline-clang/python.exe 
../cpython/experiment-clang/python.exe | tee perf.log

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17206
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3840] if TESTFN == /tmp/@test, some tests fail

2013-03-18 Thread R. David Murray

R. David Murray added the comment:

To clarify Colin's comment (we worked on this at the sprints), in 2.7 and later 
regrtest no longer will generate a TESTFN that starts with /tmp in any 
circumstance, so that includes cygwin.  (Instead regrtest creates a temporary 
directory in which the tests are run.)  So, indeed, this bug is now out of date.

--
resolution:  - out of date
stage: needs patch - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3840
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17453] logging.config.fileConfig error

2013-03-18 Thread Hervé Coatanhay

New submission from Hervé Coatanhay:

In python 2.7 this code works:

 import logging.config
 import StringIO
 a=[loggers]
... keys = root
... [logger_root]
... handlers = 
... [formatters]
... keys = 
... [handlers]
... keys = 
... 
 logging.config.fileConfig(StringIO.StringIO(a))
 

whereas in python 3.3 it raises an exception:

 import logging.config
 import io
 a=[loggers]
... keys = root
... [logger_root]
... handlers = 
... [formatters]
... keys = 
... [handlers]
... keys = 
... 
 logging.config.fileConfig(io.StringIO(a))
Traceback (most recent call last):
  File stdin, line 1, in module
  File 
/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/logging/config.py,
 line 70, in fileConfig
formatters = _create_formatters(cp)
  File 
/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/logging/config.py,
 line 114, in _create_formatters
class_name = cp[sectname].get(class)
  File 
/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/configparser.py,
 line 942, in __getitem__
raise KeyError(key)
KeyError: 'formatter_'


--
components: Library (Lib)
messages: 184435
nosy: Alzakath
priority: normal
severity: normal
status: open
title: logging.config.fileConfig error
type: behavior
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17453
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17450] Failed to build _sqlite3

2013-03-18 Thread Ezio Melotti

Ezio Melotti added the comment:

The module is not needed (unless you are planning to use sqlite), so you can 
simply ignore the warning.  See also 
http://docs.python.org/devguide/setup.html#build-dependencies.

--
nosy: +ezio.melotti
resolution:  - invalid
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17450
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17454] ld_so_aix not used when linking c++ (scipy)

2013-03-18 Thread alef

New submission from alef:

error: Command xlC_r xlC_r -bI:/pathp/to/lib/python2.7/config/python.exp 

unixccompiler.py at line 251 override linker[0] with self.compiler_cxx[0]. This 
is not true for AIX that uses the script ld_so_aix, and not xlC_r.

--
assignee: eric.araujo
components: Distutils
messages: 184437
nosy: alef, eric.araujo, tarek
priority: normal
severity: normal
status: open
title: ld_so_aix not used when linking c++ (scipy)
type: compile error
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17454
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17445] Return the type you accept

2013-03-18 Thread Nick Coghlan

Nick Coghlan added the comment:

At a glance, this just looks like a bug in difflib - it should use
different literals when handling bytes. (Given that difflib newline
processing assumes ASCII compatibility, a latin-1 based decode/encode
solution may also be viable).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17445
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2786] Names in traceback should have class names, if they're methods

2013-03-18 Thread Illia Polosukhin

Illia Polosukhin added the comment:

Talked with David Murray (r.david.murray) at @pycon2013 sprints - will try to 
address this.

--
nosy: +ilblackdragon

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2786
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17452] ftplib raises exception if ssl module is not available

2013-03-18 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 0842c5411ed6 by Giampaolo Rodola' in branch 'default':
(issue 17452 / ftplib) fix TypeError occurring in case ssl module is not 
installed
http://hg.python.org/cpython/rev/0842c5411ed6

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17452
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17452] ftplib raises exception if ssl module is not available

2013-03-18 Thread Giampaolo Rodola'

Giampaolo Rodola' added the comment:

Fixed, thanks.

--
assignee:  - giampaolo.rodola
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17452
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17299] Test cPickle with real files

2013-03-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Oh, yes.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17299
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17299] Test cPickle with real files

2013-03-18 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


Removed file: http://bugs.python.org/file29433/test_cpickle_fileio.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17299
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17455] ImportError (xml.dom.minidom) in /usr/lib/python2.7/dist-packages/apport/report.py

2013-03-18 Thread Felix Matenaar

New submission from Felix Matenaar:

We're getting the following exception in a custom testing framework using 
sqlalchemy. Our process is running several days and the exception seems to 
occurs unproducably during runtime, sometimes after a day and sometimes after a 
couple of hours. The same code is executed many times before.

To me it looks like SQLAlchemy crashed which then leads to the import error. 
Maybe I'll have to issue a bug for this specific project but first wanted to 
ask you guys.

File /home/test/research/testing/db.py, line 101, in addException
self.testrun.exceptions.append(exc)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/attributes.py, line 168, 
in _get_
return self.impl.get(instance_state(instance),dict_)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/attributes.py, line 453, 
in get
value = self.callable_(state, passive)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/strategies.py, line 563, 
in _load_for_state
result = q.all()
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py, line 1947, in 
all
return list(self)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py, line 2057, in 
_iter_
return self._execute_and_instances(context)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py, line 2070, in 
_execute_and_instances
close_with_result=True)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py, line 2061, in 
_connection_from_session
**kw)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py, line 719, in 
connection
close_with_result=close_with_result)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py, line 723, in 
_connection_for_bind
return self.transaction._connection_for_bind(engine)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py, line 266, in 
_connection_for_bind
conn = bind.contextual_connect()
File /usr/lib/python2.7/dist-packages/sqlalchemy/engine/base.py, line 2340, 
in contextual_connect
self.pool.connect(),
File /usr/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 210, in connect
return _ConnectionFairy(self).checkout()
File /usr/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 371, in _init_
rec = self._connection_record = pool._do_get()
File /usr/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 758, in _do_get
return self._create_connection()
File /usr/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 174, in 
_create_connection
return _ConnectionRecord(self)
File /usr/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 256, in _init_
self.connection = self.__connect()
File /usr/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 316, in 
__connect
connection = self.__pool._creator()
File /usr/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py, line 
80, in connect
return dialect.connect(*cargs, **cparams)
File /usr/lib/python2.7/dist-packages/sqlalchemy/engine/default.py, line 280, 
in connect
return self.dbapi.connect(*cargs, **cparams)
sqlalchemy.exc.OperationalError: (OperationalError) unable to open database 
file None None
Error in sys.excepthook:
Traceback (most recent call last):
File /usr/lib/python2.7/dist-packages/apport_python_hook.py, line 66, in 
apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File /usr/lib/python2.7/dist-packages/apport/_init_.py, line 1, in module
from apport.report import Report
File /usr/lib/python2.7/dist-packages/apport/report.py, line 15, in module
import xml.dom, xml.dom.minidom
ImportError: No module named minidom

Original exception was:
Traceback (most recent call last):
File ./test, line 72, in module
prog.run()
File ./test, line 67, in run
ts.run(self._getStorageBackend())
File /home/test/research/testing/testsets.py, line 104, in run
storage.addException(exc)
File /home/test/research/testing/db.py, line 101, in addException
self.testrun.exceptions.append(exc)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/attributes.py, line 168, 
in _get_
return self.impl.get(instance_state(instance),dict_)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/attributes.py, line 453, 
in get
value = self.callable_(state, passive)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/strategies.py, line 563, 
in _load_for_state
result = q.all()
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py, line 1947, in 
all
return list(self)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py, line 2057, in 
_iter_
return self._execute_and_instances(context)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py, line 2070, in 
_execute_and_instances
close_with_result=True)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py, line 2061, in 
_connection_from_session
**kw)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py, line 719, in 
connection
close_with_result=close_with_result)
File /usr/lib/python2.7/dist-packages/sqlalchemy/orm/session.py, line 723, in 
_connection_for_bind
return 

[issue17310] Ctypes callbacks shows problem on Windows Python (64bit)

2013-03-18 Thread Matt Clarke

Matt Clarke added the comment:

Hi Amaury.

I have tried removing pack and using /Zp1, but it makes no difference.
The size of callback_t and the one in C are 8 bytes.

Thanks,

Matt

On 13 March 2013 13:19, Amaury Forgeot d'Arc rep...@bugs.python.org wrote:


 Amaury Forgeot d'Arc added the comment:

 Is _pack_ = 1 correct? Did you compile your C library with /Zp1 or
 similar?
 Also check that ctypes.sizeof(callback_t) matches the one given by the C
 compiler.

 --

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue17310
 ___


--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17310
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17397] ttk::themes missing from ttk.py

2013-03-18 Thread klappnase

klappnase added the comment:

I am not familiar with python's test unit, but I tried my best.

As far as I see there are three possibilities to invoke the function:
* without pattern - return tuple with all themes
* with pattern that matches one or more themes
* with pattern that matches no themes - return empty tuple

So I tried to add a method to test_style.StyleTest() :

def test_themes(self):
installed_themes = self.style.themes()
some_themes = self.style.themes('*e*')
no_themes = self.style.themes('foobarbaz')

self.assertTrue(isinstance(installed_themes, tuple))
self.assertTrue(isinstance(some_themes, tuple))
self.assertTrue(isinstance(no_themes, tuple))

Oddly enough this fails on my own system (debian squeeze, tk-8.5.8, 
python-3.1.3 / -2.6.6):

$ python3 test_style.py
test_configure (__main__.StyleTest) ... ok
test_layout (__main__.StyleTest) ... ok
test_lookup (__main__.StyleTest) ... ok
test_map (__main__.StyleTest) ... ok
test_theme_use (__main__.StyleTest) ... ok
test_themes (__main__.StyleTest) ... ERROR

==
ERROR: test_themes (__main__.StyleTest)
--
Traceback (most recent call last):
  File test_style.py, line 97, in test_themes
no_themes = self.style.themes('foobarbaz')
  File /usr/lib/python3.1/tkinter/ttk.py, line 536, in themes
return self.tk.splitlist(self.tk.call('ttk::themes', pattern))
TypeError: Can't convert '_tkinter.Tcl_Obj' object to str implicitly

--
Ran 6 tests in 0.086s

FAILED (errors=1)
Traceback (most recent call last):
  File test_style.py, line 108, in module
run_unittest(*tests_gui)
  File /usr/lib/python3.1/test/support.py, line 955, in run_unittest
_run_suite(suite)
  File /usr/lib/python3.1/test/support.py, line 938, in _run_suite
raise TestFailed(err)
test.support.TestFailed: Traceback (most recent call last):
  File test_style.py, line 97, in test_themes
no_themes = self.style.themes('foobarbaz')
  File /usr/lib/python3.1/tkinter/ttk.py, line 536, in themes
return self.tk.splitlist(self.tk.call('ttk::themes', pattern))
TypeError: Can't convert '_tkinter.Tcl_Obj' object to str implicitly

The same error occurs with python-2.6.6 (same tk). Apparently this is because:

$ python3
Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) 
[GCC 4.4.5] on linux2
Type help, copyright, credits or license for more information.
 from tkinter import *
 from tkinter import ttk
 r=Tk()
 s=ttk.Style()
 x = s.themes('foo')
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python3.1/tkinter/ttk.py, line 536, in themes
return self.tk.splitlist(self.tk.call('ttk::themes', pattern))
TypeError: Can't convert '_tkinter.Tcl_Obj' object to str implicitly
 x=r.tk.call('ttk::themes', 'foo')
 x
StateSpec object at 0x9b1b6c8
 str(x)
''
 

Called from wish the same call returns an empty string as expected:

$ wish
% ttk::themes
classic default clam alt
% ttk::themes *e*
default
% ttk::themes foobarbaz
%

In python2.6, when setting Tkinter.wantobjects to 0, themes('foo') returns an 
empty tuple as expected.
So I guess this is due to a bug in debian's python/tkinter install. Can anyone 
confirm this?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17397
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17456] os.py (unexpected character)

2013-03-18 Thread Corto Nexus

New submission from Corto Nexus:

In Python 3.3 (Windows 32bits) the lib os.py start with an uncommented letter 
'r'.

--
messages: 184446
nosy: corto.nexus
priority: normal
severity: normal
status: open
title: os.py (unexpected character)
type: enhancement
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17456
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17299] Test cPickle with real files

2013-03-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Benjamin has fixed this in the changeset 6aab72424063.

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17299
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17456] os.py (unexpected character)

2013-03-18 Thread Ezio Melotti

Ezio Melotti added the comment:

os.py starts with:
rOS routines for Mac, NT, or Posix depending on what system we're on.
[...]

Do you see only the 'r'?

--
nosy: +ezio.melotti

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17456
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17456] os.py (unexpected character)

2013-03-18 Thread Anuj Gupta

Anuj Gupta added the comment:

http://docs.python.org/3/tutorial/introduction.html#strings

This seems like a good opportunity for you to learn about raw strings. :)

--
nosy: +anuj

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17456
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   3   >