ANN: xxgamma 0.06

2009-03-19 Thread Florian Diesch


I'm happy to announce xxgamma 0.06

Get it at http://www.florian-diesch.de/software/xxgamma/


xxgamma is an PyGTK based GUI for xgamma which allows you to load,
modify and store multiple gamma correction profiles for XFree86 and
X.org through a GUI and a command line interface.


Version 0.06 fixes some bugs and adds Undo and some minor GUI improvements



   Florian
-- 
http://www.florian-diesch.de/
--
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: pycairo release 1.8.4 now available

2009-03-19 Thread Steve
Pycairo is a set of Python bindings for the multi-platform 2D graphics
library cairo.
 http://cairographics.org
 http://cairographics.org/pycairo

A new pycairo release 1.8.4 is now available from:

http://cairographics.org/releases/pycairo-1.8.4.tar.gz
http://cairographics.org/releases/pycairo-1.8.4.tar.gz.md5

6adff10f58818004839fe9edc9dc6a9b  pycairo-1.8.4.tar.gz

Overview of changes from pycairo 1.8.2 to pycairo 1.8.4
===
General Changes:
Pycairo 1.8.4 requires cairo 1.8.4 (or later) and Python 2.6

Bug Fixes:
20674: Add get/set_extend for Gradient Patterns

New Classes:
cairo.ToyFontFace

New Methods:
Pattern.get_extend
Pattern.set_extend
ToyFontFace.get_family
ToyFontFace.get_slant
ToyFontFace.get_weight

Deleted Methods:
SurfacePattern.get_extend
SurfacePattern.set_extend

Other Changes:
Threading for surfaces with stream functions has been reenabled.
Documentation updates.


Steve

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

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


ANN: eGenix mxODBC Connect 1.0.1 - Python Database Interface

2009-03-19 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING
  eGenix.com mxODBC Connect

  Python Database Interface

Version 1.0.1


   Our new client-server product for connecting Python applications
  to relational databases - from all major platforms


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



INTRODUCTION

The mxODBC Connect Database Interface for Python allows users to
easily connect Python applications to all major databases on the
market today in a highly portable and convenient way.

Unlike our mxODBC Python extension, mxODBC Connect is designed
as client-server application, so you no longer need to find production
quality ODBC drivers for all the platforms you target with your Python
application.

Instead you use an easy to install Python client library which
connects directly to the mxODBC Connect database server over the
network.

This makes mxODBC Connect the ideal basis for writing cross-platform
database programs and utilities in Python, especially if you run
applications that need to communicate with databases such as MS SQL
Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase
ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more,
that run on Windows or Linux machines.

By removing the need to install and configure ODBC drivers on the
client side, mxODBC Connect greatly simplifies setup and
configuration of database driven client applications, while at
the same time making the network communication between client and
database server more efficient and more secure.

For more information, please see the product page:

http://www.egenix.com/products/python/mxODBCConnect/



NEWS

mxODBC Connect 1.0.1 is a patch-level release of our new mxODBC Connect
product.

* More Robust

We have made the client and server more robust in case of communication
failures. Even if the client applications fail to shutdown the server
connection before exiting, the server will free up resources used by the
client on the server side and rollback transactions as necessary.

* More Platform Support

With the 1.0.1 release we are also providing much better platform
support for the mxODBC Connect Client: we have fixed a problem in 1.0.0
that prevented the installation of the pre-built clients on non-Linux
systems.

The mxODBC Connect Client can now be installed on most platforms
supported by Python, since it is written in a platform independent,
portable way.

The pre-built archives also make it possible to integrate the clients
into build system such as buildout (used in Zope and Plone) or other
distutils-based deployment systems.

* Ideal for Building Bridges

As a result, connecting from e.g. Mac OS X to an SQL Server database
has never been easier. You can even keep the data sources you already
have configured on your Windows machine and connect to them as if your
application were running on the database server itself.



UPGRADING

You are encouraged to upgrade to this latest mxODBC Connect release.
When upgrading, please always upgrade both the server and the client
installations to the same version - even for patch level releases.

Customers who have purchased mxODBC Connect 1.0 licenses can download
and upgrade their existing installations without having to purchase
new licenses or upgrades. The licenses will continue to work with
version 1.0.1.

Users of our stand-alone mxODBC product will have to purchase new
licenses from our online shop in order to use mxODBC Connect.

You can request 30-day evaluation licenses by visiting our web-site
or writing to sa...@egenix.com, stating your name (or the name of the
company) and the number of eval licenses that you need.

http://www.egenix.com/products/python/mxODBCConnect/#Evaluation



DOWNLOADS

The download archives as well as instructions for installation and
configuration of the product can be found on the product page:

http://www.egenix.com/products/python/mxODBCConnect/

Evaluation licenses for the server part are available free of
charge:

http://www.egenix.com/products/python/mxODBCConnect/#Evaluation

The client part of mxODBC Connect is always free of charge.

___

SUPPORT

Commercial support for this product is available from eGenix.com.

Please see

http://www.egenix.com/services/support/

for details about our support offerings.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Mar 19 2009)
 

pylab plot_date problem

2009-03-19 Thread Shah Sultan Alam
Hi ,
 I am using following code to create a graph
def plot_plot():
  ax = pylab.subplot(111)
for count in range(len(yaxes_values)):
pylab.subplots_adjust(left=0.13, bottom=0.21,
right=0.90, top=0.90,wspace=0.20, hspace=0.20)

ax.plot_date(id_dates,yaxes_values[count],fmt='o-',label=titleList[count])
pylab.xlabel('Time Stamp')
pylab.ylabel('Values')


ax.xaxis.set_major_locator(pylab.MinuteLocator(interval=Interval))
ax.xaxis.set_major_formatter(formatter)
labels = ax.get_xticklabels()
pylab.setp(labels, rotation=90, fontsize=8)
ax.set_title(choice)
pylab.grid()
font= FontProperties(size='x-small');
pylab.legend(loc=0, prop=font)


each time I am re-initilliziing the titleList before calling the
plot_plot , This works fine for one graph,
But if I call it more then once the label keep appending ..
How to get rid of this ?

Regds
Shah Alam
--
http://mail.python.org/mailman/listinfo/python-list


Re: [python-list] Re: Strange crash issue on Windows w/ PyGTK, Cairo...

2009-03-19 Thread CJ Kucera
bieff...@gmail.com wrote:
 If you have worked with C/C++, you know that memory-related bugs can
 be very tricky.
 More than once - working with C code - I had crashes that disappeared
 if I just added
 a 'printf', because the memory allocation scheme changed and the
 memory corrupted was not anymore
 relevant.

Well, you turned out to be dead right about this, as I suppose should
have been pretty obvious given the nature of the problems I was having.

Anyway, the issue turned out to be zlib.decompress() - for larger sets
of data, if I wasn't specifying bufsize, the malloc()s that it was
doing behind-the-scenes must have been clobbering memory.  As soon as I
specified bufsize, everything was totally kosher.

Once I'm a bit more awake tomorrow I'll put together a testcase and send
it in to the bug tracker.

This does bring up one question: for larger chunks of data, is it More
Appropriate to use a zlib decompression object instead of just passing
it all through zlib.decompress()?

Thanks, everyone...

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


Re: How complex is complex?

2009-03-19 Thread Daniel Fetchinson
 When we say readability counts over complexity, how do we define what
 level of complexity is ok?
 For example:
 Say I have dict a = {'a': 2, 'c': 4, 'b': 3}
 I want to increment the values by 1 for all keys in the dictionary.
 So, should we do:
 for key in a:
 ...   a[key] = a[key] + 1
 or is it Ok to have code like:
 dict(map(lambda key: (key, a[key] + 1), a))

Before doing anything else I'd suggest leaving your code as is,
closing your editor immediately and not touching it at all before the
One True Answer arrives from the PSF.

Please mail your question (along with a self-addressed envelope) to:

Python Software Foundation
P.O. Box 848
Hampton, NH 03843
USA

where python language lawyers will consider it in great detail,
consulting GvR if necessary. Please do not try to figure this one out
by yourself! The PSF lawyers are trained to do this, such things are
better left to professionals, you don't want to shoot yourself in the
foot.

Once every nuanced detail has been carefully weighed in and a
consensus has been reached among the Supreme Python Language
Commission chamber of the PSF the appropriate answer will be mailed
back to you.

Now you should be able to open up your favorite editor and hack away
knowing full well that nobody and nothing can stop you, ever!

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


what does 64-bit python mean?

2009-03-19 Thread srinivasan srinivas

Hi,
Could someone help me in understanding what 64-bit python means?

tahnks,
Srini


  Add more friends to your messenger and enjoy! Go to 
http://messenger.yahoo.com/invite/
--
http://mail.python.org/mailman/listinfo/python-list


Re: equivalent of source command in tcl for python

2009-03-19 Thread alex23
On Mar 19, 2:42 pm, Ralf Schoenian r...@schoenian-online.de wrote:
 mark.coll...@csiro.au wrote:
  Many times I am developing a code in a file and I want to, for
  example, exit at a specific line so that I can test something. In tcl
  you can just put an exit command in and source the file. Is there an
  equivalent for python? Thanks,

 import sys
 sys.exit()

And if you run your code using the -i switch, a la:

   python -i mycode.py

Python will open the interpreter in interactive mode after it hits
sys.exit() (or any uncaught exception), with the full state of the
program up to that point available. Which can be very handy during
testing for ensuring that your expectations of that state are correct.
--
http://mail.python.org/mailman/listinfo/python-list


Re: what does 64-bit python mean?

2009-03-19 Thread Chris Rebert
On Wed, Mar 18, 2009 at 11:45 PM, srinivasan srinivas
sri_anna...@yahoo.co.in wrote:

 Hi,
 Could someone help me in understanding what 64-bit python means?

It's been compiled for 64-bit processors, so it uses 64-bit pointers
and 64-bit small integers. And I would think it would only work w/ C
extension libraries also compiled for 64-bit CPUs. So, the same
meaning 64-bit has for anything else really.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: what does 64-bit python mean?

2009-03-19 Thread Christian Heimes
Chris Rebert wrote:
 It's been compiled for 64-bit processors, so it uses 64-bit pointers
 and 64-bit small integers. And I would think it would only work w/ C
 extension libraries also compiled for 64-bit CPUs. So, the same
 meaning 64-bit has for anything else really.

A 64bit build of Python doesn't necessarily mean that the small integer
type is 64bit, too. Python uses the datatype long on all platforms. On
Windows sizeof(long) == 4 (four bytes) on 32 and 64 versions of Windows.

Christian

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


Re: what does 64-bit python mean?

2009-03-19 Thread Martin v. Löwis
 Could someone help me in understanding what 64-bit python means?

While Chris' answer is correct, it doesn't show the consequences
of using a 64-bit Python. Primarily, these are:
- strings, Unicode objects, lists, dicts, and tuples can have more than
  2**31 elements.
- you can load 64-bit DLLs into the Python process, and 64-bit
  applications (such as a 64-bit Apache or IIS process) can load
  the Python interpreter into their address spaces.
- you need a 64-bit operating system to run Python

The first item is only relevant if
a) you have that much data that you want to put into a single
   container, and
b) you have that much memory to keep the entire container in
   memory. For a list with 2**31 elements, you need 16GiB of
   memory to represent the list alone, not counting the actual
   data (e.g. for a list of 2**31 Nones). For a dict, you need
   more than 48GiB for the dict alone. For a byte string,
   2GiB are enough to get past the 2**31 elements boundary.

I just noticed that this description is not completely correct:
in a 32-bit process, the upper size of collections is actually
smaller than 2**31. For a list, you can have only up to 2**30
elements in the list; on many operating systems, only 2**29.
For a dict, the maximum number of elements is even smaller,
around 250 millions. So you would need a 64-bit Python already
to get past these boundaries.

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


Re: REDIRECT

2009-03-19 Thread Jeremiah Dodds
On Thu, Mar 19, 2009 at 4:30 AM, gaeasian...@gmail.com wrote:

 On Mar 18, 5:21 am, Tino Wildenhain t...@wildenhain.de wrote:
  gaeasian...@gmail.com wrote:
 

 3. GoogleAppEngine, Version 1.1.9
   (webapp - framework)

 What actually I'm try to do is :

 I'm having a Login page which developed in HTML. When I click on the
 Login button I want the page to validate (at datastore of google
 app) using python and redirect to other HTML page. As what I
 understand, Python is the only language that supported by the
 GoogleApps.


http://code.google.com/appengine/docs/python/tools/webapp/redirects.html

Does that help?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Do deep inheritance trees degrade efficiency?

2009-03-19 Thread Peter Otten
Anthra Norell wrote:

 Would anyone who knows the inner workings volunteer to clarify whether
 or not every additional derivation of a class hierarchy adds an
 indirection to the base class's method calls and attribute read-writes.
 In C++, I suppose, a three-level inheritance would resolve into
 something like *(*(*(*(base_class_method ().

I think in C++ the compiler can often resolve the correct class statically.
Python currently walks through the entire hierarchy.

$ cat inherit.py
class A(object):
def m(self):
return 42


B = A
for i in range(1000):
class B(B): pass

a = A()
b = B()

if __name__ == __main__:
print a.m()
print b.m()

$ python -m timeit -sfrom inherit import a a.m
1000 loops, best of 3: 0.173 usec per loop
$ python -m timeit -sfrom inherit import b b.m
1 loops, best of 3: 68.7 usec per loop

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


Re: Do deep inheritance trees degrade efficiency?

2009-03-19 Thread Chris Rebert
On Wed, Mar 18, 2009 at 6:09 AM, Anthra Norell anthra.nor...@bluewin.ch wrote:
 Would anyone who knows the inner workings volunteer to clarify whether or
 not every additional derivation of a class hierarchy adds an indirection to
 the base class's method calls and attribute read-writes. In C++, I suppose,
 a three-level inheritance would resolve into something like
 *(*(*(*(base_class_method ().

There's no effect on attribute read-writes as they all take place
within the single __dict__ of the instance. As for method lookup, it
doesn't add an indirection per se, but rather the list of classes to
look thru to find a method gets longer, making base-class method
lookups slower. IIRC, a typical method lookup does something like the
following pseudocode:

for klass in the_object.__mro__:
if method_name in klass.__dict__:
return klass.__dict__[method_name]
raise AttributeError # no such attribute

The __mro__ being the Method Resolution Order, a list containing
the_object's class and that class' superclasses. __dict__ is the
namespace dictionary of an individual class.

However, you shouldn't really worry about the inefficiency of a deep
inheritance tree as Python's dictionary implementation (used for
namespace lookup) is super-optimized, and in any case the inefficiency
ought to be negligible compared to the actual work done in the program
(if it's not, there's something wrong with how the program has been
coded).

[Note: I'm purposefully ignoring the fact that methods and attributes
are in reality looked up in the exact same way for
simplicity/clarity.]

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: How complex is complex?

2009-03-19 Thread Kottiyath
On Mar 19, 11:29 am, Daniel Fetchinson fetchin...@googlemail.com
wrote:
  When we say readability counts over complexity, how do we define what
  level of complexity is ok?
  For example:
  Say I have dict a = {'a': 2, 'c': 4, 'b': 3}
  I want to increment the values by 1 for all keys in the dictionary.
  So, should we do:
  for key in a:
  ...   a[key] = a[key] + 1
  or is it Ok to have code like:
  dict(map(lambda key: (key, a[key] + 1), a))

 Before doing anything else I'd suggest leaving your code as is,
 closing your editor immediately and not touching it at all before the
 One True Answer arrives from the PSF.

 Please mail your question (along with a self-addressed envelope) to:

 Python Software Foundation
 P.O. Box 848
 Hampton, NH 03843
 USA

 where python language lawyers will consider it in great detail,
 consulting GvR if necessary. Please do not try to figure this one out
 by yourself! The PSF lawyers are trained to do this, such things are
 better left to professionals, you don't want to shoot yourself in the
 foot.

 Once every nuanced detail has been carefully weighed in and a
 consensus has been reached among the Supreme Python Language
 Commission chamber of the PSF the appropriate answer will be mailed
 back to you.

 Now you should be able to open up your favorite editor and hack away
 knowing full well that nobody and nothing can stop you, ever!

 Cheers,
 Daniel

 --
 Psss, psss, put it down! -http://www.cafepress.com/putitdown

I understand that my question was foolish, even for a newbie.
I will not ask any more such questions in the future.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Do deep inheritance trees degrade efficiency?

2009-03-19 Thread Christian Heimes
Chris Rebert wrote:
 There's no effect on attribute read-writes as they all take place
 within the single __dict__ of the instance. As for method lookup, it
 doesn't add an indirection per se, but rather the list of classes to
 look thru to find a method gets longer, making base-class method
 lookups slower. IIRC, a typical method lookup does something like the
 following pseudocode:
 
 for klass in the_object.__mro__:
 if method_name in klass.__dict__:
 return klass.__dict__[method_name]
 raise AttributeError # no such attribute

Your assumption is no longer true. Starting with Python 2.6 and 3.0 the
lookup of attributes is cached. You can find detailed information by
searching for VERSION_TAG in the source code.

Christian

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


Re: Roulette wheel

2009-03-19 Thread mattia
Il Wed, 18 Mar 2009 23:31:09 -0200, Gabriel Genellina ha scritto:

 En Wed, 18 Mar 2009 18:49:19 -0200, mattia ger...@gmail.com escribió:
 Il Wed, 18 Mar 2009 13:20:14 -0700, Aahz ha scritto:
 In article 49c1562a$0$1115$4fafb...@reader1.news.tin.it, mattia
 ger...@gmail.com wrote:

 Yeah, and I believe that we can say the same for: 1 - t = [x*2 for x
 in range(10)]
 2 - t = list(x*2 for x in range(10))
 or not?
 The latter requires generator expressions, which means it only works
 with Python 2.4 or higher.  Personally, I think that if the intent is
 to create a list you should just use a listcomp instead of list() on a
 genexp.
 Ok, so list(x*2 for x in range(10)) actually means: list((x*2 for x in
 range(10)) -- so a generator is created and then the list function is
 called?
 
 Exactly. The (()) were considered redundant in this case.
 
 Also, dealing with memory, [...] will be deleted when the reference
 will be no longer needed and with list(...)... well, I don't know? I'm
 new to python so sorry if this are nonsense.
 
 I don't completely understand your question, but *any* object is
 destroyed when the last reference to it is gone (in CPython, the
 destructor is called at the very moment the reference count reaches
 zero; other implementations may behave differently).

OK, understood. Now, as a general rule, is it correct to say:
- use generator expression when I just need to iterate over the list or 
call a function that involve an iterator (e.g. sum) and get the result, 
so the list is not necessary anymore
- use list comprehensions when I actually have to use the list (e.g. I 
need to swap some values or I need to use sorted() etc.)
Am I right?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Do deep inheritance trees degrade efficiency?

2009-03-19 Thread Peter Otten
Peter Otten wrote:

 Anthra Norell wrote:
 
 Would anyone who knows the inner workings volunteer to clarify whether
 or not every additional derivation of a class hierarchy adds an
 indirection to the base class's method calls and attribute read-writes.
 In C++, I suppose, a three-level inheritance would resolve into
 something like *(*(*(*(base_class_method ().
 
 I think in C++ the compiler can often resolve the correct class
 statically. Python currently walks through the entire hierarchy.

currently meaning 2.5 here...
 
 $ cat inherit.py
 class A(object):
 def m(self):
 return 42
 
 
 B = A
 for i in range(1000):
 class B(B): pass
 
 a = A()
 b = B()
 
 if __name__ == __main__:
 print a.m()
 print b.m()
 
 $ python -m timeit -sfrom inherit import a a.m
 1000 loops, best of 3: 0.173 usec per loop
 $ python -m timeit -sfrom inherit import b b.m
 1 loops, best of 3: 68.7 usec per loop

[Christian Heimes]
 Your assumption is no longer true. Starting with Python 2.6 and 3.0 the
 lookup of attributes is cached. You can find detailed information by
 searching for VERSION_TAG in the source code.

I missed that change. Here are the 2.6 timings:

$ python2.6 -m timeit -sfrom inherit import a a.m
1000 loops, best of 3: 0.171 usec per loop
$ python2.6 -m timeit -sfrom inherit import b b.m
1000 loops, best of 3: 0.169 usec per loop

Impressing.

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


Re: How complex is complex?

2009-03-19 Thread Jeremiah Dodds
On Thu, Mar 19, 2009 at 9:39 AM, Kottiyath n.kottiy...@gmail.com wrote:

 I understand that my question was foolish, even for a newbie.
 I will not ask any more such questions in the future.
 --
 http://mail.python.org/mailman/listinfo/python-list


I didn't think it was a foolish question, just one with a very subjective
(and perhaps unknowable) answer. I have a feeling that Daniel wasn't
intending to come off as snarky, but who knows.

What someone considers 'readable' or 'complex' is going to vary from
individual to individual. If you look at it (or if a peer on roughly the
same skill level as you looks at it) and has to squint really hard to figure
out what it's doing, it's probably not readable enough - which may or may
not be linked to the complexity of the code itself (Depending on how what
you mean by complexity - number of instructions? number of characters?
special charachters? number of tokens? levels of indirection? etc).
--
http://mail.python.org/mailman/listinfo/python-list


Re: read web page that requires javascript on client

2009-03-19 Thread Jeremiah Dodds
On Thu, Mar 19, 2009 at 1:25 AM, Carl tg2.u...@gmail.com wrote:

 Probably the easiest thing is to actually use a browser. There are
 many examples of automating a browser via Python. So, you can
 programmatically launch the browser, point it to the JavaScript
 afflicted page, let the JS run and grab the page source. As an added
 bonus you can later interact with the page by programatically, filling
 form fields, selecting options from lists and clicking buttons.

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



I've been using the python port of mechanize (specifically
mechanize.browser) for web automation, it's rather nice.[1]

In the vast majority of cases, if I need something done with javascript,
it's just to generate a url or post data - in which case I can just read the
javascript, and figure out what it's doing - or use something like
livehttpheaders[2] to find out what I need to be sending.

This obviously doesn't cover every single case, but it works pretty fine
most of the time. I would love to see a complete javascript interpreter /
dom interface in python - but it's hard, hard stuff.

I'd love to even have the time to read the ECMAScript spec enough to have
enough working knowledge of javascript's internals to be able to contribute
to one of the current attempts at doing so.

1. http://wwwsearch.sourceforge.net/mechanize/
2. https://addons.mozilla.org/en-US/firefox/addon/3829
--
http://mail.python.org/mailman/listinfo/python-list


Re: read web page that requires javascript on client

2009-03-19 Thread James Matthews
You can try and use wxpythons broswer to execute the javascript

On Wed, Mar 18, 2009 at 10:01 PM, Greg gregsaundersem...@gmail.com wrote:

 Hello all, I've been trying to find a way to fetch and read a web page
 that requires javascript on the client side and it seems impossible.
 I've read several threads in this group that say as much but I just
 can't believe it to be true (I'm subscribing to the argument of
 personal incredulity  here).

 Clearly urllib and urllib2 don't seem to support this and I've looked
 at win32com.client and it's ScriptControl but that doesn't seem to be
 viable approach for this particular problem.

 Does anyone have any suggestions, hack or ideas or am I missing
 something really obvious.

 Thanking you all in advance!
 Greg
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 

http://www.goldwatches.com/Watches.asp?Brand=71
--
http://mail.python.org/mailman/listinfo/python-list


Re: python equivalent of java technologies

2009-03-19 Thread Jeremiah Dodds
On Tue, Mar 17, 2009 at 8:32 PM, Armin feng.sh...@gmail.com wrote:

 You could tell her to try Jython.  In that, you can just use the Java
 implementations. :)  Plus, you have things in Jython that Java doesn't :D

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


Exactly. Her challenges to find stuff have to do with the JVM, not Java the
language. Python runs on the JVM.
--
http://mail.python.org/mailman/listinfo/python-list


Unicode problem in ucs4

2009-03-19 Thread abhi
Hi,
I have a C extension, which takes a unicode or string value from
python and convert it to unicode before doing more operations on it.
The skeleton looks like:

static PyObject *unicode_helper( PyObject *self, PyObject *args){
  PyObject *sampleObj = NULL;
  Py_UNICODE *sample = NULL;

  if (!PyArg_ParseTuple(args, O, sampleObj)){
return NULL;
  }
  // Explicitly convert it to unicode and get Py_UNICODE value
  sampleObj = PyUnicode_FromObject(sampleObj);
  sample = PyUnicode_AS_UNICODE(sampleObj);
   
  // perform other operations.
   .
}

This piece of code is working fine on python with ucs2 configuration
but fails with python ucs4 config. By failing, I mean that only the
first letter comes in variable sample i.e. if I pass test from
python then sample will contain only t. However, PyUnicode_GetSize
(sampleObj) function is returning correct value (4 in this case).

Any idea on why this is happening? Any help will be appreciated.

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


Re: Style formating of multiline query, advise

2009-03-19 Thread someone
On Mar 19, 10:26 am, Marco Mariani ma...@sferacarta.com wrote:
 someone wrote:
  Also, for SQL, (A) why are you using nested joins?, and

  inner select produce smaller set which is then joined with other
  table, kind a optimization

 Did you time it?
 I've done some kind of a optimization that slowed queries by tenfold,
 because postgres didn't need my advice, and knew better. RDBMS

Query itself is fast. I'll try to time it and will report my results
here :)

 performance is non-intuitive, really. If you're using mysql, YMMV,
 because its optimizer is not as good.

That's true, I don't trust optimizer


  Yes, my original question was about formatting. It's not original
  query (only a part).

 Try this:

 http://www.dpriver.com/pp/sqlformat.htm

 My 2c: I use textwrap.dedent to strip leading spaces from every line.

textwrap.dedent? What's that? I'm new in python. Will google it.
How do your query formatting looks like then?
--
http://mail.python.org/mailman/listinfo/python-list


Style formating of multiline query, advise

2009-03-19 Thread someone
Hi,

what is good :) style for multiline queries to database?
Is that one ok?
query =  SELECT * FROM (
   SELECT a.columna, a.columnb, a.iso
  FROM all a
  WHERE (a.name = LOWER(%s))  ) AS c
 JOIN other as b on c.gid = b.id
 WHERE class = 'A'
 ORDER BY population DESC
 LIMIT %s;

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


Re: python equivalent of java technologies

2009-03-19 Thread Tim Hoffman
Oops ,

for RIA there is always pyjamas (gwt for python ;-)

T

On Mar 19, 7:52 pm, Tim Hoffman zutes...@gmail.com wrote:
 Hi

 Well zope has quite a few of these out of the box and have been around
 for a bit longer than some of the java options.

 Specifically persistence (ZODB persistence in zope is pretty much
 completely autmomatic)
 you can inplement web services with it (xmlrpc out of the box, though
 I assume you mean soap)
 zope encompasses security/ and authentication and can easily be
 integrated with a range of single signon environments.
 there are a range of scheduling services in to, but which is most like
 quartz I am not sure about.
 zope does support distributed transactions, but I not XA , but is
 ACID.

 In general there are a heap of interfaces for python do different
 message queues/buses, take you pick of you favourite platform.

 Not sure about reporting that is equivalent to jasper.

 T

 On Mar 19, 3:14 am, markolopa marko.lopa...@gmail.com wrote:

  Hello,

  When comparing python and java with a colleague who is fan of java,
  she challenged me to find in python the equivalent to the following
  technologies. Could you please help telling if we have something
  equivalent in python or not and how they compare to the java
  solutions?

  - persistance framework  (~hibernate)
  - transational monitor (distributed transaction), XA compliance
  (message system, DB) (http://en.wikipedia.org/wiki/X/Open_XA)
  - web openess sur le web (web service)
  - RIA and web deployable graphic library
  - scheduling (quartz)
  - secutity (PKI, single sign-on...)
  - reporting (Jasper)

  Thanks a lot!
  Marko



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


Re: split problem if the delimiter is inside the text limiter

2009-03-19 Thread M.-A. Lemburg
On 2009-03-19 00:30, Tim Chase wrote:
 Bruno Desthuilliers wrote:
 Tim Chase a écrit :
 (if your columns in your CSV happen to match the order of your INSERT
 statement, you can just use

   execute(sql, tuple(row))

 Or more simply:

  cursor.execute(sql, row)
 
 that's always annoyed me with the mxODBC drivers I've usedthey
 require(d?) a tuple in this position, so I developed  this habit.  I
 think the OP hinted they were using postgres drivers which may be a bit
 kinder to the user.

This requirement in mxODBC results from still providing a DB-API 1.0
compatible interface... after all, it's been around since 1997.
Back in the early days, there was only cursor.execute() and the only way
to differentiate between a list of rows and a single row was by type.

DB-API 2.0 has cursor.executemany() to make this differentiation
at the API level. mxODBC will lift this requirement in the next
version, promised :-)

 (and don't get me started on mxODBC's failure to
 determine the data-type for parameters in subqueries, raising exceptions
 on perfectly valid queries/rant)

I'm not sure what you are referring to here. mxODBC can only provide
an interface to the underlying ODBC driver.

If the ODBC driver does not provide the required information or
reports errors in situations where you don't expect them, mxODBC
can try to work around these things (and does for quite a few drivers),
but of course, we cannot cover all possible cases, since there are
far too many ODBC drivers out there, each with their own release
cycles.

That said, we are always open to reports about such issues so
we can work them into mxODBC updates where possible.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Mar 19 2009)
 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


problem with Pamie (textbox editing)

2009-03-19 Thread stanislav_ziak

Hi,

I try to test web aplication with using of modul Pamie and I have next problem,
when I edit any textbox or textarea and consequently press the button which 
works the data
in this textbox, so this textbox returns into the state before editing,

fof example:
Let I have 3 textboxes: box1, box2 and result
   and 1 button: count, which fill sum of box1 and box2 in the textbox 
result
after using textBoxSet('box1','10') and textBoxSet('box2','10') is in both 
textboxes number 10,
but using buttonClick('count') delete number 10 in box1 and box2 and both 
return to the state before editing (empty),

here is my code:
#
from cPAMIE import PAMIE

ie = PAMIE()

ie.navigate(url)

ie.textBoxSet('att$text_TBName','name')
ie.buttonClick(att$text_TBName)
time.sleep(3)
ie.elementClick(ie.elementFind(Input,name,att$copyTBProxy2A))
#
I tried it also without Pamie, but the result is the same:
#
from win32com.client import DispatchEx

ie = DispatchEx('InternetExplorer.Application')
ie.navigate(url)
ie.visible = 1
time.sleep(3)
el = ie.document.getElementsByTagName('input')
i=0
while (el[i].getAttribute('Name')  att$text_TBNname):
i+=1
el[i].value = 'name'

j=0
while (el[j].getAttribute('Name')  att$copyTBProxy2A):
j+=1
el[j].click()
#
application is ok, because
when I make it manual, so it works OK,


can somebody help me, what I make wrong,
thanks


Informacie obsiahnute v tomto  dokumente su urcene vylucne pre
potreby jeho adresata. Dokument moze obsahovat informacie chranene
ako bankove alebo obchodne tajomstvo, pripadne informacie
podliehajuce ochrane podla inych pravnych predpisov. Preto Vas v
pripade, ak Vam bol  mylne doruceny, vyzyvame, aby ste sa zdrzali
jeho odtajnenia ci jeho pouzitia pre vlastne potreby. Zaroven si Vas
dovolujeme poziadat, aby ste nas o takomto pripade bez zbytocneho
odkladu informovali a dokument nasledne zlikvidovali.

Information stated in this document is intended only for needs of proper
addressees of this document. This document can contain information
protected as a bank or business secret, or information protected by
other legal regulations. Thus in case of receiving the document by error,
we kindly ask you not to disclose, or use the document for your own
needs. Likewise we kindly ask you to notify us immediately upon such
a case by sending an email message to the sender's address, and
subsequently delete the document.

Tatra banka, a.s.
http://www.tatrabanka.sk/bankcoffee
Hodzovo namestie 3,  811 06 Bratislava 1
ICO: 00 686 930
Zapisana v obchodnom registri Okresneho sudu Bratislava I
Oddiel: Sa, vlozka cislo: 71/B

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


lipo: can't figure out the architecture type of

2009-03-19 Thread Vijayendra Bapte
Hi,

I am getting an gcc compilation error while installing FSEvents
(http://pypi.python.org/packages/source/p/pyobjc-framework-FSEvents/
pyobjc-framework-FSEvents-2.2b1.tar.gz) package on my Mac (OS X
10.4.11, Intel Core Duo 32 bit processor, Python2.6.1, gcc: i686-apple-
darwin8-gcc-4.0.1)

gcc failed while building the FSEvents._callbacks extension on $
python setup.py install

here is the error trace...

running install_lib
running build_py
running build_ext
building 'FSEvents._callbacks' extension
gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -
fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -I/Library/
Frameworks/Python.framework/Versions/2.6/include/python2.6 -c Modules/
_callbacks.m -o build/temp.macosx-10.3-i386-2.6/Modules/_callbacks.o -
O0
Modules/_callbacks.m:60: error: parse error before
'm_python_context_template'
Modules/_callbacks.m:62: warning: excess elements in scalar
initializer
Modules/_callbacks.m:62: warning: (near initialization for
'm_python_context_template')
Modules/_callbacks.m:63: warning: excess elements in scalar
initializer
.
.
.
.
(Error ending with)
Modules/_callbacks.m:133: error: previous definition of 'result' was
here
Modules/_callbacks.m:353: error: parse error before 'FSEventStreamRef'
lipo: can't figure out the architecture type of: /var/tmp//
cco6kalc.out
error: command 'gcc' failed with exit status 1

Could someone help me in solving this compilation error?
--
http://mail.python.org/mailman/listinfo/python-list


Do deep inheritance trees degrade efficiency?

2009-03-19 Thread Anthra Norell
Would anyone who knows the inner workings volunteer to clarify whether 
or not every additional derivation of a class hierarchy adds an 
indirection to the base class's method calls and attribute read-writes. 
In C++, I suppose, a three-level inheritance would resolve into 
something like *(*(*(*(base_class_method ().


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


Re: mxODBC (was split problem if the delimiter is inside the text limiter)

2009-03-19 Thread Tim Chase

DB-API 2.0 has cursor.executemany() to make this differentiation
at the API level. mxODBC will lift this requirement in the next
version, promised :-)


glad to hear...will executemany() take an arbitrary iterable?  My 
 (albeit somewhat-antiquated) version balked at anything that 
wasn't a list/tuple (don't remember off the top of my head which 
it was).  For a lot of my ETL work, it would be nice to pass a 
generator so I don't have to keep huge datasets in memory.



(and don't get me started on mxODBC's failure to
determine the data-type for parameters in subqueries, raising exceptions
on perfectly valid queries/rant)


I'm not sure what you are referring to here. mxODBC can only provide
an interface to the underlying ODBC driver.


Okay...feel free to deflect the minced oaths at MS's SQL Server 
ODBC driver then. :)  The main problem came with queries like


  cursor.execute(
SELECT a, b, c
FROM table_x
WHERE providerid = ?
  AND a IN (
   SELECT z
   FROM table_y
   WHERE accountid = ?
   ), (providerid, accountid)
)

The accountid = ? in the sub-query triggers some inability in 
some layer to determine what datatype it should be converted to, 
so it raises a FrustrateTim exception :)


-tkc






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


Emulate a printf() C-statement in Python???

2009-03-19 Thread Mr. Z
I'm trying emulate a printf() c statement that does, for example

char* name=Chris;
int age=30;
printf(My name is %s, name);
printf(My name is %s and I am %d years old., %s, %d);

In other words, printf() has a variable arguement list the we
all know.

I'm trying to do this in Python...

class MyPrintf(object):
# blah, blah
 def myprintf(object, *arg):
  # Here I'll have to know I NEED 2 arguments in format string
arg[0]
  print arg[0] % (arg[1], arg[2])

name=Chris
age=30
printf=MyPrintf()
printf.myPrintf((My name is %s and I am %d years old., name, age)
will of course print...
My name is Chris and I am 42 years old.

But
printf.myPrintf((My name is %s., name)
of course gives
Index error: list index out of range

How can I generalize the print call in the myprintf() function to do this?

print arg[0] % (arg[1])
print arg[0] % (arg[1], arg[2])
print arg[0] % (arg[1], ..., arg[n])

-- 

---
Remove XSPAM


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


Re: Do deep inheritance trees degrade efficiency?

2009-03-19 Thread Chris Rebert
On Thu, Mar 19, 2009 at 2:54 AM, Christian Heimes li...@cheimes.de wrote:
 Chris Rebert wrote:
 There's no effect on attribute read-writes as they all take place
 within the single __dict__ of the instance. As for method lookup, it
 doesn't add an indirection per se, but rather the list of classes to
 look thru to find a method gets longer, making base-class method
 lookups slower. IIRC, a typical method lookup does something like the
 following pseudocode:

 for klass in the_object.__mro__:
     if method_name in klass.__dict__:
         return klass.__dict__[method_name]
 raise AttributeError # no such attribute

 Your assumption is no longer true. Starting with Python 2.6 and 3.0 the
 lookup of attributes is cached. You can find detailed information by
 searching for VERSION_TAG in the source code.

Very interesting. Now that's a smart optimization; sounds a bit
similar to what V8 does for JavaScript.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


ANN: eGenix mxODBC Connect 1.0.1 - Python Database Interface

2009-03-19 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING
  eGenix.com mxODBC Connect

  Python Database Interface

Version 1.0.1


   Our new client-server product for connecting Python applications
  to relational databases - from all major platforms


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



INTRODUCTION

The mxODBC Connect Database Interface for Python allows users to
easily connect Python applications to all major databases on the
market today in a highly portable and convenient way.

Unlike our mxODBC Python extension, mxODBC Connect is designed
as client-server application, so you no longer need to find production
quality ODBC drivers for all the platforms you target with your Python
application.

Instead you use an easy to install Python client library which
connects directly to the mxODBC Connect database server over the
network.

This makes mxODBC Connect the ideal basis for writing cross-platform
database programs and utilities in Python, especially if you run
applications that need to communicate with databases such as MS SQL
Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase
ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more,
that run on Windows or Linux machines.

By removing the need to install and configure ODBC drivers on the
client side, mxODBC Connect greatly simplifies setup and
configuration of database driven client applications, while at
the same time making the network communication between client and
database server more efficient and more secure.

For more information, please see the product page:

http://www.egenix.com/products/python/mxODBCConnect/



NEWS

mxODBC Connect 1.0.1 is a patch-level release of our new mxODBC Connect
product.

* More Robust

We have made the client and server more robust in case of communication
failures. Even if the client applications fail to shutdown the server
connection before exiting, the server will free up resources used by the
client on the server side and rollback transactions as necessary.

* More Platform Support

With the 1.0.1 release we are also providing much better platform
support for the mxODBC Connect Client: we have fixed a problem in 1.0.0
that prevented the installation of the pre-built clients on non-Linux
systems.

The mxODBC Connect Client can now be installed on most platforms
supported by Python, since it is written in a platform independent,
portable way.

The pre-built archives also make it possible to integrate the clients
into build system such as buildout (used in Zope and Plone) or other
distutils-based deployment systems.

* Ideal for Building Bridges

As a result, connecting from e.g. Mac OS X to an SQL Server database
has never been easier. You can even keep the data sources you already
have configured on your Windows machine and connect to them as if your
application were running on the database server itself.



UPGRADING

You are encouraged to upgrade to this latest mxODBC Connect release.
When upgrading, please always upgrade both the server and the client
installations to the same version - even for patch level releases.

Customers who have purchased mxODBC Connect 1.0 licenses can download
and upgrade their existing installations without having to purchase
new licenses or upgrades. The licenses will continue to work with
version 1.0.1.

Users of our stand-alone mxODBC product will have to purchase new
licenses from our online shop in order to use mxODBC Connect.

You can request 30-day evaluation licenses by visiting our web-site
or writing to sa...@egenix.com, stating your name (or the name of the
company) and the number of eval licenses that you need.

http://www.egenix.com/products/python/mxODBCConnect/#Evaluation



DOWNLOADS

The download archives as well as instructions for installation and
configuration of the product can be found on the product page:

http://www.egenix.com/products/python/mxODBCConnect/

Evaluation licenses for the server part are available free of
charge:

http://www.egenix.com/products/python/mxODBCConnect/#Evaluation

The client part of mxODBC Connect is always free of charge.

___

SUPPORT

Commercial support for this product is available from eGenix.com.

Please see

http://www.egenix.com/services/support/

for details about our support offerings.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Mar 19 2009)
 

Re: Do deep inheritance trees degrade efficiency?

2009-03-19 Thread Terry Reedy

Anthra Norell wrote:
Would anyone who knows the inner workings volunteer to clarify whether 
or not every additional derivation of a class hierarchy adds an 
indirection to the base class's method calls and attribute read-writes. 


More potential search layers rather than pointer indirection.  But I 
doubt this is a bottleneck in very many programs.  So I would more 
concern myself first with quickly writing correct code.


tjr

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


Re: Emulate a printf() C-statement in Python???

2009-03-19 Thread Chris Rebert
On Thu, Mar 19, 2009 at 5:43 AM, Mr. Z no...@xspambellsouth.net wrote:
 I'm trying emulate a printf() c statement that does, for example

 char* name=Chris;
 int age=30;
 printf(My name is %s, name);
 printf(My name is %s and I am %d years old., %s, %d);

 In other words, printf() has a variable arguement list the we
 all know.

 I'm trying to do this in Python...

 class MyPrintf(object):
    # blah, blah
     def myprintf(object, *arg):
          # Here I'll have to know I NEED 2 arguments in format string
 arg[0]
          print arg[0] % (arg[1], arg[2])

 name=Chris
 age=30
 printf=MyPrintf()
 printf.myPrintf((My name is %s and I am %d years old., name, age)
 will of course print...
 My name is Chris and I am 42 years old.

 But
 printf.myPrintf((My name is %s., name)
 of course gives
 Index error: list index out of range

 How can I generalize the print call in the myprintf() function to do this?

 print arg[0] % (arg[1])
 print arg[0] % (arg[1], arg[2])
 print arg[0] % (arg[1], ..., arg[n])

def printf(format, *args):
print format % args

Although I fail to see the point in doing this. All you're doing is
trading the use of the % operator for a function call.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: python equivalent of java technologies

2009-03-19 Thread Tim Hoffman

Hi

Well zope has quite a few of these out of the box and have been around
for a bit longer than some of the java options.

Specifically persistence (ZODB persistence in zope is pretty much
completely autmomatic)
you can inplement web services with it (xmlrpc out of the box, though
I assume you mean soap)
zope encompasses security/ and authentication and can easily be
integrated with a range of single signon environments.
there are a range of scheduling services in to, but which is most like
quartz I am not sure about.
zope does support distributed transactions, but I not XA , but is
ACID.

In general there are a heap of interfaces for python do different
message queues/buses, take you pick of you favourite platform.

Not sure about reporting that is equivalent to jasper.

T



On Mar 19, 3:14 am, markolopa marko.lopa...@gmail.com wrote:
 Hello,

 When comparing python and java with a colleague who is fan of java,
 she challenged me to find in python the equivalent to the following
 technologies. Could you please help telling if we have something
 equivalent in python or not and how they compare to the java
 solutions?

 - persistance framework  (~hibernate)
 - transational monitor (distributed transaction), XA compliance
 (message system, DB) (http://en.wikipedia.org/wiki/X/Open_XA)
 - web openess sur le web (web service)
 - RIA and web deployable graphic library
 - scheduling (quartz)
 - secutity (PKI, single sign-on...)
 - reporting (Jasper)

 Thanks a lot!
 Marko

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


Python-URL! - weekly Python news and links (Mar 19)

2009-03-19 Thread Gabriel Genellina
QOTW:  In that case I fear Python will be far too simple ...  You've
been programming for way too long ... - Steve Holden
http://groups.google.com/group/comp.lang.python/msg/b8027713e674ef9d


Having a function called after the constructor/__init__ is done:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b9bb9d101e0cba4f/

How to add months to a date?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/13f3d0296128592a/

Processing a binary file in blocks of fixed size:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e22b468d8ef4dd78/

It's hard to find the in keyword in the Python documentation:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b28446a0c51de9fe/

Proposed format specifier for a thousands separator

http://groups.google.com/group/comp.lang.python/browse_thread/thread/3a37546abd506626/

How to make ElementTree always return Unicode texts:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/31c996da94c26714/

Class- and instance-attributes with the same name may be confusing
sometimes:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e840cd0f5e37a26a/

The future of PyPy:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/641a8f8c34781e13/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python enthusiats:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.orggroup=gmane.comp.python.develsort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://code.activestate.com/recipes/langs/python/

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available, see:
http://www.python.org/channews.rdf
For more, see:
http://www.syndic8.com/feedlist.php?ShowMatch=pythonShowStatus=all
The old Python To-Do List now lives principally in a
SourceForge reincarnation.
http://sourceforge.net/tracker/?atid=355470group_id=5470func=browse
http://www.python.org/dev/peps/pep-0042/

del.icio.us presents an intriguing approach to reference commentary.
It already aggregates quite a bit of Python intelligence.
http://del.icio.us/tag/python

*Py: the Journal of 

Re: Emulate a printf() C-statement in Python???

2009-03-19 Thread Andrii V. Mishkovskyi
On Thu, Mar 19, 2009 at 2:43 PM, Mr. Z no...@xspambellsouth.net wrote:
 I'm trying emulate a printf() c statement that does, for example

 char* name=Chris;
 int age=30;
 printf(My name is %s, name);
 printf(My name is %s and I am %d years old., %s, %d);

 In other words, printf() has a variable arguement list the we
 all know.

 I'm trying to do this in Python...

 class MyPrintf(object):
    # blah, blah
     def myprintf(object, *arg):
          # Here I'll have to know I NEED 2 arguments in format string
 arg[0]
          print arg[0] % (arg[1], arg[2])

Note: you can, of course, use any name for the instance variable in
methods, but 'self' is considered a de-facto standard, not 'object'.
Besides, you're overriding builtin which is considered a bad practice.


 name=Chris
 age=30
 printf=MyPrintf()
 printf.myPrintf((My name is %s and I am %d years old., name, age)
 will of course print...
 My name is Chris and I am 42 years old.

 But
 printf.myPrintf((My name is %s., name)
 of course gives
 Index error: list index out of range

 How can I generalize the print call in the myprintf() function to do this?

 print arg[0] % (arg[1])
 print arg[0] % (arg[1], arg[2])
 print arg[0] % (arg[1], ..., arg[n])

It's quite simple:
def printf(fmt, *args):
print fmt % args


 --

 ---
 Remove XSPAM


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




-- 
Wbr, Andrii V. Mishkovskyi.

He's got a heart of a little child, and he keeps it in a jar on his desk.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Do deep inheritance trees degrade efficiency?

2009-03-19 Thread Bruno Desthuilliers

Chris Rebert a écrit :

On Wed, Mar 18, 2009 at 6:09 AM, Anthra Norell anthra.nor...@bluewin.ch wrote:

Would anyone who knows the inner workings volunteer to clarify whether or
not every additional derivation of a class hierarchy adds an indirection to
the base class's method calls and attribute read-writes. In C++, I suppose,
a three-level inheritance would resolve into something like
*(*(*(*(base_class_method ().


There's no effect on attribute read-writes as they all take place
within the single __dict__ of the instance.


Except when:
- the attribute is a computed one (property or other descriptor)
- (for read access) the attribute is not set in the instance's dict.


As for method lookup, it
doesn't 


make much difference - the very same lookup rules apply, and it's the 
descriptor protocol (as implemented by the 'function' type) that takes 
care of returning a method object (mostly a partial application of the 
function to the instance or class) when appropriate.


(snip)


However, you shouldn't really worry about the inefficiency of a deep
inheritance tree as Python


is probably not the right tool for the job if one have such efficiency 
concerns.


(snip)


[Note: I'm purposefully ignoring the fact that methods and attributes
are in reality looked up in the exact same way for
simplicity/clarity.]


Ah, ok - then please don't take the above remarks as a personal offense !-)

(still posting this since it might be of interest to the OP or someone 
else).

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


Re: Roulette wheel

2009-03-19 Thread Gabriel Genellina

En Thu, 19 Mar 2009 08:06:35 -0200, mattia ger...@gmail.com escribió:


OK, understood. Now, as a general rule, is it correct to say:
- use generator expression when I just need to iterate over the list or
call a function that involve an iterator (e.g. sum) and get the result,
so the list is not necessary anymore
- use list comprehensions when I actually have to use the list (e.g. I
need to swap some values or I need to use sorted() etc.)
Am I right?


Yes, at least that's how I use them: a generator expression when the  
elements are consumed one by one in
the same moment, and a list comprehension when I actually want the list as  
a whole.


(Note that sorted() has to return a new list anyway, its argument may be a  
gen.expr. but sorted() starts by making a list out of it; you may be  
thinking of the list.sort() method)


--
Gabriel Genellina

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


Re: Style formating of multiline query, advise

2009-03-19 Thread Marco Mariani

someone wrote:


Also, for SQL, (A) why are you using nested joins?, and


inner select produce smaller set which is then joined with other
table, kind a optimization


Did you time it?
I've done some kind of a optimization that slowed queries by tenfold, 
because postgres didn't need my advice, and knew better. RDBMS 
performance is non-intuitive, really. If you're using mysql, YMMV, 
because its optimizer is not as good.



Yes, my original question was about formatting. It's not original
query (only a part).



Try this:

http://www.dpriver.com/pp/sqlformat.htm


My 2c: I use textwrap.dedent to strip leading spaces from every line.

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


Re: Uploading a file using POST

2009-03-19 Thread Vijayendra Bapte
On Mar 19, 7:20 am, Justin Ezequiel justin.mailingli...@gmail.com
wrote:
 On Mar 19, 8:50 am, Thomas Robitaille thomas.robitai...@gmail.com
 wrote:

  I am trying to upload a binary file (a tar.gz file to be exact) to a  
  web server using POST, from within a python script.

  What I would like is essentially the equivalent of

  form name='proceedings' method='post' action='www.whatever.com' 
  enctype=multipart/form-data
  input name=userfile type=file
  /form

 have you seenhttp://code.activestate.com/recipes/146306/

or you can use pycurl

 import pycurl
 c = pycurl.Curl()
 c.setopt(pycurl.URL, http://www.whatever.com;)
 c.setopt(pycurl.POST, 1)
 filepath = /path/of/file
 filename = filename
 c.setopt(pycurl.HTTPPOST, [('userfile', (pycurl.FORM_FILE, file_path, 
 pycurl.FORM_FILENAME, filename))])
 c.perform()

read pycurl doc for more details. http://pycurl.sourceforge.net/doc/pycurl.html

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


Re: Emulate a printf() C-statement in Python???

2009-03-19 Thread John Machin
On Mar 19, 11:43 pm, Mr. Z no...@xspambellsouth.net wrote:
 I'm trying emulate a printf() c statement that does, for example

 char* name=Chris;
 int age=30;
 printf(My name is %s, name);
 printf(My name is %s and I am %d years old., %s, %d);

 In other words, printf() has a variable arguement list the we
 all know.

 I'm trying to do this in Python...


|  def printf(fmt, *args):
| ...import sys
| ...sys.stdout.write(fmt % args)
| ...
|  printf(It's a %s %s parrot\n, 'Norwegian', 'blue')
| It's a Norwegian blue parrot
| 

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


Re: Emulate a printf() C-statement in Python???

2009-03-19 Thread Eric Brunel
Mr. Z wrote:
 I'm trying emulate a printf() c statement that does, for example

 char* name=Chris;
 int age=30;
 printf(My name is %s, name);
 printf(My name is %s and I am %d years old., %s, %d);

 In other words, printf() has a variable arguement list the we
 all know.

 I'm trying to do this in Python...

 class MyPrintf(object):
 # blah, blah
  def myprintf(object, *arg):
   # Here I'll have to know I NEED 2 arguments in format string
 arg[0]
   print arg[0] % (arg[1], arg[2])

No you don't: in Python, the % operator on strings expects a tuple as second
operand, and args is already a tuple. So:
print args[0] % arhgs[1:]
will do what you want.

Some stylistic issues:
- You don't have to put everything in a class in Python. Your myprintf looks a
lot like a function to me, so you'll probably want to define it as such.
- Don't use object as the first parameter to methods! object is the top-level
class for the whole class hierarchy, so you certainly don't want to obscure it
with a variable. For methods, use the traditional self as first parameter.
- In your function myprintf, the format string seems to be a required
argument. If it is, you might want to define as such too:

def myprintf(format_string, *args):
  print format_string % args

So now, as you can see, redefining printf in Python is not really
interesting...

HTH anyway.
 - Eric -
--
http://mail.python.org/mailman/listinfo/python-list


Re: Emulate a printf() C-statement in Python???

2009-03-19 Thread John Machin
On Mar 19, 11:52 pm, Chris Rebert c...@rebertia.com wrote:
 On Thu, Mar 19, 2009 at 5:43 AM, Mr. Z no...@xspambellsouth.net wrote:
  I'm trying emulate a printf() c statement that does, for example

  char* name=Chris;
  int age=30;
  printf(My name is %s, name);
  printf(My name is %s and I am %d years old., %s, %d);

  In other words, printf() has a variable arguement list the we
  all know.

  I'm trying to do this in Python...

  class MyPrintf(object):
     # blah, blah
      def myprintf(object, *arg):
           # Here I'll have to know I NEED 2 arguments in format string
  arg[0]
           print arg[0] % (arg[1], arg[2])

  name=Chris
  age=30
  printf=MyPrintf()
  printf.myPrintf((My name is %s and I am %d years old., name, age)
  will of course print...
  My name is Chris and I am 42 years old.

  But
  printf.myPrintf((My name is %s., name)
  of course gives
  Index error: list index out of range

  How can I generalize the print call in the myprintf() function to do this?

  print arg[0] % (arg[1])
  print arg[0] % (arg[1], arg[2])
  print arg[0] % (arg[1], ..., arg[n])

 def printf(format, *args):
     print format % args

The OP asked for an emulation of printf(), which doesn't have
softspacing and other party tricks.

 Although I fail to see the point in doing this. All you're doing is
 trading the use of the % operator for a function call.

It is one of those things that it is good to know, perhaps not so good
to practice ... somewhat akin to the English definition of a Scots
gentleman: A man who can play the bagpipes but doesn't.

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


Python benchmarks comparing 32-bit to 64-bit performance

2009-03-19 Thread python
Are there any benchmarks (pystones or other) that compare a
32-bit and 64-bit versions of Python?
Ideally I'm looking for a benchmark comparing recent Python
releases (2.6.x, 3.x) on an Intel platform.
I'm specifically interested in areas of the Python language where
a 64-bit implementation is surprisingly faster or slower than its
32-bit equivalent.
Thank you,
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list


Preferred syntax for the docstrings

2009-03-19 Thread Luis Zarrabeitia

What's the preferred style to document code in python? I usually do something
like this:

===
def somefunction(arg1, arg2, out = sys.stdout):
 This function does blahblablha with the string arg1, using 
the tuple of ints arg2 as the control sequence, and prints the 
result to out (defaults to sys.stdout) 
===

That seems sub-optimal, I can't rapidly see what are you expecting from the
arguments or the return value. I've seen some docstrings with the style

===
def somefunction(arg1, ar2, out = sys.stdout):
 brief description, possibly involving some symbolarg1, some symbol 
arg2 and some symbol arg3
some symbol arg1: string, some description
...

===

I guess there are several languages for writing the docstring. The question is,
which is the preferred one in python, and where can I learn the syntax? (the one
that python documentation viewers understand better? the one used by the
stdlib?) How should/in what order should I write the docs? (brief description,
argument types, return type, followed perhaps by some doctests).

-- 
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie




 Participe en Universidad 2010, del 8 al 12 de febrero de 2010
 La Habana, Cuba 
 http://www.universidad2010.cu
 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Emulate a printf() C-statement in Python???

2009-03-19 Thread Chris Rebert
On Thu, Mar 19, 2009 at 6:13 AM, John Machin sjmac...@lexicon.net wrote:
 On Mar 19, 11:52 pm, Chris Rebert c...@rebertia.com wrote:
 On Thu, Mar 19, 2009 at 5:43 AM, Mr. Z no...@xspambellsouth.net wrote:
  I'm trying emulate a printf() c statement that does, for example

  char* name=Chris;
  int age=30;
  printf(My name is %s, name);
  printf(My name is %s and I am %d years old., %s, %d);

  In other words, printf() has a variable arguement list the we
  all know.

  I'm trying to do this in Python...

  class MyPrintf(object):
     # blah, blah
      def myprintf(object, *arg):
           # Here I'll have to know I NEED 2 arguments in format string
  arg[0]
           print arg[0] % (arg[1], arg[2])

  name=Chris
  age=30
  printf=MyPrintf()
  printf.myPrintf((My name is %s and I am %d years old., name, age)
  will of course print...
  My name is Chris and I am 42 years old.
snip
 def printf(format, *args):
     print format % args

 The OP asked for an emulation of printf(), which doesn't have
 softspacing and other party tricks.

Well, his implementation had the same issues, so I assumed he was
going for something merely somewhat printf()-like rather than exactly
the same. Though I suppose you might as well go all the way if you're
doing something impractical like this. :)

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Preferred syntax for the docstrings

2009-03-19 Thread Chris Rebert
On Thu, Mar 19, 2009 at 6:26 AM, Luis Zarrabeitia ky...@uh.cu wrote:

 What's the preferred style to document code in python? I usually do something
 like this:

 ===
 def somefunction(arg1, arg2, out = sys.stdout):
     This function does blahblablha with the string arg1, using
    the tuple of ints arg2 as the control sequence, and prints the
    result to out (defaults to sys.stdout) 
 ===

 That seems sub-optimal, I can't rapidly see what are you expecting from the
 arguments or the return value. I've seen some docstrings with the style

 ===
 def somefunction(arg1, ar2, out = sys.stdout):
     brief description, possibly involving some symbolarg1, some symbol
        arg2 and some symbol arg3
        some symbol arg1: string, some description
        ...
    
 ===

 I guess there are several languages for writing the docstring. The question 
 is,
 which is the preferred one in python, and where can I learn the syntax? (the 
 one
 that python documentation viewers understand better? the one used by the
 stdlib?) How should/in what order should I write the docs? (brief description,
 argument types, return type, followed perhaps by some doctests).

It's pretty subjective based on which documentation generator you use
(or if you don't use one at all, just your personal style), but
personally I'd recommend reStructuredText and Sphinx
(http://sphinx.pocoo.org/) since they're used for the std lib's very
spiffy new docs. See the Sphinx homepage for how to learn the syntax.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: How complex is complex?

2009-03-19 Thread Aahz
[posted and e-mailed]

In article 033514d1-e0e9-4a1c-bca0-846781f0d...@w35g2000prg.googlegroups.com,
Kottiyath  n.kottiy...@gmail.com wrote:
On Mar 19, 11:29=A0am, Daniel Fetchinson fetchin...@googlemail.com
wrote:
 
 Once every nuanced detail has been carefully weighed in and a
 consensus has been reached among the Supreme Python Language
 Commission chamber of the PSF the appropriate answer will be mailed
 back to you.

 Now you should be able to open up your favorite editor and hack away
 knowing full well that nobody and nothing can stop you, ever!

I understand that my question was foolish, even for a newbie.  I will
not ask any more such questions in the future.

No!  Your question was *not* foolish, it was in fact a very good
question; Daniel was just making a joke in somewhat dubious taste.  

(Not in such poor taste that Daniel should apologize, but I'm guessing
that English is not your primary language, so it can be difficult to
identify jokes here.  Because the name Python is derived from the
comedy TV show Monty Python, stupid jokes are common in the Python
community.)
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Programming language design is not a rational science. Most reasoning
about it is at best rationalization of gut feelings, and at worst plain
wrong.  --GvR, python-ideas, 2009-3-1
--
http://mail.python.org/mailman/listinfo/python-list


Re: Preferred syntax for the docstrings

2009-03-19 Thread Luis Zarrabeitia

Quoting Chris Rebert c...@rebertia.com:

 
 It's pretty subjective based on which documentation generator you use
 (or if you don't use one at all, just your personal style), but
 personally I'd recommend reStructuredText and Sphinx
 (http://sphinx.pocoo.org/) since they're used for the std lib's very
 spiffy new docs. See the Sphinx homepage for how to learn the syntax.
 
 Cheers,
 Chris

That was quick! Thanks! Opening the page now.

-- 
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie


 Participe en Universidad 2010, del 8 al 12 de febrero de 2010
 La Habana, Cuba 
 http://www.universidad2010.cu
 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Do deep inheritance trees degrade efficiency?

2009-03-19 Thread Anthra Norell

Bruno Desthuilliers wrote:

Chris Rebert a écrit :
On Wed, Mar 18, 2009 at 6:09 AM, Anthra Norell 
anthra.nor...@bluewin.ch wrote:
Would anyone who knows the inner workings volunteer to clarify 
whether or
not every additional derivation of a class hierarchy adds an 
indirection to
the base class's method calls and attribute read-writes. In C++, I 
suppose,

a three-level inheritance would resolve into something like
*(*(*(*(base_class_method ().


There's no effect on attribute read-writes as they all take place
within the single __dict__ of the instance.


Except when:
- the attribute is a computed one (property or other descriptor)
- (for read access) the attribute is not set in the instance's dict.


As for method lookup, it
doesn't 


make much difference - the very same lookup rules apply, and it's the 
descriptor protocol (as implemented by the 'function' type) that takes 
care of returning a method object (mostly a partial application of the 
function to the instance or class) when appropriate.


(snip)


However, you shouldn't really worry about the inefficiency of a deep
inheritance tree as Python


is probably not the right tool for the job if one have such efficiency 
concerns.


(snip)


[Note: I'm purposefully ignoring the fact that methods and attributes
are in reality looked up in the exact same way for
simplicity/clarity.]


Ah, ok - then please don't take the above remarks as a personal 
offense !-)


(still posting this since it might be of interest to the OP or someone 
else).

--
http://mail.python.org/mailman/listinfo/python-list
The OP (that's me) thankfully acknowledges all contributions. The upshot 
of it all seems to be that there are countless ways for a compiler or 
interpreter to handle access through class hierarchies. I did a very 
crude test myself, like this:


 class A:
def do (self): pass
 class B (A): pass
 class C (B): pass
 class D (C): pass
 class E (D): pass   # Got to stop somewhere

 a = A ()
 for i in xrange (100):
   a.do ()
11 seconds

 e = E ()
 for i in xrange (100):
e.do ()
14 seconds

No significant difference indeed !

Frederic


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


Re: set_process_affinity_mask problem - Python 2.5 gcc 4.3.2 (Ubuntu 4.3.2-1ubuntu12)

2009-03-19 Thread Aahz
In article mailman.1499.1236566959.11746.python-l...@python.org,
Isaac Gouy  igo...@yahoo.com wrote:

Now I've upgraded from Ubuntu 8.04 to Ubuntu 8.10 (from gcc 4.2.3 to
gcc 4.3.2) and set_process_affinity_mask seems to fail on the x86
Ubuntu install.  It still works fine, after upgrade, on the x64 Ubuntu
install.
  [...]
Please suggest what I can do to debug / fix this problem.

Search the Ubuntu bugs first, then ask on an Ubuntu mailing list.  My
impression is that 8.10 is a bit half-baked -- I'm rather annoyed that
the feature save session on logout is completely b0rked, but it's not
so annoying that I'll downgrade.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Programming language design is not a rational science. Most reasoning
about it is at best rationalization of gut feelings, and at worst plain
wrong.  --GvR, python-ideas, 2009-3-1
--
http://mail.python.org/mailman/listinfo/python-list


Re: Emulate a printf() C-statement in Python???

2009-03-19 Thread Mr. Z
Andrii V. Mishkovskyi misho...@gmail.com wrote in message
news:mailman.2185.1237467269.11746.python-l...@python.org...
On Thu, Mar 19, 2009 at 2:43 PM, Mr. Z no...@xspambellsouth.net wrote:
 I'm trying emulate a printf() c statement that does, for example

 char* name=Chris;
 int age=30;
 printf(My name is %s, name);
 printf(My name is %s and I am %d years old., %s, %d);

 In other words, printf() has a variable arguement list the we
 all know.

 I'm trying to do this in Python...

 class MyPrintf(object):
 # blah, blah
 def myprintf(object, *arg):
 # Here I'll have to know I NEED 2 arguments in format string
 arg[0]
 print arg[0] % (arg[1], arg[2])

Note: you can, of course, use any name for the instance variable in
methods, but 'self' is considered a de-facto standard, not 'object'.
Besides, you're overriding builtin which is considered a bad practice.


 name=Chris
 age=30
 printf=MyPrintf()
 printf.myPrintf((My name is %s and I am %d years old., name, age)
 will of course print...
 My name is Chris and I am 42 years old.

 But
 printf.myPrintf((My name is %s., name)
 of course gives
 Index error: list index out of range

 How can I generalize the print call in the myprintf() function to do this?

 print arg[0] % (arg[1])
 print arg[0] % (arg[1], arg[2])
 print arg[0] % (arg[1], ..., arg[n])

It's quite simple:
def printf(fmt, *args):
print fmt % args


 --

 ---
 Remove XSPAM


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


Too simple, I love it!

-- 
Wbr, Andrii V. Mishkovskyi.

He's got a heart of a little child, and he keeps it in a jar on his desk.


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


Re: How to do this in Python? - A gotcha

2009-03-19 Thread bieffe62
On Mar 18, 6:06 pm, Jim Garrison j...@acm.org wrote:
 S Arrowsmith wrote:
  Jim Garrison  j...@acm.org wrote:
  It's a shame the iter(o,sentinel) builtin does the
  comparison itself, instead of being defined as iter(callable,callable)
  where the second argument implements the termination test and returns a
  boolean.  This would seem to add much more generality... is
  it worthy of a PEP?

  class sentinel:
      def __eq__(self, other):
          return termination_test()

  for x in iter(callable, sentinel()):
      ...

  Writing a sensible sentinel.__init__ is left as an exercise

 If I understand correctly, this pattern allows me to create
 an object (instance of class sentinel) that implements whatever
 equality semantics I need to effect loop termination.  In the
 case in point, then, I end up with

      class sentinel:
          def __eq__(self,other):
              return other=='' or other==b''

      with open(filename, rb) as f:
          for buf in iter(lambda: f.read(1000), sentinel())):
              do_something(buf)

 i.e. sentinel is really object that compares equal to both ''
 and b''.  While I appreciate how this works, I think the
 introduction of a whole new class is a bit of overkill for
 what should be expressible in iter()- Hide quoted text -

 - Show quoted text -


In the specific case it should not be needed to create a class,
because
at least with python 2.6:

 b'' == ''
True
 u'' == ''
True


so you should be able to do:

  with open(filename, rb) as f:
  for buf in iter(lambda: f.read(1000),  ):
  do_something(buf)


Ciao
--
FB


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


Re: Is python worth learning as a second language?

2009-03-19 Thread Aahz
In article 49b5196b$0$3514$426a7...@news.free.fr,
Bruno Desthuilliers  bruno.42.desthuilli...@websiteburo.invalid wrote:
Grant Edwards a écrit :

 Knowing C++ does tend to be a bit of a handicap, but I think
 any competent programmer could learn Python.

+2 QOTW !-)

Ditto!  Although I suppose you could just go for the jugular and say
that C++ is the BASIC of the 1990s.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Programming language design is not a rational science. Most reasoning
about it is at best rationalization of gut feelings, and at worst plain
wrong.  --GvR, python-ideas, 2009-3-1
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is python worth learning as a second language?

2009-03-19 Thread Aahz
In article 49b58b35$0$3548$426a7...@news.free.fr,
Bruno Desthuilliers  bdesth.quelquech...@free.quelquepart.fr wrote:
Tomasz Rola a écrit :

 I may not be objective (tried Java, hated it after 6 years).

Arf - only took me 6 months !-)

That long?  It only took me six minutes.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Programming language design is not a rational science. Most reasoning
about it is at best rationalization of gut feelings, and at worst plain
wrong.  --GvR, python-ideas, 2009-3-1
--
http://mail.python.org/mailman/listinfo/python-list


Re: supervisor 3.0a6 and Python2.6

2009-03-19 Thread Raymond Cote

George Trojan wrote:

1. Is supervisor still developed?
I note that, although the information on the site is pretty old, there 
have been some respository checkins in Feb and March of this year:

   http://lists.supervisord.org/pipermail/supervisor-checkins/
-r
--
http://mail.python.org/mailman/listinfo/python-list


can someone help me (again) stuck on ' hands on python'

2009-03-19 Thread Gary Wood
#I adjusted the 2nd  main function so i test what im trying to do can someone 
point me in the right direction please 

 
Exercise 2.3.3.1. ** Rename the example file locationsStub.py to be 
locations.py, and complete the function printLocations, to print the index of 
each location in the string s where target is located. For example, 
printLocations('This is a dish', 'is') would go through the string 'This is a 
dish' looking for the index of places where 'is' appears, and would return [2, 
5, 11]. Similarly printLocations('This is a dish', 'h') would return [1, 13]. 
The program stub already uses the string method count. You will need to add 
code using the more general form of find. 


code 

'''Exercise to complete printLocations as described below.
Create file locations.py.'''
def printLocations(target):
'''s is a string to search through, and target is the substring to look for.
Print each index where the target starts.
For example:
 printLocations('Here, there, everywhere!', 'ere')
1
8
20
'''
  

def main():
phrase = 'Here, there, everywhere!'
print('Phrase:', phrase)
for target in ['ere', 'er', 'e', 'zx']:
print('finding:', target)
printLocations(phrase, target)
print('All done!')

main()


#i adjusted the main function helps me see the code as the program runs 
def main():
phrase = 'Here, there, everywhere!'
print('Phrase:', phrase)
for target in ['ere', 'er', 'e', 'zx']:
print('finding:', target)
printLocations=(phrase, target)
print(printLocations,'locations :',phrase.find(target))
print('All done!')
   
main()

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


Re: Is python worth learning as a second language?

2009-03-19 Thread grkuntzmd
The other day one of our developers said that he thought learning
assembler language in college was a total waste of time. I can't
disagree more.

Even if assembler language is specific to one architecture, the
principles that it teaches are universal and fundamental to all other
programming languages.

Besides, programming in assembler can be fun, in a sick sort of
way... :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to do this in Python? - A gotcha

2009-03-19 Thread Scott David Daniels

bieff...@gmail.com wrote:

On Mar 18, 6:06 pm, Jim Garrison j...@acm.org wrote:

S Arrowsmith wrote:

Jim Garrison  j...@acm.org wrote:

It's a shame the iter(o,sentinel) builtin does the
comparison itself, instead of being defined as iter(callable,callable)
where the second argument implements the termination test and returns a
boolean.  This would seem to add much more generality... is
it worthy of a PEP?

class sentinel:
def __eq__(self, other):
return termination_test()
for x in iter(callable, sentinel()):
...
Writing a sensible sentinel.__init__ is left as an exercise

If I understand correctly, this pattern allows me to create
an object (instance of class sentinel) that implements whatever
equality semantics I need to effect loop termination.  In the
case in point, then, I end up with

 class sentinel:
 def __eq__(self,other):
 return other=='' or other==b''

 with open(filename, rb) as f:
 for buf in iter(lambda: f.read(1000), sentinel())):
 do_something(buf)

i.e. sentinel is really object that compares equal to both ''
and b''.  While I appreciate how this works, I think the
introduction of a whole new class is a bit of overkill for
what should be expressible in iter()- Hide quoted text -

- Show quoted text -



In the specific case it should not be needed to create a class,
because
at least with python 2.6:


b'' == ''

True

u'' == ''

True


Ah, you misunderstand the short-term expedient that 2.6 took.
Effectively, it simply said, bytes = str.

In 2.6:
 str is bytes
True
in 3.X:
 str is bytes
False
 b'' == ''
False
 type(b''), type('')
(class 'bytes', class 'str')

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: python equivalent of java technologies

2009-03-19 Thread Armin
On Thursday 19 March 2009 07:45:01 Jeremiah Dodds wrote:
 On Tue, Mar 17, 2009 at 8:32 PM, Armin feng.sh...@gmail.com wrote:
  You could tell her to try Jython.  In that, you can just use the Java
  implementations. :)  Plus, you have things in Jython that Java doesn't :D
 
  --
  Armin Moradi
  --
  http://mail.python.org/mailman/listinfo/python-list

 Exactly. Her challenges to find stuff have to do with the JVM, not Java the
 language. Python runs on the JVM.

Indeed, afaik, Jython produces Java byte-code.

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


Re: supervisor 3.0a6 and Python2.6

2009-03-19 Thread George Trojan

Raymond Cote wrote:

George Trojan wrote:

1. Is supervisor still developed?
I note that, although the information on the site is pretty old, there 
have been some respository checkins in Feb and March of this year:

   http://lists.supervisord.org/pipermail/supervisor-checkins/
-r


I found answers to both questions (the other one was: Is there a quick 
fix to the above behaviour?) - accidentally the same day, on March 17 
there was a post on supervisor-users group: 
http://lists.supervisord.org/pipermail/supervisor-users/2009-March/000311.html. 
The answer by one of supervisor's developer led me to an interesting 
thread on python-dev: asyncore fixes in Python 2.6 broke Zope's version 
of medusa dated March 4: 
http://mail.python.org/pipermail/python-dev/2009-March/thread.html#86739


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


DictReader and fieldnames

2009-03-19 Thread Ted To
Is it possible to grab the fieldnames that the csv DictReader module
automatically reads from the first line of the input file?

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


Re: mxODBC (was split problem if the delimiter is inside the text limiter)

2009-03-19 Thread M.-A. Lemburg
On 2009-03-19 13:40, Tim Chase wrote:
 DB-API 2.0 has cursor.executemany() to make this differentiation
 at the API level. mxODBC will lift this requirement in the next
 version, promised :-)
 
 glad to hear...will executemany() take an arbitrary iterable?  My
  (albeit somewhat-antiquated) version balked at anything that wasn't a
 list/tuple (don't remember off the top of my head which it was).  For a
 lot of my ETL work, it would be nice to pass a generator so I don't have
 to keep huge datasets in memory.

cursor.executemany() is designed to work on bulk data. It allows
passing a whole chunk of data to the database in one go. It will
currently accept any sequence, but not an iterator. However, we may
add support for general iterators to the next version.

If you want to use a generator with mxODBC 3.0, you are probably
better off using e.g.

cmd = 'INSERT ... VALUES (?,?,?)'
for row in iterable:
cursor.execute(cmd, row)

Since you always use the same command object, this will trigger
an optimization in mxODBC whereby the prepare step for the command
is only applied once and the already prepared command then
reused for all subsequent executes.

 (and don't get me started on mxODBC's failure to
 determine the data-type for parameters in subqueries, raising exceptions
 on perfectly valid queries/rant)

 I'm not sure what you are referring to here. mxODBC can only provide
 an interface to the underlying ODBC driver.
 
 Okay...feel free to deflect the minced oaths at MS's SQL Server ODBC
 driver then. :)  The main problem came with queries like
 
   cursor.execute(
 SELECT a, b, c
 FROM table_x
 WHERE providerid = ?
   AND a IN (
SELECT z
FROM table_y
WHERE accountid = ?
), (providerid, accountid)
 )
 
 The accountid = ? in the sub-query triggers some inability in some
 layer to determine what datatype it should be converted to, so it raises
 a FrustrateTim exception :)

Parameter binding markers are not always supported in all contexts.

The error that I get from the SQL Server ODBC driver for the above is:

mx.ODBC.Error.ProgrammingError: ('42000', 0, '[Microsoft][SQL Server Native
Client 10.0]Syntax error, permission violation, or other nonspecific error', 
7498)

In such a case, you may have more luck by using mxODBC's
cursor.executedirect(). This uses a different mechanism for preparing
and binding the data to the command which basically moves the
process to the database server side.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Mar 19 2009)
 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


Wordpress management from Python: do you know main bindings/modules to automate Wordpress blogging from .py software?

2009-03-19 Thread Aldo Ceccarelli
Hi, Everybody!

I'm a Wordpress newbie but will have need to automate posts and would
like to use Python for this purpose too: can you lead the way to this
target?


Many thanks in advance for your kind indications!


ps some times ago, I heard about a Wordpress Python Library too but I
do not know if it is maintained and where in case

Warmest regards,
Aldo
--
http://mail.python.org/mailman/listinfo/python-list


Re: Preferred syntax for the docstrings

2009-03-19 Thread Scott David Daniels

Luis Zarrabeitia wrote:

What's the preferred style to document code in python? ...
def somefunction(arg1, arg2, out = sys.stdout):
 This function does blahblablha with the string arg1, using 
the tuple of ints arg2 as the control sequence, and prints the 
result to out (defaults to sys.stdout) 

... [or] ...
def somefunction(arg1, ar2, out = sys.stdout):
 brief description, possibly involving some symbolarg1, some symbol 
arg2 and some symbol arg3

some symbol arg1: string, some description
...

I guess there are several languages for writing the docstring. The question is,
which is the preferred one in python, and where can I learn the syntax? (the one
that python documentation viewers understand better? the one used by the
stdlib?) How should/in what order should I write the docs? (brief description,
argument types, return type, followed perhaps by some doctests).


A fairly common style is to have the first line of the docstring
summarize the function (without repeating the arglist), a blank line,
and then more elaborating text.  Some systems (notably Idle) will
provide the arglist and that first line as a floating hint when
using functions/methods interactively.  Note how much of Python's
own library provide help this way.  Exploratory programming becomes
much easier when you follow that rule.

Try it, it is fun.  go into Idle and type:
 def f(a, bc, defg):
'''A trap: never use 'def' as an arg name.

In which Doris gets her oats.
'''
return 3

 f(
And at this point pause a second, the hint  will appear.  I use
both this and print(a.b.__doc__) regularly for reminders of what
I have once read.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: How complex is complex?

2009-03-19 Thread Paul McGuire
On Mar 19, 4:39 am, Kottiyath n.kottiy...@gmail.com wrote:

 I understand that my question was foolish, even for a newbie.
 I will not ask any more such questions in the future.


Gaaah! Your question was just fine, a good question on coding style.
I wish more people would ask such questions so that bad habits could
be avoided.

The newbie posts that are annoying are the ones that:
- are answered on page 1 of any tutorial (how do I get the second
character of a string?)
- are obvious homework assignments with no actual effort on the
poster's part (how do I write a Python program to find the first 10
prime numbers?)
- pontificate on what is wrong with Python, based on 2 hours'
experience with the language (often titled What's wrong with Python,
with content like Python sucks because it doesn't have a switch
statement/has significant whitespace/doesn't check types of arguments/
isn't totally object-oriented like Java/doesn't have interfaces/...)
- are so vague as to be just Usenet noise (titled Help me, with no
content, or i need to write a program and don't know where to start
can someone write it for me?)

I think Daniel's joke was on the rest of us, who each had to chime in
with our favorite dict processing algorithm.

It *would* be good for you as a newbie to get an appreciation of the
topics that were covered in these responses, though, especially the
distinction between updating the dict in-place vs. creating a new
dict.

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


Can I rely on...

2009-03-19 Thread Emanuele D'Arrigo
Hi everybody,

I just had a bit of a shiver for something I'm doing often in my code
but that might be based on a wrong assumption on my part. Take the
following code:

pattern = aPattern

compiledPatterns = [ ]
compiledPatterns.append(re.compile(pattern))

if(re.compile(pattern) in compiledPatterns):
print(The compiled pattern is stored.)

As you can see I'm effectively assuming that every time re.compile()
is called with the same input pattern it will return the exact same
object rather than a second, identical, object. In interactive tests
via python shell this seems to be the case but... can I rely on it -
always- being the case? Or is it one of those implementation-specific
issues?

And what about any other function or class/method? Is there a way to
discriminate between methods and functions that when invoked twice
with the same arguments will return the same object and those that in
the same circumstances will return two identical objects?

If the answer is no, am I right to state the in the case portrayed
above the only way to be safe is to use the following code instead?

for item in compiledPatterns:
   if(item.pattern == pattern):
--
http://mail.python.org/mailman/listinfo/python-list


Can I rely on...

2009-03-19 Thread Emanuele D'Arrigo
Sorry for the double-post, the first one was sent by mistake before
completion.

Hi everybody,

I just had a bit of a shiver for something I'm doing often in my code
but that might be based on a wrong assumption on my part. Take the
following code:

pattern = aPattern

compiledPatterns = [ ]
compiledPatterns.append(re.compile(pattern))

if(re.compile(pattern) in compiledPatterns):
print(The compiled pattern is stored.)

As you can see I'm effectively assuming that every time re.compile()
is called with the same input pattern it will return the exact same
object rather than a second, identical, object. In interactive tests
via python shell this seems to be the case but... can I rely on it -
always- being the case?

If the answer is no, am I right to state the in the case portrayed
above the only way to be safe is to use the following code instead?

for item in compiledPatterns:
   if(item.pattern == pattern):
print(The compiled pattern is stored.)
break

And what about any other function or class/method? Is there a way to
discriminate between methods and functions that when invoked twice
with the same arguments will return the same object and those that in
the same circumstances will return two identical objects? Or is it one
of those implementation-specific issues?

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


converting pipe delimited file to fixed width

2009-03-19 Thread digz
Hi,
I am trying to convert a | delimited  file to fixed width by right
padding with spaces, Here is how I have written the program , just get
the feeling this can be done in a much better ( python functional )
way rather than the procedural code i have below . Any help
appreciated

#!/usr/bin/python
def rightFill(fillString, toLength, fillChar):
return fillString+''.join([fillChar for x in range(len
(fillString),toLength)])

fieldWidth=[ 14, 6, 18, 21, 21,4, 6  ];

file = open(/home/chatdi/input.csv, r);
lines = file.readlines()
file.close()

out = open( /home/chatdi/ouptut.csv, 'w')
for line in lines:
line = line[:-1]
index = 0
for token in line.split('|'):
paddedToken = rightFill(token, fieldWidth[index], ' ' )
out.write( paddedToken )
index = index + 1
out.write(\n)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can I rely on...

2009-03-19 Thread MRAB

Emanuele D'Arrigo wrote:

Hi everybody,

I just had a bit of a shiver for something I'm doing often in my code
but that might be based on a wrong assumption on my part. Take the
following code:

pattern = aPattern

compiledPatterns = [ ]
compiledPatterns.append(re.compile(pattern))

if(re.compile(pattern) in compiledPatterns):
print(The compiled pattern is stored.)


You don't need parentheses in the 'if', or the 'print' in Python 2.x.


As you can see I'm effectively assuming that every time re.compile()
is called with the same input pattern it will return the exact same
object rather than a second, identical, object. In interactive tests
via python shell this seems to be the case but... can I rely on it -
always- being the case? Or is it one of those implementation-specific
issues?


The re module has a cache of patterns, so if the pattern is already
known then it'll return the existing compiled pattern. However, the
cache has a limited size. In reality, no 2 pattern objects are equal.


And what about any other function or class/method? Is there a way to
discriminate between methods and functions that when invoked twice
with the same arguments will return the same object and those that in
the same circumstances will return two identical objects?

If the answer is no, am I right to state the in the case portrayed
above the only way to be safe is to use the following code instead?

for item in compiledPatterns:
   if(item.pattern == pattern):


This is the same as using 'in'.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can I rely on...

2009-03-19 Thread MRAB

Emanuele D'Arrigo wrote:
[snip]

If the answer is no, am I right to state the in the case portrayed
above the only way to be safe is to use the following code instead?

for item in compiledPatterns:
   if(item.pattern == pattern):
print(The compiled pattern is stored.)
break


Correction to my last post: this isn't the same as using 'in'.

It should work, but remember that it compares only the pattern and not
any flags you might have used in the original re.compile().

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


Re: Can I rely on...

2009-03-19 Thread Albert Hopkins
On Thu, 2009-03-19 at 08:42 -0700, Emanuele D'Arrigo wrote:
 Hi everybody,
 
 I just had a bit of a shiver for something I'm doing often in my code
 but that might be based on a wrong assumption on my part. Take the
 following code:
 
 pattern = aPattern
 
 compiledPatterns = [ ]
 compiledPatterns.append(re.compile(pattern))
 
 if(re.compile(pattern) in compiledPatterns):
 print(The compiled pattern is stored.)
 
 As you can see I'm effectively assuming that every time re.compile()
 is called with the same input pattern it will return the exact same
 object rather than a second, identical, object. In interactive tests
 via python shell this seems to be the case but... can I rely on it -
 always- being the case? Or is it one of those implementation-specific
 issues?
 
 And what about any other function or class/method? Is there a way to
 discriminate between methods and functions that when invoked twice
 with the same arguments will return the same object and those that in
 the same circumstances will return two identical objects?
 
 If the answer is no, am I right to state the in the case portrayed
 above the only way to be safe is to use the following code instead?
 
 for item in compiledPatterns:
if(item.pattern == pattern):

In general, no.  You cannot rely on objects instantiated with the same
parameters to be equal. Eg.:

 class N(object):
def __init__(self, foo):
self.foo = foo

 a = N('m')
 b = N('m')
 a == b
False

If, however, the designer of the class implements it as such
(and documents it as well) then you can. E.g:

 del N
 class N(object):
def __init__(self, foo):
self.foo = foo
def __eq__(self, other):
return self.foo == other.foo

 a = N('m')
 b = N('m')
 a == b
True

For functions/methods it really depends on the implementation.  For
example, do we *really* want the following to always be true? Even
though we passed the same arguments?

 import random
 random.randint(0, 10) == random.randint(0, 10)

For the re module, unless it's documented that 

 re.compile(p) == re.compile(p)

is always true then you should not rely on it, because it's an
implementation detail that may change in the future.


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


Re: converting pipe delimited file to fixed width

2009-03-19 Thread MRAB

digz wrote:

Hi,
I am trying to convert a | delimited  file to fixed width by right
padding with spaces, Here is how I have written the program , just get
the feeling this can be done in a much better ( python functional )
way rather than the procedural code i have below . Any help
appreciated

#!/usr/bin/python
def rightFill(fillString, toLength, fillChar):
return fillString+''.join([fillChar for x in range(len
(fillString),toLength)])

fieldWidth=[ 14, 6, 18, 21, 21,4, 6  ];

file = open(/home/chatdi/input.csv, r);
lines = file.readlines()
file.close()

out = open( /home/chatdi/ouptut.csv, 'w')
for line in lines:
line = line[:-1]
index = 0
for token in line.split('|'):
paddedToken = rightFill(token, fieldWidth[index], ' ' )
out.write( paddedToken )
index = index + 1
out.write(\n)


Here's my version:

#!/usr/bin/python

field_widths = [14, 6, 18, 21, 21, 4, 6]

out = open(/home/chatdi/ouptut.csv, 'w')
for line in open(/home/chatdi/input.csv, r):
fields = line.rstrip().split('|')
padded_fields = [field.ljust(width) for field, width in zip(fields, 
field_widths)]

out.write(.join(padded_fields) + \n)

out.close()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Do deep inheritance trees degrade efficiency?

2009-03-19 Thread Terry Reedy

Terry Reedy wrote:

Anthra Norell wrote:
Would anyone who knows the inner workings volunteer to clarify whether 
or not every additional derivation of a class hierarchy adds an 
indirection to the base class's method calls and attribute read-writes. 


More potential search layers rather than pointer indirection.  But I 
doubt this is a bottleneck in very many programs.  So I would more 
concern myself first with quickly writing correct code.


I should add that when object access time matters and the object is 
accessed repeatedly, a common solution is to bind it to a local name 
*once* and then access it via the local (which is the fastest way 
possible for CPython and, I expect, for other implementation).  This 
works for all slower access methods.


tjr

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


Re: File Compare with difflib.context_diff

2009-03-19 Thread JohnV
Here is the latest version of the code:

currentdata_file = rC:\Users\Owner\Desktop\newdata.txt # the latest
download from the clock
lastdata_file = rC:\Users\Owner\Desktop\mydata.txt # the prior
download from the clock
output_file = rC:\Users\Owner\Desktop\out.txt # will hold delta
clock data

newdata = open(currentdata_file).read()[len(open(lastdata_file).read
()):]
newdata2 = newdata.strip()


file = open(output_file, 'w')
file.write(newdata2)
file.close()


Do I need to close currentdata_file and lastdata_file ?

Have not gotten the os.stat example to work yet...
thanks for the help.
--
http://mail.python.org/mailman/listinfo/python-list


Simple question about yyyy/mm/dd

2009-03-19 Thread mattia
Hi all, I need to receive in input a date represented by a string in the
form /mm/dd (or reversed), then I need to assure that the date is 
= the current date and then split the dates in variables like year, 
month, day. Is there some module to do this quickly?
--
http://mail.python.org/mailman/listinfo/python-list


Re: How complex is complex?

2009-03-19 Thread Kottiyath
On Mar 19, 8:42 pm, Paul McGuire pt...@austin.rr.com wrote:
 On Mar 19, 4:39 am, Kottiyath n.kottiy...@gmail.com wrote:



  I understand that my question was foolish, even for a newbie.
  I will not ask any more such questions in the future.

 Gaaah! Your question was just fine, a good question on coding style.
 I wish more people would ask such questions so that bad habits could
 be avoided.

 The newbie posts that are annoying are the ones that:
 - are answered on page 1 of any tutorial (how do I get the second
 character of a string?)
 - are obvious homework assignments with no actual effort on the
 poster's part (how do I write a Python program to find the first 10
 prime numbers?)
 - pontificate on what is wrong with Python, based on 2 hours'
 experience with the language (often titled What's wrong with Python,
 with content like Python sucks because it doesn't have a switch
 statement/has significant whitespace/doesn't check types of arguments/
 isn't totally object-oriented like Java/doesn't have interfaces/...)
 - are so vague as to be just Usenet noise (titled Help me, with no
 content, or i need to write a program and don't know where to start
 can someone write it for me?)

 I think Daniel's joke was on the rest of us, who each had to chime in
 with our favorite dict processing algorithm.

 It *would* be good for you as a newbie to get an appreciation of the
 topics that were covered in these responses, though, especially the
 distinction between updating the dict in-place vs. creating a new
 dict.

 -- Paul

Daniel, Sorry for misunderstanding your post. I hope I was not being
passive-aggresive - (also because I found that the second mechanism I
provided was quite horrible :-), so I was indeed being foolish
there. )

Paul/Aahz, I did understand 2 things
(1) When using map always consider that the function will be called
everytime, so the hit on the performance is more.
(2) The second mechanism and the first mechanism provides different
solutions (new dict/same dict)
both of which I did not think about at all.

Also, thank you everyone for all the help. I have been following this
thread for the last 4 months (when I started with python) and I have
learned a lot. The amount of help provided here is amazing.

p.s. - English is indeed not my first language :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: How complex is complex?

2009-03-19 Thread Kottiyath
On Mar 19, 9:33 pm, Kottiyath n.kottiy...@gmail.com wrote:
 On Mar 19, 8:42 pm, Paul McGuire pt...@austin.rr.com wrote:



  On Mar 19, 4:39 am, Kottiyath n.kottiy...@gmail.com wrote:

   I understand that my question was foolish, even for a newbie.
   I will not ask any more such questions in the future.

  Gaaah! Your question was just fine, a good question on coding style.
  I wish more people would ask such questions so that bad habits could
  be avoided.

  The newbie posts that are annoying are the ones that:
  - are answered on page 1 of any tutorial (how do I get the second
  character of a string?)
  - are obvious homework assignments with no actual effort on the
  poster's part (how do I write a Python program to find the first 10
  prime numbers?)
  - pontificate on what is wrong with Python, based on 2 hours'
  experience with the language (often titled What's wrong with Python,
  with content like Python sucks because it doesn't have a switch
  statement/has significant whitespace/doesn't check types of arguments/
  isn't totally object-oriented like Java/doesn't have interfaces/...)
  - are so vague as to be just Usenet noise (titled Help me, with no
  content, or i need to write a program and don't know where to start
  can someone write it for me?)

  I think Daniel's joke was on the rest of us, who each had to chime in
  with our favorite dict processing algorithm.

  It *would* be good for you as a newbie to get an appreciation of the
  topics that were covered in these responses, though, especially the
  distinction between updating the dict in-place vs. creating a new
  dict.

  -- Paul

 Daniel, Sorry for misunderstanding your post. I hope I was not being
 passive-aggresive - (also because I found that the second mechanism I
 provided was quite horrible :-), so I was indeed being foolish
 there. )

 Paul/Aahz, I did understand 2 things
 (1) When using map always consider that the function will be called
 everytime, so the hit on the performance is more.
 (2) The second mechanism and the first mechanism provides different
 solutions (new dict/same dict)
 both of which I did not think about at all.

 Also, thank you everyone for all the help. I have been following this
 thread for the last 4 months (when I started with python) and I have
 learned a lot. The amount of help provided here is amazing.

 p.s. - English is indeed not my first language :-)

Oops, Forgot to mention the biggest learning.

Readability is better than brevity -
Thanks to Rhodri.

This was a question which was bugging me all the time. When I look at
code, I am always envious when I see the same code written in much
smaller number of lines. Now, I will force myself to ask the questions
Rhodri proposed (esp: does it look uglier part) before deciding
whether or not to go ahead with brevity.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can I rely on...

2009-03-19 Thread Terry Reedy

Emanuele D'Arrigo wrote:

Hi everybody,

I just had a bit of a shiver for something I'm doing often in my code
but that might be based on a wrong assumption on my part. Take the
following code:

pattern = aPattern

compiledPatterns = [ ]
compiledPatterns.append(re.compile(pattern))

if(re.compile(pattern) in compiledPatterns):


Note that for this generally take time proportional to the length of the 
list.  And as MRAB said, drop the parens.



print(The compiled pattern is stored.)

As you can see I'm effectively assuming that every time re.compile()
is called with the same input pattern it will return the exact same
object rather than a second, identical, object. In interactive tests
via python shell this seems to be the case but... can I rely on it -
always- being the case? Or is it one of those implementation-specific
issues?


As MRAB indicated, this only works because the CPython re module itself 
has a cache so you do not have to make one. It is, however, limited to 
100 or so since programs that use patterns repeatedly generally use a 
limited number of patterns.  Caches usually use a dict so that 
cache[input] == output and lookup is O(1).



And what about any other function or class/method? Is there a way to
discriminate between methods and functions that when invoked twice
with the same arguments will return the same object and those that in
the same circumstances will return two identical objects?


In general, a function that calculates and return an object will return 
a new object.  The exceptions are exceptions.




If the answer is no, am I right to state the in the case portrayed
above the only way to be safe is to use the following code instead?

for item in compiledPatterns:
   if(item.pattern == pattern):


Yes.  Unless you are comparing against None (or True or False in Py3) or 
specifically know otherwise, you probably want '==' rather than 'is'.


Terry Jan Reedy

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


Re: DictReader and fieldnames

2009-03-19 Thread skip

Ted Is it possible to grab the fieldnames that the csv DictReader
Ted module automatically reads from the first line of the input file?

Like this, perhaps?

 rdr = csv.DictReader(open(f.csv, rb))
 rdr.fieldnames
['col1', 'col2', 'color']
 rdr.next()
{'color': '3', 'col2': '2', 'col1': '1'}

-- 
Skip Montanaro - s...@pobox.com - http://www.smontanaro.net/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question about yyyy/mm/dd

2009-03-19 Thread skip
 Hi all, I need to receive in input a date represented by a string in
 the form /mm/dd (or reversed), then I need to assure that the
 date is = the current date and then split the dates in variables like
 year, month, day. Is there some module to do this quickly?

The dateutil package has a parser module which works well here:

 import dateutil.parser, datetime
 dateutil.parser.parse(2008/03/31)
datetime.datetime(2008, 3, 31, 0, 0)
 dateutil.parser.parse(2008/03/31)  datetime.datetime.now()
False

-- 
Skip Montanaro - s...@pobox.com - http://www.smontanaro.net/
--
http://mail.python.org/mailman/listinfo/python-list


Threads not Improving Performance in Program

2009-03-19 Thread Ryan Rosario
I have a parser that needs to process 7 million files. After running
for 2 days, it had only processed 1.5 million. I want this script to
parse several files at once by using multiple threads: one for each
file currently being analyzed.

My code iterates through all of the directories within a directory,
and at each directory, iterates through each file in that directory. I
structured my code something like this. I think I might be
misunderstanding how to use threads:

mythreads = []
for directory in dirList:
 #some processing...
 for file in fileList:
p = Process(currDir,directory,file)#class that extends thread.Threading
mythreads.append(p)
p.start()

for thread in mythreads:
 thread.join()
 del thread

The actual class that extends threading.thread is below:

class Process(threading.Thread):
vlock = threading.Lock()
def __init__(self,currDir,directory,file):  #thread constructor
threading.Thread.__init__(self)
self.currDir = currDir
self.directory = directory
self.file = file
def run(self):
redirect = re.compile(r'#REDIRECT',re.I)
xmldoc = minidom.parse(os.path.join(self.currDir,self.file))
try:
markup =
xmldoc.firstChild.childNodes[-2].childNodes[-2].childNodes[-2].childNodes[0].data
except:
#An error occurred
Process.vlock.acquire()
BAD = open(bad.log,a)
BAD.writelines(self.file + \n)
BAD.close()
Process.vlock.release()
print Error.
return
#if successful, do more processing...


I did an experiment with a variety of numbers of threads and there is
no performance gain. The code is taking the same amount of time to
process 1000 files as it would if the code did not use threads. Any
ideas on what I am doing wrong?
--
http://mail.python.org/mailman/listinfo/python-list


Re: converting pipe delimited file to fixed width

2009-03-19 Thread Terry Reedy

digz wrote:

Hi,
I am trying to convert a | delimited  file to fixed width by right
padding with spaces, Here is how I have written the program , just get
the feeling this can be done in a much better ( python functional )
way rather than the procedural code i have below . Any help
appreciated

#!/usr/bin/python
def rightFill(fillString, toLength, fillChar):
return fillString+''.join([fillChar for x in range(len
(fillString),toLength)])


Ugh.  That should be the same as
return fillString + (toLength-length(fillString))*fillChar

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


Re: converting pipe delimited file to fixed width

2009-03-19 Thread odeits
On Mar 19, 8:51 am, digz digvijo...@gmail.com wrote:
 Hi,
 I am trying to convert a | delimited  file to fixed width by right
 padding with spaces, Here is how I have written the program , just get
 the feeling this can be done in a much better ( python functional )
 way rather than the procedural code i have below . Any help
 appreciated

 #!/usr/bin/python
 def rightFill(fillString, toLength, fillChar):
     return fillString+''.join([fillChar for x in range(len
 (fillString),toLength)])

 fieldWidth=[ 14, 6, 18, 21, 21,4, 6  ];

 file = open(/home/chatdi/input.csv, r);
 lines = file.readlines()
 file.close()

 out = open( /home/chatdi/ouptut.csv, 'w')
 for line in lines:
     line = line[:-1]
     index = 0
     for token in line.split('|'):
         paddedToken = rightFill(token, fieldWidth[index], ' ' )
         out.write( paddedToken )
         index = index + 1
     out.write(\n)


Caveat: none of the solutions (including mine) deal with the case of
the field being longer than the width. You might want to throw an
exception.

I use the csv module to do the reading of the file, i am going to do
some testing to see if i can set the delimiter to '' so that i can
also use it for the output. For now this should work.


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


import csv

fieldWidth=[ 14, 6, 18, 21, 21,4, 6  ];
csvfilepath = 'somefile.csv'

outcsvfilepath = 'someoutfile.csv'
endl = '\n'

f = open(csvfilepath)
outf = open(outcsvfilepath)


csvfile = csv.reader(f,delimiter = '|')

for row in csvfile:
outrow = [ field + fillchar * (width - len(field)) for width, field
in zip(fieldWidth,row)]
outcsv.write( ''.join(outrow))
outcsv.write( endl )

f.close()
outf.close()

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


cross compile Python to Linux-ARM

2009-03-19 Thread jefm
Hi,
We are looking to use Python on an embedded Linux ARM system.
What I gather from googling the subject is that it is not that
straight forward (a fair amount of patching  hacking).
Nobody out there that has done it claims it is easy, which makes me
worried.

I haven't seen a description on porting Python 2.6 or 3.0 yet. Is it
much different than for the earlier versions (the latest I have seem
is Python 2.5).

Does it matter whether Python is cross compiled to Linux 2.4 or Linux
2.6 ?

Can anyone point to a howto they know works well ?

What are the chances of an 'officially' supported ARM-Linux Python
distribution ?
(or is it safer to wait for industrial spec Intel Atom boards to avoid
the cross compilation altogether ?

What would it take for the Linux version of Python to be easily cross
compiled (i.e. would the Linux-Python maintainers be willing to
include and maintain cross-compilation specific functions) ?

Let's say we can get it done.
How is the performance and stability of a working Python on an
embedded ARM-Linux system ?

Does cross compiling Python automatically include the standard Python
library, or is that yet another adventure ?

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


Missing values in tuple assignment

2009-03-19 Thread Jim Garrison

Use case: parsing a simple config file line where lines start with a
keyword and have optional arguments.  I want to extract the keyword and
then pass the rest of the line to a function to process it. An obvious
use of split(None,1)

cmd,args= = line.split(None,1);
if cmd in self.switch: self.switch[cmd](self,args)
else: self.errors.append(unrecognized keyword '{0)'.format(cmd))

Here's a test in IDLE:

  a=now is the time
  x,y=a.split(None,1)
  x
 'now'
  y
 'is the time'

However, if the optional argument string is missing:

  a=now
  x,y=a.split(None,1)
 Traceback (most recent call last):
   File pyshell#42, line 1, in module
 x,y=a.split(None,1)
 ValueError: need more than 1 value to unpack

I understand the problem is not with split() but with the assignment
to a tuple.  Is there a way to get the assignment to default the
missing values to None?


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


Re: Threads not Improving Performance in Program

2009-03-19 Thread odeits
On Mar 19, 9:50 am, Ryan Rosario uclamath...@gmail.com wrote:
 I have a parser that needs to process 7 million files. After running
 for 2 days, it had only processed 1.5 million. I want this script to
 parse several files at once by using multiple threads: one for each
 file currently being analyzed.

 My code iterates through all of the directories within a directory,
 and at each directory, iterates through each file in that directory. I
 structured my code something like this. I think I might be
 misunderstanding how to use threads:

 mythreads = []
 for directory in dirList:
  #some processing...
  for file in fileList:
     p = Process(currDir,directory,file)    #class that extends 
 thread.Threading
     mythreads.append(p)
     p.start()

 for thread in mythreads:
  thread.join()
  del thread

 The actual class that extends threading.thread is below:

 class Process(threading.Thread):
         vlock = threading.Lock()
         def __init__(self,currDir,directory,file):      #thread constructor
                 threading.Thread.__init__(self)
                 self.currDir = currDir
                 self.directory = directory
                 self.file = file
         def run(self):
                 redirect = re.compile(r'#REDIRECT',re.I)
                 xmldoc = minidom.parse(os.path.join(self.currDir,self.file))
                 try:
                         markup =
 xmldoc.firstChild.childNodes[-2].childNodes[-2].childNodes[-2].childNodes[0­].data
                 except:
                         #An error occurred
                         Process.vlock.acquire()
                         BAD = open(bad.log,a)
                         BAD.writelines(self.file + \n)
                         BAD.close()
                         Process.vlock.release()
                         print Error.
                         return
                 #if successful, do more processing...

 I did an experiment with a variety of numbers of threads and there is
 no performance gain. The code is taking the same amount of time to
 process 1000 files as it would if the code did not use threads. Any
 ideas on what I am doing wrong?

Perhabs the bottleneck is the IO. How big are the files you are trying
to parse? Another possible bottleneck is that threads share memory.
Thread construction is also expensive in python, try looking up a
threadPool class. (ThreadPools are collections of threads that do
work, when they finish they go to an idle state untill you give them
more work, that way you aren't constantly creating new threads which
is expensive)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question about yyyy/mm/dd

2009-03-19 Thread Scott David Daniels

mattia wrote:

Hi all, I need to receive in input a date represented by a string in the
form /mm/dd (or reversed), then I need to assure that the date is 
= the current date and then split the dates in variables like year, 

month, day. Is there some module to do this quickly?

Look into time.strptime

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: What happened to NASA at Python? :(

2009-03-19 Thread Steve Holden
r wrote:
 On Mar 12, 3:31 am, Michele Simionato michele.simion...@gmail.com
 wrote:
 
 That's pretty much impossible. I am sure NASA uses all programming
 languages in existence,
 plus probably many internal ones we never heard of.
 
 True but...
 
 all([NASA.does_endorse(lang) for lang in NASA['languages']])
 False
 
 As the code suggests NASA doesn't sport an endorsement of X languages
 on every X language's webpage, which i feel is very important for
 Python's image, along with Google(Even more important!!), ILM, and
 others.
 
 I am really not worried if NASA *actually* uses Python or not(or to
 what extent), just as long as they say they do is good enough for
 me. *wink-wink*

There are about 40 people supporting the Mars Lander mission using
Python and aiming for a launch window this September. Wish them luck!

That's just one of the NASA groups relying heavily on Python.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Want to know? Come to PyCon - soon! http://us.pycon.org/

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


Re: Missing values in tuple assignment

2009-03-19 Thread Albert Hopkins
On Thu, 2009-03-19 at 11:57 -0500, Jim Garrison wrote:
 Use case: parsing a simple config file line where lines start with a
 keyword and have optional arguments.  I want to extract the keyword and
 then pass the rest of the line to a function to process it. An obvious
 use of split(None,1)
 
  cmd,args= = line.split(None,1);
  if cmd in self.switch: self.switch[cmd](self,args)
  else: self.errors.append(unrecognized keyword '{0)'.format(cmd))
 
 Here's a test in IDLE:
 
a=now is the time
x,y=a.split(None,1)
x
   'now'
y
   'is the time'
 
 However, if the optional argument string is missing:
 
a=now
x,y=a.split(None,1)
   Traceback (most recent call last):
 File pyshell#42, line 1, in module
   x,y=a.split(None,1)
   ValueError: need more than 1 value to unpack
 
 I understand the problem is not with split() but with the assignment
 to a tuple.  Is there a way to get the assignment to default the
 missing values to None?

why not do this?
 a= 'now'
 z = a.split(None, 1)
 x = z[0]
 y = z[1] if len(z) == 2 else None

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


Re: Strange crash issue on Windows w/ PyGTK, Cairo...

2009-03-19 Thread CJ Kucera
CJ Kucera wrote:
 Anyway, the issue turned out to be zlib.decompress() - for larger sets
 of data, if I wasn't specifying bufsize, the malloc()s that it was
 doing behind-the-scenes must have been clobbering memory.  As soon as I
 specified bufsize, everything was totally kosher.

Okay, I've got a reproducible testcase of this available up here:

http://apocalyptech.com/pygtk-zlib/

I'm no longer *totally* convinced that it's a zlib issue...  zlib's call
actually returns a valid string, and the error happens later in the app.
I've yet to be able to engineer a crash using anything other than that
cairo.ImageSurface.create_from_png() function, so it's possible that
specifying bufsize in zlib.decompress() merely allocates memory in
such a way that a bug in PyCairo doesn't come to light in that case.

So, I'm not really sure if I should submit this to Python or PyGTK's
tracker yet.  Could someone check it out and let me know what you think?
That'd be great.  Thanks!

As I mention on that page, removing import os and import sys will
fix the issue on XP, though you can remove them on win2k and still see
the crash.

Thanks,
CJ

-- 
WOW: Flemmy|   The ships hung in the sky in much the same
p...@apocalyptech.com   |way that bricks don't. - Douglas Adams,
24.24.2.3171   | _The Hitchhiker's Guide To The Galaxy_
--
http://mail.python.org/mailman/listinfo/python-list


Re: Memory efficient tuple storage

2009-03-19 Thread psaff...@googlemail.com
In the end, I used a cStringIO object to store the chromosomes -
because there are only 23, I can use one character for each chromosome
and represent the whole lot with a giant string and a dictionary to
say what each character means. Then I used numpy arrays for the data
and coordinates. This squeezed each file into under 100MB.

Thanks again for the help!

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


Re: What happened to NASA at Python? :(

2009-03-19 Thread Steve Holden
s...@pobox.com wrote:
  In fact, graphics were added for several organizations.  I believe
  they will be chosen randomly.  NASA is still there.
 
 MiO In that case, they must be using the random number generator from
 MiO Dilbert. You know, the one that said 9, 9, 9, 9,...
 
 Sorry, randomly chosen whenever the front page is rebuilt by one of the web
 gnomes.  It's not chosen randomly on each page fetch.
 
Though of course it easily *could* be, and I hope it soon *will* be.

More about that in my PyCon talk ...

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Want to know? Come to PyCon - soon! http://us.pycon.org/

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


Re: Can I rely on...

2009-03-19 Thread Emanuele D'Arrigo
Thank you everybody for the informative replies.

I'll have to comb my code for all the instances of item in sequence
statement because I suspect some of them are as unsafe as my first
example. Oh well. One more lesson learned.

Thank you again.

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


Re: What happened to NASA at Python? :(

2009-03-19 Thread Dotan Cohen
 There are about 40 people supporting the Mars Lander mission using
 Python and aiming for a launch window this September. Wish them luck!


What, exactly, are they using Python for?

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
ا-ب-ت-ث-ج-ح-خ-د-ذ-ر-ز-س-ش-ص-ض-ط-ظ-ع-غ-ف-ق-ك-ل-م-ن-ه‍-و-ي
А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я
а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я
ä-ö-ü-ß-Ä-Ö-Ü
--
http://mail.python.org/mailman/listinfo/python-list


Re: How complex is complex?

2009-03-19 Thread Paul Hildebrandt
On Mar 19, 9:41 am, Kottiyath n.kottiy...@gmail.com wrote:
 On Mar 19, 9:33 pm, Kottiyath n.kottiy...@gmail.com wrote:



  On Mar 19, 8:42 pm, Paul McGuire pt...@austin.rr.com wrote:

   On Mar 19, 4:39 am, Kottiyath n.kottiy...@gmail.com wrote:

I understand that my question was foolish, even for a newbie.
I will not ask any more such questions in the future.

   Gaaah! Your question was just fine, a good question on coding style.
   I wish more people would ask such questions so that bad habits could
   be avoided.

   The newbie posts that are annoying are the ones that:
   - are answered on page 1 of any tutorial (how do I get the second
   character of a string?)
   - are obvious homework assignments with no actual effort on the
   poster's part (how do I write a Python program to find the first 10
   prime numbers?)
   - pontificate on what is wrong with Python, based on 2 hours'
   experience with the language (often titled What's wrong with Python,
   with content like Python sucks because it doesn't have a switch
   statement/has significant whitespace/doesn't check types of arguments/
   isn't totally object-oriented like Java/doesn't have interfaces/...)
   - are so vague as to be just Usenet noise (titled Help me, with no
   content, or i need to write a program and don't know where to start
   can someone write it for me?)

   I think Daniel's joke was on the rest of us, who each had to chime in
   with our favorite dict processing algorithm.

   It *would* be good for you as a newbie to get an appreciation of the
   topics that were covered in these responses, though, especially the
   distinction between updating the dict in-place vs. creating a new
   dict.

   -- Paul

  Daniel, Sorry for misunderstanding your post. I hope I was not being
  passive-aggresive - (also because I found that the second mechanism I
  provided was quite horrible :-), so I was indeed being foolish
  there. )

  Paul/Aahz, I did understand 2 things
  (1) When using map always consider that the function will be called
  everytime, so the hit on the performance is more.
  (2) The second mechanism and the first mechanism provides different
  solutions (new dict/same dict)
  both of which I did not think about at all.

  Also, thank you everyone for all the help. I have been following this
  thread for the last 4 months (when I started with python) and I have
  learned a lot. The amount of help provided here is amazing.

  p.s. - English is indeed not my first language :-)

 Oops, Forgot to mention the biggest learning.

 Readability is better than brevity -

I rewrote your sentence to be more optimized.

Readability  brevity

;-)


 Thanks to Rhodri.

 This was a question which was bugging me all the time. When I look at
 code, I am always envious when I see the same code written in much
 smaller number of lines. Now, I will force myself to ask the questions
 Rhodri proposed (esp: does it look uglier part) before deciding
 whether or not to go ahead with brevity.

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


Re: What happened to NASA at Python? :(

2009-03-19 Thread Aahz
[posted and e-mailed]

In article mailman.2216.1237483574.11746.python-l...@python.org,
Dotan Cohen  dotanco...@gmail.com wrote:

PiBUaGVyZSBhcmUgYWJvdXQgNDAgcGVvcGxlIHN1cHBvcnRpbmcgdGhlIE1hcnMgTGFuZGVyIG1p
c3Npb24gdXNpbmcKPiBQeXRob24gYW5kIGFpbWluZyBmb3IgYSBsYXVuY2ggd2luZG93IHRoaXMg
U2VwdGVtYmVyLiBXaXNoIHRoZW0gbHVjayEKPgoKV2hhdCwgZXhhY3RseSwgYXJlIHRoZXkgdXNp
bmcgUHl0aG9uIGZvcj8KCi0tIApEb3RhbiBDb2hlbgoKaHR0cDovL3doYXQtaXMtd2hhdC5jb20K
aHR0cDovL2dpYmJlcmlzaC5jby5pbAoK15At15Et15It15Mt15Qt15Ut15Yt15ct15gt15kt15ot
15st15wt150t154t158t16At16Et16It16Mt16Qt16Ut16Yt16ct16gt16kt16oK2Kct2Kgt2Kot
2Kst2Kwt2K0t2K4t2K8t2LAt2LEt2LIt2LMt2LQt2LUt2LYt2Lct2Lgt2Lkt2Lot2YEt2YIt2YMt
2YQt2YUt2YYt2YfigI0t2Ygt2YoK0JAt0JEt0JIt0JMt0JQt0JUt0IEt0JYt0Jct0Jgt0Jkt0Jot
0Jst0Jwt0J0t0J4t0J8t0KAt0KEt0KIt0KMt0KQt0KUt0KYt0Kct0Kgt0Kkt0Kot0Kst0Kwt0K0t
0K4t0K8K0LAt0LEt0LIt0LMt0LQt0LUt0ZEt0LYt0Lct0Lgt0Lkt0Lot0Lst0Lwt0L0t0L4t0L8t
0YAt0YEt0YIt0YMt0YQt0YUt0YYt0Yct0Ygt0Ykt0Yot0Yst0Ywt0Y0t0Y4t0Y8Kw6Qtw7Ytw7wt
w58tw4Qtw5Ytw5wK

Could you perhaps be persuaded to post in ASCII?
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Programming language design is not a rational science. Most reasoning
about it is at best rationalization of gut feelings, and at worst plain
wrong.  --GvR, python-ideas, 2009-3-1
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >