Tuesday, January 26, 2010

comp.lang.python - 25 new messages in 12 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Authenticated encryption with PyCrypto - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/26ef2de83c5a0337?hl=en
* Any Swisses here? - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/474e4bb231d93e43?hl=en
* list.pop(0) vs. collections.dequeue - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/9221d87f93748b3f?hl=en
* Sikuli: the coolest Python project I have yet seen... - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/766e5530f706ed52?hl=en
* announcement: expy release 0.5 - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/7c9c5945c3e2e38b?hl=en
* Accessing the name of an actual parameter - 7 messages, 6 authors
http://groups.google.com/group/comp.lang.python/t/8f475dd9c4d9b409?hl=en
* Splitting text at whitespace but keeping the whitespace in thereturned list -
1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/22533b4383d301bb?hl=en
* pylint and the 'missing docstring' warning - 4 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/dc667186a8854284?hl=en
* My experiences building a small app on Python - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/2c0da79b32b28a73?hl=en
* PIL: Wiping out metadata on save only on progressive JPG's - 1 messages, 1
author
http://groups.google.com/group/comp.lang.python/t/bdc0b3aadb729035?hl=en
* ANN: Veusz 1.6 - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f1b847d483f92fb5?hl=en
* ctypes for AIX - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/a93f969410d0d086?hl=en

==============================================================================
TOPIC: Authenticated encryption with PyCrypto
http://groups.google.com/group/comp.lang.python/t/26ef2de83c5a0337?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 9:26 pm
From: Daniel


Just got done reading this thread:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b31a5b5f58084f12/0e09f5f5542812c3

and I'd appreciate feedback on this recipe:

http://code.activestate.com/recipes/576980/

Of course, it does not meet all of the requirements set forth by the
OP in the referenced thread (the pycrypto dependency is a problem),
but it is an attempt to provide a simple interface for performing
strong, password-based encryption. Are there already modules out there
that provide such a simple interface? If there are, they seem to be
hiding somewhere out of Google's view.

I looked at ezPyCrypto, but it seemed to require public and private
keys, which was not convenient in my situation... maybe password-based
encryption is trivial to do with ezPyCrypto as well? In addition to
ezPyCrypto, I looked at Google's keyczar, but despite the claims of
the documentation, the API seemed overly complicated. Is it possible
to have a simple API for an industry-strength encryption module? If
not, is it possible to document that complicated API such that a non-
cryptographer could use it and feel confident that he hadn't made a
critical mistake?

Also, slightly related, is there an easy way to get the sha/md5
deprecation warnings emitted by PyCrypto in Python 2.6 to go away?

~ Daniel

==============================================================================
TOPIC: Any Swisses here?
http://groups.google.com/group/comp.lang.python/t/474e4bb231d93e43?hl=en
==============================================================================

== 1 of 4 ==
Date: Tues, Jan 26 2010 12:14 am
From: Gabriel Rossetti


n00m wrote:
> Congrats!
> Your choice -- to ban building of muslim mosques -- is the only choice
> to save our civililazation.
> This yellow plague (incl. Chinese etc) must be eliminated from our
> Planet,
> They are very cunning critters, they can play on strings of
> compassion,
> but its riffraffs. What do you know about Russia? Who are yuo against
> Russia?
> Nothing. Dust. We are simply tired people.
>

Actually, I am Swiss and I have to say that the vote does not represent
Switzerland. In
fact, a lot of people didn't vote because they were sure it would never
pass. They just
came out with an official analysis/statistics of the vote results and it
shows that people
with higher education voted against the ban, that Christians voted for
the ban and
atheists against it. Also, if you look at the outcome for each Canton
(State), the rural
ones voted for the ban and the metropolitan/cosmopolitan ones against
it. What happened
is basically what happened in Nazi Germany, a strong campaign for the
masses and sadly
it worked.

I have several Russian friends and I have no idea what their view is on
the subject. Russia
has several Muslim ethnic groups and with most there seems to be no
problem (I'm excluding
Chechnya, even thought the conflict is more about power than religion).

Gabriel

Disclaimer:
the views expressed in this email are solely mine and not in any way
representative
of my company's views or ideologies.


== 2 of 4 ==
Date: Tues, Jan 26 2010 2:07 am
From: n00m


Now , Gabriel, tell me:

why "they" are not much (to say the least) intrested
to build the mosques in e.g. Zimbabwe or in my Belarus?
Because in Belarus they'll get $100 per month with prices
of everything (esp food) of W.Europe level.
But nobody (nor the state, nor me) will ban this buidings.
Welcom, any nation, to live in here! No kidding.

I just see the root of the "problem".
Italians, Frenches, Germans made their country (Swiss) by their
own hands.


== 3 of 4 ==
Date: Tues, Jan 26 2010 3:39 am
From: n00m


And Russia is a very different story.
There muslims live side by side with "pure" Russians
for centuries. PS: Chechnya is OK (more or less) now.


== 4 of 4 ==
Date: Tues, Jan 26 2010 7:52 am
From: n00m


And let me to remind the fact one more time.

~100 years ago Swiss was a very very poor country.
They was coming to Tzar' Russia to earn some money
working as humble servants in Moscow's restaurants,
hotels and so on.

But they didn't demand to let them to build there
"new mosques" (Catholic cathedrals, for example).

They made their country by their brains and hands.
And they and their votes deserved to be respected
by any outsiders.

==============================================================================
TOPIC: list.pop(0) vs. collections.dequeue
http://groups.google.com/group/comp.lang.python/t/9221d87f93748b3f?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 1:27 am
From: Steve Howell


On Jan 25, 9:00 pm, Steve Howell <showel...@yahoo.com> wrote:
> On Jan 24, 11:28 am, a...@pythoncraft.com (Aahz) wrote:
>
>
>
> > In article <b4440231-f33f-49e1-9d6f-5fbce0a63...@b2g2000yqi.googlegroups.com>,
> > Steve Howell  <showel...@yahoo.com> wrote:
>
> > >Even with realloc()'s brokenness, you could improve pop(0) in a way
> > >that does not impact list access at all, and the patch would not change
> > >the time complexity of any operation; it would just add negligible
> > >extract bookkeeping within list_resize() and a few other places.
>
> > Again, your responsibility is to provide a patch and a spectrum of
> > benchmarking tests to prove it.  Then you would still have to deal with
> > the objection that extensions use the list internals -- that might be an
> > okay sell given the effort otherwise required to port extensions to
> > Python 3, but that's not the way to bet.
>
> Ok, I just submitted a patch to python-dev that illustrates a 100x
> speedup on an admittedly artificial program.  It still has a long way
> to go, but it demonstrates proof of concept.  I'm done for the day,
> but tomorrow I will try to polish it up and improve it, even if its
> doomed for rejection.  Apologies to all I have offended in this
> thread.  I frankly found some of the pushback to be a bit hasty and
> disrespectful, but I certainly overreacted to some of the criticism.
> And now I'm in the awkward position of asking the people I offended to
> help me with the patch.  If anybody can offer me a hand in
> understanding some of CPython's internals, particularly with regard to
> memory management, it would be greatly appreciated.
>
> (Sorry I don't have a link to the python-dev posting; it is not
> showing up in the archives yet for some reason.)

Here is the latest version of the patch, which passes all the tests on
my debug build.

Not exactly trivial, but not super complicated either.

Index: Include/listobject.h

===================================================================
--- Include/listobject.h (revision 77751)
+++ Include/listobject.h (working copy)
@@ -36,6 +36,7 @@
* the list is not yet visible outside the function that
builds it.
*/
Py_ssize_t allocated;
+ Py_ssize_t orphans;
} PyListObject;

PyAPI_DATA(PyTypeObject) PyList_Type;
Index: Objects/listobject.c

===================================================================
--- Objects/listobject.c (revision 77751)
+++ Objects/listobject.c (working copy)
@@ -27,13 +27,25 @@
PyObject **items;
size_t new_allocated;
Py_ssize_t allocated = self->allocated;
+ Py_ssize_t needed;

+ if (self->orphans >= newsize) {
+ items = self->ob_item - self->orphans;
+ memmove(items, &items[self->orphans],
+ (newsize)*sizeof(PyObject *));
+ self->ob_item = items;
+ self->orphans = 0;
+ }
+
+ needed = newsize + self->orphans;
+ items = self->ob_item - self->orphans;
+
/* Bypass realloc() when a previous overallocation is large
enough
to accommodate the newsize. If the newsize falls lower
than half
the allocated size, then proceed with the realloc() to
shrink the list.
*/
- if (allocated >= newsize && newsize >= (allocated >> 1)) {
- assert(self->ob_item != NULL || newsize == 0);
+ if (allocated >= needed && needed >= (allocated >> 1)) {
+ assert(items != NULL || newsize == 0);
Py_SIZE(self) = newsize;
return 0;
}
@@ -45,28 +57,32 @@
* system realloc().
* The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72,
88, ...
*/
- new_allocated = (newsize >> 3) + (newsize < 9 ? 3 : 6);
+ new_allocated = (needed >> 3) + (needed < 9 ? 3 : 6);

/* check for integer overflow */
- if (new_allocated > PY_SIZE_MAX - newsize) {
+ if (new_allocated > PY_SIZE_MAX - needed) {
PyErr_NoMemory();
return -1;
} else {
- new_allocated += newsize;
+ new_allocated += needed;
}

- if (newsize == 0)
+ if (needed == 0)
new_allocated = 0;
- items = self->ob_item;
- if (new_allocated <= ((~(size_t)0) / sizeof(PyObject *)))
+ /*
+ fprintf(stderr, "ob_item: %p", self->ob_item);
+ fprintf(stderr, "items: %p", items);
+ */
+ if (new_allocated <= ((~(size_t)0) / sizeof(PyObject *))) {
PyMem_RESIZE(items, PyObject *, new_allocated);
+ }
else
items = NULL;
if (items == NULL) {
PyErr_NoMemory();
return -1;
}
- self->ob_item = items;
+ self->ob_item = items + self->orphans;
Py_SIZE(self) = newsize;
self->allocated = new_allocated;
return 0;
@@ -158,6 +174,7 @@
}
Py_SIZE(op) = size;
op->allocated = size;
+ op->orphans = 0;
_PyObject_GC_TRACK(op);
return (PyObject *) op;
}
@@ -304,9 +321,10 @@
There's a simple test case where somehow this reduces
thrashing when a *very* large list is created and
immediately deleted. */
+ op->ob_item -= op->orphans;
i = Py_SIZE(op);
while (--i >= 0) {
- Py_XDECREF(op->ob_item[i]);
+ Py_XDECREF(op->ob_item[i+op->orphans]);
}
PyMem_FREE(op->ob_item);
}
@@ -548,12 +566,13 @@
if (item != NULL) {
/* Because XDECREF can recursively invoke operations on
this list, we make it empty first. */
+ item -= a->orphans;
i = Py_SIZE(a);
Py_SIZE(a) = 0;
a->ob_item = NULL;
a->allocated = 0;
while (--i >= 0) {
- Py_XDECREF(item[i]);
+ Py_XDECREF(item[i + a->orphans]);
}
PyMem_FREE(item);
}
@@ -638,18 +657,32 @@
memcpy(recycle, &item[ilow], s);

if (d < 0) { /* Delete -d items */
- memmove(&item[ihigh+d], &item[ihigh],
- (Py_SIZE(a) - ihigh)*sizeof(PyObject *));
+ if (ilow == 0) {
+ a->orphans += (-1 * d);
+ a->ob_item += (-1 * d);
+ }
+ else {
+ memmove(&item[ihigh+d], &item[ihigh],
+ (Py_SIZE(a) - ihigh)*sizeof(PyObject *));
+ }
list_resize(a, Py_SIZE(a) + d);
item = a->ob_item;
}
else if (d > 0) { /* Insert d items */
- k = Py_SIZE(a);
- if (list_resize(a, k+d) < 0)
- goto Error;
- item = a->ob_item;
- memmove(&item[ihigh+d], &item[ihigh],
- (k - ihigh)*sizeof(PyObject *));
+ if (ilow == 0 && d <= a->orphans) {
+ a->orphans += (-1 * d);
+ a->ob_item += (-1 * d);
+ item = a->ob_item;
+ list_resize(a, Py_SIZE(a) + d);
+ }
+ else {
+ k = Py_SIZE(a);
+ if (list_resize(a, k+d) < 0)
+ goto Error;
+ item = a->ob_item;
+ memmove(&item[ihigh+d], &item[ihigh],
+ (k - ihigh)*sizeof(PyObject *));
+ }
}
for (k = 0; k < n; k++, ilow++) {
PyObject *w = vitem[k];
@@ -838,7 +871,7 @@
}
break;
}
- if (Py_SIZE(self) < self->allocated) {
+ if (Py_SIZE(self) + self->orphans < self->allocated) {
/* steals ref */
PyList_SET_ITEM(self, Py_SIZE(self), item);
++Py_SIZE(self);
@@ -852,7 +885,7 @@
}

/* Cut back result list if initial guess was too large. */
- if (Py_SIZE(self) < self->allocated)
+ if (Py_SIZE(self) + self->orphans < self->allocated)
list_resize(self, Py_SIZE(self)); /* shrinking can't fail
*/

Py_DECREF(it);
@@ -2290,7 +2323,7 @@
{
Py_ssize_t res;

- res = sizeof(PyListObject) + self->allocated * sizeof(void*);
+ res = sizeof(PyListObject) + (self->allocated + self->orphans) *
sizeof(void*);
return PyLong_FromSsize_t(res);
}

Index: Lib/test/test_list.py

===================================================================
--- Lib/test/test_list.py (revision 77751)
+++ Lib/test/test_list.py (working copy)
@@ -51,6 +51,15 @@
self.assertEqual(len([0]), 1)
self.assertEqual(len([0, 1, 2]), 3)

+ def test_pop_and_prepend(self):
+ # This guards against faulty optimizations on list that
+ # attempt to makes pops and prepends at the beginning of
the
+ # list work faster.
+ lst = [5] * 100
+ del lst[0]
+ lst.insert(0, 4)
+ self.assertEqual(lst, [4] + [5] * 99)
+
def test_overflow(self):
lst = [4, 5, 6, 7]
n = int((sys.maxsize*2+2) // len(lst))
Index: Lib/test/test_iter.py

===================================================================
--- Lib/test/test_iter.py (revision 77751)
+++ Lib/test/test_iter.py (working copy)
@@ -875,7 +875,18 @@
except TypeError:
pass

+ def test_extends(self):
+ # This test would break on an incomplete patch to
listobject.c
+ def gen():
+ for i in range(500):
+ yield i
+ lst = [0] * 500
+ for i in range(240):
+ lst.pop(0)
+ lst.extend(gen())

+
+
def test_main():
run_unittest(TestCase)

Index: Lib/test/test_sys.py

===================================================================
--- Lib/test/test_sys.py (revision 77751)
+++ Lib/test/test_sys.py (working copy)
@@ -515,7 +515,7 @@
# bool objects are not gc tracked
self.assertEqual(sys.getsizeof(True), size(vh) +
self.longdigit)
# but lists are
- self.assertEqual(sys.getsizeof([]), size(vh + 'PP') +
gc_header_size)
+ self.assertEqual(sys.getsizeof([]), size(vh + 'PPi') +
gc_header_size)

def test_default(self):
h = self.header
@@ -638,7 +638,7 @@
# list
samples = [[], [1,2,3], ['1', '2', '3']]
for sample in samples:
- check(sample, size(vh + 'PP') + len(sample)*self.P)
+ check(sample, size(vh + 'PPi') + len(sample)*self.P)
# sortwrapper (list)
# XXX
# cmpwrapper (list)

==============================================================================
TOPIC: Sikuli: the coolest Python project I have yet seen...
http://groups.google.com/group/comp.lang.python/t/766e5530f706ed52?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 1:49 am
From: Jean-Michel Pichavant


Terry Reedy wrote:
> On 1/25/2010 9:14 AM, Javier Collado wrote:
>
>> I think the site is under maintenance. I tried a couple of hours ago
>> and it worked fine.
>>
>> As an alternative, I found that this link also worked:
>> http://www.sikuli.org/
>
> This just redirects to the link below
>
>>>> http://sikuli.csail.mit.edu/ I also did this
>
>>> This link is broken!
>
> Worked for me both yesterday and now.
>
I confirmed it now works.
The demo is pretty impressive.

However one should not be the kind of guy changing its desktop theme on
a regular basis. If I got it well, all is based on bitmap recognition
(with some tolerance though). I'll still give it a try.

JM

==============================================================================
TOPIC: announcement: expy release 0.5
http://groups.google.com/group/comp.lang.python/t/7c9c5945c3e2e38b?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 3:17 am
From: Yingjie Lan


Hi all,

This is to announce expy release 0.5.

expy is an express way to extend Python.

For more information and tutorials on expy, see:

http://expy.sf.net/

Cheers,

Yingjie

==============================================================================
TOPIC: Accessing the name of an actual parameter
http://groups.google.com/group/comp.lang.python/t/8f475dd9c4d9b409?hl=en
==============================================================================

== 1 of 7 ==
Date: Tues, Jan 26 2010 3:48 am
From: Hellmut Weber


Hi,

consider the following piece of code, please

----- -----

def f(param):
nameOfParam = ???
# here I want to access the name of the variable
# which was given as parameter to the function
print nameOfParam, param
return

if __name__ == __main__:

a = 1
f(a)

b = 'abcd'
f(a)

----- -----

The output should be:

'a' 1
'b' 'abcd'

----- -----

I tried to look at globals() and locals(), gave a look to the frames
(sys._getframe(0) and sys._getframe(1),
but did not see a possibility to access the information a want

How can this be done?

TIA

Hellmut


--
Dr. Hellmut Weber mail@hellmutweber.de
Degenfeldstraße 2 tel +49-89-3081172
D-80803 München-Schwabing mobil +49-172-8450321
please: No DOCs, no PPTs. why: tinyurl.com/cbgq

== 2 of 7 ==
Date: Tues, Jan 26 2010 3:58 am
From: Chris Rebert


On Tue, Jan 26, 2010 at 3:48 AM, Hellmut Weber <mail@hellmutweber.de> wrote:
> Hi,
>
> consider the following piece of code, please
>
> ----- -----
>
> def f(param):
>  nameOfParam = ???
>  # here I want to access the name of the variable
>  # which was given as parameter to the function
>  print nameOfParam, param
>  return
>
> if __name__ == __main__:
>
>  a = 1
>  f(a)
>
>  b = 'abcd'
>  f(a)
>
> ----- -----
>
> The output should be:
>
> 'a' 1
> 'b' 'abcd'
>
> ----- -----
>
> I tried to look at globals() and locals(), gave a look to the frames
> (sys._getframe(0) and sys._getframe(1),
> but did not see a possibility to access the information a want
>
> How can this be done?

It's an FAQ that's not in the FAQ. The popular answer is "Don't try to
do that! There's usually a less magic way to accomplish your goal.".
Alternatives can usually be proffered if the exact use case is
explained specifically.

Cheers,
Chris
--
http://blog.rebertia.com


== 3 of 7 ==
Date: Tues, Jan 26 2010 4:01 am
From: "Alf P. Steinbach"


* Hellmut Weber:
>
> consider the following piece of code, please
>
> ----- -----
>
> def f(param):
> nameOfParam = ???
> # here I want to access the name of the variable
> # which was given as parameter to the function
> print nameOfParam, param
> return
>
> if __name__ == __main__:
>
> a = 1
> f(a)
>
> b = 'abcd'
> f(a)
>
> ----- -----
>
> The output should be:
>
> 'a' 1
> 'b' 'abcd'
>
> ----- -----
>
> I tried to look at globals() and locals(), gave a look to the frames
> (sys._getframe(0) and sys._getframe(1),
> but did not see a possibility to access the information a want
>
> How can this be done?

Not in any efficient way. A debugger can do it, and you can do it in the same
way as a debugger, checking stack frames and the source code. But if it's
debugging that you're after then use a debugger -- that's what they're for.

Otherwise, just change the way that you invoke the routine.

For example,

>>> def f( **kwa ):
... print( kwa )
...
>>> a = 1234
>>> b = "huh"
>>> f( a = a, b = b )
{'a': 1234, 'b': 'huh'}
>>> _


Cheers & hth.,

- Alf


== 4 of 7 ==
Date: Tues, Jan 26 2010 4:06 am
From: Jean-Michel Pichavant


Hellmut Weber wrote:
> Hi,
>
> consider the following piece of code, please
>
> ----- -----
>
> def f(param):
> nameOfParam = ???
> # here I want to access the name of the variable
> # which was given as parameter to the function
> print nameOfParam, param
> return
>
> if __name__ == __main__:
>
> a = 1
> f(a)
>
> b = 'abcd'
> f(a)
>
> ----- -----
>
> The output should be:
>
> 'a' 1
> 'b' 'abcd'
>
> ----- -----
>
> I tried to look at globals() and locals(), gave a look to the frames
> (sys._getframe(0) and sys._getframe(1),
> but did not see a possibility to access the information a want
>
> How can this be done?
>
> TIA
>
> Hellmut
>
>
I don't know if it's possible (maybe using smelling hackish code).
What I know for sure, is that your function should ask the required
informations as parameters. That what parameters are for.

Tell us whant you want to achieve precisely with the parameter names,
maybe we'll find something suitable.

JM


== 5 of 7 ==
Date: Tues, Jan 26 2010 7:50 am
From: Gary Herron


Hellmut Weber wrote:
> Hi,
>
> consider the following piece of code, please
>
> ----- -----
>
> def f(param):
> nameOfParam = ???
> # here I want to access the name of the variable
> # which was given as parameter to the function
> print nameOfParam, param
> return
>
> if __name__ == __main__:
>
> a = 1
> f(a)
>
> b = 'abcd'
> f(a)
>
> ----- -----
>
> The output should be:
>
> 'a' 1
> 'b' 'abcd'
>
> ----- -----
>
> I tried to look at globals() and locals(), gave a look to the frames
> (sys._getframe(0) and sys._getframe(1),
> but did not see a possibility to access the information a want
>
> How can this be done?
>
> TIA
>
> Hellmut
>
>

It's naive to think this question even makes sense. There are many ways
f can be called which don't involve a parameter:

f(42)
f(time())
f(a+123)
f(sin(a))
f(f(1))

and so on.

Cheers,
Gary Herron

== 6 of 7 ==
Date: Tues, Jan 26 2010 7:54 am
From: Gary Herron


Gary Herron wrote:
> Hellmut Weber wrote:
>> Hi,
>>
>> consider the following piece of code, please
>>
>> ----- -----
>>
>> def f(param):
>> nameOfParam = ???
>> # here I want to access the name of the variable
>> # which was given as parameter to the function
>> print nameOfParam, param
>> return
>>
>> if __name__ == __main__:
>>
>> a = 1
>> f(a)
>>
>> b = 'abcd'
>> f(a)
>>
>> ----- -----
>>
>> The output should be:
>>
>> 'a' 1
>> 'b' 'abcd'
>>
>> ----- -----
>>
>> I tried to look at globals() and locals(), gave a look to the frames
>> (sys._getframe(0) and sys._getframe(1),
>> but did not see a possibility to access the information a want
>>
>> How can this be done?
>>
>> TIA
>>
>> Hellmut
>>
>>
>
> It's naive to think this question even makes sense. There are many
> ways f can be called which don't involve a parameter:
That's worded poorly, Rather I should have said: "don't involve a
parameter that comes from a single variable."
>
> f(42)
> f(time())
> f(a+123)
> f(sin(a))
> f(f(1))
>
> and so on.
> Cheers,
> Gary Herron
>

== 7 of 7 ==
Date: Tues, Jan 26 2010 8:13 am
From: Duncan Booth


Gary Herron <gherron@islandtraining.com> wrote:

> It's naive to think this question even makes sense. There are many ways
> f can be called which don't involve a parameter:
>
> f(42)
> f(time())
> f(a+123)
> f(sin(a))
> f(f(1))
>
> and so on.

So long as the OP doesn't care if they get no names or several name that
might not matter. However, explicitly passing in the name you want to use
is likely to be more useful.

>>> def getcallersnames(obj):
f = inspect.currentframe().f_back.f_back
return [name for name in f.f_locals if f.f_locals[name] is obj]

>>> def bip(x):
print getcallersnames(x)


>>> def foo(bar):
baz = bar
bip(baz)
bip(baz+1)


>>> foo(3)
['bar', 'baz']
[]

>>> bip(bip)
['bip']

--
Duncan Booth http://kupuguy.blogspot.com

==============================================================================
TOPIC: Splitting text at whitespace but keeping the whitespace in thereturned
list
http://groups.google.com/group/comp.lang.python/t/22533b4383d301bb?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 4:40 am
From: Roy Smith


In article <hjklfd$llm$1@foggy.unx.sas.com>,
"Tim Arnold" <tim.arnold@sas.com> wrote:

> also, partition works though it returns a tuple instead of a list.
> >>> s = 'hello world'
> >>> s.partition(' ')
> ('hello', ' ', 'world')

I've never used partition() before; my first thought on reading the above
was, "That's weird, it should be returning a list". Then I went and looked
at the docs. Given the description (returns specifically a 3-tuple), I
guess a tuple makes sense, but now I'm wondering what the use case was for
this method when it was invented?

Having a variant of split() which either leaves the delimiter on the end of
each word, or returns a list of alternating [word, delimiter, word,
delimiter, word] seems logical and orthogonal. In fact, partition() is
really just the hypothetical whitespace-preserving variant of split(), with
maxsplit=1, except that it returns a tuple instead of a list.

So, what was the original problem partition() was trying to solve?

==============================================================================
TOPIC: pylint and the 'missing docstring' warning
http://groups.google.com/group/comp.lang.python/t/dc667186a8854284?hl=en
==============================================================================

== 1 of 4 ==
Date: Tues, Jan 26 2010 5:43 am
From: Jean-Michel Pichavant


Hello,

Does anyone using pylint knows a way to make pylint ignore these
'missing docstring' warnings when the base class version of the method
actually defines the docstring ?
'Cause my doc builder (epydoc) handle it properly and propagate
docstrings if asked to. Too bad pylint is complaining about it.
I don't want to deactivate this warning.

Any hint would be apreciated

JM


== 2 of 4 ==
Date: Tues, Jan 26 2010 5:56 am
From: John Posner


On 1/26/2010 8:43 AM, Jean-Michel Pichavant wrote:
> Hello,
>
> Does anyone using pylint knows a way to make pylint ignore these
> 'missing docstring' warnings when the base class version of the method
> actually defines the docstring ?
> 'Cause my doc builder (epydoc) handle it properly and propagate
> docstrings if asked to. Too bad pylint is complaining about it.
> I don't want to deactivate this warning.
>

Look for this setting in the pylint configuration file:

# not require a docstring
no-docstring-rgx=__.*__

-John


== 3 of 4 ==
Date: Tues, Jan 26 2010 6:22 am
From: Jean-Michel Pichavant


John Posner wrote:
> On 1/26/2010 8:43 AM, Jean-Michel Pichavant wrote:
>> Hello,
>>
>> Does anyone using pylint knows a way to make pylint ignore these
>> 'missing docstring' warnings when the base class version of the method
>> actually defines the docstring ?
>> 'Cause my doc builder (epydoc) handle it properly and propagate
>> docstrings if asked to. Too bad pylint is complaining about it.
>> I don't want to deactivate this warning.
>>
>
> Look for this setting in the pylint configuration file:
>
> # not require a docstring
> no-docstring-rgx=__.*__
>
> -John
>
>
If I'm no wrong this just disables docstring checks for methods matching
__.*__
I'd like to disable it for any method which base class version already
defines the docstring.

JM


== 4 of 4 ==
Date: Tues, Jan 26 2010 8:19 am
From: John Posner


On 1/26/2010 9:22 AM, Jean-Michel Pichavant wrote:
> John Posner wrote:
>> On 1/26/2010 8:43 AM, Jean-Michel Pichavant wrote:
>>> Hello,
>>>
>>> Does anyone using pylint knows a way to make pylint ignore these
>>> 'missing docstring' warnings when the base class version of the method
>>> actually defines the docstring ?
>>> 'Cause my doc builder (epydoc) handle it properly and propagate
>>> docstrings if asked to. Too bad pylint is complaining about it.
>>> I don't want to deactivate this warning.
>>>
>>
>> Look for this setting in the pylint configuration file:
>>
>> # not require a docstring
>> no-docstring-rgx=__.*__
>>
>> -John
>>
>>
> If I'm no wrong this just disables docstring checks for methods matching
> __.*__
> I'd like to disable it for any method which base class version already
> defines the docstring.
>

I'm a Pylint newbie myself. The only (half-baked) idea I can come up
with is to use a naming convention for such derived classes. For
example, if all such class names ended with "_d" (ugh!), you could
modify the configuration setting like this:

no-docstring-rgx=(__.*__|.*_d)

-John

==============================================================================
TOPIC: My experiences building a small app on Python
http://groups.google.com/group/comp.lang.python/t/2c0da79b32b28a73?hl=en
==============================================================================

== 1 of 2 ==
Date: Tues, Jan 26 2010 5:51 am
From: Cascade3891


Hello Python community,

I built a small app with Python for the first time. It has served a
very useful and productive purpose for me and my colleagues at work.

I have shared my experiences on the following link due to the better
web presentation tools and coding presentation tools:
http://www.daniweb.com/forums/thread255458.html

It's a bit of a read. But insightful.

If you have any feedback or tips and advice, please let me know.

I've fallen in love with programming because of Python. =)

Thank you in advance.

Cheers.


== 2 of 2 ==
Date: Tues, Jan 26 2010 7:02 am
From: Simon Brunning


2010/1/26 Cascade3891 <mlee3891@gmail.com>:
> It's a bit of a read. But insightful.

We'll be the judge of that, surely? ;-)

--
Cheers,
Simon B.

==============================================================================
TOPIC: PIL: Wiping out metadata on save only on progressive JPG's
http://groups.google.com/group/comp.lang.python/t/bdc0b3aadb729035?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 5:52 am
From: "frankborell@gmail.com"


Hello,

I've tested on PIL 1.16 and 1.17. Metadata(IPTC and EXIF) are saved
fine when the jpg image is NOT progressive. But when the jpg is
progressive, the metadata gets wiped out. Does anyone have any ideas
on how to preserve?

im = Image.open('progressive jpeg path')

im.save('jpeg path') or
im.save('jpeg path',option={'progression':False,'quality':
60,'optimize':True})

Thanks,
Frank

==============================================================================
TOPIC: ANN: Veusz 1.6
http://groups.google.com/group/comp.lang.python/t/f1b847d483f92fb5?hl=en
==============================================================================

== 1 of 1 ==
Date: Mon, Jan 25 2010 1:42 pm
From: Jeremy Sanders


Veusz 1.6
---------
Velvet Ember Under Sky Zenith
-----------------------------
http://home.gna.org/veusz/

Veusz is Copyright (C) 2003-2010 Jeremy Sanders <jeremy@jeremysanders.net>
Licenced under the GPL (version 2 or greater).

Veusz is a Qt4 based scientific plotting package. It is written in
Python, using PyQt4 for display and user-interfaces, and numpy for
handling the numeric data. Veusz is designed to produce
publication-ready Postscript/PDF/SVG output. The user interface aims
to be simple, consistent and powerful.

Veusz provides a GUI, command line, embedding and scripting interface
(based on Python) to its plotting facilities. It also allows for
manipulation and editing of datasets. Data can be captured from
external sources such as internet sockets or other programs.

Changes in 1.6:
* User defined constants, functions or external Python imports can be
defined for use when evaluating expressions.
* Import descriptor is much more tolerant of syntax, e.g. "x,+- y,+,-" can
now be specified as "x +- y + -".
* New SVG export (PyQt >= 4.6). Supports clipping and exports text
as paths for full WYSIWYG.
* Dataset names can now contain any character except "`". Names containing
non-alphanumeric characters can be quoted in expressions `like so`*1.23
* Widget names can contain any character except "/"
* A transparency dataset can be provided to specify the per-pixel
transparency of the image widget.
* A polygon widget has been added.
* There is a new option to place axis ticks outside the plot (outer ticks
setting on axis widget)
* Several new line styles have been added.
* Several new plotting markers have been added.
* The capture dialog can optionally retain the last N values captured.

Minor changes:
* Use of flat cap line style for plotting error bars for exactness.
* Add fixes for saving imported unicode text.
* Fix image colors for big endian systems (e.g. Mac PPC).
* Add boxfill error bar style, plotting errors as filled boxes.
* Positive and negative error bars are forced to have the correct sign.

Features of package:
* X-Y plots (with errorbars)
* Line and function plots
* Contour plots
* Images (with colour mappings and colorbars)
* Stepped plots (for histograms)
* Bar graphs
* Plotting dates
* Fitting functions to data
* Stacked plots and arrays of plots
* Plot keys
* Plot labels
* Shapes and arrows on plots
* LaTeX-like formatting for text
* EPS/PDF/PNG/SVG/EMF export
* Scripting interface
* Dataset creation/manipulation
* Embed Veusz within other programs
* Text, CSV and FITS importing
* Data can be captured from external sources

Requirements for source install:
Python (2.4 or greater required)
http://www.python.org/
Qt >= 4.3 (free edition)
http://www.trolltech.com/products/qt/
PyQt >= 4.3 (SIP is required to be installed first)
http://www.riverbankcomputing.co.uk/pyqt/
http://www.riverbankcomputing.co.uk/sip/
numpy >= 1.0
http://numpy.scipy.org/

Optional:
Microsoft Core Fonts (recommended for nice output)
http://corefonts.sourceforge.net/
PyFITS >= 1.1 (optional for FITS import)
http://www.stsci.edu/resources/software_hardware/pyfits
pyemf >= 2.0.0 (optional for EMF export)
http://pyemf.sourceforge.net/
For EMF and better SVG export, PyQt >= 4.6 or better is
required, to fix a bug in the C++ wrapping

For documentation on using Veusz, see the "Documents" directory. The
manual is in PDF, HTML and text format (generated from docbook). The
examples are also useful documentation.

Issues with the current version:

* Due to Qt, hatched regions sometimes look rather poor when exported
to PostScript, PDF or SVG.

* Due to a bug in Qt, some long lines, or using log scales, can lead
to very slow plot times under X11. It is fixed by upgrading to
Qt-4.5.1 (or using a binary). Switching off antialiasing in the options
may help.

If you enjoy using Veusz, I would love to hear from you. Please join
the mailing lists at

https://gna.org/mail/?group=veusz

to discuss new features or if you'd like to contribute code. The
latest code can always be found in the SVN repository.

Jeremy Sanders


==============================================================================
TOPIC: ctypes for AIX
http://groups.google.com/group/comp.lang.python/t/a93f969410d0d086?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Jan 26 2010 8:07 am
From: nn


On Jan 25, 6:36 pm, "Waddle, Jim" <jim.wad...@boeing.com> wrote:
> Chris,
> Thanks for responding to my email.
> I apologize for the remark about python only being developed for windows. I got the impression when I was looking at the ActivePython web site and saw that the version of python that they had available was not supported on very many unix systems. I should not make general statement based on only one web site. After reading your email I decided to see for myself what the issue was about compiling python on AIX 5.3.
>
> This is the error I saw the first time I tried to use ctypes.
>
> Python 2.4.3 (#1, Jul 17 2006, 20:00:23) [C] on aix5
> Type "help", "copyright", "credits" or "license" for more information.>>> import ctypes
>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> ImportError: No module named ctypes
>
> This version of python was downloaded and installed from ActivePython and when I checked their webpage it states that ctypes is not available on AIX.
> I then figured I would get a new copy of python and install it on AIX. I downloaded python.2.5.5c2 fromhttp://www.python.org. I did the configure and make which posted many errors in the ctypes function which I guess is the reason that is does not get include in the final make.
>
> an example of the build error I get when doing the make is:
> xlc_r -q64 -DNDEBUG -O -I. -I/s/users/cz030a/xferjunk/python/Python-2.5.5c2/./Include -Ibuild/temp.aix-5.3-2.5/libffi/inclu
> de -Ibuild/temp.aix-5.3-2.5/libffi -I/s/users/cz030a/xferjunk/python/Python-2.5.5c2/Modules/_ctypes/libffi/src -I/s/users/c
> z030a/xferjunk/ots/python2.5/include -I. -IInclude -I./Include -I/s/users/cz030a/xferjunk/python/Python-2.5.5c2/Include -I/
> s/users/cz030a/xferjunk/python/Python-2.5.5c2 -c /s/users/cz030a/xferjunk/python/Python-2.5.5c2/Modules/_ctypes/_ctypes.c -
> o build/temp.aix-5.3-2.5/s/users/cz030a/xferjunk/python/Python-2.5.5c2/Modules/_ctypes/_ctypes.o
> "/s/users/cz030a/xferjunk/python/Python-2.5.5c2/Modules/_ctypes/_ctypes.c", line 2820.31: 1506-068 (W) Operation between ty
> pes "void*" and "int(*)(void)" is not allowed.
> "/s/users/cz030a/xferjunk/python/Python-2.5.5c2/Modules/_ctypes/_ctypes.c", line 3363.28: 1506-280 (W) Function argument as
> signment between types "int(*)(void)" and "void*" is not allowed.
> "/s/users/cz030a/xferjunk/python/Python-2.5.5c2/Modules/_ctypes/_ctypes.c", line 4768.67: 1506-280 (W) Function argument as
> signment between types "void*" and "void*(*)(void*,const void*,unsigned long)" is not allowed.
> "/s/users/cz030a/xferjunk/python/Python-2.5.5c2/Modules/_ctypes/_ctypes.c", line 4769.66: 1506-280 (W) Function argument as
> signment between types "void*" and "void*(*)(void*,int,unsigned long)" is not allowed.
>
> I do not have sufficient knowledge to know how to fix this. I would think that this error somehow is related to compiling on aix. If you have any suggestions on how to correct this problem , I would appreciate it
>
> Jim Waddle
> KIT-D
> 425-785-5194
>
> -----Original Message-----
> From: ch...@rebertia.com [mailto:ch...@rebertia.com] On Behalf Of Chris Rebert
> Sent: Sunday, January 24, 2010 7:31 AM
> To: Waddle, Jim
>
> Cc: python-l...@python.org
> Subject: Re: ctypes for AIX
>
> On Sun, Jan 24, 2010 at 5:54 AM, Waddle, Jim <jim.wad...@boeing.com> wrote:
> > I need to use ctypes with python running on AIX.
>
> According to the ctypes readme, ctypes is based on libffi, which
> according to its website, supports AIX for PowerPC64.
> So, perhaps you could state what the actual error or problem you're
> encountering is?
> It is theoretically possible the ctypes-bundled libffi is either
> outdated or had the AIX-specific bits removed; I don't know, I'm not a
> CPython dev.
>
> > It appears that python is being developed mostly for windows.
>
> No, not really; your statement is especially ironic considering one of
> Python's primary areas of use is for web applications as part of a
> LAMP stack.
>
> > Is there a policy concerning getting functions like ctypes working on AIX.
>
> No idea. Someone will probably chime in though.
>
> Cheers,
> Chris
> --http://blog.rebertia.com
>
>

Look at this website:

http://pware.hvcc.edu/news.html

"8/1/2009 Python with ctypes!"

Good luck.


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate