PyPy 1.8 released

2012-02-10 Thread Maciej Fijalkowski

PyPy 1.8 - business as usual


We're pleased to announce the 1.8 release of PyPy. As habitual this
release brings a lot of bugfixes, together with performance and memory
improvements over the 1.7 release. The main highlight of the release
is the introduction of `list strategies`_ which makes homogenous lists
more efficient both in terms of performance and memory. This release
also upgrades us from Python 2.7.1 compatibility to 2.7.2. Otherwise
it's business as usual in the sense that performance improved
roughly 10% on average since the previous release.

you can download the PyPy 1.8 release here:

http://pypy.org/download.html

.. _`list strategies`:
http://morepypy.blogspot.com/2011/10/more-compact-lists-with-list-strategies.html

What is PyPy?
=

PyPy is a very compliant Python interpreter, almost a drop-in replacement for
CPython 2.7. It's fast (`pypy 1.8 and cpython 2.7.1`_ performance comparison)
due to its integrated tracing JIT compiler.

This release supports x86 machines running Linux 32/64, Mac OS X 32/64 or
Windows 32. Windows 64 work has been stalled, we would welcome a volunteer
to handle that.

.. _`pypy 1.8 and cpython 2.7.1`: http://speed.pypy.org


Highlights
==

* List strategies. Now lists that contain only ints or only floats should
  be as efficient as storing them in a binary-packed array. It also improves
  the JIT performance in places that use such lists. There are also special
  strategies for unicode and string lists.

* As usual, numerous performance improvements. There are many examples
  of python constructs that now should be faster; too many to list them.

* Bugfixes and compatibility fixes with CPython.

* Windows fixes.

* NumPy effort progress; for the exact list of things that have been done,
  consult the `numpy status page`_. A tentative list of things that has
  been done:

  * multi dimensional arrays

  * various sizes of dtypes

  * a lot of ufuncs

  * a lot of other minor changes

  Right now the `numpy` module is available under both `numpy` and `numpypy`
  names. However, because it's incomplete, you have to `import numpypy` first
  before doing any imports from `numpy`.

* New JIT hooks that allow you to hook into the JIT process from your python
  program. There is a `brief overview`_ of what they offer.

* Standard library upgrade from 2.7.1 to 2.7.2.

Ongoing work


As usual, there is quite a bit of ongoing work that either didn't make it to
the release or is not ready yet. Highlights include:

* Non-x86 backends for the JIT: ARMv7 (almost ready) and PPC64 (in progress)

* Specialized type instances - allocate instances as efficient as C structs,
  including type specialization

* More numpy work

* Since the last release there was a significant breakthrough in PyPy's
  fundraising. We now have enough funds to work on first stages of `numpypy`_
  and `py3k`_. We would like to thank again to everyone who donated.

* It's also probably worth noting, we're considering donations for the
  Software Transactional Memory project. You can read more about `our plans`_

Cheers,
The PyPy Team

.. _`brief overview`: http://doc.pypy.org/en/latest/jit-hooks.html
.. _`numpy status page`: http://buildbot.pypy.org/numpy-status/latest.html
.. _`numpy status update blog report`:
http://morepypy.blogspot.com/2012/01/numpypy-status-update.html
.. _`numpypy`: http://pypy.org/numpydonate.html
.. _`py3k`: http://pypy.org/py3donate.html
.. _`our plans`:
http://morepypy.blogspot.com/2012/01/transactional-memory-ii.html
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Re: what is the difference between @property and method

2012-02-10 Thread Zheng Li
Thank you

On 2012/02/10, at 0:36, John Posner wrote:

 On 2:59 PM, Devin Jeanpierre wrote:
 
 
 It is kind of funny that the docs don't ever explicitly say what a
 property is. http://docs.python.org/library/functions.html#property --
 Devin 
 
 Here's a writeup that does:
 http://wiki.python.org/moin/AlternativeDescriptionOfProperty
 
 -John
 

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


Re: ANN: eGenix mxODBC Zope Database Adapter 2.0.2

2012-02-10 Thread anon hung
Thanks a bunch for the whole team!

Best,
anonhung

On 2/9/12, eGenix Team: M.-A. Lemburg i...@egenix.com wrote:
 
 ANNOUNCEMENT

  mxODBC Zope Database Adapter

 Version 2.0.2

  for Zope and the Plone CMS

 Available for Zope 2.10 and later on
 Windows, Linux, Mac OS X, FreeBSD and other platforms

 This announcement is also available on our web-site for online reading:
 http://www.egenix.com/company/news/eGenix-mxODBC-Zope-DA-2.0.2-GA.html

 
 INTRODUCTION

 The eGenix mxODBC Zope Database Adapter allows you to easily connect
 your Zope or Plone installation to just about any database backend on
 the market today, giving you the reliability of the commercially
 supported eGenix product mxODBC and the flexibility of the ODBC
 standard as middle-tier architecture.

 The mxODBC Zope Database Adapter is highly portable, just like Zope
 itself and provides a high performance interface to all your ODBC data
 sources, using a single well-supported interface on Windows, Linux,
 Mac OS X, FreeBSD and other platforms.

 This makes it ideal for deployment in ZEO Clusters and Zope hosting
 environments where stability and high performance are a top priority,
 establishing an excellent basis and scalable solution for your Plone
 CMS.

 Product page:

 http://www.egenix.com/products/zope/mxODBCZopeDA/

 
 NEWS

 We are pleased to announce a new version 2.0.2 of our mxODBC Zope DA
 product.

 With the patch level 2.0.2 release we have updated the integrated
 mxODBC Python Extension to the latest 3.1.1 release, which
 includes a number of important workarounds for these ODBC drivers:

  * Oracle 10gR1 and 10gR2
  * Oracle 11gR1 and 11gR2
  * Teradata 13
  * Netezza

 Due to popular demand, we have also added instructions on how to
 install mxODBC Zope DA 2.0 with Plone 4.1 and Zope 2.13 - even though
 this combination is not officially supported by the mxODBC Zope DA 2.0
 series:

 http://www.egenix.com/products/zope/mxODBCZopeDA/#Installation

 
 UPGRADING

 Licenses purchased for version 2.0.x of the mxODBC Zope DA will continue
 to work with the 2.0.2 patch level release.

 Licenses purchased for version 1.0.x of the mxODBC Zope DA will not
 work with version 2.0. More information about available licenses
 is available on the product page:

 http://www.egenix.com/products/zope/mxODBCZopeDA/#Licensing

 Compared to the popular mxODBC Zope DA 1.0, version 2.0 offers
 these enhancements:

  * Includes mxODBC 3.1 with updated support for many current ODBC
drivers, giving you more portability and features for a wider
range of database backends.

  * Mac OS X 10.6 (Snow Leopard) support.

  * Plone 3.2, 3.3, 4.0 support. Plone 4.1 works as well.

  * Zope 2.10, 2.11, 2.12 support. Zope 2.13 works as well.

  * Python 2.4 - 2.6 support.

  * Zero maintenance support to automatically reconnect the
Zope connection after a network or database problem.

  * More flexible Unicode support with options to work with
pure Unicode, plain strings or mixed setups - even for
databases that don't support Unicode

  * Automatic and transparent text encoding and decoding

  * More flexible date/time support including options to work
with Python datetime objects, mxDateTime, strings or tuples

  * New decimal support to have the Zope DA return decimal
column values using Python's decimal objects.

  * Fully eggified to simplify easy_install and zc.buildout based
installation

 
 MORE INFORMATION

 For more information on the mxODBC Zope Database Adapter, licensing
 and download instructions, please visit our web-site:

 http://www.egenix.com/products/zope/mxODBCZopeDA/

 You can buy mxODBC Zope DA licenses online from the eGenix.com shop at:

 http://shop.egenix.com/

 

 Thank you,
 --
 Marc-Andre Lemburg
 eGenix.com

 Professional Python Services directly from the Source  (#1, Feb 09 2012)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/
 

 ::: Try our new mxODBC.Connect Python Database Interface for free ! 


eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611

Re: Common LISP-style closures with Python

2012-02-10 Thread 88888 Dihedral
在 2012年2月4日星期六UTC+8上午8时27分56秒,Antti J Ylikoski写道:
 In Python textbooks that I have read, it is usually not mentioned that
 we can very easily program Common LISP-style closures with Python.  It
 is done as follows:
 
 -
 
 # Make a Common LISP-like closure with Python.
 #
 # Antti J Ylikoski 02-03-2012.
 
 def f1():
  n = 0
  def f2():
  nonlocal n
  n += 1
  return n
  return f2
 
 -
 
 and now we can do:
 
 -
 
  
   a=f1()
   b=f1()
   a()
 1
   a()
 2
   a()
 3
   a()
 4
   b()
 1
   b()
 2
   a()
 5
   b()
 3
   b()
 4
  
 
 -
 
 i. e. we can have several functions with private local states which
 are kept between function calls, in other words we can have Common
 LISP-like closures.
 
 yours, Antti J Ylikoski
 Helsinki, Finland, the EU

We are not in the 1990's now. A descent  CAD or internet application now should 
be able to support users with at least one or more   script
languages  easily. Whether it's javascript or java or flash in the 
browser-based applications, or go, python in the google desktop API, 
commercial SW applications to be able to evolve in the long run  are not jobs 
from the publishers and the original writers of the SW packages only.

I don't want to include a big fat compiler in my software, 
what else can I do ?
 
 LISP is too fat, too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Guide to: Learning Python Decorators

2012-02-10 Thread 88888 Dihedral
I prefer to decorate a function not a method.

I prefer to decorate an object to own a new method from the existed ones  
inherited  in all the  class levels.

I do not decorate a class if not necessary. 
  
I believe this is more pythonic to add functionalities to objects in classes by
aggregated scripts that use similar modules over a period of time. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round down to nearest number

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 06:21, Ian Kelly ian.g.ke...@gmail.com wrote:
 (3219 + 99) // 100 * 100
 3300
 (3289 + 99) // 100 * 100
 3300
 (328678 + 99) // 100 * 100
 328700
 (328 + 99) // 100 * 100
 400

 Those are all rounded up to the nearest 100 correctly.

 One thing to be aware of though is that while the round down formula
 works interchangeably for ints and floats, the round up formula does
 not.

 (3300.5 + 99) // 100 * 100
 3300.0


I'm surprised I haven't seen:

 212 - (212 % -100)
300

Here's a function that:
* rounds up and down
* works for both integers and floats
* is only two operations (as opposed to 3 in the solutions given above)

 def round(n, k):
... return n - n%k
...
 # Round down with a positive k:
... round(167, 100)
100
 round(-233, 100
... )
-300
 # Round up with a negative k:
... round(167, -100)
200
 round(-233, -100)
-200
 # Edge cases
... round(500, -100)
500
 round(500, 100)
500
 # Floats
... round(100.5, -100)
200.0
 round(199.5, 100)
100.0

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


Re: frozendict

2012-02-10 Thread Chris Angelico
On Fri, Feb 10, 2012 at 1:30 PM, Nathan Rice
nathan.alexander.r...@gmail.com wrote:
 The only thing needed to avoid the hash collision is that your hash
 function is not not 100% predictable just by looking at the python
 source code.  I don't see why every dict would have to be created
 differently.  I would think having the most ubiquitous data structure
 in your language be more predictable would be a priority.  Oh well

It's perfectly predictable. If you put a series of keys into it, you
get those same keys back. Nobody ever promised anything about order.

If your hash function is not 100% predictable, that means it varies on
the basis of something that isn't part of either the Python
interpreter or the script being run. That means that, from one
execution to another of the exact same code, the results could be
different. The keys will come out in different orders.

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


Any idea for build code bars???

2012-02-10 Thread sisifus
Hello all,

I new in python but i want to practice very much.

In interesting in build an application which read a text file, translate
the information in 128 bar code format and print all the information in a
printer.

File text content:
123456
123456

Where each line mean:
1º -- Print in text format (Ej: 123456)
2º -- Print in bar code format (Ej: |||)

With this information my script hast to build a documento (pdf, html, etc)
and send it to the printer.

Can any one say me what python modules i could use?


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


Re: Read-only attribute in module

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 03:27, Terry Reedy tjre...@udel.edu wrote:
 On 2/9/2012 8:04 PM, Steven D'Aprano wrote:

 Python happily violates consenting adults all over the place. We have
 properties, which can easily create read-only and write-once attributes.


 So propose that propery() work at module level, for module attributes, as
 well as for class attributes.

I think Steven would like something else: bare names that cannot be
rebound. E.g. something like:

 const a = 42
 a = 7

Would raise an exception.  Is that right?

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


Re: Any idea for build code bars???

2012-02-10 Thread Mark Lawrence

On 10/02/2012 10:10, sisifus wrote:

Hello all,

I new in python but i want to practice very much.

In interesting in build an application which read a text file, translate
the information in 128 bar code format and print all the information in a
printer.

File text content:
123456
123456

Where each line mean:
1º --  Print in text format (Ej: 123456)
2º --  Print in bar code format (Ej: |||)

With this information my script hast to build a documento (pdf, html, etc)
and send it to the printer.

Can any one say me what python modules i could use?


Regards



Studying this should give you some ideas.
http://pypi.python.org/pypi/pyBarcode

--
Cheers.

Mark Lawrence.

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


Re: multiple namespaces within a single module?

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 00:05, Ethan Furman et...@stoneleaf.us wrote:
 Ethan Furman wrote:

 Hrm -- and functions/classes/etc would have to refer to each other that
 way as well inside the namespace... not sure I'm in love with that...



 Not sure I hate it, either.  ;)

 Slightly more sophisticated code:

 code
 class NameSpace(object):
    def __init__(self, current_globals):
        self.globals = current_globals
        self.saved_globals = current_globals.copy()

    def __enter__(self):
        return self
    def __exit__(self, *args):
        new_items = []
        for key, value in self.globals.items():
            if (key not in self.saved_globals and value is not self
                    or key in self.saved_globals
                    and value != self.saved_globals[key]):

                new_items.append((key, value))
        for key, value in new_items:
            setattr(self, key, value)
            del self.globals[key]
        self.globals.update(self.saved_globals)

 if __name__ == '__main__':
    x = 'inside main!'
    with NameSpace(globals()) as a:
        x = 'inside a?'
        def fn1():
            print(a.x)
    with NameSpace(globals()) as b:
        x = 'inside b?'
        def fn1():
            print(b.x)
        def fn2():
            print('hello!')
            b.fn1()
    y = 'still inside main'
    a.fn1()
    b.fn1()
    print(x)
    print(y)
 /code

Please! Metaclasses are the obvious way to proceed here :)  Then there
is no need for the 'a.x' and 'b.x' cruft.

marigold:junk arno$ cat namespace.py
function = type(lambda:0)

def change_globals(f, g):
return function(f.__code__, g, f.__name__, f.__defaults__, f.__closure__)

class MetaNamespace(type):
def __new__(self, name, bases, attrs):
attrs['__builtins__'] = __builtins__
for name, value in attrs.items():
if isinstance(value, function):
attrs[name] = change_globals(value, attrs)
return type.__new__(self, name, bases, attrs)

class Namespace(metaclass=MetaNamespace):
pass


x = inside main

class a(Namespace):
x = inside a
def fn1():
print(x)

class b(Namespace):
x = inside b
def fn1():
print(x)
def fn2():
print(hello)
fn1()

y = inside main

a.fn1()
b.fn1()
b.fn2()
print(x)
print(y)
marigold:junk arno$ python3 namespace.py
inside a
inside b
hello
inside b
inside main
inside main

A bit more work would be needed to support nested functions and closures...

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


Re: when to use import statements in the header, when to use import statements in the blocks where they are used?

2012-02-10 Thread Arnaud Delobelle
On 8 February 2012 01:48, Lei Cheng pat.ins...@gmail.com wrote:
 Hi all,

    In a py file, when to use import statements in the header, when to use
 import statements in the blocks where they are used?
    What are the best practices?
    Thanks!

Aside from other answers: in some rare cases, importing within a
function can avoid circularity problems (e.g. A imports B which tries
itself to import A)

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


Re: round down to nearest number

2012-02-10 Thread Alec Taylor
o.O

Very nice

On Fri, Feb 10, 2012 at 8:58 PM, Arnaud Delobelle arno...@gmail.com wrote:
 On 10 February 2012 06:21, Ian Kelly ian.g.ke...@gmail.com wrote:
 (3219 + 99) // 100 * 100
 3300
 (3289 + 99) // 100 * 100
 3300
 (328678 + 99) // 100 * 100
 328700
 (328 + 99) // 100 * 100
 400

 Those are all rounded up to the nearest 100 correctly.

 One thing to be aware of though is that while the round down formula
 works interchangeably for ints and floats, the round up formula does
 not.

 (3300.5 + 99) // 100 * 100
 3300.0


 I'm surprised I haven't seen:

 212 - (212 % -100)
 300

 Here's a function that:
 * rounds up and down
 * works for both integers and floats
 * is only two operations (as opposed to 3 in the solutions given above)

 def round(n, k):
 ...     return n - n%k
 ...
 # Round down with a positive k:
 ... round(167, 100)
 100
 round(-233, 100
 ... )
 -300
 # Round up with a negative k:
 ... round(167, -100)
 200
 round(-233, -100)
 -200
 # Edge cases
 ... round(500, -100)
 500
 round(500, 100)
 500
 # Floats
 ... round(100.5, -100)
 200.0
 round(199.5, 100)
 100.0

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


Re: multiple namespaces within a single module?

2012-02-10 Thread Peter Otten
jkn wrote:

 Hi Peter
 
 On Feb 9, 7:33 pm, Peter Otten __pete...@web.de wrote:
 jkn wrote:
  is it possible to have multiple namespaces within a single python
  module?

 Unless you are abusing classes I don't think so.

  I have a small app which is in three or four .py files. For various
  reasons I would like to (perhaps optionally) combine these into one
  file.

 Rename your main script into __main__.py, put it into a zip file together
 with the other modules and run that.
 
 Hmm ... thanks for mentioning this feature, I didn't know of it
 before. Sounds great, except that I gather it needs Python 2.5? I'm
 stuck with v2.4 at the moment unfortunately...

You can import and run explicitly, 

$ PYTHONPATH mylib.zip python -c'import mainmod; mainmod.main()'

assuming you have a module mainmod.py containing a function main() in 
mylib.zip.

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


Re: Read-only attribute in module

2012-02-10 Thread mloskot

Terry Reedy wrote
 
 On 2/9/2012 6:43 AM, Mateusz Loskot wrote:
 import xyz print(xyz.flag)  # OK
 xyz.flag = 0 # error due to no write access
 
 Why prevent that? If you called it 'FLAG', that would indicate that it 
 is a constant that should not be changed. While Python make some effort 
 to prevent bugs, it is generally a 'consenting adults' language.
 

Terry,

The intent of xyz.flag is that it is a value set by the module internally.
xyz is a module wrapping a C library.
The C library defines concept of a global flag set by the C functions at
some events,
so user can check value of this flag.
I can provide access to it with function: xyz.get_flag()
But, I thought it would be more convenient to have a read-only property in
scope of the module.

Sometimes, especially when wrapping C code, it is not possible to map C API
semantics to Python concepts as 1:1.

-
-- 
Mateusz Loskot
http://mateusz.loskot.net
--
View this message in context: 
http://python.6.n6.nabble.com/Read-only-attribute-in-module-tp4378950p4382967.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


log and figure out what bits are slow and optimize them.

2012-02-10 Thread sajuptpm
Hi,

I want to log time taken to complete database requests inside a method/
function using decorator .  is it possible 
I think, i have to inject log code inside the method/fuctions or
modify it.
I wrote a decorator to log taken by a method/function to complete it
execution and its working well.

My requirement : log everything and figure out what bits are slow and
optimize them.

What are your suggestions ??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: log and figure out what bits are slow and optimize them.

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 12:30, sajuptpm sajup...@gmail.com wrote:
 Hi,

 I want to log time taken to complete database requests inside a method/
 function using decorator .  is it possible 
 I think, i have to inject log code inside the method/fuctions or
 modify it.
 I wrote a decorator to log taken by a method/function to complete it
 execution and its working well.

 My requirement : log everything and figure out what bits are slow and
 optimize them.

 What are your suggestions ??

Are you familiar with this?

http://docs.python.org/library/profile.html

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


Re: log and figure out what bits are slow and optimize them.

2012-02-10 Thread Saju M
Hi,

Yes i saw profile module,
I think i have to do function call via

cProfile.run('foo()')

I know, we can debug this way.

But i need a fixed logging system ..



On Fri, Feb 10, 2012 at 6:08 PM, Arnaud Delobelle arno...@gmail.com wrote:

 On 10 February 2012 12:30, sajuptpm sajup...@gmail.com wrote:
  Hi,
 
  I want to log time taken to complete database requests inside a method/
  function using decorator .  is it possible 
  I think, i have to inject log code inside the method/fuctions or
  modify it.
  I wrote a decorator to log taken by a method/function to complete it
  execution and its working well.
 
  My requirement : log everything and figure out what bits are slow and
  optimize them.
 
  What are your suggestions ??

 Are you familiar with this?

 http://docs.python.org/library/profile.html

 --
 Arnaud




-- 
Regards
Saju Madhavan
+91 09535134654

Anyone who has never made a mistake has never tried anything new -- Albert
Einstein
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: log and figure out what bits are slow and optimize them.

2012-02-10 Thread Saju M
On Fri, Feb 10, 2012 at 6:12 PM, Saju M sajup...@gmail.com wrote:

 Hi,

 Yes i saw profile module,
 I think i have to do function call via

 cProfile.run('foo()')

 I know, we can debug this way.

 But i need a fixed logging system ..



 On Fri, Feb 10, 2012 at 6:08 PM, Arnaud Delobelle arno...@gmail.comwrote:

 On 10 February 2012 12:30, sajuptpm sajup...@gmail.com wrote:
  Hi,
 
  I want to log time taken to complete database requests inside a method/
  function using decorator .  is it possible 
  I think, i have to inject log code inside the method/fuctions or
  modify it.
  I wrote a decorator to log taken by a method/function to complete it
  execution and its working well.
 
  My requirement : log everything and figure out what bits are slow and
  optimize them.
 
  What are your suggestions ??

 Are you familiar with this?

 http://docs.python.org/library/profile.html




  I need a fixed logging system and want to use it in production.
  I think, we can't permanently include profile's debugging code in
source code,
 will cause any performance issue ??




 --
 Arnaud




 --
 Regards
 Saju Madhavan
 +91 09535134654

 Anyone who has never made a mistake has never tried anything new -- Albert
 Einstein




-- 
Regards
Saju Madhavan
+91 09535134654

Anyone who has never made a mistake has never tried anything new -- Albert
Einstein
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: log and figure out what bits are slow and optimize them.

2012-02-10 Thread Saju M
Yes i saw profile module,
I think, i have to do function call via
cProfile.run('foo()')
I know, we can debug this way.
But, I need a fixed logging system and want to use it in production.
  I think, we can't permanently include profile's debugging code in
source code,
 will cause any performance issue ??


On Fri, Feb 10, 2012 at 6:18 PM, Saju M sajup...@gmail.com wrote:



 On Fri, Feb 10, 2012 at 6:12 PM, Saju M sajup...@gmail.com wrote:

 Hi,

 Yes i saw profile module,
 I think i have to do function call via

 cProfile.run('foo()')

 I know, we can debug this way.

 But i need a fixed logging system ..



 On Fri, Feb 10, 2012 at 6:08 PM, Arnaud Delobelle arno...@gmail.comwrote:

 On 10 February 2012 12:30, sajuptpm sajup...@gmail.com wrote:
  Hi,
 
  I want to log time taken to complete database requests inside a method/
  function using decorator .  is it possible 
  I think, i have to inject log code inside the method/fuctions or
  modify it.
  I wrote a decorator to log taken by a method/function to complete it
  execution and its working well.
 
  My requirement : log everything and figure out what bits are slow and
  optimize them.
 
  What are your suggestions ??

 Are you familiar with this?

 http://docs.python.org/library/profile.html




   I need a fixed logging system and want to use it in production.
   I think, we can't permanently include profile's debugging code in
 source code,
  will cause any performance issue ??




  --
 Arnaud




 --
 Regards
 Saju Madhavan
 +91 09535134654

 Anyone who has never made a mistake has never tried anything new --
 Albert Einstein




 --
 Regards
 Saju Madhavan
 +91 09535134654

 Anyone who has never made a mistake has never tried anything new -- Albert
 Einstein




-- 
Regards
Saju Madhavan
+91 09535134654

Anyone who has never made a mistake has never tried anything new -- Albert
Einstein
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: log and figure out what bits are slow and optimize them.

2012-02-10 Thread sajuptpm
Hi,

Yes i saw profile module,
I think i have to do function call via

cProfile.run('foo()')

I know, we can debug this way.

But, i need a fixed logging system and want to use it in production.
  I think, we can't permanently include profile's debugging code
in source code,
 will cause any performance issue ??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: changing sys.path

2012-02-10 Thread Andrea Crotti

I think I finally located the issue with the sys.path extension.

The problem is that I have many namespace directories, for example

lib:
 - sub1
 - sub2

lib:
  - sub3
  - sub4

But to have everything working I had lib.sub3 in easy-install.pth.
Now if I try to add something else to the path it doesn't take care of 
the namespace

declaration
(every __init__.py in the packages contains: 
__import__('pkg_resources').declare_namespace(__name__))

and just doesn't find the other submodules..

If I try to add manually lib.sub1, lib.sub2 changing the sys.path the 
imports will only work for the first one.


Strangely if I just create a dev_main.pth in site-packages containing 
the same paths, everything works perfectly.


Any suggestions now that the problem is more clear?
Thanks,
Andrea
--
http://mail.python.org/mailman/listinfo/python-list


Re: changing sys.path

2012-02-10 Thread Dave Angel

On 02/10/2012 08:08 AM, Andrea Crotti wrote:

I think I finally located the issue with the sys.path extension.

The problem is that I have many namespace directories, for example

lib:
 - sub1
 - sub2

lib:
  - sub3
  - sub4

But to have everything working I had lib.sub3 in easy-install.pth.
Now if I try to add something else to the path it doesn't take care of 
the namespace

declaration
(every __init__.py in the packages contains: 
__import__('pkg_resources').declare_namespace(__name__))

and just doesn't find the other submodules..

If I try to add manually lib.sub1, lib.sub2 changing the sys.path the 
imports will only work for the first one.


Strangely if I just create a dev_main.pth in site-packages containing 
the same paths, everything works perfectly.


Any suggestions now that the problem is more clear?
Thanks,
Andrea


The only code I saw in this thread was:

sys.path.extend(paths_to_add)

Can you add a print of paths_to_add, and of sys.path after you execute it?

If there's only one path, are you putting it in a list anyway?  If not 
then it won't do what you expect.




--

DaveA

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


Re: log and figure out what bits are slow and optimize them.

2012-02-10 Thread Mark Lawrence

Please don't top post.

On 10/02/2012 12:59, Saju M wrote:

Yes i saw profile module,
I think, i have to do function call via
cProfile.run('foo()')
I know, we can debug this way.
But, I need a fixed logging system and want to use it in production.
   I think, we can't permanently include profile's debugging code in
source code,
  will cause any performance issue ??



How about http://docs.python.org/library/logging.html ?

--
Cheers.

Mark Lawrence.

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


Re: changing sys.path

2012-02-10 Thread Andrea Crotti
Ok now it's getting really confusing, I tried a small example to see 
what is the real behaviour,
so I created some package namespaces (where the __init__.py declare the 
namespace package).


  /home/andrea/test_ns:
  total used in directory 12 available 5655372
  drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:46 a.b
  drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:46 a.c
  -rw-r--r-- 1 andrea andrea  125 Feb 10 14:46 test.py

  /home/andrea/test_ns/a.b:
  total 8
  drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:47 a
  -rw-r--r-- 1 andrea andrea   56 Feb 10 14:35 __init__.py

  /home/andrea/test_ns/a.b/a:
  total 8
  drwxr-xr-x 2 andrea andrea 4096 Feb 10 14:47 b
  -rw-r--r-- 1 andrea andrea   56 Feb 10 14:35 __init__.py

  /home/andrea/test_ns/a.b/a/b:
  total 12
  -rw-r--r-- 1 andrea andrea  25 Feb 10 14:36 api.py
  -rw-r--r-- 1 andrea andrea 153 Feb 10 14:37 api.pyc
  -rw-r--r-- 1 andrea andrea  56 Feb 10 14:35 __init__.py

  /home/andrea/test_ns/a.c:
  total 8
  drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:47 a
  -rw-r--r-- 1 andrea andrea   56 Feb 10 14:35 __init__.py

  /home/andrea/test_ns/a.c/a:
  total 8
  drwxr-xr-x 2 andrea andrea 4096 Feb 10 14:47 c
  -rw-r--r-- 1 andrea andrea   56 Feb 10 14:35 __init__.py

  /home/andrea/test_ns/a.c/a/c:
  total 12
  -rw-r--r-- 1 andrea andrea  20 Feb 10 14:36 api.py
  -rw-r--r-- 1 andrea andrea 148 Feb 10 14:38 api.pyc
  -rw-r--r-- 1 andrea andrea  56 Feb 10 14:35 __init__.py


So this test.py works perfectly:
import sys
sys.path.insert(0, 'a.c')
sys.path.insert(0, 'a.b')

from a.b import api as api_ab

from a.c import api as api_ac

While just mixing the order:
import sys
sys.path.insert(0, 'a.b')

from a.b import api as api_ab

sys.path.insert(0, 'a.c')
from a.c import api as api_ac

Doesn't work anymore

[andrea@precision test_ns]$ python2 test.py
Traceback (most recent call last):
  File test.py, line 7, in module
from a.c import api as api_ac
ImportError: No module named c



Am I missing something/doing something stupid?
--
http://mail.python.org/mailman/listinfo/python-list


Re: changing sys.path

2012-02-10 Thread Dave Angel

On 02/10/2012 09:51 AM, Andrea Crotti wrote:

Ok now it's getting really confusing, I tried a small example to see
what is the real behaviour,
so I created some package namespaces (where the __init__.py declare the
namespace package).

/home/andrea/test_ns:
total used in directory 12 available 5655372
drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:46 a.b
drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:46 a.c
-rw-r--r-- 1 andrea andrea 125 Feb 10 14:46 test.py

/home/andrea/test_ns/a.b:
total 8
drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:47 a
-rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py

/home/andrea/test_ns/a.b/a:
total 8
drwxr-xr-x 2 andrea andrea 4096 Feb 10 14:47 b
-rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py

/home/andrea/test_ns/a.b/a/b:
total 12
-rw-r--r-- 1 andrea andrea 25 Feb 10 14:36 api.py
-rw-r--r-- 1 andrea andrea 153 Feb 10 14:37 api.pyc
-rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py

/home/andrea/test_ns/a.c:
total 8
drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:47 a
-rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py

/home/andrea/test_ns/a.c/a:
total 8
drwxr-xr-x 2 andrea andrea 4096 Feb 10 14:47 c
-rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py

/home/andrea/test_ns/a.c/a/c:
total 12
-rw-r--r-- 1 andrea andrea 20 Feb 10 14:36 api.py
-rw-r--r-- 1 andrea andrea 148 Feb 10 14:38 api.pyc
-rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py


So this test.py works perfectly:
import sys
sys.path.insert(0, 'a.c')
sys.path.insert(0, 'a.b')

from a.b import api as api_ab

from a.c import api as api_ac

While just mixing the order:
import sys
sys.path.insert(0, 'a.b')

from a.b import api as api_ab

sys.path.insert(0, 'a.c')
from a.c import api as api_ac

Doesn't work anymore

[andrea@precision test_ns]$ python2 test.py
Traceback (most recent call last):
File test.py, line 7, in module
from a.c import api as api_ac
ImportError: No module named c



Am I missing something/doing something stupid?


Yes, you've got periods in your directory names.  A period means 
something special within python, and specifically within the import.


When you say  from a.c import api

You're telling it:from package a  get module c, and from there 
impoort the symbol api


But package a has no module c, so it complains.


In an earlier message you asserted you were using all absolute paths in 
your additions to sys.path.  Here you're inserting relative ones.  How come?


--

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


Re: changing sys.path

2012-02-10 Thread Andrea Crotti

On 02/10/2012 03:06 PM, Dave Angel wrote:


Yes, you've got periods in your directory names.  A period means 
something special within python, and specifically within the import.


When you say  from a.c import api

You're telling it:from package a  get module c, and from there 
impoort the symbol api


But package a has no module c, so it complains.


In an earlier message you asserted you were using all absolute paths 
in your additions to sys.path.  Here you're inserting relative ones.  
How come?




Well yes I have periods, but that's also the real-world situation.
We have many directories that are contributing to the same namespace in 
the same superdirectory

which should not interfere, so it was decided to give this naming.
It would be quite hard to change I guess and I have to prove that this 
is problem.


I renamed everything and this
import sys
from os import path
sys.path.insert(0, path.abspath('ab'))

from a.b import api as api_ab

sys.path.insert(0, path.abspath('ac'))
from a.c import api as api_ac

still fails, so the period in the name is not the problem.

Also absolute or relative paths in this small example doesn't make any 
difference.


Adding all the paths in one go works perfectly fine anyway, so I 
probably have to make sure

I add them *all* before anything is imported.

If there are better solutions I would like to hear them :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: changing sys.path

2012-02-10 Thread Peter Otten
Andrea Crotti wrote:

 Ok now it's getting really confusing, I tried a small example to see
 what is the real behaviour,
 so I created some package namespaces (where the __init__.py declare the
 namespace package).
 
/home/andrea/test_ns:
total used in directory 12 available 5655372
drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:46 a.b
drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:46 a.c
-rw-r--r-- 1 andrea andrea  125 Feb 10 14:46 test.py
 
/home/andrea/test_ns/a.b:
total 8
drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:47 a
-rw-r--r-- 1 andrea andrea   56 Feb 10 14:35 __init__.py
 
/home/andrea/test_ns/a.b/a:
total 8
drwxr-xr-x 2 andrea andrea 4096 Feb 10 14:47 b
-rw-r--r-- 1 andrea andrea   56 Feb 10 14:35 __init__.py
 
/home/andrea/test_ns/a.b/a/b:
total 12
-rw-r--r-- 1 andrea andrea  25 Feb 10 14:36 api.py
-rw-r--r-- 1 andrea andrea 153 Feb 10 14:37 api.pyc
-rw-r--r-- 1 andrea andrea  56 Feb 10 14:35 __init__.py
 
/home/andrea/test_ns/a.c:
total 8
drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:47 a
-rw-r--r-- 1 andrea andrea   56 Feb 10 14:35 __init__.py
 
/home/andrea/test_ns/a.c/a:
total 8
drwxr-xr-x 2 andrea andrea 4096 Feb 10 14:47 c
-rw-r--r-- 1 andrea andrea   56 Feb 10 14:35 __init__.py
 
/home/andrea/test_ns/a.c/a/c:
total 12
-rw-r--r-- 1 andrea andrea  20 Feb 10 14:36 api.py
-rw-r--r-- 1 andrea andrea 148 Feb 10 14:38 api.pyc
-rw-r--r-- 1 andrea andrea  56 Feb 10 14:35 __init__.py
 
 
 So this test.py works perfectly:
 import sys
 sys.path.insert(0, 'a.c')
 sys.path.insert(0, 'a.b')
 
 from a.b import api as api_ab
 
 from a.c import api as api_ac
 
 While just mixing the order:
 import sys
 sys.path.insert(0, 'a.b')
 
 from a.b import api as api_ab
 
 sys.path.insert(0, 'a.c')
 from a.c import api as api_ac
 
 Doesn't work anymore
 
 [andrea@precision test_ns]$ python2 test.py
 Traceback (most recent call last):
File test.py, line 7, in module
  from a.c import api as api_ac
 ImportError: No module named c
 
 
 
 Am I missing something/doing something stupid?

The package a will be either a.c/a/ or a.b/a/ depending on whether a.c/ or 
a.b/ appears first in sys.path.

If it's  a.c/a, that does not contain a c submodule or subpackage.

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


Re: changing sys.path

2012-02-10 Thread Andrea Crotti

On 02/10/2012 03:27 PM, Peter Otten wrote:
The package a will be either a.c/a/ or a.b/a/ depending on whether 
a.c/ or a.b/ appears first in sys.path. If it's a.c/a, that does not 
contain a c submodule or subpackage. 



I would agree if I didn't have this declaration
__import__('pkg_resources').declare_namespace(__name__)
in each subdirectory.

And how do you explain the fact that changing the order everything works?
Namespace packages are supposed to work exactly like this, if it doesn't 
resolve the
c instead of raising an Exception it goes forward in the sys.path and 
try again, which

is what actually happens when I do this

sys.path.append(path.abspath('ab'))
sys.path.append(path.abspath('ac'))

from a.b import api as api_ab
from a.c import api as api_ac

Maybe this:
Definition: pkgutil.extend_path(path, name)
Docstring:
Extend a package's path.

Intended use is to place the following code in a package's __init__.py:

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)


might come handy, from what I'm gathering is the only way to have a more 
dynamic path

manipulation with namespace packages..
--
http://mail.python.org/mailman/listinfo/python-list


Re: changing sys.path

2012-02-10 Thread Peter Otten
Peter Otten wrote:

 If it's  a.c/a, that does not contain a c submodule or subpackage.

Sorry, I meant a.b/a 


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


Re: changing sys.path

2012-02-10 Thread Peter Otten
Andrea Crotti wrote:

 On 02/10/2012 03:27 PM, Peter Otten wrote:
 The package a will be either a.c/a/ or a.b/a/ depending on whether
 a.c/ or a.b/ appears first in sys.path. If it's a.c/a, that does not
 contain a c submodule or subpackage.
 
 
 I would agree if I didn't have this declaration
 __import__('pkg_resources').declare_namespace(__name__)
 in each subdirectory.

Sorry, you didn't mention that in the post I responded to and I didn't 
follow the thread closely.

I found a description for declare_namespace() at
http://peak.telecommunity.com/DevCenter/PkgResources

but the text explaining the function is completely unintelligible to me, so 
I cannot contribute anything helpful here :(

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


Fabric Engine + Python benchmarks

2012-02-10 Thread Fabric Paul
Hi all - just letting you know that we recently integrated Fabric with
Python. Fabric is a high-performance multi-threading engine that
integrates with dynamic languages. We're releasing soon (probably
under AGPL), and we just released these benchmarks.

http://fabric-engine.com/2012/02/fabric-engine-python-value-at-risk-benchmark/

Before anyone starts attacking the vanilla python :), the point we
want to make is that our Python integration performs just as well as
our Node.js implementation (benchmarks found at 
http://fabric-engine.com/tag/benchmarks/).
Obviously, it's pretty trivial to compile Python to byte code, and
present multi-threaded versions of the program - however, the goal of
Fabric is to handle that side of things automatically (that's what the
engine does). This means we take care of threading, dynamic
compilation, memory management etc

Interested to get your feedback.

Kind regards,

Paul (I work at Fabric)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: frozendict

2012-02-10 Thread Nathan Rice
On Fri, Feb 10, 2012 at 5:08 AM, Chris Angelico ros...@gmail.com wrote:
 On Fri, Feb 10, 2012 at 1:30 PM, Nathan Rice
 nathan.alexander.r...@gmail.com wrote:
 The only thing needed to avoid the hash collision is that your hash
 function is not not 100% predictable just by looking at the python
 source code.  I don't see why every dict would have to be created
 differently.  I would think having the most ubiquitous data structure
 in your language be more predictable would be a priority.  Oh well

 It's perfectly predictable. If you put a series of keys into it, you
 get those same keys back. Nobody ever promised anything about order.

 If your hash function is not 100% predictable, that means it varies on
 the basis of something that isn't part of either the Python
 interpreter or the script being run. That means that, from one
 execution to another of the exact same code, the results could be
 different. The keys will come out in different orders.

I think having a hash function that is not referentially transparent
is a bad thing.  Basing your language on a non-deterministic function?
 Yeah...

A type factory that produces the dict type on interpreter
initialization (or, replaces the hash function, rather), and uses
time/system information/etc would solve the problem, while limiting
the introduced non-determinism.  I don't care if the order of
iteration for keys is different from interpreter run to run.

I have used frozenset(mydict.items()) when my requirements dictated.
It is a minor performance hit.

Lets also not forget that knowing an object is immutable lets you do a
lot of optimizations; it can be inlined, it is safe to convert to a
contiguous block of memory and stuff in cache, etc.  If you know the
input to a function is guaranteed to be frozen you can just go crazy.
Being able to freeze(anyobject) seems like a pretty clear win.
Whether or not it is pythonic is debatable.  I'd argue if the meaning
of pythonic in some context is limiting, we should consider updating
the term rather than being dogmatic.

Just my 2 cents...


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


Re: frozendict

2012-02-10 Thread Chris Rebert
On Fri, Feb 10, 2012 at 8:53 AM, Nathan Rice
nathan.alexander.r...@gmail.com wrote:
snip
 Lets also not forget that knowing an object is immutable lets you do a
 lot of optimizations; it can be inlined, it is safe to convert to a
 contiguous block of memory and stuff in cache, etc.  If you know the
 input to a function is guaranteed to be frozen you can just go crazy.
 Being able to freeze(anyobject) seems like a pretty clear win.
 Whether or not it is pythonic is debatable.  I'd argue if the meaning
 of pythonic in some context is limiting, we should consider updating
 the term rather than being dogmatic.

It's been proposed previously and rejected:
PEP 351 -- The freeze protocol
http://www.python.org/dev/peps/pep-0351/

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


Re: multiple namespaces within a single module?

2012-02-10 Thread jkn
Hi Peter

On Feb 10, 11:10 am, Peter Otten __pete...@web.de wrote:

[...]

  Hmm ... thanks for mentioning this feature, I didn't know of it
  before. Sounds great, except that I gather it needs Python 2.5? I'm
  stuck with v2.4 at the moment unfortunately...

 You can import and run explicitly,

 $ PYTHONPATH mylib.zip python -c'import mainmod; mainmod.main()'

 assuming you have a module mainmod.py containing a function main() in
 mylib.zip.

That looks very useful  -thanks for the tip!

J^n
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fabric Engine + Python benchmarks

2012-02-10 Thread Stefan Behnel
Fabric Paul, 10.02.2012 17:04:
 Fabric is a high-performance multi-threading engine that
 integrates with dynamic languages.

Hmm, first of all, fabric is a tool for automating
admin/deployment/whatever tasks:

http://pypi.python.org/pypi/Fabric/1.3.4

http://docs.fabfile.org/en/1.3.4/index.html

Not sure which went first, but since you mentioned that you're releasing
soon, you may want to stop the engines for a moment and reconsider the name.

Stefan

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


Re: Fabric Engine + Python benchmarks

2012-02-10 Thread Fabric Paul
On Feb 10, 12:21 pm, Stefan Behnel stefan...@behnel.de wrote:
 Fabric Paul, 10.02.2012 17:04:

  Fabric is a high-performance multi-threading engine that
  integrates with dynamic languages.

 Hmm, first of all, fabric is a tool for automating
 admin/deployment/whatever tasks:

 http://pypi.python.org/pypi/Fabric/1.3.4

 http://docs.fabfile.org/en/1.3.4/index.html

 Not sure which went first, but since you mentioned that you're releasing
 soon, you may want to stop the engines for a moment and reconsider the name.

 Stefan

Hi Stefan - Thanks for the heads up. Fabric Engine has been going for
about 2 years now. Registered company etc. I'll be sure to refer to it
as Fabric Engine so there's no confusion. We were unaware there was a
python tool called Fabric.

Thanks,

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


Re: round down to nearest number

2012-02-10 Thread noydb
On Feb 10, 4:58 am, Arnaud Delobelle arno...@gmail.com wrote:
 On 10 February 2012 06:21, Ian Kelly ian.g.ke...@gmail.com wrote:





  (3219 + 99) // 100 * 100
  3300
  (3289 + 99) // 100 * 100
  3300
  (328678 + 99) // 100 * 100
  328700
  (328 + 99) // 100 * 100
  400

  Those are all rounded up to the nearest 100 correctly.

  One thing to be aware of though is that while the round down formula
  works interchangeably for ints and floats, the round up formula does
  not.

  (3300.5 + 99) // 100 * 100
  3300.0

 I'm surprised I haven't seen:

  212 - (212 % -100)

 300

 Here's a function that:
 * rounds up and down
 * works for both integers and floats
 * is only two operations (as opposed to 3 in the solutions given above)

  def round(n, k):

 ...     return n - n%k
 ... # Round down with a positive k:

 ... round(167, 100)
 100 round(-233, 100

 ... )
 -300 # Round up with a negative k:

 ... round(167, -100)
 200 round(-233, -100)
 -200
  # Edge cases

 ... round(500, -100)
 500 round(500, 100)
 500
  # Floats

 ... round(100.5, -100)
 200.0 round(199.5, 100)

 100.0

 --
 Arnaud- Hide quoted text -

 - Show quoted text -

Thanks!  Covers all bases, good.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: frozendict

2012-02-10 Thread Nathan Rice
 Lets also not forget that knowing an object is immutable lets you do a
 lot of optimizations; it can be inlined, it is safe to convert to a
 contiguous block of memory and stuff in cache, etc.  If you know the
 input to a function is guaranteed to be frozen you can just go crazy.
 Being able to freeze(anyobject) seems like a pretty clear win.
 Whether or not it is pythonic is debatable.  I'd argue if the meaning
 of pythonic in some context is limiting, we should consider updating
 the term rather than being dogmatic.

Sweet, looking at the reason for rejection:

1. How dicts (and multiply nested objects) should be frozen was not
completely obvious
2. frozen() implies in place, thus confusing users
3. freezing something like a list is confusing because some list
methods would disappear or cause errors
4. Because automatic conversion in the proposal was seen as too
involved to be so magical
5. Because frozendicts are the main end user benefit, and using dicts
as keys was seen as suspect

Honestly, as far as #1, we already have copy and deepcopy, the can of
worms is already opened (and necessarily so).  For 2, choose a better
name?  For 3, we have abstract base classes now, which make a nice
distinction between mutable and immutable sequences; nominal types are
a crutch, thinking in terms of structure is much more powerful.  I
agree with point 4, if magic does anything besides make the code
conform to what an informed user would expect, it should be considered
heretical.  As for #5, I feel using a collection of key value
relations as a key in another collection is not inherently bad, it
just depends on the context... The mutability is the rub.  Also,
immutability provides scaffolding to improve performance and
concurrency (both of which are top tier language features).

I understand that this is one of those cases where Guido has a strong
bad feeling about something, and I think a consequence of that is
people tread lightly.  Perhaps I'm a bit of a language communist in
that regard (historically a dangerous philosophy :)

As an aside, I find it kind of schizophrenic how on one hand Python is
billed as a language for consenting adults (see duck typing, no data
hiding, etc) and on the other hand users need to be protected from
themselves.  Better to serve just one flavor of kool-aid imo.


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


Re: frozendict

2012-02-10 Thread John Nagle

On 2/10/2012 10:14 AM, Nathan Rice wrote:

Lets also not forget that knowing an object is immutable lets you do a
lot of optimizations; it can be inlined, it is safe to convert to a
contiguous block of memory and stuff in cache, etc.  If you know the
input to a function is guaranteed to be frozen you can just go crazy.
Being able to freeze(anyobject) seems like a pretty clear win.
Whether or not it is pythonic is debatable.  I'd argue if the meaning
of pythonic in some context is limiting, we should consider updating
the term rather than being dogmatic.


A real justification for the ability to make anything immutable is
to make it safely shareable between threads.  If it's immutable, it
doesn't have to be locked for access.  Mozilla's new Rust
language takes advantage of this.  Take a look at Rust's concurrency
semantics.  They've made some progress.

John Nagle


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


Removing items from a list

2012-02-10 Thread Thomas Philips
In the past, when deleting items from a list, I looped through the
list in reverse to avoid accidentally deleting items I wanted to keep.
I tried something different today, and, to my surprise, was able to
delete items correctly, regardless of the direction in which I looped,
in both Python 3.2.2. and 2..1 -  does the remove() function somehow
allow the iteration to continue correctly even when items are removed
from the midde of the list?

 x = list(range(10))
 x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 for i in x:
if i % 2 == 0:
x.remove(i)

 x
[1, 3, 5, 7, 9]
 for i in reversed(x):
if i % 2 == 0:
x.remove(i)

 x
[1, 3, 5, 7, 9]
 x = list(range(10))
 for i in reversed(x):
if i % 2 == 0:
x.remove(i)


 x
[1, 3, 5, 7, 9]

Sincerely

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


Re: Removing items from a list

2012-02-10 Thread Ian Kelly
On Fri, Feb 10, 2012 at 1:04 PM, Thomas Philips tkp...@gmail.com wrote:
 In the past, when deleting items from a list, I looped through the
 list in reverse to avoid accidentally deleting items I wanted to keep.
 I tried something different today, and, to my surprise, was able to
 delete items correctly, regardless of the direction in which I looped,
 in both Python 3.2.2. and 2..1 -  does the remove() function somehow
 allow the iteration to continue correctly even when items are removed
 from the midde of the list?

No.  Your test works because you never attempt to remove two adjacent
items, so the skipping of items doesn't end up mattering.  Try the
same thing, but print out the values as you iterate over them:


 x = list(range(10))
 x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 for i in x:
...   print(i)
...   if i % 2 == 0:
... x.remove(i)
...
0
2
4
6
8
 x
[1, 3, 5, 7, 9]


Had you attempted to remove any of the odd numbers as well, it would
have failed.

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


Re: Forking simplejson

2012-02-10 Thread Amirouche Boubekki
Héllo,

I did it, it wasn't that difficult actually.

the source is available @ https://github.com/amirouche/jsonir

there is example :
https://github.com/amirouche/jsonir/blob/master/example.py

What makes the implementation of __json__ awkward is the iterencode support
of simplejson that I kept. I'm wondering if it makes
sens to have such a feature, what do you think ?

I does not support multiple json representation of an object
out-of-the-box, one solution is to __json__ hook a parameter of the
encoder.

I did not test it.

Cheers,

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


Re: Removing items from a list

2012-02-10 Thread MRAB

On 10/02/2012 20:04, Thomas Philips wrote:

In the past, when deleting items from a list, I looped through the
list in reverse to avoid accidentally deleting items I wanted to keep.
I tried something different today, and, to my surprise, was able to
delete items correctly, regardless of the direction in which I looped,
in both Python 3.2.2. and 2..1 -  does the remove() function somehow
allow the iteration to continue correctly even when items are removed
from the midde of the list?


 x = list(range(10))
 x

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

 for i in x:

if i % 2 == 0:
x.remove(i)


 x

[1, 3, 5, 7, 9]

 for i in reversed(x):

if i % 2 == 0:
x.remove(i)


 x

[1, 3, 5, 7, 9]

 x = list(range(10))
 for i in reversed(x):

if i % 2 == 0:
x.remove(i)



 x

[1, 3, 5, 7, 9]


The answer is no. For example:

 for i in x:
print(i is, i)
if i % 2 == 0:
x.remove(i)


i is 0
i is 1
i is 2
i is 4
 x
[0, 1, 3, 5]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing items from a list

2012-02-10 Thread Thomas Philips
Thanks for the insight. I saw the behavious as soon as I extended x
with a bunch of 0's

 x = list(range(10))
 x.extend([0]*10)
 x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
 for i in reversed(x):
if i % 2 == 0:
x.remove(i)

 x
[1, 3, 5, 7, 9]

 x = list(range(10))
 x.extend([0]*10)
 x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
 for i in x:
if i % 2 == 0:
x.remove(i)


 x
[1, 3, 5, 7, 9, 0, 0, 0, 0, 0]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: changing sys.path

2012-02-10 Thread Andrea Crotti

On 02/10/2012 04:00 PM, Peter Otten wrote:

Sorry, you didn't mention that in the post I responded to and I didn't
follow the thread closely.

I found a description for declare_namespace() at
http://peak.telecommunity.com/DevCenter/PkgResources

but the text explaining the function is completely unintelligible to me, so
I cannot contribute anything helpful here :(



Well in the end I submitted a bug report
http://bugs.python.org/issue13991
I'm not sure it's really a bug and maybe I'm just doing something wrong,
but to me the behavior is at least unexpected..
--
http://mail.python.org/mailman/listinfo/python-list


Re: round down to nearest number

2012-02-10 Thread Olive
On Thu, 9 Feb 2012 17:43:58 -0800
Chris Rebert c...@rebertia.com wrote:

 On Thu, Feb 9, 2012 at 5:23 PM, noydb jenn.du...@gmail.com wrote:
  hmmm, okay.
 
  So how would you round UP always?  Say the number is 3219, so you
  want 3300 returned.
 
 http://stackoverflow.com/questions/17944/how-to-round-up-the-result-of-integer-division/96921
 
 Thus: (3219 + 99) // 100
 
 Slight tangent: Beware negative numbers when using // or %.

This trick work always (even if the entry is a float):


-(-a//100)*100

 -(-3219//100)*100
3300

 -(-3200.1//100)*100

3300.0

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


How can I catch misnamed variables?

2012-02-10 Thread John Gordon
Recently I was been bitten by some stupid errors in my code, and I'm
wondering if there's a simple way to catch them.

One error was of the form:

  my_object.some_function()

.. when I hadn't declared an object named my_object.

The other error was similar:

  x = my_module.CONSTANT

.. when I hadn't imported my_module.

Of course both of these errors were deep inside a long-running function
call, so it took a while for them to crop up.

Is there an automated way to catch errors like these?  I'm using the
compileall module to build my program and it does catch some errors
such as incorrect indentation, but not errors like the above.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

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


Re: How can I catch misnamed variables?

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 21:06, John Gordon gor...@panix.com wrote:
 Recently I was been bitten by some stupid errors in my code, and I'm
 wondering if there's a simple way to catch them.

 One error was of the form:

  my_object.some_function()

 .. when I hadn't declared an object named my_object.

 The other error was similar:

  x = my_module.CONSTANT

 .. when I hadn't imported my_module.

 Of course both of these errors were deep inside a long-running function
 call, so it took a while for them to crop up.

 Is there an automated way to catch errors like these?  I'm using the
 compileall module to build my program and it does catch some errors
 such as incorrect indentation, but not errors like the above.

There's pychecker and pylint

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


Re: How can I catch misnamed variables?

2012-02-10 Thread Kev Dwyer
John Gordon wrote:

 Recently I was been bitten by some stupid errors in my code, and I'm
 wondering if there's a simple way to catch them.
 
snip


Pyflakes is another static checker that can catch these sorts of errors.

Cheers,

Kev 


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


datetime module and timezone

2012-02-10 Thread Olive
In the datetime module, it has support for a notion of timezone but is
it possible to use one of the available timezone (I am on Linux). Linux
has a notion of timezone (in my distribution, they are stored
in /usr/share/zoneinfo). I would like to be able 1) to know the current
timezone and 2) to be able to use the timezone available on the system.
How can I do that?

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


Re: How can I catch misnamed variables?

2012-02-10 Thread Ben Finney
John Gordon gor...@panix.com writes:

 Is there an automated way to catch errors like these?

Use a static code checker, such as ‘pyflakes’ (simple but limited) or
‘pylint’ (complex but highly configurable) to catch these and many other
problems in Python code.

-- 
 \  “It's a terrible paradox that most charities are driven by |
  `\ religious belief.… if you think altruism without Jesus is not |
_o__)  altruism, then you're a dick.” —Tim Minchin, 2010-11-28 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime module and timezone

2012-02-10 Thread John Gordon
In 20120210222545.4cbe6...@bigfoot.com Olive di...@bigfoot.com writes:

 In the datetime module, it has support for a notion of timezone but is
 it possible to use one of the available timezone (I am on Linux). Linux
 has a notion of timezone (in my distribution, they are stored
 in /usr/share/zoneinfo). I would like to be able 1) to know the current
 timezone and 2) to be able to use the timezone available on the system.
 How can I do that?

I believe the current user's timezone is stored in the TZ environment
variable.

I don't understand your second question.  Are you asking for a list of
of all the possible timezone choices?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

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


Re: Removing items from a list

2012-02-10 Thread Chris Angelico
On Sat, Feb 11, 2012 at 7:04 AM, Thomas Philips tkp...@gmail.com wrote:
 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 for i in x:
        if i % 2 == 0:
                x.remove(i)

Just a quickie, is there a reason you can't use a list comprehension?

x = [i for i in x if i % 2]

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


Re: datetime module and timezone

2012-02-10 Thread Chris Rebert
On Fri, Feb 10, 2012 at 1:25 PM, Olive di...@bigfoot.com wrote:
 In the datetime module, it has support for a notion of timezone but is
 it possible to use one of the available timezone (I am on Linux). Linux
 has a notion of timezone (in my distribution, they are stored
 in /usr/share/zoneinfo). I would like to be able 1) to know the current
 timezone

time.tzname gives the zone names (plural due to DST); time.timezone
and time.altzone gives their UTC offsets.

 and 2) to be able to use the timezone available on the system.

You can use the name to look it up in pytz (http://pypi.python.org/pypi/pytz/ ).
And python-dateutil (http://labix.org/python-dateutil ) can apparently
parse zoneinfo files, if that's what you mean.

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


OT (waaaayyyyyyyyy off-topic) [was Re: How can I catch misnamed variables?]

2012-02-10 Thread Ethan Furman

Ben Finney wrote (from signature):
 “It's a terrible paradox that most charities are driven by religious
 belief. . . . if you think altruism without Jesus is not altruism,
 then you're a dick.” —Tim Minchin, 2010-11-28

1) Why is it paradoxical?  If anything it's a sad commentary on those 
who don't ascribe to a religion, as it would appear that they care less 
for their society.


2) altruism: unselfish regard for or devotion to the welfare of 
others... no mention of religion of any kind, or Jesus in particular.


Altruistic-yet-paradoxically-religious-ly yours,
~Ethan~

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


Re: Read-only attribute in module

2012-02-10 Thread Steven D'Aprano
On Thu, 09 Feb 2012 22:27:50 -0500, Terry Reedy wrote:

 On 2/9/2012 8:04 PM, Steven D'Aprano wrote:
 
 Python happily violates consenting adults all over the place. We have
 properties, which can easily create read-only and write-once
 attributes.
 
 So propose that propery() work at module level, for module attributes,
 as well as for class attributes.


I'm not wedded to a specific implementation.

Besides, it's not just a matter of saying property should work in 
modules -- that would require the entire descriptor protocol work for 
module lookups, and I don't know how big a can of worms that is. Constant 
names is a lot more constrained than computed name lookups.



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


Re: Read-only attribute in module

2012-02-10 Thread Terry Reedy

On 2/10/2012 6:11 AM, mloskot wrote:


The intent of xyz.flag is that it is a value set by the module internally.
xyz is a module wrapping a C library.
The C library defines concept of a global flag set by the C functions at
some events,
so user can check value of this flag.
I can provide access to it with function: xyz.get_flag()


If the value of the flag can change during a run, I would do that. 
Otherwise, you have to make sure the local copy keeps in sync. Users 
might also think that it is a true constant that they could read once.


I understand that you might be concerned that one person in a 
multi-programmer project might decide to rebind xyz.flag and mess up 
everyone else. I think the real solution might be an option to freeze an 
entire module.


--
Terry Jan Reedy

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


Re: log and figure out what bits are slow and optimize them.

2012-02-10 Thread Kev Dwyer
sajuptpm wrote:

 Hi,
 
 Yes i saw profile module,
 I think i have to do function call via
 
 cProfile.run('foo()')
 
 I know, we can debug this way.
 
 But, i need a fixed logging system and want to use it in production.
   I think, we can't permanently include profile's debugging code
 in source code,
  will cause any performance issue ??

*Any* instrumentation code is going to affect performance.

It's a trade-off that you need to analyse and manage in the context of your 
application.

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


Re: OT (waaaayyyyyyyyy off-topic)

2012-02-10 Thread Ben Finney

Thanks for responding. Rather than take this discussion too far where
it's quite off-topic, I'll respond briefly and ask for a change of forum
if we want to continue.


Ethan Furman et...@stoneleaf.us writes:

 Ben Finney wrote (from signature):
  “It's a terrible paradox that most charities are driven by religious
  belief. . . . if you think altruism without Jesus is not altruism,
  then you're a dick.” —Tim Minchin, 2010-11-28

The quote is from an interview with Tim Minchin
URL:http://www.guardian.co.uk/stage/2010/nov/28/tim-minchin-comedian.

 1) Why is it paradoxical? If anything it's a sad commentary on those
 who don't ascribe to a religion, as it would appear that they care
 less for their society.

It's an outcome of history that religious institutions have historically
been well-situated to be the facilitators of charitable work (and much
other work) simply because they have been ubiquitous in most societies.
The paradox is that they spend much of their resources away from the
worldly, i.e. secular, work of charity.

But charitable work is not dependent on religious belief, and indeed in
recent decades there are now a great many wholly secular charities (e.g.
International Red Cross and Oxfam) which do not divert their resources
from addressing the real world.

 2) altruism: unselfish regard for or devotion to the welfare of
 others... no mention of religion of any kind, or Jesus in particular.

Yes, that's the point. Altruism is a human activity independent of
religious belief, yet the default assumption of too many is that they
are somehow necessarily connected.

 Altruistic-yet-paradoxically-religious-ly yours,

As you rightly point out, this discussion is off-topic here. So while
I'm open to discussion on this topic, we should move it to some other
forum.

-- 
 \“Most people, I think, don't even know what a rootkit is, so |
  `\ why should they care about it?” —Thomas Hesse, Sony BMG, 2006 |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fabric Engine + Python benchmarks

2012-02-10 Thread Paul Rubin
Fabric Paul technove...@gmail.com writes:
 Hi Stefan - Thanks for the heads up. Fabric Engine has been going for
 about 2 years now. Registered company etc. I'll be sure to refer to it
 as Fabric Engine so there's no confusion. We were unaware there was a
 python tool called Fabric.

There will still be confusion.  The Fabric configuration tool is quite
well known in the python and sysadmin communities, so it will be the
first thing people will think of.  If you weren't already aware of it,
I'd guess you're pretty far out of contact with Python's existing user
population, so there may be further sources of mismatch between your
product and what else is out there (I'm thinking of Stackless, PyPy,
etc.)  Still, yoour product sounds pretty cool.

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


Postpone evaluation of argument

2012-02-10 Thread Righard van Roy
Hello,

I want to add an item to a list, except if the evaluation of that item
results in an exception.
I could do that like this:

def r(x):
if x  3:
raise(ValueError)

try:
list.append(r(1))
except:
pass
try:
list.append(r(5))
except:
pass

This looks rather clumbsy though, and it does not work with i.e. list
comprehensions.

I was thinking of writing a decorator like this:

def tryAppendDecorator(fn):
def new(*args):
try:
fn(*args)
except:
pass
return new

@tryAppendDecorator
def tryAppend(list, item):
list.append(item)

tryAppend(list, r(1))
tryAppend(list, r(5))

This does not work however because the 'item' argument gets evaluated
before the decorator does it's magic.

Is there a way to postpone the evaluation of 'item' till it gets used
inside the decorator. Like it is possible to quote a form in Lisp.

Thank you,
Righard
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: log and figure out what bits are slow and optimize them.

2012-02-10 Thread John Gordon
In mailman.5685.1328913452.27778.python-l...@python.org Kev Dwyer 
kevin.p.dw...@gmail.com writes:

 *Any* instrumentation code is going to affect performance.

Funny story about that...

I wanted to profile some code of mine, and a colleague recommended the
'hotshot' module.

It's pretty easy to use: there are functions to start profiling, stop
profiling and print results.

So I added the function calls and ran my code and it took a really
long time.  I mean a REALLY long time.  In fact I eventually had to kill
the process.

I briefly wondered if my coworker was playing a prank on me... then I
realized that I had neglected to call the function to stop profiling!

So when I went to print the results, it was still profiling... endlessly.

(Okay, maybe it wasn't that funny.)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

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


Re: Postpone evaluation of argument

2012-02-10 Thread Chris Rebert
On Fri, Feb 10, 2012 at 3:01 PM, Righard van Roy pluij...@gmail.com wrote:
 Hello,

 I want to add an item to a list, except if the evaluation of that item
 results in an exception.
 I could do that like this:

 def r(x):
    if x  3:
        raise(ValueError)

 try:
    list.append(r(1))
 except:
    pass
 try:
    list.append(r(5))
 except:
    pass

 This looks rather clumbsy though, and it does not work with i.e. list
 comprehensions.

 I was thinking of writing a decorator like this:

 def tryAppendDecorator(fn):
    def new(*args):
        try:
            fn(*args)
        except:
            pass
    return new

 @tryAppendDecorator
 def tryAppend(list, item):
    list.append(item)

 tryAppend(list, r(1))
 tryAppend(list, r(5))

 This does not work however because the 'item' argument gets evaluated
 before the decorator does it's magic.

 Is there a way to postpone the evaluation of 'item' till it gets used
 inside the decorator. Like it is possible to quote a form in Lisp.

Nope. All arguments always get evaluated before control passes to the
callee. You'd have to quote the arguments manually by putting them
in lambdas, thus explicitly delaying their evaluation.

Cheers,
Chris
--
http://rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I catch misnamed variables?

2012-02-10 Thread Christian Heimes
Am 10.02.2012 22:06, schrieb John Gordon:
 Is there an automated way to catch errors like these?  I'm using the
 compileall module to build my program and it does catch some errors
 such as incorrect indentation, but not errors like the above.

Write unit tests and use coverage to aim for 100% code and branch coverage.

If you want to write high quality code and avoid problems like misnamed
variables then you have to write unit tests and functional tests for
your program. I'm well aware that it's hard and requires time. But in
the long run it will *save* lots of time.

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


Re: Fabric Engine + Python benchmarks

2012-02-10 Thread Albert W. Hopkins
On Fri, 2012-02-10 at 14:52 -0800, Paul Rubin wrote:
 Fabric Paul technove...@gmail.com writes:
  Hi Stefan - Thanks for the heads up. Fabric Engine has been going for
  about 2 years now. Registered company etc. I'll be sure to refer to it
  as Fabric Engine so there's no confusion. We were unaware there was a
  python tool called Fabric.
 
 There will still be confusion.  The Fabric configuration tool is quite
 well known in the python and sysadmin communities, so it will be the
 first thing people will think of.  If you weren't already aware of it,
 I'd guess you're pretty far out of contact with Python's existing user
 population, so there may be further sources of mismatch between your
 product and what else is out there (I'm thinking of Stackless, PyPy,
 etc.)  Still, yoour product sounds pretty cool.
 

Indeed.  When I first saw the subject header I thought it was referring
to the Python-based deployment tool.  It's just going to confuse people.
It's enough already that we have a bunch of stuff with pi and py in
the name :|

Does the OSS community *really* need another Firebird incident?

-a


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


Re: Postpone evaluation of argument

2012-02-10 Thread Paul Rubin
Righard van Roy pluij...@gmail.com writes:
 I want to add an item to a list, except if the evaluation of that item
 results in an exception.

This may be overkill and probably slow, but perhaps most in the spirit
that you're asking.

from itertools import chain

def r(x):
if x  3:
raise(ValueError)
return x

def maybe(func):
  try:
 yield func()
  except:
 return

def p(i): return maybe(lambda: r(i))

your_list = list(chain(p(1), p(5)))
print your_list
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: dbf.py 0.90.001

2012-02-10 Thread Ethan Furman

Still messing with .dbf files?

Somebody brought you a 15 year old floppy, which still luckily (?) 
worked, and now wants that ancient data?


dbf to the rescue!

Supported tables/features
=
  - dBase III
  - FoxPro
  - Visual FoxPro supported
  - Null value

Supported field types
=
  - Char
  - Date
  - Logical
  - Memo
  - Numeric
  - Currency (returns Decimal)
  - DateTime
  - Double
  - Float (same as Numeric)
  - General
  - Integer
  - Picture

Still to come (or, Not Yet Working ;)
=

 - Index files (although you can create temporary
   memory indices)
 - auto incrementing fields

Latest version can be found on PyPI at http://pypi.python.org/pypi/dbf.

Comments, bug reports, etc, appreciated!

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


problems with shelve(), collections.defaultdict, self

2012-02-10 Thread 7stud
The following code demonstrates that a collections.defaultdict is
shelve worthy:


import shelve
import collections as c


dd = c.defaultdict(int)
dd[Joe] = 3
print(dd)

my_shelve = shelve.open('data.shelve')
my_shelve['strike_record'] = dd
my_shelve.close()

my_shelve = shelve.open('data.shelve')
data = my_shelve['strike_record']
my_shelve.close()

dd.clear()
dd.update(data)
print(dd)

--output:--
defaultdict(class 'int', {'Joe': 3})
defaultdict(class 'int', {'Joe': 3})


And the following code demonstrates that a class that inherits from
dict can shelve itself:

import collections as c
import shelve

class Dog(dict):
def __init__(self):
super().__init__(Joe=1)
print('', self)

def save(self):
my_shelve = shelve.open('data22.shelve')
my_shelve['x'] = self
my_shelve.close()

def load(self):
my_shelve = shelve.open('data22.shelve')
data = my_shelve['x']
my_shelve.close()

print(data)


d = Dog()
d.save()
d.load()

--output:--
 {'Joe': 1}
{'Joe': 1}


But I cannot get a class that inherits from collections.defaultdict to
shelve itself:


import collections as c
import shelve

class Dog(c.defaultdict):
def __init__(self):
super().__init__(int, Joe=0)
print('', self)

def save(self):
my_shelve = shelve.open('data22.shelve')
my_shelve['dd'] = self
my_shelve.close()

def load(self):
my_shelve = shelve.open('data22.shelve')
data = my_shelve['dd']
my_shelve.close()

print(data)


d = Dog()
d.save()
d.load()

--output:--

 defaultdict(class 'int', {'Joe': 30})
Traceback (most recent call last):
  File /Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/shelve.py, line 111, in __getitem__
value = self.cache[key]
KeyError: 'dd'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File 3.py, line 95, in module
d.load()
  File 3.py, line 87, in load
data = my_shelve['dd']
  File /Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/shelve.py, line 114, in __getitem__
value = Unpickler(f).load()
TypeError: __init__() takes exactly 1 positional argument (2 given)



I deleted all *.shelve.db files between program runs.  I can't figure
out what I'm doing wrong.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems with shelve(), collections.defaultdict, self

2012-02-10 Thread 7stud
On Feb 10, 7:48 pm, 7stud 7s...@excite.com wrote:

 But I cannot get a class that inherits from collections.defaultdict to
 shelve itself:

 import collections as c
 import shelve

 class Dog(c.defaultdict):
     def __init__(self):
         super().__init__(int, Joe=0)
         print('', self)

Whoops.  I changed:

super().__init__(int, Joe=0)

to:

super().__init__(int, Joe=30)

hence this output..

 --output:--

  defaultdict(class 'int', {'Joe': 30})
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems with shelve(), collections.defaultdict, self

2012-02-10 Thread 7stud
On Feb 10, 7:52 pm, 7stud 7s...@excite.com wrote:

I don't know if this helps, but I notice when I initially do this:

shelve.open('data22')

the file is saved as 'data22.db'.   But on subsequent calls to
shelve.open(), if I use the file name 'data22.db', I get a different
error:

--output:--

 defaultdict(class 'int', {'Joe': 30})
Traceback (most recent call last):
  File 3.py, line 95, in module
d.load()
  File 3.py, line 86, in load
my_shelve = shelve.open('data22.db')
  File /Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/shelve.py, line 232, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
  File /Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/shelve.py, line 216, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol,
writeback)
  File /Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/dbm/__init__.py, line 83, in open
raise error[0](db type could not be determined)
dbm.error: db type could not be determined



The code that produced that error:



import collections as c
import shelve

class Dog(c.defaultdict):
def __init__(self):
super().__init__(int, Joe=30)
print('', self)

def save(self):
my_shelve = shelve.open('data22')
my_shelve['dd'] = self
my_shelve.close()

def load(self):
my_shelve = shelve.open('data22.db')
data = my_shelve['dd']
my_shelve.close()

print(data)


d = Dog()
d.save()
d.load()


I'm using python 3.2.2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: frozendict

2012-02-10 Thread 88888 Dihedral
在 2012年2月11日星期六UTC+8上午2时57分34秒,John Nagle写道:
 On 2/10/2012 10:14 AM, Nathan Rice wrote:
  Lets also not forget that knowing an object is immutable lets you do a
  lot of optimizations; it can be inlined, it is safe to convert to a
  contiguous block of memory and stuff in cache, etc.  If you know the
  input to a function is guaranteed to be frozen you can just go crazy.
  Being able to freeze(anyobject) seems like a pretty clear win.
  Whether or not it is pythonic is debatable.  I'd argue if the meaning
  of pythonic in some context is limiting, we should consider updating
  the term rather than being dogmatic.
 
  A real justification for the ability to make anything immutable is
 to make it safely shareable between threads.  If it's immutable, it
 doesn't have to be locked for access.  Mozilla's new Rust
 language takes advantage of this.  Take a look at Rust's concurrency
 semantics.  They've made some progress.
 
   John Nagl


Lets model the system as an asynchronous set of objects with multiple threads
performing operatons on objects as in the above.

This reminds me  the old problem solved before in the digital hardware. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime module and timezone

2012-02-10 Thread Bob Martin
in 671891 20120210 212545 Olive di...@bigfoot.com wrote:
In the datetime module, it has support for a notion of timezone but is
it possible to use one of the available timezone (I am on Linux). Linux
has a notion of timezone (in my distribution, they are stored
in /usr/share/zoneinfo). I would like to be able 1) to know the current
timezone and 2) to be able to use the timezone available on the system.
How can I do that?

For 1) just type date on the command line.
-- 
http://mail.python.org/mailman/listinfo/python-list


ldap proxy user bind

2012-02-10 Thread sajuptpm
I have developed a LDAP auth system using python-ldap module.
Using that i can validate username and password,  fetch user and
groups info from LDAP directory.
Now i want to implement ldap proxy user bind to the ldap server.
I googled and find this http://ldapwiki.willeke.com/wiki/LDAPProxyUser
But i don't have any idea about how implement it usng python-ldap.

My existing LDAP settings at client side
ldap_enabled = True
ldap_host = your_ldap_server
ldap_port = 389
ldap_basedn = o=My_omain
ldap_user_key = cn
ldap_group_key = groupMembership
ldap_email_key = mail
ldap_user_search = ou=Users
ldap_group_search = ou=Groups
ldap_group_objectclass = groupOfNames

I want to add following 2 new flags

ldap_proxy_user = ldap_proxy
ldap_proxy_pwd = secret


I don't know how this ldapproxy system would works.
Could you please point me to an python article/example ??

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


Re: log and figure out what bits are slow and optimize them.

2012-02-10 Thread sajuptpm

I decided to create a decorator like.

import cProfile
def debug_time(method):
def timed(*args, **kw):
prof = cProfile.Profile()
prof.enable(subcalls=False, builtins=False)
result = prof.runcall(method, *args, **kw)
#prof.print_stats()
msg = \n\n\n\n###
msg += \n\nURL : %s %(tg.request.url)
msg += \nMethod: %r %(method.__name__)
print --ddd, type(prof.getstats())
msg += \n\nStatus : %s %(prof.print_stats())
msg += \n\n###
print msg
LOGGER.info(msg)
return result
return timed

Ref : 
http://stackoverflow.com/questions/5375624/a-decorator-that-profiles-a-method-call-and-logs-the-profiling-result


I want to log it in existing log file in my project,
so i tried prof.print_stats() and prof.getstats(). prof.getstats()
will need extra loop for fetch data.
prof.print_stats() will log library calls also.

Please suggest a better way to log profiler output.


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


[issue13984] Python2.6 compilation breaking on mips64 bit machine

2012-02-10 Thread Shivam

New submission from Shivam shivam.agar...@aricent.com:

Hi All,
  I am getting follwoing error when compiling Python2.6 on mips 64.


Failed to find the necessary bits to build these modules:
_bsddb _tkinter   bsddb185
bz2dl imageop 
readline   sunaudiodevzlib
To find the necessary bits, look in setup.py in detect_modules() for the 
module's name.


Failed to build these modules:
_ctypesdatetime   dbm 


--
components: None
messages: 153031
nosy: shivam_python_issues
priority: normal
severity: normal
status: open
title: Python2.6 compilation breaking on mips64 bit machine
type: compile error
versions: Python 2.6

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



[issue13960] Handling of broken comments in HTMLParser

2012-02-10 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

I'll fix this for 3.x non-strict and then see if it can be backported to 2.7 
(there are still other fixes that should be backported to 2.7 before this can 
be applied).

--

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



[issue13984] Python2.6 compilation breaking on mips64 bit machine

2012-02-10 Thread Martin v . Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

Python 2.6 is in a mode where only security issues get fixed. Please use Python 
2.7 or Python 3.2.

--
nosy: +loewis
resolution:  - out of date
status: open - closed

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



[issue13984] Python2.6 compilation breaking on mips64 bit machine

2012-02-10 Thread Martin v . Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

Also understand that this output does not indicate an error. It just means that 
it couldn't build these modules. Python itself works just fine.

--

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



[issue13960] Handling of broken comments in HTMLParser

2012-02-10 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 242b697449d8 by Ezio Melotti in branch '3.2':
#13960: HTMLParser is now able to handle broken comments when strict=False.
http://hg.python.org/cpython/rev/242b697449d8

New changeset 44366541dd86 by Ezio Melotti in branch 'default':
#13960: merge with 3.2.
http://hg.python.org/cpython/rev/44366541dd86

--
nosy: +python-dev

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



[issue13960] Handling of broken comments in HTMLParser

2012-02-10 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

This is now fixed in 3.2/3.3, I'll wait for 2.7 before closing it.
On a side note, the empty ! comment doesn't seem to be valid in HTML5.
HTMLParser just ignores it, and doesn't report it as an empty comment (so this 
should be fine).

--

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



[issue13985] Menu.tk_popup : menu doesn't disapear when main window is iconified.

2012-02-10 Thread marc dechico

New submission from marc dechico marc.dech...@gmail.com:

actions do discover the bug  with the source I have given:

pushing the right button to get the pop-up menu .

going out of the popup_menu  still pushing the right button.

the menu doesn't disapear when releasing the button.

and still doesn't disapear when iconnifying the main window.

I suppose the pop up_menu  should behave in a transient way.

when doing such a thing with google-chrome I first have my popup menu disapear 
and I need to click again to iconify.

perhaps we should have the choice and have access to a transient function.

--
components: Tkinter
files: popupmenu.py
messages: 153037
nosy: marc.dechico
priority: normal
severity: normal
status: open
title: Menu.tk_popup  : menu doesn't disapear when main window is iconified.
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file24474/popupmenu.py

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



[issue13189] New bdist_simple binary distribution format for packaging

2012-02-10 Thread Paul Moore

Paul Moore p.f.mo...@gmail.com added the comment:

I'm writing a PEP, also as a result of Nick's suggestion on python-ideas. I 
don't think it will be too hard to get the basic framework of the PEP in place. 
When I'm done, would you like to see it and comment before I post to the wider 
python-dev, or should I just post it and see what happens?

--

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



[issue13986] ValueError: cannot convert float NaN to integer

2012-02-10 Thread Shivam

New submission from Shivam shivam.agar...@aricent.com:

Hi Team,
   Kindly help me in resolving below issue which arises when we do make 
install as it is show stopper for us.

Listing /usr/local/lib/python2.7 ...
Compiling /usr/local/lib/python2.7/BaseHTTPServer.py ...
Traceback (most recent call last):
  File /usr/local/lib/python2.7/compileall.py, line 213, in module
exit_status = int(not main())
  File /usr/local/lib/python2.7/compileall.py, line 200, in main
force, rx, quiet):
  File /usr/local/lib/python2.7/compileall.py, line 50, in compile_dir
if not compile_file(fullname, ddir, force, rx, quiet):
  File /usr/local/lib/python2.7/compileall.py, line 99, in compile_file
ok = py_compile.compile(fullname, None, dfile, True)
  File /usr/local/lib/python2.7/py_compile.py, line 108, in compile
timestamp = long(os.fstat(f.fileno()).st_mtime)
ValueError: cannot convert float NaN to integer
make: *** [libinstall] Error 1


Addtionaly:
---
At the time of make below message is flashed as well:

Failed to build these modules:
datetime   dbm

--
components: Build
messages: 153039
nosy: shivam_python_issues
priority: normal
severity: normal
status: open
title: ValueError: cannot convert float NaN to integer
type: compile error
versions: Python 2.7

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



[issue13986] ValueError: cannot convert float NaN to integer

2012-02-10 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +haypo

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



[issue13986] ValueError: cannot convert float NaN to integer

2012-02-10 Thread Shivam

Shivam shivam.agar...@aricent.com added the comment:

Hi Team,
   I am having this issue on mips 64bit machine running debian.

Regards
Shivam Agarwal

--

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



[issue13590] extension module builds fail with python.org OS X installers on OS X 10.7 and 10.6 with Xcode 4.2

2012-02-10 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 29507a2acdb5 by Ned Deily in branch '2.7':
Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
http://hg.python.org/cpython/rev/29507a2acdb5

New changeset 5c784b0f263d by Ned Deily in branch '3.2':
Issue #13590: On OS X 10.7 and 10.6 with Xcode 4.2, building
http://hg.python.org/cpython/rev/5c784b0f263d

New changeset 35bd40b16a91 by Ned Deily in branch 'default':
Issue #13590: merge
http://hg.python.org/cpython/rev/35bd40b16a91

--
nosy: +python-dev

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



[issue13590] extension module builds fail with python.org OS X installers on OS X 10.7 and 10.6 with Xcode 4.2

2012-02-10 Thread Ned Deily

Ned Deily n...@acm.org added the comment:

Éric: I've replied to your review comments in Rietveld.  Thanks.

Ronald: distutils would not only have to check for gcc-4.2 vs. clang, but also 
needs to strip -arch ppc from the compiler flags when it is present and it 
cannot use gcc-4.2.   Otherwise you cannot build extensions for the 32-bit 
python installer on OSX 10.7 with Xcode 4.2.

The 32-bit-only installers uses gcc-4.0, not -4.2 and it uses the 10.4u SDK, 
neither of which is available with Xcode 4.*.  The patch does not currently 
attempt to support building extensions for the 32-bit-only installers.  Besides 
stripping arch ppc, it would also have to substitute an available SDK (10.6 is 
the oldest SDK shipping with Xcode 4.2).  CFLAGS and LDFLAGS would also have to 
be edited to remove ppc and the use of 10.3 as a deployment target results in 
warning messages:
  #warning Building for Intel with Mac OS X Deployment Target  10.4 is invalid
even though for simple cases it seems to work.

But I think trying to automatically support the 32-bit-only configuration is 
too intrusive and unnecessary for most users.  There are disadvantages to 
trying to use the old 32-bit-only configuration on newer systems, such as using 
the older, more broken, or less feature-rich system APIs.  One reasonable use 
case I can think of is for app developers who want to distribute Python-based 
apps on OS X that run on a range of systems, say 10.4 to 10.7.  For those 
presumably more sophisticated users, documenting the unsupported environment 
variable settings to override when attempting to build with Xcode 4 should be 
sufficient.  (The safer options of building with Xcode 3 on 10.6 (or earlier) 
or building their own custom Pythons remain, of course.)

W.r.t. the patch: is it really necessary to use a subshell to look for the 
compiler? I'd either walk os.environ['PATH'] myself or use xcodebuild to locate 
binaries.

I suppose that could be done.  I've tried to minimize the performance impact by 
only performing the check the first time it is needed and caching the result so 
it's only done once per Python invocation.  I'm concerned about the added 
complexity of getting the PATH parsing and semantics right; I don't know of any 
Python code in the standard library that does this.  My immediate concern is 
for the imminent code cutoffs for Python 3.2.3 and 2.7.3 so I've committed the 
patch, updated for other review comments, for them.

I'm deferring looking at doing a PATH walk for the 3.3 version of the code 
which is needed along with corresponding changes to packaging.  There also 
should be some OS X installer README and/or other documentation of this and 
other 10.7 and 10.6 issues.  I'm considering how to handle that.

--
priority: release blocker - deferred blocker
stage: patch review - needs patch

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



[issue13986] ValueError: cannot convert float NaN to integer

2012-02-10 Thread Mark Dickinson

Changes by Mark Dickinson dicki...@gmail.com:


--
nosy: +mark.dickinson

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



[issue13982] python returning errorneous value for sqrt

2012-02-10 Thread Mark Dickinson

Changes by Mark Dickinson dicki...@gmail.com:


--
nosy: +mark.dickinson

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



[issue13987] Handling of broken markup in HTMLParser on 2.7

2012-02-10 Thread Ezio Melotti

New submission from Ezio Melotti ezio.melo...@gmail.com:

The attached patch fixes a few problems with HTMLParser on 2.7.
Instead of raising error when invalid markup is detected, the parser now 
consumes the invalid input and proceeds.  This patch is a partial backport of 
#1486713.

After this two more patches will follow.
The first will get rid of errors raised while parsing declarations and should 
also solve #13576:
 def unknown_decl(self, data):
-self.error(unknown declaration: %r % (data,))
+pass

The second will take care of bogus comments (see #13960).

Once this is done HTMLParser should be able to parse (almost) everything.  I'm 
planning to commit this before the release of 2.7.3.

--
assignee: ezio.melotti
components: Library (Lib)
files: issue13987.diff
keywords: patch
messages: 153043
nosy: benjamin.peterson, eric.araujo, ezio.melotti, r.david.murray
priority: normal
severity: normal
stage: patch review
status: open
title: Handling of broken markup in HTMLParser on 2.7
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file24475/issue13987.diff

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



[issue13987] Handling of broken markup in HTMLParser on 2.7

2012-02-10 Thread Eli Bendersky

Changes by Eli Bendersky eli...@gmail.com:


--
nosy: +eli.bendersky

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



[issue13966] Add disable_interspersed_args() to argparse.ArgumentParser

2012-02-10 Thread Christophe Kalt

Christophe Kalt k...@taranis.org added the comment:

nice, thank you!

--
nosy: +kalt

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



[issue13922] argparse handling multiple -- in args improperly

2012-02-10 Thread Christophe Kalt

Christophe Kalt k...@taranis.org added the comment:

Hah.. was just about to report this.  I'm in the midst of converting a bunch of 
scripts from optparse to argparse, and this is one of the problems I'm hitting.

--
nosy: +kalt

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



[issue10049] Add a no-op (null) context manager to contextlib

2012-02-10 Thread Nick Coghlan

Nick Coghlan ncogh...@gmail.com added the comment:

FWIW, it's likely I'll be adding contextlib.ContextStack (see [1]) for 3.3. 
While it's far from the primary use case, that API also serves as a no-op 
context manager (if you never register any contexts or callbacks, the __exit__ 
impl does nothing).

[1] 
http://contextlib2.readthedocs.org/en/latest/index.html#contextlib2.ContextStack

--

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



[issue1559549] ImportError needs attributes for module and file name

2012-02-10 Thread Brett Cannon

Brett Cannon br...@python.org added the comment:

The patch looks fine for its current semantics except for the fact that the 
macro doesn't work under clang; ##macro_var is supposed to be used only when 
concatenating parts of a string to create a complete identifier, not 
concatenating two identifiers next to each other (e.g. gooblede##gook is fine, 
but self-##gook isn't because '-' is its own identifier).

But one issue is that for my purposes I need 'name' to be the full name of the 
module, not just the tail of the full name. The reason is that pydoc needs a 
way to tell when a module import failed because the module isn't there vs. when 
a module had an actual error itself. Using the tail end of the name doesn't 
help me because it means I can't tell if an import of a module named 'bunk' 
containing the line 'import test.bunk' fails because the module 'bunk' doesn't 
exist or because the import line failed since in both cases name == 'bunk'. But 
if name == 'test.bunk' there is no ambiguity. Pydoc used to do this by 
inspecting the stack and seeing where the exception was thrown which is just 
nasty and brittle (i.e. doesn't work with importlib since the stack goes much 
farther until ImportError is thrown).

IOW I don't think we should be tossing out valuable data just because 
historically modules that didn't exist only returned the tail end of the full 
module name. Anyone object to switching to using the full name of the module 
triggering the exception? The message wouldn't change to use the full name 
(unfortunately) for backwards-compatibility reasons of course.

--

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



[issue1559549] ImportError needs attributes for module and file name

2012-02-10 Thread Brett Cannon

Brett Cannon br...@python.org added the comment:

And to answer David's joke, I carpool from Toronto to Waterloo four days a week 
so I have an hour each direction to work on stuff.

--

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



[issue10049] Add a no-op (null) context manager to contextlib

2012-02-10 Thread Alexander Jones

Alexander Jones aj.d...@gmail.com added the comment:

That's very reassuring. Thanks, Nick!

--

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



[issue13947] gdbm reorganize() leaves hanging file descriptor

2012-02-10 Thread Jesús Cea Avión

Jesús Cea Avión j...@jcea.es added the comment:

I can't reproduce. Sorry.

Reading the GDBM documentation, all filedescriptors management seem to be 
inside gdbm, not Python. Anyway, if I can't reproduce, I can not diagnose 
neither patch. Sorry.

--

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



[issue1559549] ImportError needs attributes for module and file name

2012-02-10 Thread Brett Cannon

Brett Cannon br...@python.org added the comment:

Oh, and there are no forward declarations for the new functions added to 
errors.c

--

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



  1   2   >