pylib/py.test 1.3.4: fixes and new native traceback option

2010-09-15 Thread holger krekel
pylib/py.test 1.3.4 is a minor maintenance release mostly containing bug fixes
and a new --tb=native traceback option to show normal Python standard
tracebacks instead of the py.test enhanced tracebacks.  See below for more 
change info and http://pytest.org for more general information on features 
and configuration of the testing tool. 

Thanks to the issue reporters and generally to Ronny Pfannschmidt for help. 

cheers,
holger krekel

Changes between 1.3.3 and 1.3.4
==

- fix issue111: improve install documentation for windows
- fix issue119: fix custom collectability of __init__.py as a module
- fix issue116: --doctestmodules work with __init__.py files as well
- fix issue115: unify internal exception passthrough/catching/GeneratorExit
- fix issue118: new --tb=native for presenting cpython-standard exceptions

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

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


OpenOpt 0.31, FuncDesigner 0.21, DerApproximator 0.21

2010-09-15 Thread dmitrey
Hi all,

I'm glad to inform you about new releases of our completely free (BSD
license) cross-platform software, written using Python language and
NumPy:
OpenOpt 0.31 (numerical optimization), FuncDesigner 0.21 (automatic
differentiation, modelling, interpolation, integration),
DerApproximator 0.21 (finite-differences derivatives approximation).

For release details see
http://forum.openopt.org/viewtopic.php?id=299
or visit our homepage
http://openopt.org

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

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


python call a procedure at the specified time

2010-09-15 Thread Von
Hi,
I have a python script running behind the scene,and I need it to call a
method on sunday 9 o'clock.
I get an idea,that I get the current time,and calculate the seconds to
sunday 9 o'clock,
then sleep these seconds and call my method,I think there could be an
elegant way to resolve this.

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


Re: python call a procedure at the specified time

2010-09-15 Thread Nitin Pawar
are you looking for something like cron?

On Wed, Sep 15, 2010 at 11:43 AM, Von von...@gmail.com wrote:

 Hi,
 I have a python script running behind the scene,and I need it to call a
 method on sunday 9 o'clock.
 I get an idea,that I get the current time,and calculate the seconds to
 sunday 9 o'clock,
 then sleep these seconds and call my method,I think there could be an
 elegant way to resolve this.

 Regards,

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




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


Re: python call a procedure at the specified time

2010-09-15 Thread Von
Hi Nitin,I need a python solution for that.

On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar nitinpawar...@gmail.comwrote:

 are you looking for something like cron?

 On Wed, Sep 15, 2010 at 11:43 AM, Von von...@gmail.com wrote:

 Hi,
 I have a python script running behind the scene,and I need it to call a
 method on sunday 9 o'clock.
 I get an idea,that I get the current time,and calculate the seconds to
 sunday 9 o'clock,
 then sleep these seconds and call my method,I think there could be an
 elegant way to resolve this.

 Regards,

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




 --
 Nitin Pawar


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


Re: python call a procedure at the specified time

2010-09-15 Thread Nitin Pawar
I think to do so either you will need to schedule a cron or write a daemon
process which will run continuously.
Assuming that its running only once a day or say timely manner daemon will
be a  costly affair for system resources

To schedule crons for python, this might be useful (using yaml)
http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml

Thanks,
Nitin

On Wed, Sep 15, 2010 at 11:54 AM, Von von...@gmail.com wrote:

 Hi Nitin,I need a python solution for that.


 On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar nitinpawar...@gmail.comwrote:

 are you looking for something like cron?

 On Wed, Sep 15, 2010 at 11:43 AM, Von von...@gmail.com wrote:

 Hi,
 I have a python script running behind the scene,and I need it to call a
 method on sunday 9 o'clock.
 I get an idea,that I get the current time,and calculate the seconds to
 sunday 9 o'clock,
  then sleep these seconds and call my method,I think there could be an
 elegant way to resolve this.

 Regards,

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




 --
 Nitin Pawar





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


Re: String formatting with the format string syntax

2010-09-15 Thread Peter Otten
Andre Alexander Bell wrote:

 On 09/14/2010 08:20 PM, Miki wrote:
 You can use ** syntax:
 english = {'hello':'hello'}
 s.format(**english)
 
 Thanks for your answer. Actually your answer tells me that my example
 was misleading. Consider the template
 
 s = 'A template with {variable1} and {variable2} placeholders.'
 
 I'm seeking a way to extract the named placesholders, i.e. the names
 'variable1' and 'variable2' from the template. I'm not trying to put in
 values for them.
 
 I hope this is clearer.

 s = 'A template with {variable1} and {variable2} placeholders.'
 [name for _, name, _, _ in s._formatter_parser() if name is not None]
['variable1', 'variable2']

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


google app engine _method? put(self):

2010-09-15 Thread kristiannissen
How can I get the request passed on to my views when using this
middleware?

class RestHTTPMiddleware(object):
  def __init__(self, app):
self.app = app

  def __call__(self, environ, start_response):
request = Request(environ)
body = StringIO.StringIO(request.body)

method = webapp.Request(environ).get('_method', None)

if method:
  environ['REQUEST_METHOD'] = method.upper()
  environ['wsgi.input'] = body

return self.app(environ, start_response)

when i test :

class Spot(webapp.RequestHandler):
  def put(self):
  logging.info(hello from put %s, self.request.get(author))

the following is logged: spot put but with no value.

This is how it's implemented:

def main():
  app = webapp.WSGIApplication([
(r'/spot/new/$', Spot),
],
   debug=True)
  # run_wsgi_app(application)
  wsgiref.handlers.CGIHandler().run(RestHTTPMiddleware(app))

and this is the form:

form method=post action=/spot/new/
input type=hidden name=_method value=put /
input type=text name=name value= /
input type=submit value=Save /
/form
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python call a procedure at the specified time

2010-09-15 Thread Von
Thanks Nitin,I wonder how cron works,does it create a timer thread for each
task?

On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar nitinpawar...@gmail.comwrote:

 I think to do so either you will need to schedule a cron or write a daemon
 process which will run continuously.
 Assuming that its running only once a day or say timely manner daemon will
 be a  costly affair for system resources

 To schedule crons for python, this might be useful (using yaml)

 http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml

 Thanks,
 Nitin


 On Wed, Sep 15, 2010 at 11:54 AM, Von von...@gmail.com wrote:

 Hi Nitin,I need a python solution for that.


 On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar nitinpawar...@gmail.comwrote:

 are you looking for something like cron?

 On Wed, Sep 15, 2010 at 11:43 AM, Von von...@gmail.com wrote:

 Hi,
 I have a python script running behind the scene,and I need it to call a
 method on sunday 9 o'clock.
 I get an idea,that I get the current time,and calculate the seconds to
 sunday 9 o'clock,
  then sleep these seconds and call my method,I think there could be an
 elegant way to resolve this.

 Regards,

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




 --
 Nitin Pawar





 --
 Nitin Pawar


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


Re: python call a procedure at the specified time

2010-09-15 Thread Von
I have read the cron man page just now,It says that cron wakes up every
minute to check task.
I will try install/uninstall with cron.

Cheers,

On Wed, Sep 15, 2010 at 3:25 PM, Von von...@gmail.com wrote:

 Thanks Nitin,I wonder how cron works,does it create a timer thread for each
 task?


 On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar nitinpawar...@gmail.comwrote:

 I think to do so either you will need to schedule a cron or write a daemon
 process which will run continuously.
 Assuming that its running only once a day or say timely manner daemon will
 be a  costly affair for system resources

 To schedule crons for python, this might be useful (using yaml)

 http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml

 Thanks,
 Nitin


 On Wed, Sep 15, 2010 at 11:54 AM, Von von...@gmail.com wrote:

 Hi Nitin,I need a python solution for that.


 On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar nitinpawar...@gmail.comwrote:

 are you looking for something like cron?

 On Wed, Sep 15, 2010 at 11:43 AM, Von von...@gmail.com wrote:

 Hi,
 I have a python script running behind the scene,and I need it to call a
 method on sunday 9 o'clock.
 I get an idea,that I get the current time,and calculate the seconds to
 sunday 9 o'clock,
  then sleep these seconds and call my method,I think there could be an
 elegant way to resolve this.

 Regards,

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




 --
 Nitin Pawar





 --
 Nitin Pawar



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


Re: python call a procedure at the specified time

2010-09-15 Thread Nitin Pawar
cron is daemon running which maps the tasks with the frequency

if you want to run a task at a specific time, you can schedule it for the
same

if you need any help, ping on gtalk, can help you out

Thanks,
Nitin

On Wed, Sep 15, 2010 at 1:05 PM, Von von...@gmail.com wrote:

 I have read the cron man page just now,It says that cron wakes up every
 minute to check task.
 I will try install/uninstall with cron.

 Cheers,


 On Wed, Sep 15, 2010 at 3:25 PM, Von von...@gmail.com wrote:

 Thanks Nitin,I wonder how cron works,does it create a timer thread for
 each task?


 On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar nitinpawar...@gmail.comwrote:

 I think to do so either you will need to schedule a cron or write a
 daemon process which will run continuously.
 Assuming that its running only once a day or say timely manner daemon
 will be a  costly affair for system resources

 To schedule crons for python, this might be useful (using yaml)

 http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml

 Thanks,
 Nitin


 On Wed, Sep 15, 2010 at 11:54 AM, Von von...@gmail.com wrote:

 Hi Nitin,I need a python solution for that.


 On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar 
 nitinpawar...@gmail.comwrote:

 are you looking for something like cron?

 On Wed, Sep 15, 2010 at 11:43 AM, Von von...@gmail.com wrote:

 Hi,
 I have a python script running behind the scene,and I need it to call
 a method on sunday 9 o'clock.
 I get an idea,that I get the current time,and calculate the seconds to
 sunday 9 o'clock,
  then sleep these seconds and call my method,I think there could be an
 elegant way to resolve this.

 Regards,

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




 --
 Nitin Pawar





 --
 Nitin Pawar






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


Re: String formatting with the format string syntax

2010-09-15 Thread Peter Otten
Peter Otten wrote:

 Andre Alexander Bell wrote:
 
 On 09/14/2010 08:20 PM, Miki wrote:
 You can use ** syntax:
 english = {'hello':'hello'}
 s.format(**english)
 
 Thanks for your answer. Actually your answer tells me that my example
 was misleading. Consider the template
 
 s = 'A template with {variable1} and {variable2} placeholders.'
 
 I'm seeking a way to extract the named placesholders, i.e. the names
 'variable1' and 'variable2' from the template. I'm not trying to put in
 values for them.
 
 I hope this is clearer.
 
 s = 'A template with {variable1} and {variable2} placeholders.'
 [name for _, name, _, _ in s._formatter_parser() if name is not None]
 ['variable1', 'variable2']

Caveat: the format spec may contain names, too. 
Here's an attempt to take that into account:

def extract_names(t, recurse=1):
for _, name, fmt, _ in t._formatter_parser():
if name is not None:
yield name
if recurse and fmt is not None:
for name in extract_names(fmt, recurse-1):
yield name

t = before {one:{two}{three}} after
print(t)

for name in extract_names(t):
print(name)

 list(extract_names({one:{two}{three}}))
['one', 'two', 'three']

Don't expect correct results for illegal formats:
 list(extract_names({one:{two:{three}}}))
['one', 'two']
 {one:{two:{three}}}.format(one=1, two=2, three=3)
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: Max string recursion exceeded

Duplicate names may occur:
 list(extract_names({one} {one} {one}))
['one', 'one', 'one']

Positional arguments are treated like names:
 list(extract_names({0} {1} {0}))
['0', '1', '0']
 list(extract_names({} {} {}))
['', '', '']

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


Re: String formatting with the format string syntax

2010-09-15 Thread Andre Alexander Bell

On 09/15/2010 10:00 AM, Peter Otten wrote:

def extract_names(t, recurse=1):
 for _, name, fmt, _ in t._formatter_parser():
 if name is not None:
 yield name
 if recurse and fmt is not None:
 for name in extract_names(fmt, recurse-1):
 yield name


Thanks Peter, I very much like this generator solution. It will work for 
all situations I can currently think of.


However, one thing remains. It is based on the _format_parser method. 
And as I wrote in my original post this one - since it starts with _ - 
suggests to me to better not be used. So if using this method is 
completely ok, why does it start with _, why is it almost undocumented? 
Or did I miss something, some docs somewhere?


Best regards


Andre

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


Re: String formatting with the format string syntax

2010-09-15 Thread Peter Otten
Andre Alexander Bell wrote:

 On 09/15/2010 10:00 AM, Peter Otten wrote:
 def extract_names(t, recurse=1):
  for _, name, fmt, _ in t._formatter_parser():
  if name is not None:
  yield name
  if recurse and fmt is not None:
  for name in extract_names(fmt, recurse-1):
  yield name
 
 Thanks Peter, I very much like this generator solution. It will work for
 all situations I can currently think of.
 
 However, one thing remains. It is based on the _format_parser method.
 And as I wrote in my original post this one - since it starts with _ -
 suggests to me to better not be used. So if using this method is
 completely ok, why does it start with _, why is it almost undocumented?
 Or did I miss something, some docs somewhere?

Sorry, I really should have read your original post carefully/completely. It 
would have spared me from finding _formatter_parser() independently...

I personally would not be too concerned about the leading underscore, but 
you can use

string.Formatter().parse(template)

instead.

Peter

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


Accessing windoze file attributes

2010-09-15 Thread Douglas
Environment: X86, 1Gb RAM, Win XP, latest SP, Excel 2003.

Hi, can anyone direct a relative newbie to the best source of info?
I am writing my own backup app in Python 2.5.2 (all my company will
allow me to use) using IDLE.
I intend to run this app daily via the Task Scheduler to back up a
mission-critical spreadsheet that only I use.
It works well enough, but now I want to make it sensitive to the A
attribute (only backup the file if it is set), and update it
afterwards (unset it). This will help me avoid wasted disk due to
needless backups.
I have searched the inter-web and not found any info on how to do
access/alter Windows file attributes.
Please can someone direct me to a web page with suitable info
(preferably with code snyppyts)?
Many thanks, in advance.
-- Douglas
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: OpenOpt 0.31, FuncDesigner 0.21, DerApproximator 0.21

2010-09-15 Thread dmitrey
Hi all,

I'm glad to inform you about new releases of our completely free (BSD
license) cross-platform software, written using Python language and
NumPy:
OpenOpt 0.31 (numerical optimization), FuncDesigner 0.21 (automatic
differentiation, modelling, interpolation, integration),
DerApproximator 0.21 (finite-differences derivatives approximation).

For release details see
http://forum.openopt.org/viewtopic.php?id=299
or visit our homepage
http://openopt.org

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


python cxfreeze package pyqt app lost icon and tray icon

2010-09-15 Thread Von
Hi,
Here is my command:
cxfreeze --target-dir=AutoOrder gui.py
--base-name=D:\Python31\Lib\site-packages\cx_Freeze\bases\Win32GUI.exe
--include-path=. -z icon.jpg

Both app icon and tray icon used icon.jpg

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


Re: String formatting with the format string syntax

2010-09-15 Thread Andre Alexander Bell

On 09/15/2010 10:48 AM, Peter Otten wrote:

I personally would not be too concerned about the leading underscore, but
you can use

string.Formatter().parse(template)

instead.


Thanks for this pointer. I like it this way. So if I now combine your 
generator with your suggestion, I end up with something like this:


def extract_names(t, recurse=1):
import string
for _, name, fmt, _ in string.Formatter().parse(t):
if name is not None:
yield name
if recurse and fmt is not None:
for name in extract_names(fmt, recurse-1):
yield name

Pretty cool. Thanks a lot.

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


Re: help with calling a static method in a private class

2010-09-15 Thread lallous
On Sep 14, 4:38 pm, de...@web.de (Diez B. Roggisch) wrote:
 lallouslall...@lgwm.org writes:
  How can I keep the class private and have the following work:

  [code]
  class __internal_class(object):
      @staticmethod
      def meth1(s):
          print meth1:, s

      @staticmethod
      def meth2(s):
          print meth2:,
          __internal_class.meth1(s)

  x = __internal_class()

  x.meth2('sdf')
  [/code]

 By not using a double underscore. It is effectless on classes anyway
 (they are not hidden because of that).

 And additionally, but simply not using staticmethods at all. It's a
 rather obscure feature ofpython- usually, classmethods are what is
 considered a static method in other languages. And with that, even your
 double underscores work:

 class __internal_class(object):
     @classmethod
     def meth1(cls, s):
         print meth1:, s

     @classmethod
     def meth2(cls, s):
         print meth2:,
         cls.meth1(s)

 x = __internal_class()

 x.meth2('sdf')

 Diez

Thanks, that does the trick.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python call a procedure at the specified time

2010-09-15 Thread Von
I used timer way,and I found that threading.Timer didn't work with PyQt,so I
used QTimer instead,and it did work.

On Wed, Sep 15, 2010 at 3:44 PM, Nitin Pawar nitinpawar...@gmail.comwrote:

 cron is daemon running which maps the tasks with the frequency

 if you want to run a task at a specific time, you can schedule it for the
 same

 if you need any help, ping on gtalk, can help you out

 Thanks,
 Nitin

 On Wed, Sep 15, 2010 at 1:05 PM, Von von...@gmail.com wrote:

 I have read the cron man page just now,It says that cron wakes up every
 minute to check task.
 I will try install/uninstall with cron.

 Cheers,


 On Wed, Sep 15, 2010 at 3:25 PM, Von von...@gmail.com wrote:

 Thanks Nitin,I wonder how cron works,does it create a timer thread for
 each task?


 On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar nitinpawar...@gmail.comwrote:

 I think to do so either you will need to schedule a cron or write a
 daemon process which will run continuously.
 Assuming that its running only once a day or say timely manner daemon
 will be a  costly affair for system resources

 To schedule crons for python, this might be useful (using yaml)

 http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml

 Thanks,
 Nitin


 On Wed, Sep 15, 2010 at 11:54 AM, Von von...@gmail.com wrote:

 Hi Nitin,I need a python solution for that.


 On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar 
 nitinpawar...@gmail.comwrote:

 are you looking for something like cron?

 On Wed, Sep 15, 2010 at 11:43 AM, Von von...@gmail.com wrote:

 Hi,
 I have a python script running behind the scene,and I need it to call
 a method on sunday 9 o'clock.
 I get an idea,that I get the current time,and calculate the seconds
 to sunday 9 o'clock,
  then sleep these seconds and call my method,I think there could be
 an elegant way to resolve this.

 Regards,

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




 --
 Nitin Pawar





 --
 Nitin Pawar






 --
 Nitin Pawar


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


Re: Accessing windoze file attributes

2010-09-15 Thread Diez B. Roggisch
Douglas mumm...@gmail.com writes:

 Hi, can anyone direct a relative newbie to the best source of info?
 I am writing my own backup app in Python 2.5.2 (all my company will
 allow me to use) using IDLE.
 I intend to run this app daily via the Task Scheduler to back up a
 mission-critical spreadsheet that only I use.
 It works well enough, but now I want to make it sensitive to the A
 attribute (only backup the file if it is set), and update it
 afterwards (unset it). This will help me avoid wasted disk due to
 needless backups.
 I have searched the inter-web and not found any info on how to do
 access/alter Windows file attributes.
 Please can someone direct me to a web page with suitable info
 (preferably with code snyppyts)?

No windows nowhere here, but os.stat should be your friend.

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


Re: Accessing windoze file attributes

2010-09-15 Thread David Robinow
On Wed, Sep 15, 2010 at 4:51 AM, Douglas mumm...@gmail.com wrote:
 Environment: X86, 1Gb RAM, Win XP, latest SP, Excel 2003.

 Hi, can anyone direct a relative newbie to the best source of info?
 I am writing my own backup app in Python 2.5.2 (all my company will
 allow me to use) using IDLE.
 I intend to run this app daily via the Task Scheduler to back up a
 mission-critical spreadsheet that only I use.
 It works well enough, but now I want to make it sensitive to the A
 attribute (only backup the file if it is set), and update it
 afterwards (unset it). This will help me avoid wasted disk due to
 needless backups.
 I have searched the inter-web and not found any info on how to do
 access/alter Windows file attributes.
 Please can someone direct me to a web page with suitable info
 (preferably with code snyppyts)?

http://code.activestate.com/recipes/303343-changing-file-attributes-on-windows/
-- 
http://mail.python.org/mailman/listinfo/python-list


30 is True

2010-09-15 Thread Yingjie Lan
Hi, 

I am not sure how to interprete this, in the interactive mode:

 30 is True
False
 (30) is True
True
 3 (0 is True)
True

Why did I get the first 'False'? I'm a little confused.

Thanks in advance for anybody who shed some light on this. 

YL


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


Re: Accessing windoze file attributes

2010-09-15 Thread Lawrence D'Oliveiro
In message
8dc0fa8e-f0e6-4603-9283-186551597...@a19g2000vbi.googlegroups.com, Douglas 
wrote:

 It works well enough, but now I want to make it sensitive to the A
 attribute (only backup the file if it is set), and update it
 afterwards (unset it). This will help me avoid wasted disk due to
 needless backups.

Why reinvent rsync?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: distutils, cygwin, 'not a regular file'

2010-09-15 Thread Lawrence D'Oliveiro
In message 8faqj0fno...@mid.individual.net, Paul Watson wrote:

 ' not a regular file -- skipping
 ' not a regular file -- skipping
 ' not a regular file -- skipping

Just a guess, is the file it’s complaining about named “'”?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 30 is True

2010-09-15 Thread Michael Ricordeau
Because is operator take precedence on  operator .

Le Wed, 15 Sep 2010 05:34:06 -0700 (PDT),
Yingjie Lan lany...@yahoo.com a écrit :

 Hi, 
 
 I am not sure how to interprete this, in the interactive mode:
 
  30 is True
 False
  (30) is True
 True
  3 (0 is True)
 True
 
 Why did I get the first 'False'? I'm a little confused.
 
 Thanks in advance for anybody who shed some light on this. 
 
 YL
 
 
   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 30 is True

2010-09-15 Thread Peter Otten
Yingjie Lan wrote:

 I am not sure how to interprete this, in the interactive mode:
 
 30 is True
 False
 (30) is True
 True
 3 (0 is True)
 True
 
 Why did I get the first 'False'? I'm a little confused.

http://docs.python.org/reference/expressions.html#notin


Unlike C, all comparison operations in Python have the same priority, which 
is lower than that of any arithmetic, shifting or bitwise operation. Also 
unlike C, expressions like a  b  c have the interpretation that is 
conventional in mathematics:

comparison::=  or_expr ( comp_operator or_expr )*
comp_operator ::=   |  | == | = | = |  | !=
   | is [not] | [not] in

Comparisons yield boolean values: True or False.
Comparisons can be chained arbitrarily, e.g., x  y = z is equivalent to x 
 y and y = z, except that y is evaluated only once (but in both cases z is 
not evaluated at all when x  y is found to be false).


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


Re: 30 is True

2010-09-15 Thread Jussi Piitulainen
Yingjie Lan writes:

 I am not sure how to interprete this, in the interactive mode:
 
  30 is True
 False
  (30) is True
 True
  3 (0 is True)
 True
 
 Why did I get the first 'False'? I'm a little confused.

It is interpreted as equivalent to this:

 3  0 and 0 is True
False

From the language reference at python.org (section 5.9 Comparisons):

expressions like a  b  c have the interpretation that is
conventional in mathematics
...

Comparisons can be chained arbitrarily, e.g., x  y = z is
equivalent to x  y and y = z, except that y is evaluated only
once (but in both cases z is not evaluated at all when x  y is
found to be false).

URL:http://docs.python.org/reference/expressions.html#notin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 30 is True

2010-09-15 Thread Mel
Yingjie Lan wrote:
 I am not sure how to interprete this, in the interactive mode:
 
 30 is True
 False
 (30) is True
 True
 3 (0 is True)
 True
 
 Why did I get the first 'False'? I'm a little confused.
 
 Thanks in advance for anybody who shed some light on this.

This looks like comparison chaining.  `is` is a comparison operator, like 
``, and chains of comparisons are handled differently.

`a  b  c` is equivalent to `(a  b) and (b  c)`

Therefore the first expression is testing

(3  0) and (0 is True)


Mel.

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


Re: 30 is True

2010-09-15 Thread Michael Ricordeau
Not really true for  and is :
  http://docs.python.org/reference/expressions.html#evaluation-order

Operator  and operator is are in the same precedence but in group 
Comparisons :
  Operators in the same box group left to right (except for comparisons, 
including tests, which all have the same precedence and chain from left to 
right — see section Comparisons
  The important words here are :
 all have the SAME PRECEDENCE and chain from left to right

 See also :
  http://docs.python.org/reference/expressions.html#comparisons


So for :
   3  0 is True

  #first evaluation is :
   3  0  --- True
  #second evaluation is :
   0 is True  --- False  (and second evaluation is not result of first one 
!)



Le Wed, 15 Sep 2010 14:47:11 +0200,
Michael Ricordeau michael.ricord...@gmail.com a écrit :

 Because is operator take precedence on  operator .
 
 Le Wed, 15 Sep 2010 05:34:06 -0700 (PDT),
 Yingjie Lan lany...@yahoo.com a écrit :
 
  Hi, 
  
  I am not sure how to interprete this, in the interactive mode:
  
   30 is True
  False
   (30) is True
  True
   3 (0 is True)
  True
  
  Why did I get the first 'False'? I'm a little confused.
  
  Thanks in advance for anybody who shed some light on this. 
  
  YL
  
  


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


Re: 30 is True

2010-09-15 Thread Jon Siddle
 As others have said, it's not a matter of precendence. Using the 
compiler module

you can see how python actually parses this:

3  (0 is True)
Compare(Const(3), [('', Compare(Const(0), [('is', Name('True'))]))])

No great surprise there.

3  0 is True
Compare(Const(3), [('', Const(0)), ('is', Name('True'))])

As you can see, it's not the same. Two comparisons are being done at 
once, not

one comparison on the result of another.

Hope this helps



On 15/09/10 13:34, Yingjie Lan wrote:

Hi,

I am not sure how to interprete this, in the interactive mode:


30 is True

False

(30) is True

True

3  (0 is True)

True

Why did I get the first 'False'? I'm a little confused.

Thanks in advance for anybody who shed some light on this.

YL






--
Jon Siddle, CoreFiling Limited
Software Tools Developer
http://www.corefiling.com
Phone: +44-1865-203192

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


Re: 30 is True

2010-09-15 Thread Yingjie Lan
 From: Jon Siddle j...@corefiling.co.uk
 Subject: Re: 30 is True
 To: python-list@python.org
 Date: Wednesday, September 15, 2010, 5:04 PM
   As others have said, it's not
 a matter of precendence. Using the 
 compiler module
 you can see how python actually parses this:
 
 3  (0 is True)
 Compare(Const(3), [('', Compare(Const(0), [('is',
 Name('True'))]))])
 
 No great surprise there.
 
 3  0 is True
 Compare(Const(3), [('', Const(0)), ('is',
 Name('True'))])
 
 As you can see, it's not the same. Two comparisons are
 being done at 
 once, not
 one comparison on the result of another.
 
 Hope this helps

Thank you all for nailing down this itching issue for me!

All I can say is: Wow!

You all have a teribly nice day!

Yingjie


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


os.path.normcase rationale?

2010-09-15 Thread Chris Withers

Hi All,

I'm curious as to why, with a file called Foo.txt 
os.path.normcase('FoO.txt') will return foo.txt rather than Foo.txt?


Yes, I know the behaviour is documented, but I'm wondering if anyone can 
remember the rationale for that behaviour?


cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
- http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: business date and calendar libraries?

2010-09-15 Thread nn
On Sep 13, 3:02 pm, David Robinow drobi...@gmail.com wrote:
 On Mon, Sep 13, 2010 at 1:06 PM, Chris Withers ch...@simplistix.co.uk wrote:
  I'm wondering what libraries people would use to answer the following
  questions relating to business days:

  - on a less-naive level; same question but taking into account public
  holidays

  This depends on which government is oppressing you.

  - on a horrific level; same question, but taking into account business days
  of a particular market (NYSE, LSE, etc)

  This is just an instance of the public holiday case. You need to
 define the holidays.
  If you read lisp you might want to look at the emacs calendar module
 for some hints on how they describe holidays, such as, for a US-biased
 example,  Martin Luther King day is the third Monday in January,
 Memorial Day is the last Monday in May, Good Friday is not a public
 holiday but some markets are closed.

A good way to do this IMHO is to keep a list of holidays for each
year in your program and check if a day is in the list to do your
calculations. The list could be automatically generated by an
algorithm that figures out all the weird holiday dates or -as is done
in many companies- some honcho adds them according to his preference
to a database.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy: Multiplying arrays of matrices

2010-09-15 Thread Colin J. Williams

On 14-Sep-10 19:54 PM, Gregory Ewing wrote:

Suppose I have two N+2 dimensional arrays, representing
N-d arrays of 2-d matrices. I want to perform matrix
multiplication between corresponding matrices in these
arrays.

I had thought that dot() might do this, but it appears
not, because e.g. applying it to two 3-d arrays gives
a 4-d array, not another 3-d array.

I'd also like to be able to find the inverse of each
matrix in one of these arrays, but again, inv() doesn't
do what I want -- it only works on 2-d arrays.

Any thoughts on how to achieve these things using numpy
functions?




There is a Matrix sub-class which permit you to do that sort of thimg.

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


Deleting widgets from PyQt4 QFormWidget

2010-09-15 Thread Andrew
I'm trying to remove the widgets from the QFormLayout widget from
PyQt4. According to the documentation I should be able to use the
command .takeAt(int) which will delete the widget from the layout and
then return to me the QLayoutWidget.
It currently is giving me back the widget, but is not removing it from
the layout.
At the moment, I'm simply trying to clear out all the widgets on the
layout with this:

def clearForm(self):
print (Clearing)
print self.dataForm.rowCount()
for i in range(self.dataForm.rowCount()-1, -1, -1):
print  .,
tmp = self.dataForm.takeAt(i)
print tmp.widget()
tmp = 
print self.dataForm.rowCount()

It goes through each widget on the layout, and prints out the
classes .__repr__ on the tmp.widget() line since tmp is a
QLayoutWidget. So it's doing the returning part, but they still exist
instead of being deleted like the documentation explains.

Am I missing a step or is this just broken? I haven't been able to
find anything else on this issue yet. If it's broke, is there any
potential workaround?

I'm using python 2.6.4 and PyQt4 4.7.6

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


Re: Deleting widgets from PyQt4 QFormWidget

2010-09-15 Thread Andrew
On Sep 15, 9:53 am, Andrew andrewt.h...@gmail.com wrote:
 I'm trying to remove the widgets from the QFormLayout widget from
 PyQt4. According to the documentation I should be able to use the
 command .takeAt(int) which will delete the widget from the layout and
 then return to me the QLayoutWidget.
 It currently is giving me back the widget, but is not removing it from
 the layout.
 At the moment, I'm simply trying to clear out all the widgets on the
 layout with this:

 def clearForm(self):
                 print (Clearing)
                 print self.dataForm.rowCount()
                 for i in range(self.dataForm.rowCount()-1, -1, -1):
                         print  .,
                         tmp = self.dataForm.takeAt(i)
                         print tmp.widget()
                         tmp = 
                 print self.dataForm.rowCount()

 It goes through each widget on the layout, and prints out the
 classes .__repr__ on the tmp.widget() line since tmp is a
 QLayoutWidget. So it's doing the returning part, but they still exist
 instead of being deleted like the documentation explains.

 Am I missing a step or is this just broken? I haven't been able to
 find anything else on this issue yet. If it's broke, is there any
 potential workaround?

 I'm using python 2.6.4 and PyQt4 4.7.6

 Thanks,
 Andrew

QLayoutWidget, I meant a QWidgetItem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy: Multiplying arrays of matrices

2010-09-15 Thread Shashwat Anand
On Tue, Sep 14, 2010 at 7:54 PM, Gregory Ewing
greg.ew...@canterbury.ac.nzwrote:

 Suppose I have two N+2 dimensional arrays, representing
 N-d arrays of 2-d matrices. I want to perform matrix
 multiplication between corresponding matrices in these
 arrays.

 I had thought that dot() might do this, but it appears
 not, because e.g. applying it to two 3-d arrays gives
 a 4-d array, not another 3-d array.

 I'd also like to be able to find the inverse of each
 matrix in one of these arrays, but again, inv() doesn't
 do what I want -- it only works on 2-d arrays.

 Any thoughts on how to achieve these things using numpy
 functions?


Unrelated to numpy, but you can apply the basics of dynamic programming to
optimize the stuff.


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




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


Re: Accessing windoze file attributes

2010-09-15 Thread Douglas
@Diez and @David
Thanks guys. Both excellent leads. Colour me happy.  I can now make
progress and meet some deadlines. :)

@Lawrence
 Why reinvent rsync?
In what way is rsync relevant to the stated problem? Did you actually
READ the question?
Note: I use Linux at home (yes, even rsync) and very much prefer it to
Windows. However, at work I have no choice but to use the resources
the company provides - which is Windows; have you got that straight
now?
If you have something more helpful and mature to say, relevant to the
actual question, then I will gladly hear it, and even apologise.
Otherwise, don't bother. I already enough from respondents who were
far more adult, knowledgeable and helpful ... and all the more
impressive in comparison.

Sincerely,
-- Douglas
-- 
http://mail.python.org/mailman/listinfo/python-list


Debugger - fails to continue with breakpoint set

2010-09-15 Thread Ed Greenberg
I'm pretty new to Python, but I am really enjoying it as an alternative 
to Perl and PHP.


When I run the debugger [import pdb; pdb.set_trace()] and then do next 
and step, and evaluate variables, etc, when I hit 'c' for continue, we 
go to the end, just fine.


As soon as I set a breakpoint down the line, [b line number] the 
behavior of 'c' changes. Instead of continuing until the breakpoint, or 
until the end, if the breakpoint is hidden by a conditional, the 
debugger starts to treat 'c' as a step (or a next, I'm not sure which.)


This behavior is repeatable and consistent.

I see this in python 2.6.4 on Ubuntu 9.10 and also in 2.5.2 on Ubuntu 
8.04 (Hardy), both using the installed packages.


I must be missing something. Assistance will be welcome.

Thanks,

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


socket.error: [Errno 98] Address already in use

2010-09-15 Thread cerr
Hi There,

I get a socket error [Errno 98] Address already in use when i try to
open a socket that got closed before with close(). How come close()
doesn't close the socket properly?
My socket code :

  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s.bind((host, port))
  s.listen(1)
...
...
...
  while loop:
conn, addr = s.accept()
while conn and loop:
...
...
...
  conn.close()

Shouldn't that clean it all up properly?

Thanks for hints  suggestions!
Ron
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket.error: [Errno 98] Address already in use

2010-09-15 Thread Thomas Jollans
On Wednesday 15 September 2010, it occurred to cerr to exclaim:
 Hi There,
 
 I get a socket error [Errno 98] Address already in use when i try to
 open a socket that got closed before with close(). How come close()
 doesn't close the socket properly?
 My socket code :
 
   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.bind((host, port))
   s.listen(1)
 ...
 ...
 ...
   while loop:
 conn, addr = s.accept()
 while conn and loop:
 ...
 ...
 ...
 conn.close()
 
 Shouldn't that clean it all up properly?

`s` is still listening?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: distutils, cygwin, 'not a regular file'

2010-09-15 Thread Thomas Jollans
On Wednesday 15 September 2010, it occurred to Paul Watson to exclaim:
 So, what is not a regular file about this?  Is there any way to find out
 which files are being considered irregular?

Regular files are the kind of files used to store bytes. Other kinds of files 
you might find in a file system include:

directories
symbolic links
pipes (FIFOs)
sockets (UNIX/LOCAL domain)
character devices
block devices

Also, for help on interpreting the message at hand, see Lawrence d'Oliveiro's 
response.

 
 $ uname -a
 CYGWIN_NT-6.0-WOW64 pwatson 1.7.7(0.230/5/3) 2010-08-31 09:58 i686 Cygwin
 
 $ cat setup.py
 
 from distutils.core import setup
 
 setup(
  name='xlsexport',
  version='0.3',
 
  py_modules=['xlsexport']
  )
 20:47 pwatson [ pwatson:/cygdrive/c/Users/pwatson/bin/xlsexport] 12
 $ python setup.py sdist
 running sdist
 warning: sdist: missing required meta-data: url
 warning: sdist: missing meta-data: either (author and author_email) or
 (maintainer and maintainer_email) must be supplied
 reading manifest file 'MANIFEST'
 creating xlsexport-0.3
 making hard links in xlsexport-0.3...
 ' not a regular file -- skipping
 ' not a regular file -- skipping
 ' not a regular file -- skipping
 tar -cf dist/xlsexport-0.3.tar xlsexport-0.3
 gzip -f9 dist/xlsexport-0.3.tar
 removing 'xlsexport-0.3' (and everything under it)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cross Compiling Python for ARM

2010-09-15 Thread Hans Mulder

Thomas Jollans wrote:

On Tuesday 14 September 2010, it occurred to Neil Benn to exclaim:

#
./python

-sh: ./python: not found



I'm guessing either there is no file ./python, or /bin/sh is fundamentally 
broken.


 or ./python is a symlink to a file that does not exist, or ./python
is a script and the shebang line points to an interpreter that does not
exist.

The most popular way to get the latter problem is to write the script
on a Windows box and then upload it to Unix box using FTP in binary
mode (or some other transport that doesn't adjust the line endings).

Try the command file ./python.  If it reports something like:

./python: a /usr/bin/python\015 script text executable

, then the \015 tells you that you need to use dos2unix.

It may be the case that /bin/sh is fundamentally broken if it reports
./python: file not found if the problem is really the shebang line.
Unfortunately, some shells are fundamentally broken this way.


Hope this helps,

-- HansM

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


Re: socket.error: [Errno 98] Address already in use

2010-09-15 Thread Grant Edwards
On 2010-09-15, cerr ron.egg...@gmail.com wrote:

 I get a socket error [Errno 98] Address already in use when i try to
 open a socket that got closed before with close(). How come close()
 doesn't close the socket properly?
 My socket code :

   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.bind((host, port))
   s.listen(1)
 ...
 ...
 ...
   while loop:
 conn, addr = s.accept()
 while conn and loop:
 ...
 ...
 ...
 conn.close()

At what line does the error occur?

To what does the phrase open a socket refer?

Have you tried the usual solution of setting the SO_REUSEADDR option
on the socket before calling bind?

http://www.google.com/search?q=socket+%27address+already+in+use%27

-- 
Grant Edwards   grant.b.edwardsYow! I own seven-eighths of
  at   all the artists in downtown
  gmail.comBurbank!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Debugger - fails to continue with breakpoint set

2010-09-15 Thread Thomas Jollans
On Wednesday 15 September 2010, it occurred to Ed Greenberg to exclaim:
 I'm pretty new to Python, but I am really enjoying it as an alternative
 to Perl and PHP.
 
 When I run the debugger [import pdb; pdb.set_trace()] and then do next
 and step, and evaluate variables, etc, when I hit 'c' for continue, we
 go to the end, just fine.
 
 As soon as I set a breakpoint down the line, [b line number] the
 behavior of 'c' changes. Instead of continuing until the breakpoint, or
 until the end, if the breakpoint is hidden by a conditional, the
 debugger starts to treat 'c' as a step (or a next, I'm not sure which.)
 
 This behavior is repeatable and consistent.
 
 I see this in python 2.6.4 on Ubuntu 9.10 and also in 2.5.2 on Ubuntu
 8.04 (Hardy), both using the installed packages.
 
 I must be missing something. Assistance will be welcome.

I can't reproduce this. Please post a small script and debugger session 
transcript that illustrate the problem clearly.

Maybe, on the way, you'll discover something you'd been missing. Maybe someone 
here will be able to help you then (maybe someone is now, but not me...). 
Maybe it's a bug (which it would be, if it behaves as you describe, but as I 
said, it appears to work for me).
-- 
http://mail.python.org/mailman/listinfo/python-list


Multiprocessing Queue strange behavior

2010-09-15 Thread Bruno Oliveira
Hi list,

I recently found a bug in my company's code because of a strange behavior
using multiprocessing.Queue. The following code snippet:

from multiprocessing import Queue

queue = Queue()
queue.put('x')
print queue.get_nowait()

Fails with:

...
  File
E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py,
line 153, in getNoWait
return self.get(False)
  File
E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py,
line 129, in get
raise Empty
Queue.Empty

Strangely, changing this to:

queue = Queue()
queue.put('x')
time.sleep(0.1) # 
print queue.get_nowait()

Works as expected. Using the original snippet changing the import to
threading's Queue also works.

It seems like there's a bug in multiprocessing's Queue implementation.
Opinions?

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


Re: Multiprocessing Queue strange behavior

2010-09-15 Thread MRAB

On 15/09/2010 21:10, Bruno Oliveira wrote:

Hi list,

I recently found a bug in my company's code because of a strange
behavior using multiprocessing.Queue. The following code snippet:

from multiprocessing import Queue

queue = Queue()
queue.put('x')
print queue.get_nowait()
Fails with:

...
   File
E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py,
line 153, in getNoWait
 return self.get(False)
   File
E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py,
line 129, in get
 raise Empty
Queue.Empty

Strangely, changing this to:

queue = Queue()
queue.put('x')
time.sleep(0.1) # 
print queue.get_nowait()
Works as expected. Using the original snippet changing the import to
threading's Queue also works.

It seems like there's a bug in multiprocessing's Queue implementation.
Opinions?


I don't think it's a bug as such.

The purpose of the multiprocessing queue is to transfer data between
different processes, which don't have a shared address space (unlike
threads, which do).

The transfer involves passing the data between the processes via a
pipe. This is done in a background thread and takes some time to
complete, so the data won't appear immediately. It looks like it
doesn't matter that the putter and the getter happen to be in the same
process, possibly because no-one expected that someone would use a
multiprocessing queue within the same process like that, so it doesn't
check for a shortcut.
--
http://mail.python.org/mailman/listinfo/python-list


Please I need help!

2010-09-15 Thread Maria
 I urgently need money help!https://siteheart.com/js/chat/chat.html?
ent=9228hash=97b8aa4b4eec4801f941b0aa97cd2587ipcsid=842e10a5515ee7299638a546b6b2997f
Maria
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.normcase rationale?

2010-09-15 Thread Ben Finney
Chris Withers ch...@simplistix.co.uk writes:

 I'm curious as to why, with a file called Foo.txt
 os.path.normcase('FoO.txt') will return foo.txt rather than
 Foo.txt?

What kind of answer are you looking for?

A direct answer would be: it does that because on case-insensitive
filesystems, it doesn't matter what the case is, so there's no need for
anything more complex than all lowercase.

 Yes, I know the behaviour is documented

The docstring is fairly poor, IMO. You might want to submit a bug report
to improve it.

 but I'm wondering if anyone can remember the rationale for that
 behaviour?

I can't speak to that. Does the above answer seem sufficient?

-- 
 \ “I think there is a world market for maybe five computers.” |
  `\ —Thomas Watson, chairman of IBM, 1943 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: business date and calendar libraries?

2010-09-15 Thread Robert Kern

On 9/13/10 12:06 PM, Chris Withers wrote:

Hi All,

I'm wondering what libraries people would use to answer the following questions
relating to business days:

- on a naive level; what's give me the last business day (ie: skipping 
weekends)

- on a less-naive level; same question but taking into account public holidays

- on a horrific level; same question, but taking into account business days of a
particular market (NYSE, LSE, etc)


Quantlib has a fairly good (by which I mean, horrific) collection of these 
implemented in C++:



http://quantlib.svn.sourceforge.net/viewvc/quantlib/trunk/QuantLib/ql/time/calendars/

If you only need a few of these, it can be more straightforward to look at them 
and recode them rather than trying to build Quantlib and its wrappers. Most of 
them have some algorithmic component (e.g. weekends, easy recurring holidays) 
and some exceptional cases (e.g. the days NYSE was closed after 2001-09-11).


--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Numpy: Multiplying arrays of matrices

2010-09-15 Thread Robert Kern

On 9/15/10 11:36 AM, Colin J. Williams wrote:

On 14-Sep-10 19:54 PM, Gregory Ewing wrote:

Suppose I have two N+2 dimensional arrays, representing
N-d arrays of 2-d matrices. I want to perform matrix
multiplication between corresponding matrices in these
arrays.

I had thought that dot() might do this, but it appears
not, because e.g. applying it to two 3-d arrays gives
a 4-d array, not another 3-d array.

I'd also like to be able to find the inverse of each
matrix in one of these arrays, but again, inv() doesn't
do what I want -- it only works on 2-d arrays.

Any thoughts on how to achieve these things using numpy
functions?


There is a Matrix sub-class which permit you to do that sort of thimg.


No, it doesn't.

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Debugger - fails to continue with breakpoint set

2010-09-15 Thread Ed Greenberg

On 09/15/2010 02:04 PM, Thomas Jollans wrote:

On Wednesday 15 September 2010, it occurred to Ed Greenberg to exclaim:
   

I'm pretty new to Python, but I am really enjoying it as an alternative
to Perl and PHP.

When I run the debugger [import pdb; pdb.set_trace()] and then do next
and step, and evaluate variables, etc, when I hit 'c' for continue, we
go to the end, just fine.

As soon as I set a breakpoint down the line, [bline number] the
behavior of 'c' changes. Instead of continuing until the breakpoint, or
until the end, if the breakpoint is hidden by a conditional, the
debugger starts to treat 'c' as a step (or a next, I'm not sure which.)

This behavior is repeatable and consistent.

I see this in python 2.6.4 on Ubuntu 9.10 and also in 2.5.2 on Ubuntu
8.04 (Hardy), both using the installed packages.

I must be missing something. Assistance will be welcome.
 

I can't reproduce this. Please post a small script and debugger session
transcript that illustrate the problem clearly.

Maybe, on the way, you'll discover something you'd been missing. Maybe someone
here will be able to help you then (maybe someone is now, but not me...).
Maybe it's a bug (which it would be, if it behaves as you describe, but as I
said, it appears to work for me).
   


Here is my debugger session as requested.  Note that I set a breakpoint 
at line 7, but c still stops at lines 4, 5 and 6.  I hope somebody can 
explain this.

-
r...@cloud4:~# python --version
Python 2.6.4
r...@cloud4:~# python test.py
 /root/test.py(3)module()
- a=1
(Pdb) l
  1  #!/usr/bin/python
  2  import pdb;pdb.set_trace()
  3  -a=1
  4  b=2
  5  c=3
  6  d=4
  7  print a,b,c,d
  8
[EOF]
(Pdb) b 7
Breakpoint 1 at /root/test.py:7
(Pdb) c
 /root/test.py(4)module()
- b=2
(Pdb) c
 /root/test.py(5)module()
- c=3
(Pdb) c
 /root/test.py(6)module()
- d=4
(Pdb) c
 /root/test.py(7)module()
- print a,b,c,d
(Pdb) c
1 2 3 4
--Return--
 /root/test.py(7)module()-None
- print a,b,c,d
(Pdb) c
r...@cloud4:~#

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


Re: os.path.normcase rationale?

2010-09-15 Thread Gregory Ewing

Ben Finney wrote:

it doesn't matter what the case is, so there's no need for
anything more complex than all lowercase.


Also doing what was suggested would require looking at
what's in the file system, which would be a lot of bother
to go to for no good reason, and would fail for paths
that don't correspond to an existing file.

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


it doesn't work ;) [class recursive function]

2010-09-15 Thread Ethan Furman

I need some fresh eyes, or better brains, or both!

The expected debugging output is a list of names in alphabetical order 
from each node (there are about 90 of them);  what I am getting is this:


-- dbf.tables.Index.from_file('', r'aad13658_last_name_for_state.idx')

starting next_item call for root
-
open file 'aad13658_last_name_for_state.idx', mode 'rb' at 0x013BD458 
512 30

-
more nodes
CARNAHAN   1536
ENGLUND1024
HOLSTEIN   2048
MATTHEWS   2560
ROSENFELD  3072
TERWILLIGER3584
YAZZOLINO  4096

and then it stops.  I should get about nine of these sections, and I'm 
only getting one.


code snippet

class Index(object):
@classmethod
def from_file(cls, table, index_file):

def get_idx_records(data, length, howmany):
print get_idx_records: keylen - %d;  howmany - %d %\
   (length, howmany)
ptr = 0
current = 0
while current  howmany:
key = data[ptr:ptr+length].replace('\x00','')
rec = io.unpackLongInt(data[ptr+length:ptr+length+4],\
   bigendian=True)
yield key, rec
ptr += length + 4
current += 1

def next_item(idx_file, node_loc, keylen):
print idx_file, node_loc, keylen, '\n','-'
idx_file.seek(node_loc)
data_chunk = idx_file.read(512)
attributes = io.unpackShortInt(data_chunk[:2])
howmany = io.unpackShortInt(data_chunk[2:4])
if attributes in (2, 3):
print actual records
for key, rec in get_idx_records(data_chunk[12:512],\
keylen, howmany):
yield key, rec
else:
print more nodes
for ignore, next_node in \
   get_idx_records(data_chunk[12:512],\
   keylen, howmany):
print ignore, next_node
next_item(idx_file, next_node, keylen)


idx = object.__new__(cls)
#- idx.key = lambda rec: DoNotIndex
data = open(index_file, 'rb')
header = data.read(512)
rootnode = io.unpackLongInt(header[:4])
keylen = io.unpackShortInt(header[12:14])
idx.__doc__ = header[16:236].replace('\x00','')
for_expr = header[236:456].replace('\x00','')
if for_expr:
idx.__doc__ += ' for ' + for_expr.replace('=','==')
print starting next_item call for root
for rec in next_item(data, rootnode, keylen):
print rec

/code snippet

Any ideas appreciated!

~Ethan~


aad13658_last_name_for_state.idx
Description: Binary data
-- 
http://mail.python.org/mailman/listinfo/python-list


compiling python 3.1.2 with local readline fails to get readline - help!

2010-09-15 Thread gavino
I compiled readline 6.1 myself.

#  ./configure --prefix=/home/apps/python --disable-shared --with-
pymalloc --with-threads --with-pth --enable-big-digits --disable-ipv6
--enable-readline --with-readline=/home/apps/readline/lib/
#  make -j14


modules not installed:
readline   .

Python starts but no readline.

What is the proper configure flag to use a locally compiled readline?
I tried with and without --with-readline and with readline/ and
readline/lib as shown above.
thx for help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: it doesn't work ;) [class recursive function]

2010-09-15 Thread MRAB

On 16/09/2010 00:23, Ethan Furman wrote:

I need some fresh eyes, or better brains, or both!

The expected debugging output is a list of names in alphabetical order
from each node (there are about 90 of them); what I am getting is this:

-- dbf.tables.Index.from_file('', r'aad13658_last_name_for_state.idx')

starting next_item call for root
-
open file 'aad13658_last_name_for_state.idx', mode 'rb' at 0x013BD458
512 30
-
more nodes
CARNAHAN 1536
ENGLUND 1024
HOLSTEIN 2048
MATTHEWS 2560
ROSENFELD 3072
TERWILLIGER 3584
YAZZOLINO 4096

and then it stops. I should get about nine of these sections, and I'm
only getting one.

code snippet


[snip code]


/code snippet

Any ideas appreciated!


'next_item' is a generator, but it's just calling itself and discarding
the result. I think it should be yielding the results to its caller.
That fix gives me 7 sections in total.
--
http://mail.python.org/mailman/listinfo/python-list


Re: compiling python 3.1.2 with local readline fails to get readline - help!

2010-09-15 Thread James Mills
On Thu, Sep 16, 2010 at 9:58 AM, gavino gavcom...@gmail.com wrote:
 I compiled readline 6.1 myself.

 #  ./configure --prefix=/home/apps/python --disable-shared --with-
 pymalloc --with-threads --with-pth --enable-big-digits --disable-ipv6
 --enable-readline --with-readline=/home/apps/readline/lib/
 #  make -j14
 
 
 modules not installed:
     readline   .

 Python starts but no readline.

 What is the proper configure flag to use a locally compiled readline?
 I tried with and without --with-readline and with readline/ and
 readline/lib as shown above.
 thx for help

AFAIK, there are no readline specific options in python 2.x's
./configure options:

# pwd
/usr/ports/opt/python/Python-2.6.5
# ./configure --help | grep readline -i
#

I could be wrong... Are you sure you've configured and compile
readline correctly and that you've set the appropriate environment
variables and paths for C/C++ compilers (eg: GCC) to pick it up ?

cheers
James

-- 
-- James Mills
--
-- Problems are solved by method
-- 
http://mail.python.org/mailman/listinfo/python-list


classes and dictionaries

2010-09-15 Thread Jason Swails
Hello everyone,

I'm encountering an issue in one of my Python classes that makes extensive
use of dictionaries.  I was under the impression that each time an object
was instantiated, all of its variables were created in a new section of
memory, so that if you change the value of the variable in one instance, it
left that variable's value in another instance alone.  In the object that I
wrote, I have 3 different dictionaries: parm_data, pointers, and formats,
all defined in the same place.  When I load 2 instances of this object,
parm_data and formats each take on different values between the two objects
(as they should), but for some reason pointers does not.  I've seen this
problem with python2.6.4 and 2.6.1 (and I believe earlier versions as well,
but I'm not sure).  I've attached a tarball with the relevant code and a
sample script that shows what I mean.

If anyone can tell me why the dictionary from 2 different objects are
exactly the same for pointers, but are different for, e.g. parm_data and
formats, that would be greatly appreciated.

Thanks!
Jason

-- 
Jason M. Swails
Quantum Theory Project,
University of Florida
Ph.D. Graduate Student
352-392-4032


prmtop_test.tgz
Description: GNU Zip compressed data
-- 
http://mail.python.org/mailman/listinfo/python-list


program organization question for web development with python

2010-09-15 Thread Hans
Hi,

I'm new to this area. Please allow me to ask some (maybe stupid)
questions.

I'm planning to write a web application which used for searching my
mysql database.

1. files organization

I have this in my main.py:
print a href=display_tb.py?id=%stable=%scursor=%s%s/a %
(record[0],table_name,cursor_name,record1)

it kind of works but not comfortable to me.

Do I have to use two files(main.py and display_tb.py)? does that means
each hyper-link needs a single file? Can I put those files together
and then they can share variables,classes, modules, etc?

2. database cursor as parameter?
I created database cursor in my main.py and then I have to use it in
another file(display_tb.py), Can I?  I put cursor as a parameter and
try to send it through hyper-link. but it somehow does not work.
error log listed below:

 /usr/lib/cgi-bin/display_tb.py in ()
   20 sql_str = SELECT * FROM %s  % search_str_list
   21 print p%s/p % sql_str
   22 cursor_ptr.execute(sql_str)
   23 result = cursor_ptr.fetchall()
   24
cursor_ptr = 'MySQLdb.cursors.Cursor object at 0xb786b36c',
cursor_ptr.execute undefined, sql_str = 'SELECT * FROM env_test where
id=20 '

type 'exceptions.AttributeError': 'str' object has no attribute
'execute'
  args = ('str' object has no attribute 'execute',)
  message = 'str' object has no attribute 'execute'

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


work opportunity

2010-09-15 Thread Health Coach
FREE to Join !
You get up to 35% cashback for every qualified purchase you make on
the site. On any personal referrals, you'll also make 1/2% on their
qualifying purchases!
*
www.ma360eMall.com
Everything you need and want
Get paid to shop with Cashback up to 35%
Many more hot deals
ma360em...@gmail.com
**

http://w.mawebcenters.com/ma360emall/
http://motivescosmetics.marketamerica.com/MA360EMALL/
http://isotonix.marketamerica.com/MA360EMALL/USA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classes and dictionaries

2010-09-15 Thread James Mills
On Thu, Sep 16, 2010 at 10:13 AM, Jason Swails jason.swa...@gmail.com wrote:
 Hello everyone,

 I'm encountering an issue in one of my Python classes that makes extensive
 use of dictionaries.  I was under the impression that each time an object
 was instantiated, all of its variables were created in a new section of
 memory, so that if you change the value of the variable in one instance, it
 left that variable's value in another instance alone.  In the object that I
 wrote, I have 3 different dictionaries: parm_data, pointers, and formats,
 all defined in the same place.  When I load 2 instances of this object,
 parm_data and formats each take on different values between the two objects
 (as they should), but for some reason pointers does not.  I've seen this
 problem with python2.6.4 and 2.6.1 (and I believe earlier versions as well,
 but I'm not sure).  I've attached a tarball with the relevant code and a
 sample script that shows what I mean.

 If anyone can tell me why the dictionary from 2 different objects are
 exactly the same for pointers, but are different for, e.g. parm_data and
 formats, that would be greatly appreciated.

In short (without creating a huge thread of unnecessary chatter), if
you reference an object in 2 different dictionaries,
the values (dictionary values) will be identical.

The following example might help you understand this.

 class Foo(object):
...def __init__(self, data=None):
...   self.data = {params: data}
...
 a = b = object()
 id(a), id(b)
(3075279112L, 3075279112L)
 foo = Foo(a)
 bar = Foo(b)
 foo.data, bar.data
({'params': object object at 0xb74d0908}, {'params': object object
at 0xb74d0908})
 id(foo.data[params]), id(bar.data[params])
(3075279112L, 3075279112L)


cheers
James

-- 
-- James Mills
--
-- Problems are solved by method
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: program organization question for web development with python

2010-09-15 Thread James Mills
On Thu, Sep 16, 2010 at 10:14 AM, Hans hans...@gmail.com wrote:
 I'm new to this area. Please allow me to ask some (maybe stupid)
 questions.

Without reading the rest of your post too much. Designs are up to you,
I can't comment.

I can only share in a fairly common view, and that is, we'd encourage
you to use a web framework
as opposed to plain old CGI.

cheers
james

-- 
-- James Mills
--
-- Problems are solved by method
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classes and dictionaries

2010-09-15 Thread MRAB

On 16/09/2010 01:13, Jason Swails wrote:

Hello everyone,

I'm encountering an issue in one of my Python classes that makes
extensive use of dictionaries.  I was under the impression that each
time an object was instantiated, all of its variables were created in a
new section of memory, so that if you change the value of the variable
in one instance, it left that variable's value in another instance
alone.  In the object that I wrote, I have 3 different dictionaries:
parm_data, pointers, and formats, all defined in the same place.  When I
load 2 instances of this object, parm_data and formats each take on
different values between the two objects (as they should), but for some
reason pointers does not.  I've seen this problem with python2.6.4 and
2.6.1 (and I believe earlier versions as well, but I'm not sure).  I've
attached a tarball with the relevant code and a sample script that shows
what I mean.

If anyone can tell me why the dictionary from 2 different objects are
exactly the same for pointers, but are different for, e.g. parm_data and
formats, that would be greatly appreciated.


When you bind to a name in the class namespace:

class Example:
 foo = class attribute

the name is an attribute of the class.

If you want a name to be an attribute of an instance then you should
refer to the instance explicitly:

class Example:
def __init__(self):
self.bar = instance attribute
--
http://mail.python.org/mailman/listinfo/python-list


Re: socket.error: [Errno 98] Address already in use

2010-09-15 Thread jipalaciosort...@gmail.com
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
 
El 15/09/2010 20:58, Grant Edwards escribió:
 On 2010-09-15, cerr ron.egg...@gmail.com wrote:

 I get a socket error [Errno 98] Address already in use when i
 try to open a socket that got closed before with close(). How
 come close() doesn't close the socket properly? My socket code :

 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.bind((host, port)) s.listen(1) ... ... ... while loop: conn,
 addr = s.accept() while conn and loop: ... ... ... conn.close()

 At what line does the error occur?

 To what does the phrase open a socket refer?

 Have you tried the usual solution of setting the SO_REUSEADDR
 option on the socket before calling bind?

 http://www.google.com/search?q=socket+%27address+already+in+use%27

Maybe, you have any other proccess in your system using your listen
port, for example apache...

- -- 
   _ _ _   _   _ _ _ _   _ _ _
Jose Ignacio Palacios Ortega  /_   _/ / / /  _   / / _   /
Telf: +34 637 058 813   / /  / / / /_ / / / / / /
Correo-e: jipalaciosort...@gmail.com  _/ /  / / / _ _ _/ / / / /
Msn: jipalaciosort...@gmail.com  / /_ / /  / / / /  / /_/ /
ID firma PGP: 0x0EB87E48 \ _ _ /  /_/ /_/  /_ _ _/
Huella PGP:61CC 5DA0 827B C3AB F83C 2A55 78AF B317 0EB8 7E48
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
iEYEARECAAYFAkyRafgACgkQeK+zFw64fkjH2wCffe4v8ho2z4d8LWaPaiJRu0OZ
4cgAniOoR70hu7UylkpgAr3JI5hxNXYP
=MoYK
-END PGP SIGNATURE-

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


Re: compiling python 3.1.2 with local readline fails to get readline - help!

2010-09-15 Thread gavino
On Sep 15, 5:12 pm, James Mills prolo...@shortcircuit.net.au wrote:
 On Thu, Sep 16, 2010 at 9:58 AM, gavino gavcom...@gmail.com wrote:
  I compiled readline 6.1 myself.

  #  ./configure --prefix=/home/apps/python --disable-shared --with-
  pymalloc --with-threads --with-pth --enable-big-digits --disable-ipv6
  --enable-readline --with-readline=/home/apps/readline/lib/
  #  make -j14
  
  
  modules not installed:
      readline   .

  Python starts but no readline.

  What is the proper configure flag to use a locally compiled readline?
  I tried with and without --with-readline and with readline/ and
  readline/lib as shown above.
  thx for help

 AFAIK, there are no readline specific options in python 2.x's
 ./configure options:

 # pwd
 /usr/ports/opt/python/Python-2.6.5
 # ./configure --help | grep readline -i
 #

 I could be wrong... Are you sure you've configured and compile
 readline correctly and that you've set the appropriate environment
 variables and paths for C/C++ compilers (eg: GCC) to pick it up ?

 cheers
 James

 --
 -- James Mills
 --
 -- Problems are solved by method

I am comiling 3.1.2.
I am not root but a user.
I compiled readline and it did not complain.
gdb and zlib  and some other modules also were not found.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] problem with python 3.1

2010-09-15 Thread James Mills
(Posting to python general discussion).

On Thu, Sep 16, 2010 at 10:17 AM, João Vitor john...@hotmail.com wrote:
 I made a program that, according to my teacher, is correct but is not
 running properly.
 The program is really simple:
 import math
 x = input (Coloque o valor do primeiro cateto:)
 y = input (Coloque o valor do segundo cateto:)
 z = x**2
 w = y**2
 soma = z + w
 h = math.sqrt (soma)
 print = O valor da hipotenusa é:, h
 But after I put the value of x and y this error appears:
 Traceback (most recent call last):
   File C:/lista03.py, line 4, in module
     z = x**2
 TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
 My teacher said the program ran normally in his computer, but in my it
 doesn't!
 why?

You're teacher has clearly overlooked that you must convert the values
of x and y to
int's using either:

x = int(input(...))

or

x = int(x)

You cannot perform (most) mathematical operators where the operands
are of different types (in Python)
eg: str and int

cheers
James

PS: Please post questions like this to either the tutor or general
python mailing list(s).

-- 
-- James Mills
--
-- Problems are solved by method
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compiling python 3.1.2 with local readline fails to get readline - help!

2010-09-15 Thread James Mills
On Thu, Sep 16, 2010 at 11:10 AM, gavino gavcom...@gmail.com wrote:
 I am comiling 3.1.2.
 I am not root but a user.
 I compiled readline and it did not complain.
 gdb and zlib  and some other modules also were not found.

Like I said earlier in my previous post, is the readline line that
you compiled and installed to your home directory actually
working and can you actually compile any C programs that
use this custom readline ?

cheers
James


-- 
-- James Mills
--
-- Problems are solved by method
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WMI in Python

2010-09-15 Thread alex23
KING LABS kinglabs...@gmail.com wrote:
 The following information is exactly what I am trying to collect for
 the inventory. I can find vb scripts with googling. I want to do the
 same with Python  Win32. Use Server/Client architecture .
 Client(agent) updates the information to server.

I highly agree with the recommendations for Tim Golden's WMI library.
I once used it during an MS VBScript course for sys admins to produce
python equivalents of the VBS code; it was far, _far_ easier to
componentise  reuse python code than VBS.

However, for a quick  ready solution, have you looked at Microsoft's
Scriptomatic?[2] It's a handy little tool that lets you specify the
WMI query you want and produces code for you, with Python being one of
the targets. It _should_ be able to handle most of everything you're
after, with the exception of Software Information (from memory that's
not something WMI covers?).

Once Scriptomatic has generated the bulk of the WMI code, that's the
payload of your client-side script. There are many many many ways of
doing simple client/server set ups in python, just google and pick one
that works at a suitable abstraction level for you. Here's a
straightforward sockets-based approach[3] (that I've never used but
looks okay).

1: http://timgolden.me.uk/python/wmi/index.html
2: 
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178displaylang=en
3: http://wdvl.internet.com/Authoring/python/client/watts06152009.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing windoze file attributes

2010-09-15 Thread Lawrence D'Oliveiro
In message
a3cb644c-ea77-484a-9509-bf6fea9e9...@q18g2000vbm.googlegroups.com, Douglas 
wrote:

 Why reinvent rsync?
 In what way is rsync relevant to the stated problem? Did you actually
 READ the question?

Yes.

 Note: I use Linux at home (yes, even rsync) and very much prefer it to
 Windows. However, at work I have no choice but to use the resources
 the company provides - which is Windows; have you got that straight
 now?

Doesn’t change the fact that you’re reinventing rsync.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WMI in Python

2010-09-15 Thread Lawrence D'Oliveiro
In message
d8d3a07f-118c-4f8b-a6fc-f6f8762c9...@x18g2000pro.googlegroups.com, alex23 
wrote:

 However, for a quick  ready solution, have you looked at Microsoft's
 Scriptomatic?[2] It's a handy little tool that lets you specify the
 WMI query you want and produces code for you, with Python being one of
 the targets.

Why not just call Scriptomatic directly from within the Python script, then? 
Machine-generated code has no place in a source file to be maintained by a 
human.
-- 
http://mail.python.org/mailman/listinfo/python-list


How do you preserve time values with date.datefromtimestamp()

2010-09-15 Thread Rodrick Brown
I'm doing something like

 today = datetime.date.fromtimestamp(1284584357.241863)
 today.ctime()
'Wed Sep 15 00:00:00 2010'

Why isn't the time field being populated what I expect is to see something
like Wed Sep 15 2010 16:59:17:241863

-- 
[ Rodrick R. Brown ]
http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown
-- 
http://mail.python.org/mailman/listinfo/python-list


Argparse: add_argument with action=append appends to default

2010-09-15 Thread John O'Hagan
I find this surprising:

 import argparse
 parser = argparse.ArgumentParser()
 parser.add_argument('--test', action='append', default=['default'])
[...]
 parser.parse_args(['--test', 'arg'])
Namespace(test=['default', 'arg'])

As an argument is provided, I didn't expect to see the default in there as 
well. From the argparse docs: the default value is used when the option 
string was not present at the command line. While it doesn't say _only_ 
when..., that's what I would have expected. 

Is there a reason for this behaviour? Is there a way to do what I want, to get 
a list of appended options _or_ a default list (apart from setting defaults 
outside the parser, a good way to lose track of things)?

Thanks,

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


Re: How do you preserve time values with date.datefromtimestamp()

2010-09-15 Thread Cameron Simpson
On 15Sep2010 22:31, Rodrick Brown rodrick.br...@gmail.com wrote:
| I'm doing something like
| 
|  today = datetime.date.fromtimestamp(1284584357.241863)
|  today.ctime()
| 'Wed Sep 15 00:00:00 2010'
| 
| Why isn't the time field being populated what I expect is to see something
| like Wed Sep 15 2010 16:59:17:241863

Because you asked for a date. A date only has day resolution.
It's like going:

  i = int(1.234)

which quite legitimately results in 1 (the interger, not a string).

You want a datetime, thus:

   today = datetime.datetime.fromtimestamp(1284584357.241863)  
   today
  datetime.datetime(2010, 9, 16, 6, 59, 17, 241863)
   today.ctime()
  'Thu Sep 16 06:59:17 2010'

Note that .ctime() is a specific historic time reporting format of very
limited utility - you're a lot better off not considering it as a
storage value or as a value to print, unless you actually need to work
in the domains where it is used.

Cheers,
-- 
Cameron Simpson c...@zip.com.au DoD#743
http://www.cskk.ezoshosting.com/cs/

Tiggers don't like honey.   - A.A.Milne, The House at Pooh Corner
-- 
http://mail.python.org/mailman/listinfo/python-list


select() call and filedescriptor out of range in select error

2010-09-15 Thread k3xji
Hi all,

We have a select-based server written in Python. Occasionally, maybe
twice a month there occurs a weird problem, select() returns with
filedescriptor out of range in select() error. This is of course a
normal error and handled gracefully. Our policy is to take down few
users for select() to handle the next cycle. However, once this error
occurs, this also fails too:

self.__Sockets.remove(socket)

self.__Socket's is the very basic list of sockets we use in our IO
loop. The call fails with:
remove(x): x not in list

First of all, in our entire application there is no line of code like
remove(x), meaning there is no x variable. Second, the Exception shows
the line number containing above code. So
self.__Sockets.remove(socket) this fails with remove(x): x not in
list

I cannot understand the problem. It happens in sporadic manner and it
feels that the ValueError of select() call somehow corrupts the List
structure itself in Python? Not sure if something like that is
possible.

Thanks in advance,
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Numpy: Multiplying arrays of matrices

2010-09-15 Thread Carl Banks
On Sep 14, 4:54 pm, Gregory Ewing greg.ew...@canterbury.ac.nz wrote:
 Suppose I have two N+2 dimensional arrays, representing
 N-d arrays of 2-d matrices. I want to perform matrix
 multiplication between corresponding matrices in these
 arrays.

 I had thought that dot() might do this, but it appears
 not, because e.g. applying it to two 3-d arrays gives
 a 4-d array, not another 3-d array.

 I'd also like to be able to find the inverse of each
 matrix in one of these arrays, but again, inv() doesn't
 do what I want -- it only works on 2-d arrays.

 Any thoughts on how to achieve these things using numpy
 functions?

I find for situations like this the best thing I can do is hand code
the bounded operation and use the slicing to handle the arbitrarily
large stuff with slicing.

So,

r[:,:,1,1] = a[:,:,1,1]*b[:,:,1,1] + a[:,:,2,1]*b[:,:,1,2]
r[:,:,1,2] = a[:,:,1,2]*b[:,:,1,1] + a[:,:,2,2]*b[:,:,1,2]
etc.


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


Re: help with calling a static method in a private class

2010-09-15 Thread Steven D'Aprano
On Tue, 14 Sep 2010 16:38:50 +0200, Diez B. Roggisch wrote:


 And additionally, but simply not using staticmethods at all. It's a
 rather obscure feature of python - usually, classmethods are what is
 considered a static method in other languages. 

Are you sure about that? I know Java isn't necessarily other languages, 
but my understanding is that static methods in Java are the same as 
static methods in Python -- they're essentially ordinary functions glued 
to a class, and they don't receive either the instance or the class as an 
argument.

http://leepoint.net/notes-java/flow/methods/50static-methods.html


(Aside: I don't know about others, but I find that article *incredibly* 
hard to read. E.g. 

Static methods typically take all they data from 
parameters and compute something from those parameters, 
with no reference to variables.

What, parameters aren't variables? What about local variables? I know 
what they *mean*, but it causes a double-take every time I read it. And 
when they distinguish between *classes* and *objects*, that's another 
double-take, because of course in Python classes are objects.)


C# seems to be the same:

http://dotnetperls.com/static-method

as is C++ (I believe), except I'm too lazy to find a good reference.


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


Re: select() call and filedescriptor out of range in select error

2010-09-15 Thread Ned Deily
In article 
bafd7b25-8a4a-4ef9-b839-adc42b62d...@i17g2000vbq.googlegroups.com,
 k3xji sum...@gmail.com wrote:
 We have a select-based server written in Python. Occasionally, maybe
 twice a month there occurs a weird problem, select() returns with
 filedescriptor out of range in select() error. This is of course a
 normal error and handled gracefully. Our policy is to take down few
 users for select() to handle the next cycle. However, once this error
 occurs, this also fails too:
 
 self.__Sockets.remove(socket)
 
 self.__Socket's is the very basic list of sockets we use in our IO
 loop. The call fails with:
 remove(x): x not in list
 
 First of all, in our entire application there is no line of code like
 remove(x), meaning there is no x variable. Second, the Exception shows
 the line number containing above code. So
 self.__Sockets.remove(socket) this fails with remove(x): x not in
 list
 
 I cannot understand the problem. It happens in sporadic manner and it
 feels that the ValueError of select() call somehow corrupts the List
 structure itself in Python? Not sure if something like that is
 possible.

That error message is a generic exception message.  It just means the 
object to be removed is not in the list.  For example:

 l = [a, b]
 a, b = 1, 2
 l = [a, b]
 l.remove(a)
 l.remove(a)
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: list.remove(x): x not in list

If the problem is that the socket object in question no longer exists, 
you can protect your code there by enclosing the remove operation in a 
try block, like:

try:
self.__Sockets.remove(socket)
except ValueError:
pass

-- 
 Ned Deily,
 n...@acm.org

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


Re: select() call and filedescriptor out of range in select error

2010-09-15 Thread Steven D'Aprano
On Wed, 15 Sep 2010 21:05:49 -0700, k3xji wrote:

 Hi all,
 
 We have a select-based server written in Python. Occasionally, maybe
 twice a month there occurs a weird problem, select() returns with
 filedescriptor out of range in select() error. This is of course a
 normal error and handled gracefully. Our policy is to take down few
 users for select() to handle the next cycle. However, once this error
 occurs, this also fails too:
 
 self.__Sockets.remove(socket)
 
 self.__Socket's is the very basic list of sockets we use in our IO loop.
 The call fails with:
 remove(x): x not in list


Please show the *exact* error message, including the traceback, by 
copying and pasting it. Do not retype it by hand, or summarize it, or put 
it into your own words.


 
 First of all, in our entire application there is no line of code like
 remove(x), meaning there is no x variable. 

Look at this example:

 sockets = []
 sockets.remove(Hello world)
Traceback (most recent call last):
  File stdin, line 1, in module
ValueError: list.remove(x): x not in list


x is just a placeholder. It doesn't refer to an actual variable x.


 Second, the Exception shows
 the line number containing above code. So self.__Sockets.remove(socket)
 this fails with remove(x): x not in list

Exactly.


 
 I cannot understand the problem. It happens in sporadic manner and it
 feels that the ValueError of select() call somehow corrupts the List
 structure itself in Python? Not sure if something like that is possible.

Anything is possible, but it's not likely. What's far more likely is that 
you have a bug in your code, and that somehow, under rare circumstances, 
it tries to remove something from a list that was never inserted into the 
list. Or it tries to remove it twice.

My guess is something like this:

try:
socket = get_socket()
self._sockets.append(socket)
except SomeError:
pass
# later on
self._sockets.remove(socket)




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


Re: select() call and filedescriptor out of range in select error

2010-09-15 Thread James Mills
On Thu, Sep 16, 2010 at 2:49 PM, Ned Deily n...@acm.org wrote:
 If the problem is that the socket object in question no longer exists,
 you can protect your code there by enclosing the remove operation in a
 try block, like:


The question that remains to be seen however is:

Why does your list contain dirty data ? Your code has likely removed
the socket object from the list before, why is it attempting to remove
it again ?

I would consider you re-look at your code's logic rather than patch
up the code with a band-aid-solution.

cheers
James


-- 
-- James Mills
--
-- Problems are solved by method
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue9315] The trace module lacks unit tests

2010-09-15 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 It looks like 3.1 with computed gotos produces the yet another different 
 tracing of list comprehensions:
 
 
 2: l = [i for
10:  i in
 1:  range(10)]

Well, this kind of thing is going to depend on the exact bytecode, the
way the evaluation loop is written, etc. That's why I would suggest
checking that the number of traced iterations is between, e.g. 10 (since
it's the number of loop iterations) and 15 (to account for any
additional iterations due to various inner jumps in the bytecode.

--

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



[issue9759] GzipFile object should raise ValueError on .read() after .close()

2010-09-15 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

You should make sure that all operations (except close() itself) raise 
ValueError. Currently:

 f = gzip.open(test.gz, rb)
 f.close()
 f.read()
b''
 f.seek(0)
0

Also, you don't have to post a patch for 2.7. We'll do the porting ourselves.
Thanks for contributing!

--
stage: needs patch - patch review

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



[issue9315] The trace module lacks unit tests

2010-09-15 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
Removed message: http://bugs.python.org/msg116438

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



[issue9858] RawIOBase doesn't define readinto

2010-09-15 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +benjamin.peterson, stutzbach

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



[issue9857] SkipTest in tearDown is reported an as an error

2010-09-15 Thread Michael Foord

Michael Foord mich...@voidspace.org.uk added the comment:

Interesting use case.

If the test has not yet failed this is fine. The problem is that if an 
exception has *already* been raised then it will already have been added to the 
result - so by then skipping is meaningless (or contradictory - the test can 
fail *and* skip).

--

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



[issue9858] RawIOBase doesn't define readinto

2010-09-15 Thread Benjamin Peterson

Benjamin Peterson benja...@python.org added the comment:

+1 for a failing one. (Does the base implementation not raise?)

Is it even possible to implement a real one without buffering?

--

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



[issue9858] RawIOBase doesn't define readinto

2010-09-15 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 +1 for a failing one. (Does the base implementation not raise?)

The base implementation doesn't exist :)

 Is it even possible to implement a real one without buffering?

FileIO does. It's the same as read(), except that you read into an existing 
buffer rather than allocating a new bytes object.

--

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



[issue9858] Python and C implementations of io are out of sync

2010-09-15 Thread Daniel Stutzbach

Daniel Stutzbach dan...@stutzbachenterprises.com added the comment:

Attached is a script to find all of the mismatches between the C and Python 
implementations.  There are several.  Below is the output:

RawIOBase C is missing: ['readinto', 'write']
StringIO C is missing: ['name']
StringIO python is missing: ['__getstate__', '__setstate__']
BufferedRandom python is missing: ['raw']
BlockingIOError python is missing: ['characters_written']
TextIOWrapper python is missing: ['buffer']
BufferedReader python is missing: ['raw']
BufferedWriter python is missing: ['raw']
BytesIO python is missing: ['__setstate__']

Since the Python version was the original reference implementation, adding the 
attributes missing from the C side seems to be a straightforward decision (and 
it should simply match whatever the Python version does).  It looks like a 
number of new attributes have creeped into the C side, which will require more 
thoughtful decision making.

We should probably double-check that each of these is documented, while we're 
at it.

--
priority: low - normal
resolution:  - accepted
title: RawIOBase doesn't define readinto - Python and C implementations of io 
are out of sync
Added file: http://bugs.python.org/file18889/missing_methods.py

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



[issue9859] Add tests to verify API match of modules with 2 implementations

2010-09-15 Thread Daniel Stutzbach

New submission from Daniel Stutzbach dan...@stutzbachenterprises.com:

Recently it came to light that the classes in C and Python implementations of 
the io module have slightly different attributes (issue9858).  I propose the 
addition of a helper function in Lib/test/support.py to verify that the classes 
in two different implementations define the same attributes.  Then, we can add 
tests to use that function to verify that C and Python implementations define 
the same API (for the io module, but also for other modules where we have two 
implementations).  The script I added to issue9858 could serve as a starting 
point for such a function.

Since CPython's standard library is the de facto reference implementation, it's 
important that it define one API and not two slightly different ones. :-)

--
components: Tests
messages: 116445
nosy: stutzbach
priority: low
severity: normal
stage: needs patch
status: open
title: Add tests to verify API match of modules with 2 implementations
type: feature request
versions: Python 3.2

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



[issue9858] Python and C implementations of io are out of sync

2010-09-15 Thread Daniel Stutzbach

Daniel Stutzbach dan...@stutzbachenterprises.com added the comment:

FWIW, I just opened Issue9859: Add tests to verify API match of modules with 2 
implementations.

--

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



[issue9851] multiprocessing socket timeout will break client

2010-09-15 Thread Jesse Noller

Jesse Noller jnol...@gmail.com added the comment:

Calling it stupid doesn't incentivize me to help you, or fix it.

--

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



[issue9857] SkipTest in tearDown is reported an as an error

2010-09-15 Thread Raghuram Devarakonda

Changes by Raghuram Devarakonda draghu...@gmail.com:


--
nosy: +draghuram

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



[issue9860] Building python outside of source directory fails

2010-09-15 Thread Alexander Belopolsky

New submission from Alexander Belopolsky belopol...@users.sourceforge.net:

When testing config options, it is often useful to build python in a directory 
different from the root of the source tree.  This is supported by autoconf 
based builds as follows: you cd to the desired directory run configure with an 
explicit path. For example:

$ cd ../altdir
$ ../python-source/configure
$ make

However, this fails for python 3.1 and 3.2 with the following error:


i686-apple-darwin10-gcc-4.2.1: Parser/tokenizer_pgen.o: No such file or 
directory
i686-apple-darwin10-gcc-4.2.1: Parser/printgrammar.o: No such file or directory
i686-apple-darwin10-gcc-4.2.1: Parser/pgenmain.o: No such file or directory
make: *** [Parser/pgen] Error 1

--
assignee: belopolsky
components: Interpreter Core
messages: 116448
nosy: belopolsky
priority: normal
severity: normal
stage: needs patch
status: open
title: Building python outside of source directory fails
type: compile error
versions: Python 3.1, Python 3.2

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



[issue678264] test_resource fails when file size is limited

2010-09-15 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

The test does not fail if FSIZE is not max on linux/py3k, but max is still 
represented as -1 on linux.  So the reported bug is no longer valid, but 
Martin's concern has not been addressed.

--
nosy: +r.david.murray

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



[issue9861] subprocess module changed exposed attributes

2010-09-15 Thread paul clinch

New submission from paul clinch pcli...@internet-glue.co.uk:

Some attributes, e.g. STARTF_USESHOWWINDOW have moved to 
_subrocess.STARTF_USESHOWWINDOW. This breaks old code.

--
components: Library (Lib)
messages: 116450
nosy: pclinch
priority: normal
severity: normal
status: open
title: subprocess module changed exposed attributes
type: behavior
versions: Python 2.6

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



[issue9860] Building python outside of source directory fails

2010-09-15 Thread Alexander Belopolsky

Alexander Belopolsky belopol...@users.sourceforge.net added the comment:

I think the problem is with the following explicit rules in Makefile:


Parser/tokenizer_pgen.o:$(srcdir)/Parser/tokenizer.c

Parser/pgenmain.o:  $(srcdir)/Include/parsetok.h

It looks like these rules are not VPATH friendly.  Per Antoine's suggestions, 
adding build experts to the nosy list.

--
nosy: +dmalcolm, doko

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



[issue9859] Add tests to verify API match of modules with 2 implementations

2010-09-15 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

Shouldn't the test suite catch such discrepancies by testing all of the API?  
So your script catching something would be the equivalent of oops, we forgot a 
test (or oops, this name shouldn't be public).  Which is not a bad thing to 
have as part of the test suite.

--
nosy: +r.david.murray

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



[issue9859] Add tests to verify API match of modules with 2 implementations

2010-09-15 Thread Daniel Stutzbach

Daniel Stutzbach dan...@stutzbachenterprises.com added the comment:

Yes, exactly. :-)

(see also Issue9731, which has a similar flavor)

--

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



[issue9516] sysconfig: $MACOSX_DEPLOYMENT_TARGET mismatch: now 10.3 but 10.5 during configure

2010-09-15 Thread Stonewall Ballard

Stonewall Ballard ston...@gmail.com added the comment:

I just ran into this with Python 2.7, installed using port. I'm using python to 
process a text file in an Xcode 3.2 Script build step, and it's throwing the 
error because my Xcode target has a base sdk of 10.5.

--
nosy: +stoneyb

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



[issue9858] Python and C implementations of io are out of sync

2010-09-15 Thread Benjamin Peterson

Benjamin Peterson benja...@python.org added the comment:

2010/9/15 Daniel Stutzbach rep...@bugs.python.org:

 Daniel Stutzbach dan...@stutzbachenterprises.com added the comment:

 Attached is a script to find all of the mismatches between the C and Python 
 implementations.  There are several.  Below is the output:

 BufferedRandom python is missing: ['raw']
 TextIOWrapper python is missing: ['buffer']
 BufferedReader python is missing: ['raw']
 BufferedWriter python is missing: ['raw']

These attributes exist; they're just not properties.

--

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



  1   2   >