Re: Cycle around a sequence

2012-02-09 Thread Peter Otten
Chris Angelico wrote:

> On Thu, Feb 9, 2012 at 2:55 PM, Steven D'Aprano
>  wrote:
>> If your data is humongous but only available lazily, buy more memory :)
> 
> Or if you have a huge iterable and only need a small index into it,
> snag those first few entries into a list, then yield everything else,
> then yield the saved ones:

> def cycle(seq,n):
> seq=iter(seq)
> lst=[next(seq) for i in range(n)]
> try:
> while True: yield next(seq)
> except StopIteration:
> for i in lst: yield i

I think that should be spelt

def cycle2(seq, n):
seq = iter(seq)
head = [next(seq) for i in range(n)]
for item in seq:
yield item
for item in head:
yield item

or, if you are into itertools,

def cycle3(seq, n):
seq = iter(seq)
return chain(seq, list(islice(seq, n)))

$ python -m timeit -s'from tmp import cycle; data = range(1000); start=10' 
'for item in cycle(data, 10): pass'
1000 loops, best of 3: 358 usec per loop
$ python -m timeit -s'from tmp import cycle2; data = range(1000); start=10' 
'for item in cycle2(data, 10): pass'
1000 loops, best of 3: 172 usec per loop
$ python -m timeit -s'from tmp import cycle3; data = range(1000); start=10' 
'for item in cycle3(data, 10): pass'
1 loops, best of 3: 56.5 usec per loop

For reference:

$ python -m timeit -s'data = range(1000); start=10' 'for item in 
data[start:] + data[:start]: pass'
1 loops, best of 3: 56.4 usec per loop


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


Re: Cycle around a sequence

2012-02-09 Thread Peter Otten
Mark Lawrence wrote:

> I'm looking at a way of cycling around a sequence i.e. starting at some
> given location in the middle of a sequence and running to the end before
> coming back to the beginning and running to the start place.  About the
> best I could come up with is the following, any better ideas for some
> definition of better?

You could use a deque instead of a list and .rotate() that:

>>> from collections import deque
>>> d = deque(range(10))
>>> d.rotate(-4)
>>> d
deque([4, 5, 6, 7, 8, 9, 0, 1, 2, 3])

> 
> PythonWin 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
> (Intel)] on win32.
> Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin'
> for further copyright information.
>  >>> from itertools import chain
>  >>> a=range(10)
>  >>> g = chain((a[i] for i in xrange(4, 10, 1)), (a[i] for i in
>  >>> xrange(4))) for x in g: print x,
> ...
> 4 5 6 7 8 9 0 1 2 3
>  >>>


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


what is the difference between @property and method

2012-02-09 Thread Zheng Li
class A(object):
@properymethod
def value1(self):
 return 'value1'

def value2(self):
return 'value2'

what is the difference between value1 and value2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what is the difference between @property and method

2012-02-09 Thread Devin Jeanpierre
On Thu, Feb 9, 2012 at 3:50 AM, Zheng Li  wrote:
> class A(object):
>@properymethod
>def value1(self):
> return 'value1'
>
>def value2(self):
>return 'value2'
>
> what is the difference between value1 and value2.

There is no such thing as @properymethod

After you change the code to use @property, try writing it in the
interactive interpreter and calling A().value2(). Then try calling
A().value1() .

Or maybe try googling for it. The fourth result for "property python"
for me is http://adam.gomaa.us/blog/2008/aug/11/the-python-property-builtin/

--

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


Re: Cycle around a sequence

2012-02-09 Thread Serhiy Storchaka

08.02.12 22:15, Terry Reedy написав(ла):

To make a repeating rotator is only a slight adjustment:

k = n - len(seq)
while True:
i = k
while i < n:
yield seq[i]
i += 1


for i in range(n, len(seq)):
yield seq[i]
while True:
for x in seq:
yield x

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


Re: Cycle around a sequence

2012-02-09 Thread Chris Angelico
On Thu, Feb 9, 2012 at 7:33 PM, Peter Otten <[email protected]> wrote:
> Chris Angelico wrote:
>
>> def cycle(seq,n):
>>         seq=iter(seq)
>>         lst=[next(seq) for i in range(n)]
>>         try:
>>                 while True: yield next(seq)
>>         except StopIteration:
>>                 for i in lst: yield i
>
> I think that should be spelt
>
> def cycle2(seq, n):
>    seq = iter(seq)
>    head = [next(seq) for i in range(n)]
>    for item in seq:
>        yield item
>    for item in head:
>        yield item

Thanks, yeah, don't know what I was thinking :) Too much C work lately!

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


Re: frozendict

2012-02-09 Thread Duncan Booth
Nathan Rice  wrote:

> I put dicts in sets all the time.  I just tuple the items, but that
> means you have to re-dict it on the way out to do anything useful with
> it.  I am too lazy to write a frozendict or import one, but I would
> use it if it was a builtin.
> 
I hope you sort the items before putting them in a tuple, otherwise how do 
you handle two identical dicts that return their items in a different 
order?


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


unicode printing on Windows

2012-02-09 Thread BlueBird
Hi,

The question is not totally related to Python but there is a strong
connection. Everytime that I try to debug some python programs under
Windows, I encounter the issue that things printed on the console
simply break the program because :
1. My windows console does not support UTF8
2. Things printed by the program on the stdout / stderr do not
necessarily use sys.getpreferredencoding() so break with UnicodeError.

Does anybody know how to fix problem 1 ? That way, I could at least
deal with programs that print UTF8 on stdout.

Regarding point 2, I must admit even when I am the author of the
program, printing debug information (in unicode) on the stdout is a
really really tricky thing. Is there a recommendation on how to do
that properly ?

Important information : I am using Python 2.5

cheers,

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


Re: unicode printing on Windows

2012-02-09 Thread Andrew Berg
On 2/9/2012 4:46 AM, BlueBird wrote:
> Does anybody know how to fix problem 1 ? That way, I could at least
> deal with programs that print UTF8 on stdout.
I'm pretty sure there isn't a way. cp65001 is supposed to be UTF-8, but
it doesn't work in my experience (I fed it some UTF-8 demo text and I
got garbage and beeping). Python 3.3 will support cp65001, 3.2 and below
do not.

> Regarding point 2, I must admit even when I am the author of the
> program, printing debug information (in unicode) on the stdout is a
> really really tricky thing. Is there a recommendation on how to do
> that properly ?
Use the logging module, perhaps? It has handled encoding issues
automatically, at least in my experience. In Python 3, you can convert a
string to bytes from one encoding, then convert to another encoding, but
Python 2 has things set up very differently (and my experience is with
py3k, so I can't help much).

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


Re: standalone python web server

2012-02-09 Thread Thomas Bach
Rita  writes:

> I am building a small intranet website and I would like to use
> Python. I was wondering if there was a easy and medium performance
> python based web server available. 

Are you going to use a framework? Most of these ship with a light
web server implementation… You probably want to check these out too…

I got a pretty robust setup via
+ nginx,
+ supervisord,
+ the web server shipped with Pyramid

If you want to use the WSGI standard I'd recommend to read

http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/deployment.html
 

This document describes several possible set ups to serve an WSGI
application…


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


Re: Issue with Scrapping Data from a webpage- Noob Question

2012-02-09 Thread anon hung
> Hi Fellow Pythoners,
>
> I'm trying to collect table data from an authenticated webpage (Tool) to
> which I have access.
>
> I will have the required data after 'click'ing a submit button on the tool
> homepage.
> When I inspect the submit button i see
> 
>
> Thus the tool's homepage is of the form www.example.com/Tool and on
> clicking the submit button the data I need will be at
> www.example.com/Tool/index.do
>
> The problem that I'm running into is in my below code is giving me the
> source of homepage(www.example.com/Tool) and not the of the submitted page(
> www.example.com/Tool/index.do)
>
> url="www.example.com/Tool/index.do"
> request = urllib2.Request(url, data, {'Authorization': "Basic " +
> base64.b64encode("%s:%s" % (username, password))})
> Response_Page=urllib2.urlopen(request).read()
>
> Is there a way I can access the source of the submitted page?
>
> PS: Sorry for laying out very tiny details on what I'm trying to do, I just
> wanted to explain myself clearly :)
>
> Thanks in advance for your time on this one.

Have you checked beautifulsoup?

Best,
anonhung


-- 
Viktor Orban Prime minister of Hungary
http://spreadingviktororban.weebly.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Read-only attribute in module

2012-02-09 Thread Mateusz Loskot
Hi,

I'm implementing Python 3 extension using the Python C API.
I am familiar with defining new types, implementing get/set for attributes, etc.

I'm wondering, is there any mean to implement attribute in module
scope which is read-only?

So, the following

import xyz
print(xyz.flag)  # OK
xyz.flag = 0# error due to no write access

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-only attribute in module

2012-02-09 Thread Ben Finney
Mateusz Loskot  writes:

> I'm wondering, is there any mean to implement attribute in module
> scope which is read-only?

Python is designed by and for consenting adults. Rather than
restricting, instead use conventions to make your intent clear to the
user of your library.

> So, the following
>
> import xyz
> print(xyz.flag)  # OK
> xyz.flag = 0# error due to no write access

PEP 8 http://www.python.org/dev/peps/pep-0008/> gives the style
guide for Python code (strictly for the standard library, but it is
recommended for all Python code).

If you want a module attribute that is intended to remain bound to the
same value, use PEP 8's recommendation and name the attribute in
‘ALL_UPPER_CASE’.

If you want an attribute that is intended only for internal use (an
implementation detail that should not be relied upon outside the
library), use PEP 8's recommendation and name the attribute with a
‘_single_leading_underscore’.

-- 
 \   “We jealously reserve the right to be mistaken in our view of |
  `\  what exists, given that theories often change under pressure |
_o__)  from further investigation.” —Thomas W. Clark, 2009 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can not get the result of query in pymssql module of python...

2012-02-09 Thread Rod Person
On Thu, 9 Feb 2012 12:34:25 +0530
amarjeet yadav  wrote:

> Hi All,
>This is my first post to any mailing group. I am QA engg
> and using python for testing automation. I need to connect with Mysql
> (2008) and mssql databases for executing some queries.
> 
> I have installed following modules & softwares in python 2.7 :
> 
> python 2.7.2
> setuptools
> MySQLdb Module
> pymssql module
> yum install mysql msql-devel freetdf
> 
> I have installed freetds 0.9version. After installation of all the
> above components, I have done following things
> 
> Python 2.6 (r26:66714, Apr  8 2010, 08:46:35)
> [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import pymssql
> >>> conn = pymssql.connect(host='mssql_server', user='_username',
> password='_password', database='_db',as_dict=True)
> >>> cur = conn.cursor()
> >>> cur.execute('select count(*) from D2.dbo.abc (nolock)')
> >>> print cur.fetchall()

What if you change this to 

print cur.fetchone()

About 95% of my python database work is with MS SQL. I use fetchone when
as_dict is True and it seems to work better for me.

> []
> >>> cur.rowcount
> -1
> >>> exit()
> 
> I am expecting that the result of the query will be 16. But it is not
> retuning any data from query with no error at any place. On execting
> the same query in tsql, I got result as 16.
> 



-- 

Rod Person  http://www.rodperson.com  [email protected]

'Silence is a fence around wisdom'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: standalone python web server

2012-02-09 Thread Rita
yes, I would like to use a framework. I like the twisted method the user
posted. Are there any examples of it using a framework, get/post, etc..?



On Thu, Feb 9, 2012 at 6:28 AM, Thomas Bach wrote:

> Rita  writes:
>
> > I am building a small intranet website and I would like to use
> > Python. I was wondering if there was a easy and medium performance
> > python based web server available.
>
> Are you going to use a framework? Most of these ship with a light
> web server implementation… You probably want to check these out too…
>
> I got a pretty robust setup via
> + nginx,
> + supervisord,
> + the web server shipped with Pyramid
>
> If you want to use the WSGI standard I'd recommend to read
>
>
> http://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/deployment.html
>
> This document describes several possible set ups to serve an WSGI
> application…
>
>
> Regards,
>vince
>



-- 
--- Get your facts first, then you can distort them as you please.--
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Komodo 7 release (Python development tools)

2012-02-09 Thread Rod Person
On Wed, 08 Feb 2012 16:52:50 -0500
Terry Reedy  wrote:

> On 2/8/2012 3:14 PM, Todd Whiteman wrote:
> 
> > My name is Todd. I'm the lead developer for Komodo IDE (Interactive
> > Development Environment) and Komodo Edit (a free, open-source
> > editor) at ActiveState. I wanted to announce that the newest
> > version, Komodo 7, has been released:
> 
> This is a pretty good release announcement, but a few questions.
> ...
>  >http://www.activestate.com/komodo-ide/python-editor
> 
> It would seem that the Professional Python Editor is the same as
> Komodo Edit, but it is unclear why only Python editing would be
> featured for Komodo IDE.
> 
> http://www.activestate.com/komodo-edit
> 
> is the page with the link people need to download just the editor.
> 
> Does K.Edit let me run a program with one key, like F5 in IDLE?
> If so, does it leave me in interactive mode (python -i) as IDLE does?
> 

I'm not an ActiveState employee, but I have used Komodo IDE since
version 4, on FreeBSD and Windows. The selling point of the IDE is
definitely the interactive python debugger which isn't in the editor.

It also supports more than python, just in case for some old reason
you'd find the need to write Perl, Ruby or TCL code.

-- 

Rod Person  http://www.rodperson.com  [email protected]

'Silence is a fence around wisdom'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Id of methods

2012-02-09 Thread [email protected]
On Feb 9, 5:06 am, Chris Angelico  wrote:
> On Thu, Feb 9, 2012 at 2:48 PM, Emeka  wrote:
>
> > My question is why is it that the id of Boo.daf  is different from daf's hex
> > value in the above dict?
>
>
> daf is not a function, it's a special object for an unbound method.

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

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


Software tool for stochastic simulation as well as for the stochastic optimization

2012-02-09 Thread John Oksz
Hello Python World,

I am starting work on stochastic approach.

I plan to work in decision support field in environmental engineering
so I will use both the stochastic simulation as well as the stochastic
optimization.
I would like to select the best for both approaches software tool.

what you suggest ... Matlab ... python ... something else?

Any thoughts would be appreciated,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: turbogears 1

2012-02-09 Thread Roy Smith
In article ,
 anon hung  wrote:

> >> Hey guys, someone asked me to maintain his old website, trouble is,
> >> it's in python, more trouble is it's in turbogears 1. I'm not fluent
> >> in python but all right, I can learn, but this turbogears
> >> thing..
> >>
> >> First of all, is it still alive? Looks like turbogears 2 is the most
> >> recent version but even that is being abandoned.
> >
> > Yup, looks dead to me.  Hasn't had a release in almost 2 months or a
> > commit to the GIT repo in 2 days.  Must be nailed to its perch or
> > something.
> >
> > http://turbogears.org/en/current-status
> > http://sourceforge.net/p/turbogears2/tg2/commit_browser
> 
> All right, what I got confused about is that they talk about pyramid
> these days which will not be turbogears 2 based.
> 
> >> Am I basically given vaporware? Does anyone have any up to date info?
> >
> > Have you considered Ruby on Rails?
> 
> This is joke, right? :)

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


Re: Naming convention for in-house modules (Newbie question)

2012-02-09 Thread Laurent Claessens



Here is my question: I would like to start an in-house library of small
modules to import, for things like error handling/logging. That's easy
enough, but is there a recommended way of naming such modules? I am
concerned about avoiding name clashes with standard modules and site
packages.

Thanks.



This is not 100% an answer to the question, but you should read that :
http://www.python.org/dev/peps/pep-0008/

This explain you WhatCaseToChoose for_naming youVariables.

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


Re: frozendict

2012-02-09 Thread Nathan Rice
On Thu, Feb 9, 2012 at 5:33 AM, Duncan Booth
 wrote:
> Nathan Rice  wrote:
>
>> I put dicts in sets all the time.  I just tuple the items, but that
>> means you have to re-dict it on the way out to do anything useful with
>> it.  I am too lazy to write a frozendict or import one, but I would
>> use it if it was a builtin.
>>
> I hope you sort the items before putting them in a tuple, otherwise how do
> you handle two identical dicts that return their items in a different
> order?

Two dicts created from the same inputs will return items in the same
arbitrary order.  As long as you don't insert or delete a key you're
fine.


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


Re: Naming convention for in-house modules (Newbie question)

2012-02-09 Thread Arnaud Delobelle
On 9 February 2012 14:00, Laurent Claessens  wrote:
>
>> Here is my question: I would like to start an in-house library of small
>> modules to import, for things like error handling/logging. That's easy
>> enough, but is there a recommended way of naming such modules? I am
>> concerned about avoiding name clashes with standard modules and site
>> packages.
>>
>> Thanks.
>>
>
> This is not 100% an answer to the question, but you should read that :
> http://www.python.org/dev/peps/pep-0008/

The OP mentions PEP 8 in the bit of his message that you *don't* quote.

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


Re: frozendict

2012-02-09 Thread Duncan Booth
Nathan Rice  wrote:

> On Thu, Feb 9, 2012 at 5:33 AM, Duncan Booth
> wrote:
>> Nathan Rice  wrote:
>>
>>> I put dicts in sets all the time.  I just tuple the items, but that
>>> means you have to re-dict it on the way out to do anything useful
>>> with it.  I am too lazy to write a frozendict or import one, but I
>>> would use it if it was a builtin.
>>>
>> I hope you sort the items before putting them in a tuple, otherwise
>> how d 
> o
>> you handle two identical dicts that return their items in a different
>> order?
> 
> Two dicts created from the same inputs will return items in the same
> arbitrary order.  As long as you don't insert or delete a key you're
> fine.
> 
Two dicts that contain the same keys and values may or may not return them 
in the same order:

>>> dict.fromkeys('ia')
{'i': None, 'a': None}
>>> dict.fromkeys('ai')
{'a': None, 'i': None}

Would your system count those two dicts as the same?

If the sequence in which the keys were added to the dict (and deleted if 
appropriate) is exactly the same then it is likely but still not guaranteed 
that they will have the same order. The only ordering guarantee is that 
within a single dict keys and values will appear in a consistent order so 
long as you don't add/delete keys between calls.


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


Re: frozendict

2012-02-09 Thread Nathan Rice
>> Two dicts created from the same inputs will return items in the same
>> arbitrary order.  As long as you don't insert or delete a key you're
>> fine.
>>
> Two dicts that contain the same keys and values may or may not return them
> in the same order:
>
 dict.fromkeys('ia')
> {'i': None, 'a': None}
 dict.fromkeys('ai')
> {'a': None, 'i': None}
>
> Would your system count those two dicts as the same?
>
> If the sequence in which the keys were added to the dict (and deleted if
> appropriate) is exactly the same then it is likely but still not guaranteed
> that they will have the same order. The only ordering guarantee is that
> within a single dict keys and values will appear in a consistent order so
> long as you don't add/delete keys between calls.

As I said, two dictionaries created from the same input will be the
same...  'ai' != 'ia'.  If I need to hash a dict that I don't know was
created in a deterministic order, I'd frozenset(thedict.items()).


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


ANN: eGenix mxODBC Zope Database Adapter 2.0.2

2012-02-09 Thread eGenix Team: M.-A. Lemburg

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
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: what is the difference between @property and method

2012-02-09 Thread John Posner
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: Software tool for stochastic simulation as well as for the stochastic optimization

2012-02-09 Thread Wolfgang Keller
> I plan to work in decision support field in environmental engineering
> so I will use both the stochastic simulation as well as the stochastic
> optimization.
> I would like to select the best for both approaches software tool.
> 
> what you suggest ... Matlab ... python ... something else?

I have no clue whether it does stochastic simulation and optimisation,
but R is THE free open-source statistic analysis tool. It does have
a Python interface, RPy. And there's a free open-source replacement for
Matlab, Scilab. Which has a Python interface as well.

Sincerely,

Wolfgang

-- 
HOMO HOMINI HOSTISIN FELIBUS FELICITAS
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: frozendict

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 8:19 AM, Nathan Rice
 wrote:
> As I said, two dictionaries created from the same input will be the
> same...

That's an implementation detail, not a guarantee.  It will hold for
current versions of CPython but not necessarily for other Python
implementations.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-only attribute in module

2012-02-09 Thread mloskot

Ben Finney-10 wrote
> 
> Mateusz Loskot  writes:
> 
>> So, the following
>>
>> import xyz
>> print(xyz.flag)  # OK
>> xyz.flag = 0# error due to no write access
> 
> PEP 8 ; gives the style
> guide for Python code (strictly for the standard library, but it is
> recommended for all Python code).
> 

Ben,

That's what I thought really.
Thank you for confirming the sanity of the style-powered conventions.

Best regards,

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


Re: frozendict

2012-02-09 Thread Nathan Rice
On Thu, Feb 9, 2012 at 11:35 AM, Ian Kelly  wrote:
> On Thu, Feb 9, 2012 at 8:19 AM, Nathan Rice
>  wrote:
>> As I said, two dictionaries created from the same input will be the
>> same...
>
> That's an implementation detail, not a guarantee.  It will hold for
> current versions of CPython but not necessarily for other Python
> implementations.

That is true.  The implications of the function that creates
dictionaries being non-deterministic are a little scary though, so I
suspect that it will hold :)

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


Re: Naming convention for in-house modules (Newbie question)

2012-02-09 Thread Laurent Claessens



 This is not 100% an answer to the question, but you should read that :
 http://www.python.org/dev/peps/pep-0008/


The OP mentions PEP 8 in the bit of his message that you *don't* quote.


Well... I've to sleep. Sorry :(

Laurent


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


Re: unicode printing on Windows

2012-02-09 Thread Terry Reedy

On 2/9/2012 5:46 AM, BlueBird wrote:

Hi,

The question is not totally related to Python but there is a strong
connection. Everytime that I try to debug some python programs under
Windows, I encounter the issue that things printed on the console
simply break the program because :
1. My windows console does not support UTF8


The IDLE shell (now) is friendlier to unicode, supporting the entire 
BMP. So you may have more success loading into an IDLE editor and 
running from there with F5. Or perhaps execfile in the shell (I never 
tried this). Of course, import and pdb in the shell work. This all 
depends on what 'debugging' means to you.



Important information : I am using Python 2.5


I don't know if IDLE was different then.

--
Terry Jan Reedy

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


multiple namespaces within a single module?

2012-02-09 Thread jkn
Hello there

is it possible to have multiple namespaces within a single python
module?

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. I was hoping that there might be a simple mechanism that would
let me do this and maintain the namespaces referred to: so that the
'combined' file would look something like

#
# not real python
#

# originally from a.py
with namespace a:
def function():
pass

# ...

# originally from b.py
with namespace b:
def function():
pass

# originally from main module

a.function()
b.function()

etc.

Is there anything like this available?

Thanks
J^n

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


Re: frozendict

2012-02-09 Thread Duncan Booth
Nathan Rice  wrote:

> As I said, two dictionaries created from the same input will be the
> same...  'ai' != 'ia'.  If I need to hash a dict that I don't know was
> created in a deterministic order, I'd frozenset(thedict.items()).
> 
Fair enough, the idea scares me, but it's your code and your risk.

BTW, make sure that if you ever copy any of those dictionaries they all get 
copied the same number of times as simply copying a dict can change the key 
order.

>>> dict.fromkeys('me')
{'e': None, 'm': None}
>>> dict(dict.fromkeys('me'))
{'m': None, 'e': None}
>>> dict(dict(dict.fromkeys('me')))
{'e': None, 'm': None}

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


Apparent "double imports" (was: Naming convention for in-house modules (Newbie question))

2012-02-09 Thread HoneyMonster
On Thu, 09 Feb 2012 14:36:52 +, Arnaud Delobelle wrote:

> On 9 February 2012 14:00, Laurent Claessens  wrote:
>>
>>> Here is my question: I would like to start an in-house library of
>>> small modules to import, for things like error handling/logging.
>>> That's easy enough, but is there a recommended way of naming such
>>> modules? I am concerned about avoiding name clashes with standard
>>> modules and site packages.
>>>
>>> Thanks.
>>>
>>>
>> This is not 100% an answer to the question, but you should read that :
>> http://www.python.org/dev/peps/pep-0008/
> 
> The OP mentions PEP 8 in the bit of his message that you *don't* quote.

Thank you for that Arnaud, and thanks to Chris R. I'm going along with 
Chris's suggestion for the moment.

One issue I have run into, which may or may not be a problem: I am 
finding that modules in the in-house "library" package sometimes have to 
import modules like sys and os, which are also imported by the "calling" 
module. Is this a problem or an overhead, or does it just result in two 
names for the same object?

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


Re: Apparent "double imports" (was: Naming convention for in-house modules (Newbie question))

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 11:53 AM, HoneyMonster  wrote:
> One issue I have run into, which may or may not be a problem: I am
> finding that modules in the in-house "library" package sometimes have to
> import modules like sys and os, which are also imported by the "calling"
> module. Is this a problem or an overhead, or does it just result in two
> names for the same object?

Two names for the same object.  When a module is imported, the module
object is stored in the sys.modules dict.  Further imports of the same
module just return the same module object from sys.modules.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-only attribute in module

2012-02-09 Thread Terry Reedy

On 2/9/2012 6:43 AM, Mateusz Loskot wrote:

Hi,

I'm implementing Python 3 extension using the Python C API. I am
familiar with defining new types, implementing get/set for
attributes, etc.

I'm wondering, is there any mean to implement attribute in module
scope which is read-only?


Not that I know of. Python intentionally leaves modules mutable even 
after the code has executed so they can be monkey-patched from outside. 
The argument for is that it is unusual to do so but sometimes very 
useful and necessary. The main argument against is that it prevents 
optimizations that would make code in modules run faster.



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 Jan Reedy

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


Re: what is the difference between @property and method

2012-02-09 Thread Terry Reedy

On 2/9/2012 10:36 AM, 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


Suggested doc changes on the tracker get reviewed, and often applied.

--
Terry Jan Reedy

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


Re: multiple namespaces within a single module?

2012-02-09 Thread Peter Otten
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.


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


Re: Read-only attribute in module

2012-02-09 Thread Mark Lawrence

On 09/02/2012 11:43, Mateusz Loskot wrote:

Hi,

I'm implementing Python 3 extension using the Python C API.
I am familiar with defining new types, implementing get/set for attributes, etc.

I'm wondering, is there any mean to implement attribute in module
scope which is read-only?

So, the following

import xyz
print(xyz.flag)  # OK
xyz.flag = 0# error due to no write access

Best regards,


There's a recipe by Alex Martelli here 
http://code.activestate.com/recipes/65207-constants-in-python/ but most 
people wouldn't bother with it.  As others have said simply use 
THIS_IS_A_CONSTANT.


--
Cheers.

Mark Lawrence.

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


Re: Apparent "double imports" (was: Naming convention for in-house modules (Newbie question))

2012-02-09 Thread HoneyMonster
On Thu, 09 Feb 2012 12:02:03 -0700, Ian Kelly wrote:

> On Thu, Feb 9, 2012 at 11:53 AM, HoneyMonster
>  wrote:
>> One issue I have run into, which may or may not be a problem: I am
>> finding that modules in the in-house "library" package sometimes have
>> to import modules like sys and os, which are also imported by the
>> "calling"
>> module. Is this a problem or an overhead, or does it just result in two
>> names for the same object?
> 
> Two names for the same object.  When a module is imported, the module
> object is stored in the sys.modules dict.  Further imports of the same
> module just return the same module object from sys.modules.

Excellent! It seems it is not a problem at all, then. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Apparent "double imports"

2012-02-09 Thread Dave Angel

On 02/09/2012 02:40 PM, HoneyMonster wrote:

On Thu, 09 Feb 2012 12:02:03 -0700, Ian Kelly wrote:


On Thu, Feb 9, 2012 at 11:53 AM, HoneyMonster
  wrote:

One issue I have run into, which may or may not be a problem: I am
finding that modules in the in-house "library" package sometimes have
to import modules like sys and os, which are also imported by the
"calling"
module. Is this a problem or an overhead, or does it just result in two
names for the same object?

Two names for the same object.  When a module is imported, the module
object is stored in the sys.modules dict.  Further imports of the same
module just return the same module object from sys.modules.

Excellent! It seems it is not a problem at all, then. Thank you.
Just to add a little subtlety, there is a problem with mutually 
recursive imports.  If module aaa imports module bbb, and modole bbb 
imports aaa, there can be some problems.  Most can be avoided by putting 
the imports right at the beginning of each file, so no work has been 
done before doing the imports.  Then by the time some code tries to use 
them, they're all resolved.  One exception is if you try to import the 
file that is your script file.  This one is made into a module by the 
special name of __main__, and if you import it using the original name, 
you'll have two copies around.  That can lead to some very interesting 
anomalies.


Better is to make sure no loops exist in the importing tree, which is a 
desirable structuring goal anyway.  When two modules need each other, 
try to either move the common stuff to a 3rd module they each import, or 
do something with callbacks or other mechanism that reflects what's 
really going on.


Of cours that last paragraph is strictly my own opinion.

--

DaveA

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


Formate a number with commas

2012-02-09 Thread noydb
How do you format a number to print with commas?

Some quick searching, i came up with:

>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
>>> locale.format('%d', 2348721, True)
'2,348,721'


I'm a perpetual novice, so just looking for better, slicker, more
proper, pythonic ways to do this.

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


Re: Formate a number with commas

2012-02-09 Thread Neil Cerutti
On 2012-02-09, noydb  wrote:
> How do you format a number to print with commas?
>
> Some quick searching, i came up with:
>
 import locale
 locale.setlocale(locale.LC_ALL, "")
 locale.format('%d', 2348721, True)
> '2,348,721'
>
> I'm a perpetual novice, so just looking for better, slicker,
> more proper, pythonic ways to do this.

I think you've found an excellent way to do it.

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


Re: Reading files in from the proper directory

2012-02-09 Thread SMac2347
On Feb 7, 3:16 pm, Peter Otten <[email protected]> wrote:
> [email protected] wrote:
> > xls_files   = glob.glob(in_dir + "*.xls")
>
> Try changing that to
>
> pattern = os.path.join(in_dir, "*.xls")
> xls_files = glob.glob(pattern)
>
> os.path.join() inserts a (back)slash between directory and filename if
> necessary.
>
> > merge_xls(in_dir="C:\Documents and Settings\smacdon\Desktop\09 Aggregate 
> > JWS")
>
> If you paste the directory name literal into the interactive interpreter
> you'll be surprised:
>
> >>> "C:\Documents and Settings\smacdon\Desktop\09 Aggregate JWS"
>
> 'C:\\Documents and Settings\\smacdon\\Desktop\x009 Aggregate JWS'
>
> "\09" is intrpreted as chr(9). Use a raw string to prevent Python from
> interpreting a backslash as the start of an escape sequence
>
> >>> r"C:\Documents and Settings\smacdon\Desktop\09 Aggregate JWS"
>
> 'C:\\Documents and Settings\\smacdon\\Desktop\\09 Aggregate JWS'
>
> or use forward slashes as directory separators.

Peter, thanks so much for your help, your suggestions were spot on. So
now my program runs and is able to find and process the files
correctly, but I end up getting the following message:

Traceback (most recent call last):
  File "C:/Documents and Settings/smacdon/My Documents/
excel_merge_files_indirectory v2.py", line 49, in 
merge_xls(in_dir=r"C:\Documents and Settings\smacdon\Desktop\09
Aggregate JWS")
  File "C:/Documents and Settings/smacdon/My Documents/
excel_merge_files_indirectory v2.py", line 36, in merge_xls
merged_book.save(out_file)
  File "C:\Python27\lib\site-packages\xlwt\Workbook.py", line 634, in
save
doc.save(filename, self.get_biff_data())
  File "C:\Python27\lib\site-packages\xlwt\CompoundDoc.py", line 507,
in save
f = open(file_name_or_filelike_obj, 'wb')
TypeError: file() argument 1 must be encoded string without NULL
bytes, not str


If I am interpreting correctly, am I to understand that it would
appear the issue is tracing back to functions in the xlwt module? If
so, what can I do to fix this? Again, any and all help is appreciated!

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


Re: Formate a number with commas

2012-02-09 Thread Peter Otten
noydb wrote:

> How do you format a number to print with commas?
> 
> Some quick searching, i came up with:
> 
 import locale
 locale.setlocale(locale.LC_ALL, "")
 locale.format('%d', 2348721, True)
> '2,348,721'
> 
> 
> I'm a perpetual novice, so just looking for better, slicker, more
> proper, pythonic ways to do this.

>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'de_DE.UTF-8'
>>> "{:n}".format(1234) # locale-aware
'1.234'
>>> "{:,d}".format(1234) # always a comma
'1,234'



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


Re: Reading files in from the proper directory

2012-02-09 Thread SMac2347
On Feb 7, 3:16 pm, Peter Otten <[email protected]> wrote:
> [email protected] wrote:
> > xls_files   = glob.glob(in_dir + "*.xls")
>
> Try changing that to
>
> pattern = os.path.join(in_dir, "*.xls")
> xls_files = glob.glob(pattern)
>
> os.path.join() inserts a (back)slash between directory and filename if
> necessary.
>
> > merge_xls(in_dir="C:\Documents and Settings\smacdon\Desktop\09 Aggregate 
> > JWS")
>
> If you paste the directory name literal into the interactive interpreter
> you'll be surprised:
>
> >>> "C:\Documents and Settings\smacdon\Desktop\09 Aggregate JWS"
>
> 'C:\\Documents and Settings\\smacdon\\Desktop\x009 Aggregate JWS'
>
> "\09" is intrpreted as chr(9). Use a raw string to prevent Python from
> interpreting a backslash as the start of an escape sequence
>
> >>> r"C:\Documents and Settings\smacdon\Desktop\09 Aggregate JWS"
>
> 'C:\\Documents and Settings\\smacdon\\Desktop\\09 Aggregate JWS'
>
> or use forward slashes as directory separators.

Disregard my last post, I was able to figure it out, I also had to
cover the out_file file name into a raw string as well. Thanks again
for all the help!!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formate a number with commas

2012-02-09 Thread Chris Rebert
On Thu, Feb 9, 2012 at 12:39 PM, Peter Otten <[email protected]> wrote:
> noydb wrote:
>
>> How do you format a number to print with commas?
>>
>> Some quick searching, i came up with:
>>
> import locale
> locale.setlocale(locale.LC_ALL, "")
> locale.format('%d', 2348721, True)
>> '2,348,721'
>>
>>
>> I'm a perpetual novice, so just looking for better, slicker, more
>> proper, pythonic ways to do this.
>
 import locale
 locale.setlocale(locale.LC_ALL, "")
> 'de_DE.UTF-8'
 "{:n}".format(1234) # locale-aware
> '1.234'
 "{:,d}".format(1234) # always a comma
> '1,234'

The latter requires Python 3.1+ and is courtesy PEP 378
(http://www.python.org/dev/peps/pep-0378/ ).

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


Re: Reading files in from the proper directory

2012-02-09 Thread Peter Otten
[email protected] wrote:

> On Feb 7, 3:16 pm, Peter Otten <[email protected]> wrote:
>> [email protected] wrote:
>> > xls_files   = glob.glob(in_dir + "*.xls")
>>
>> Try changing that to
>>
>> pattern = os.path.join(in_dir, "*.xls")
>> xls_files = glob.glob(pattern)
>>
>> os.path.join() inserts a (back)slash between directory and filename if
>> necessary.
>>
>> > merge_xls(in_dir="C:\Documents and Settings\smacdon\Desktop\09
>> > Aggregate JWS")
>>
>> If you paste the directory name literal into the interactive interpreter
>> you'll be surprised:
>>
>> >>> "C:\Documents and Settings\smacdon\Desktop\09 Aggregate JWS"
>>
>> 'C:\\Documents and Settings\\smacdon\\Desktop\x009 Aggregate JWS'
>>
>> "\09" is intrpreted as chr(9). Use a raw string to prevent Python from

Sorry, I was wrong here. "\09" is actually "\0" (i. e. chr(0))
followed by "9". Escape sequences starting with 0 are octal numbers
in Python 2 and thus may never contain digits > 7.

>> interpreting a backslash as the start of an escape sequence
>>
>> >>> r"C:\Documents and Settings\smacdon\Desktop\09 Aggregate JWS"
>>
>> 'C:\\Documents and Settings\\smacdon\\Desktop\\09 Aggregate JWS'
>>
>> or use forward slashes as directory separators.
> 
> Peter, thanks so much for your help, your suggestions were spot on. So
> now my program runs and is able to find and process the files
> correctly, but I end up getting the following message:
> 
> Traceback (most recent call last):
>   File "C:/Documents and Settings/smacdon/My Documents/
> excel_merge_files_indirectory v2.py", line 49, in 
> merge_xls(in_dir=r"C:\Documents and Settings\smacdon\Desktop\09
> Aggregate JWS")
>   File "C:/Documents and Settings/smacdon/My Documents/
> excel_merge_files_indirectory v2.py", line 36, in merge_xls
> merged_book.save(out_file)
>   File "C:\Python27\lib\site-packages\xlwt\Workbook.py", line 634, in
> save
> doc.save(filename, self.get_biff_data())
>   File "C:\Python27\lib\site-packages\xlwt\CompoundDoc.py", line 507,
> in save
> f = open(file_name_or_filelike_obj, 'wb')
> TypeError: file() argument 1 must be encoded string without NULL
> bytes, not str
> 
> 
> If I am interpreting correctly, am I to understand that it would
> appear the issue is tracing back to functions in the xlwt module? If
> so, what can I do to fix this? Again, any and all help is appreciated!

You probably forgot to convert the default value for out_file into a 
raw string:

def merge_xls(in_dir, out_file=
r"C:\Documents and Settings\smacdon\Desktop\09 Aggregate 
JWS\09_merged_data.xls"):

"\0" is therefore interpreted as chr(0) which marks the end of a C string and 
may not occur in a file name. chr(0) is called "NULL byte" in the error message 
you get.

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


Re: Formate a number with commas

2012-02-09 Thread Alain Ketterlin
noydb  writes:

> How do you format a number to print with commas?

 import locale
 locale.setlocale(locale.LC_ALL, "")

This sets the locale according to the environment (typically LANG---I'm
talking about linux, don't know others).

 locale.format('%d', 2348721, True)
> '2,348,721'

This would not give the same result in environments with other locales
(typically de or fr or ...)

Anyway, it's probably the right thing to do: the user will get numbers
written according to its own locale.

If you really want commas whatever locale you're running in, you will
need to use setlocale to change number formatting to a locale that uses
commas. For instance:

locale.setlocale(LC_NUMERIC,"en_US.utf8")
locale.format('%d', 2348721, True)

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


Re: Formate a number with commas

2012-02-09 Thread Peter Otten
Chris Rebert wrote:

> On Thu, Feb 9, 2012 at 12:39 PM, Peter Otten <[email protected]> wrote:

> import locale
> locale.setlocale(locale.LC_ALL, "")
>> 'de_DE.UTF-8'
> "{:n}".format(1234) # locale-aware
>> '1.234'
> "{:,d}".format(1234) # always a comma
>> '1,234'
> 
> The latter requires Python 3.1+ and is courtesy PEP 378
> (http://www.python.org/dev/peps/pep-0378/ ).

I actually ran the above session in 2.7, so that should do, too.

http://docs.python.org/whatsnew/2.7.html#pep-378-format-specifier-for-
thousands-separator


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


Re: multiple namespaces within a single module?

2012-02-09 Thread Ethan Furman

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



Speaking of...


class NameSpace(object):
def __init__(self, globals):
self.globals = globals
self.current_keys = list(globals.keys())
def __enter__(self):
return self
def __exit__(self, *args):
new_items = []
for key, value in self.globals.items():
if key not in self.current_keys and value is not self:
new_items.append((key, value))
for key, value in new_items:
setattr(self, key, value)
del self.globals[key]

if __name__ == '__main__':
with NameSpace(globals()) as a:
def function():
print('inside a!')
with NameSpace(globals()) as b:
def function():
print('inside b!')

a.function()
b.function()
print(vars())


The NameSpace objects do *not* get their own copy of globals(), but for 
functions, etc., it should work fine.  As a bonus the above code works 
for both 2.x and 3.x.


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


Re: multiple namespaces within a single module?

2012-02-09 Thread Peter Otten
Ethan Furman wrote:

> Peter Otten 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.
> 
> 
> Speaking of...
> 
> 
> class NameSpace(object):
>  def __init__(self, globals):
>  self.globals = globals
>  self.current_keys = list(globals.keys())
>  def __enter__(self):
>  return self
>  def __exit__(self, *args):
>  new_items = []
>  for key, value in self.globals.items():
>  if key not in self.current_keys and value is not self:
>  new_items.append((key, value))
>  for key, value in new_items:
>  setattr(self, key, value)
>  del self.globals[key]
> 
> if __name__ == '__main__':
>  with NameSpace(globals()) as a:
>  def function():
>  print('inside a!')
>  with NameSpace(globals()) as b:
>  def function():
>  print('inside b!')
> 
>  a.function()
>  b.function()
>  print(vars())
> 
> 
> The NameSpace objects do *not* get their own copy of globals(), but for
> functions, etc., it should work fine.  As a bonus the above code works
> for both 2.x and 3.x.

Hm, what about

with NameSpace(globals()) as a:
x = "inside a!"
def function():
print(x)
with NameSpace(globals()) as b:
x = "inside b!"
def function():
print(x)

x = "inside main!"
a.function()
b.function()


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


Re: Apparent "double imports"

2012-02-09 Thread HoneyMonster
On Thu, 09 Feb 2012 15:05:52 -0500, Dave Angel wrote:

> On 02/09/2012 02:40 PM, HoneyMonster wrote:
>> On Thu, 09 Feb 2012 12:02:03 -0700, Ian Kelly wrote:
>>
>>> On Thu, Feb 9, 2012 at 11:53 AM, HoneyMonster
>>>   wrote:
 One issue I have run into, which may or may not be a problem: I am
 finding that modules in the in-house "library" package sometimes have
 to import modules like sys and os, which are also imported by the
 "calling"
 module. Is this a problem or an overhead, or does it just result in
 two names for the same object?
>>> Two names for the same object.  When a module is imported, the module
>>> object is stored in the sys.modules dict.  Further imports of the same
>>> module just return the same module object from sys.modules.
>> Excellent! It seems it is not a problem at all, then. Thank you.
> Just to add a little subtlety, there is a problem with mutually
> recursive imports.  If module aaa imports module bbb, and modole bbb
> imports aaa, there can be some problems.  Most can be avoided by putting
> the imports right at the beginning of each file, so no work has been
> done before doing the imports.  Then by the time some code tries to use
> them, they're all resolved.  One exception is if you try to import the
> file that is your script file.  This one is made into a module by the
> special name of __main__, and if you import it using the original name,
> you'll have two copies around.  That can lead to some very interesting
> anomalies.
> 
> Better is to make sure no loops exist in the importing tree, which is a
> desirable structuring goal anyway.  When two modules need each other,
> try to either move the common stuff to a 3rd module they each import, or
> do something with callbacks or other mechanism that reflects what's
> really going on.
> 
> Of cours that last paragraph is strictly my own opinion.

Thanks, Dave. I'm sure I won't have a problem with circular imports. The 
structure I have in mind is:

A package (say ihlib) consisting of in-house "library" routines for local 
use. The directory above ihlib will be added to PYTHONPATH, so that 
imports can find ihlib.

"Top level" modules will import ihlib.blah as necessary in order to avoid 
code duplication amongst them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formate a number with commas

2012-02-09 Thread Chris Rebert
On Thu, Feb 9, 2012 at 1:16 PM, Peter Otten <[email protected]> wrote:
> Chris Rebert wrote:
>> On Thu, Feb 9, 2012 at 12:39 PM, Peter Otten <[email protected]> wrote:
>> import locale
>> locale.setlocale(locale.LC_ALL, "")
>>> 'de_DE.UTF-8'
>> "{:n}".format(1234) # locale-aware
>>> '1.234'
>> "{:,d}".format(1234) # always a comma
>>> '1,234'
>>
>> The latter requires Python 3.1+ and is courtesy PEP 378
>> (http://www.python.org/dev/peps/pep-0378/ ).
>
> I actually ran the above session in 2.7, so that should do, too.
>
> http://docs.python.org/whatsnew/2.7.html#pep-378-format-specifier-for-
> thousands-separator

Argh. The 2.7 docs say it was added in 2.7, but the 3.3a0 docs say it
was added in 3.1 (Guido's backporting time machine messes with
"causality").
Both statements are completely technically correct, but misleading
when not taken together.

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


Re: multiple namespaces within a single module?

2012-02-09 Thread Ethan Furman

Peter Otten wrote:

Hm, what about

with NameSpace(globals()) as a:
x = "inside a!"
def function():
print(x)
with NameSpace(globals()) as b:
x = "inside b!"
def function():
print(x)

x = "inside main!"
a.function()
b.function()




It would have to be `a.x = ...` and `b.x = ...` with corresponding 
`print(a.x)` and `print(b.x)`.


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


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


Want to improve my code.

2012-02-09 Thread Ian

Hi all,

I'm using  lxml etree, and have written a routine to remove nodes in the 
parsed tree.


Typically, I load html, and remove  tags, so I am moving the font 
tags children up and moving the text and tail data about.  The code of 
the deleteElem routine is here  http://snipt.org/GSoo0


It troubles me that there is so much repetition in the lines that call 
joiner.


How can I improve the code?

Regards

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


Re: Formate a number with commas

2012-02-09 Thread John Posner
On 2:59 PM, noydb wrote:
> How do you format a number to print with commas?

I would readily admit that both the "locale" module and "format" method
are preferable to this regular expression, which certainly violates the
"readability counts" dictum:

r"(?<=\d)(?=(\d\d\d)+$)"

# python 2.6.6
import re
find_blocks = re.compile(r"(?<=\d)(?=(\d\d\d)+$)")
for numstr in "1 12 123 1234 12345 123456 1234567 12345678".split():
print find_blocks.sub("," , numstr)

output is:

1
12
123
1,234
12,345
123,456
1,234,567
12,345,678

-John

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


Re: multiple namespaces within a single module?

2012-02-09 Thread jkn
Hi Peter

On Feb 9, 7:33 pm, Peter Otten <[email protected]> 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...

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


Re: multiple namespaces within a single module?

2012-02-09 Thread Ethan Furman

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:


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)


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


Re: Guide to: Learning Python Decorators

2012-02-09 Thread Ian

On 09/02/2012 21:41, Aaron France wrote:
How many pages is that? The amazon page conveniently left that off. 
There is an average of 5.1 chars per word in English, and usually about 
350 words an A4 page.


The 215K file is
a) Compressed - typically by 60%
b) Contains simple html and images as its source.
c) Must contain the cover image.

As a *very* rough guess, that means the files expands to 344K.

Remove the cover image at 250-300kb  leaves  44 to 94KB

That is 8700 words to 18400 words   or approx 25 to 50 pages.

But that is *very* *very* rough.

Regards

Ian

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


round down to nearest number

2012-02-09 Thread noydb
How do you round down ALWAYS to nearest 100?  Like, if I have number
3268, I want that rounded down to 3200.  I'm doing my rounding like
>>> round(3268, -2)
But, how to round DOWN?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 5:30 PM, noydb  wrote:
> How do you round down ALWAYS to nearest 100?  Like, if I have number
> 3268, I want that rounded down to 3200.  I'm doing my rounding like
 round(3268, -2)
> But, how to round DOWN?

>>> 3268 // 100 * 100
3200

For more complicated cases, Decimal objects allow you to specify
alternate rounding modes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read-only attribute in module

2012-02-09 Thread Steven D'Aprano
On Thu, 09 Feb 2012 23:32:59 +1100, Ben Finney wrote:

> Mateusz Loskot  writes:
> 
>> I'm wondering, is there any mean to implement attribute in module scope
>> which is read-only?
> 
> Python is designed by and for consenting adults. Rather than
> restricting, instead use conventions to make your intent clear to the
> user of your library.

Oh I agree. The convention I want to use to make my intent clear is the 
same convention used for the rest of Python: a runtime exception.

I find this "consenting adults" argument less than convincing. We already 
have constants in Python -- every int and float and string is a constant. 
You can't modify the object 1 to have the value 42, and for very good 
reason, "consenting adults" be damned.

What we don't have is *named* constants.

Python has no shortage of read-only values and members, e.g.:

>>> class A(object):
... pass
...
>>> A.__dict__ = {}
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: attribute '__dict__' of 'type' objects is not writable


Consider this:

If you pass an int to len(), you get a runtime error telling you that you 
did something wrong. Does this violate "consenting adults"? No, if you 
want to, you can monkey-patch len to accept ints, but you have to work at 
it. The normal behaviour is to get an error, not some arbitrary but 
meaningless behaviour. You certainly don't get told to use a naming 
convention (Hungarian notation, perhaps) to avoid passing the wrong value 
to len().

If you assign to something which is intended to be constant, you don't 
get an exception telling you that you made a mistake. Instead, you get 
unspecified (but almost certainly incorrect) behaviour in the module, and 
told to use a naming convention to remind you not to screw up.

The excuse given is that Python is for "consenting adults", but I don't 
believe it. I believe that the real reason is that it is hard to 
introduce named constants to Python, and rather than solve that hard 
problem, people just whitewash the issue and pretend that it's a feature. 
It's not a feature, it's a wart. There is no conceivable use-case for 
allowing math.pi = 2.5 to succeed.

Python happily violates "consenting adults" all over the place. We have 
properties, which can easily create read-only and write-once attributes. 
We have descriptors which can be used for the same. We have immutable 
types, and constant values, but not constant names.

Python can enforce all common software contracts I can think of, except 
the contract that a name will be set to a specific value. And that is, in 
my opinion, a weakness in Python.


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


Re: frozendict

2012-02-09 Thread Steven D'Aprano
On Thu, 09 Feb 2012 09:35:52 -0700, Ian Kelly wrote:

> On Thu, Feb 9, 2012 at 8:19 AM, Nathan Rice
>  wrote:
>> As I said, two dictionaries created from the same input will be the
>> same...
> 
> That's an implementation detail, not a guarantee.  It will hold for
> current versions of CPython but not necessarily for other Python
> implementations.

That day may be sooner than you think. It is very likely that in Python 
3.3, dict order will be randomized on creation as a side-effect of adding 
a random salt to hashes to prevent a serious vulnerability in dicts.

http://securitytracker.com/id/1026478

http://bugs.python.org/issue13703


If there is anyone still assuming that dicts have a predictable order, 
they're going to be in for a nasty surprise one of these days.



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


Re: round down to nearest number

2012-02-09 Thread noydb
hmmm, okay.

So how would you round UP always?  Say the number is 3219, so you want
3300 returned.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round down to nearest number

2012-02-09 Thread Chris Kaynor
On Thu, Feb 9, 2012 at 5:23 PM, noydb  wrote:

> hmmm, okay.
>
> So how would you round UP always?  Say the number is 3219, so you want
> 3300 returned.
>

You may want to look into the mathematical floor and ceiling functions[1].
Python exposes them in the math module as floor and ceil[2].

[1] http://en.wikipedia.org/wiki/Floor_and_ceiling_functions
[2] http://docs.python.org/library/math.html#math.floor and
http://docs.python.org/library/math.html#math.ceil


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


Re: round down to nearest number

2012-02-09 Thread Chris Kaynor
On Thu, Feb 9, 2012 at 5:40 PM, Chris Kaynor wrote:

> On Thu, Feb 9, 2012 at 5:23 PM, noydb  wrote:
>
>> hmmm, okay.
>>
>> So how would you round UP always?  Say the number is 3219, so you want
>> 3300 returned.
>>
>
> You may want to look into the mathematical floor and ceiling functions[1].
> Python exposes them in the math module as floor and ceil[2].
>
> [1] http://en.wikipedia.org/wiki/Floor_and_ceiling_functions
> [2] http://docs.python.org/library/math.html#math.floor and
> http://docs.python.org/library/math.html#math.ceil
>
>

I should have added, you can use multiplication and division to apply those
functions to other digits rather than the base one. For example, multiply
by 10, floor, divide by ten, will floor to one decimal point.


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


Re: round down to nearest number

2012-02-09 Thread Chris Rebert
On Thu, Feb 9, 2012 at 5:23 PM, noydb  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 %.

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


Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 6:43 PM, Chris Rebert  wrote:
> On Thu, Feb 9, 2012 at 5:23 PM, noydb  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 %.

There's no problem with negative numbers here, as long as you actually
want to round *up* or *down*, as opposed to away from zero or toward
zero.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: round down to nearest number

2012-02-09 Thread noydb
That {>>> (3219 + 99) // 100} doesnt work if the number is other then
4 digits.


(for rounding up to nearest 100):
>>> (3219 + 99)//100
33
>>> (3289 + 99)//100
33
>>> (328678 + 99)//100
3287
>>> (328 + 99)//100
4
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: frozendict

2012-02-09 Thread Nathan Rice
On Thu, Feb 9, 2012 at 8:24 PM, Steven D'Aprano
 wrote:
> On Thu, 09 Feb 2012 09:35:52 -0700, Ian Kelly wrote:
>
>> On Thu, Feb 9, 2012 at 8:19 AM, Nathan Rice
>>  wrote:
>>> As I said, two dictionaries created from the same input will be the
>>> same...
>>
>> That's an implementation detail, not a guarantee.  It will hold for
>> current versions of CPython but not necessarily for other Python
>> implementations.
>
> That day may be sooner than you think. It is very likely that in Python
> 3.3, dict order will be randomized on creation as a side-effect of adding
> a random salt to hashes to prevent a serious vulnerability in dicts.
>
> http://securitytracker.com/id/1026478
>
> http://bugs.python.org/issue13703
>
>
> If there is anyone still assuming that dicts have a predictable order,
> they're going to be in for a nasty surprise one of these days.

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


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


Re: Formate a number with commas

2012-02-09 Thread Terry Reedy

On 2/9/2012 5:12 PM, Chris Rebert wrote:


Argh. The 2.7 docs say it was added in 2.7, but the 3.3a0 docs say it
was added in 3.1 (Guido's backporting time machine messes with
"causality").


Python 2 docs refer to Python 2.
Python 3 docs refer to Python 3.
So 'it' was in neither 2.6 nor 3.1.


Both statements are completely technically correct, but misleading
when not taken together.


--
Terry Jan Reedy

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


Re: Guide to: Learning Python Decorators

2012-02-09 Thread Terry Reedy

On 2/9/2012 5:43 PM, Ian wrote:

On 09/02/2012 21:41, Aaron France wrote:

How many pages is that? The amazon page conveniently left that off.

There is an average of 5.1 chars per word in English, and usually about
350 words an A4 page.

The 215K file is
a) Compressed - typically by 60%
b) Contains simple html and images as its source.
c) Must contain the cover image.

As a *very* rough guess, that means the files expands to 344K.
Remove the cover image at 250-300kb leaves 44 to 94KB
That is 8700 words to 18400 words or approx 25 to 50 pages.
But that is *very* *very* rough.


The file is about 500 'locations'. The Kindle Users Guide, 3rd Ed., has 
1300, Lao Tza, the Art of War, (project Gutenberg), aaabut 2100. I read 
about half in an hour. Even knowing the material, it is slower than a novel.


--
Terry Jan Reedy

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


Re: Read-only attribute in module

2012-02-09 Thread Terry Reedy

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.


--
Terry Jan Reedy

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


Re: round down to nearest number

2012-02-09 Thread Terry Reedy

On 2/9/2012 8:23 PM, noydb wrote:

So how would you round UP always?  Say the number is 3219, so you want

>>> (//100+1)*100
3400

--
Terry Jan Reedy

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


Re: frozendict

2012-02-09 Thread Terry Reedy

On 2/9/2012 9:30 PM, Nathan Rice wrote:


That day may be sooner than you think. It is very likely that in Python
3.3, dict order will be randomized on creation as a side-effect of adding
a random salt to hashes to prevent a serious vulnerability in dicts.

http://securitytracker.com/id/1026478

http://bugs.python.org/issue13703


If there is anyone still assuming that dicts have a predictable order,
they're going to be in for a nasty surprise one of these days.


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


I believe 'on creation' means 'on process startup', not on dict 
creation. There have, however, been several variants suggested, and the 
focus has been on choosing one first for past and current versions. 3.3 
is about 6 months off and hash for it may still be debated.


--
Terry Jan Reedy

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


Re: round down to nearest number

2012-02-09 Thread MRAB

On 10/02/2012 02:25, noydb wrote:

That {>>>  (3219 + 99) // 100} doesnt work if the number is other then
4 digits.


(for rounding up to nearest 100):

 (3219 + 99)//100

33

 (3289 + 99)//100

33

 (328678 + 99)//100

3287

 (328 + 99)//100

4


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


Re: round down to nearest number

2012-02-09 Thread MRAB

On 10/02/2012 03:29, Terry Reedy wrote:

On 2/9/2012 8:23 PM, noydb wrote:

 So how would you round UP always?  Say the number is 3219, so you want

  >>>  (//100+1)*100
3400


Doing it that way doesn't always work. For example:

>>> (3400 // 100 + 1) * 100
3500

However:

>>> (3400 + 99) // 100 * 100
3400
--
http://mail.python.org/mailman/listinfo/python-list


Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 8:36 PM, MRAB  wrote:
> On 10/02/2012 02:25, noydb wrote:
>>
>> That {>>>  (3219 + 99) // 100} doesnt work if the number is other then
>> 4 digits.
>>
>>
>> (for rounding up to nearest 100):
>
>  (3219 + 99)//100
>>
>> 33
>
>  (3289 + 99)//100
>>
>> 33
>
>  (328678 + 99)//100
>>
>> 3287
>
>  (328 + 99)//100
>>
>> 4
>
>
 (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

A more consistent alternative is to negate the number, round down, and
then negate again.

>>> -(-(3300.5) // 100 * 100)
3400.0

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


Re: Guide to: Learning Python Decorators

2012-02-09 Thread sajuptpm
Hi,

Thanks for replay,
I am looking for PDF version of same book. Please share if you can.

http://www.amazon.com/gp/product/B006ZHJSIM/ref=as_li_tf_tl?ie=UTF8&tag=8012-20&linkCode=as2&camp=1789&creative=9325&creativeASIN=B006ZHJSIM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Common LISP-style closures with Python

2012-02-09 Thread John Nagle

On 2/3/2012 4:27 PM, Antti J Ylikoski wrote:


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:


   Most dynamic languages have closures.  Even Perl and Javascript
have closures.  Javascript really needs them, because the "callback"
orientation of Javascript means you often need to package up state
and pass it into a callback.  It really has very little to do with
functional programming.

   If you want to see a different style of closure, check out Rust,
Mozilla's new language.  Rust doesn't have the "spaghetti stack"
needed to implement closures, so it has more limited closure
semantics.  It's more like some of the C add-ons for closures,
but sounder.

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


Re: frozendict

2012-02-09 Thread anon hung
> I've been trying for a few days (only a little bit at a time) to come up
> with a way of implementing a frozendict that doesn't suck. I'm gradually
> converging to a solution, but I can't help but think that there's some
> subtlety that I'm probably missing which is why it's not already provided.

The freezing temperature of typical dicts is around - 10 Celsius.

HTH,
anonhung

-- 
Viktor Orban Prime minister of Hungary
http://spreadingviktororban.weebly.com
-- 
http://mail.python.org/mailman/listinfo/python-list