lambda functions

2009-08-31 Thread Pierre
Hello,

I would like to know if it is possible to define a loop in a lambda
function

How to manage the indents ? Example :
s_minus_1 = lambda s : for index in range(0, len(s)) : s[index] = s
[index]-1


Thanks !

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


Re: An assessment of Tkinter and IDLE

2009-08-31 Thread eb303
On Aug 28, 4:41 pm, r  wrote:
> Thanks eb303 for the wonderful post
>
> I have looked over the new ttk widgets and everything looks nice. I am
> very glad to see the death of Tix as i never much liked it anyhow and
> always believed these widgets should have been in the main Tkinter
> module to start with. The tree widget has been needed for some time.
>
> However, i am not sure about the new "style" separation. Previously a
> simple command like root.option_add('*Label.Font'...) accomplished the
> same thing with less typing, but there may be a future method to this
> current madness that i am unaware of...???

The new widgets have been made mainly to make tk look better by making
it possible to use native widgets. The drawback is that it limits a
lot the possibilities of configuration you can have: on many
platforms, the looks of the widgets are decided by the user via a
system preference, not by the application programmer. This is why ttk
widgets are not configurable directly, because 'native' styles usually
don't allow it at application level anyway.

Keep in mind that the new ttk widgets are not replacements for former
widgets, but an addition to them. 'Old' widgets are still here, and
there is no plan I know of to remove them. If you want to do an
application with a very specific look, you can still use these.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda functions

2009-08-31 Thread Javier Collado
Hello,

This page has some advice about how to avoid some of the lambda
functions limitations:
http://p-nand-q.com/python/stupid_lambda_tricks.html

In particular, it suggests to use map function instead of for loops.

Best regards,
Javier

2009/8/31 Pierre :
> Hello,
>
> I would like to know if it is possible to define a loop in a lambda
> function
>
> How to manage the indents ? Example :
> s_minus_1 = lambda s : for index in range(0, len(s)) : s[index] = s
> [index]-1
>
>
> Thanks !
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: initilize a memory zone in python

2009-08-31 Thread Diez B. Roggisch

Mug schrieb:

On Aug 30, 8:58 pm, "Diez B. Roggisch"  wrote:

Mug schrieb:


hello, i'm new in python, i used to program in C,
i have a small problem, i tryed to do some serial port things
manipulation
with python.
i have something like:
import sys,termios
fd = sys.stdin.fileno()
term_conf=termios.tcgetattr(fd);
now i want to modify the actuall values in term_conf  zone to zero
i don't see how to do it,
in C we can do : bzero(&term_conf,sizeof(struct termios));
i want to know if it exist a similar function in python, thanks

In python you don't modify memory like that.

For the above function, you pass a value as the one you got to
tcgetattr, with values modified as you desire them.

i tryed
print term_conf
and i saw that the term_conf is actually represent with an array in
python:

zsh/3 4201 [1] % python test.py
[27906, 5, 1215, 35387, 15, 15, ['\x03', '\x1c', '\x7f', '\x15',
'\x04', '\x00', '\x01', '\xff', '\x11', '\x13', '\x1a', '\xff',
'\x12', '\x0f', '\x17', '\x16', '\xff', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00',
'\x00', '\x00', '\x00', '\x00']]

it's a array of 7 elements, with the seventh element it self a array,
so in order to initialize them to zero, there's no other way than
modify them
one by one in a loop? is there a fonction like "memset" or "bzero" in
python?


Again: no, there is no such function. But for the above, you'd easily write:

foo = [0] * 7 # only do this with immutables
foo[-1] = ['\x00'] * 16

alternatively, you modify the result you got from tcgetattr in the 
places you want.




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


Re: lambda functions

2009-08-31 Thread Chris Rebert
On Mon, Aug 31, 2009 at 12:41 AM, Pierre wrote:
> Hello,
>
> I would like to know if it is possible to define a loop in a lambda
> function

Not possible. Lambdas can only contain a single expression. A loop is
a block statement.
Just use a named function instead. There's nothing that can be done
with a lambda that can't be done with a named function instead.

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


Re: lambda functions

2009-08-31 Thread Gabriel Genellina
En Mon, 31 Aug 2009 04:41:57 -0300, Pierre   
escribió:



I would like to know if it is possible to define a loop in a lambda
function

How to manage the indents ? Example :
s_minus_1 = lambda s : for index in range(0, len(s)) : s[index] = s
[index]-1


You can't. lambda is just a way to define a short, inline, anonymous  
function, and its body can only contain expressions, not statements.


Even if what you want were legal, giving a name to the resulting  
expression kind of defeats the purpose of lambda - use a normal function  
instead:


def s_minus_1(s):
  "document usage here"
  for index,item in enumerate(s):
s[index] -= 1

--
Gabriel Genellina

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


Re: An assessment of the Unicode standard

2009-08-31 Thread Hendrik van Rooyen
On Sunday 30 August 2009 22:46:49 Dennis Lee Bieber wrote:

>   Rather elitist viewpoint... Why don't we just drop nukes on some 60%
> of populated landmasses that don't have a "western" culture and avoid
> the whole problem?

Now yer talking, boyo!  It will surely help with the basic problem which is 
the heavy infestation of people on the planet!
:-)

- Hendrik

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


Re: map

2009-08-31 Thread Hendrik van Rooyen
On Monday 31 August 2009 06:55:52 elsa wrote:

8< - map question 

>
> (Ultimately, I want to call myFunc(myList[0], 'booHoo'), myFunc(myList
> [1], 'booHoo'), myFunc(myList[2], 'booHoo') etc. However, I might want
> to call myFunc(myList[0], 'woo'), myFunc(myList[1], 'woo'), myFunc
> (myList[2], 'woo') some other time).

Here is some heretical advice:

Do not use stuff like map and reduce unless they fit what you want to do 
perfectly, and "JustWorks" the first time.

You have a very clear idea of what you want to do, so why do you not just 
simply write something to do it?

something like this (untested):

def woofer(thefunc,thelist,thething):
theanswers = []
for x in thelist:
theanswers.append(thefunc(x,thething))
return theanswers

And the advantage is that you do not have to remember what map does...

*ducks away from the inevitable flames*

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


rcond in numpy :

2009-08-31 Thread Pierre

Hello,

Anyone knows the numpy equivalent of the matlab function : rcond
(Matrix reciprocal condition number estimate) ?

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


Re: map

2009-08-31 Thread Gabriel Genellina
En Mon, 31 Aug 2009 05:43:07 -0300, Hendrik van Rooyen  
 escribió:

On Monday 31 August 2009 06:55:52 elsa wrote:


(Ultimately, I want to call myFunc(myList[0], 'booHoo'), myFunc(myList
[1], 'booHoo'), myFunc(myList[2], 'booHoo') etc. However, I might want
to call myFunc(myList[0], 'woo'), myFunc(myList[1], 'woo'), myFunc
(myList[2], 'woo') some other time).


Here is some heretical advice:

Do not use stuff like map and reduce unless they fit what you want to do
perfectly, and "JustWorks" the first time.


I think of that advice as "orthodox", not "heretical"! (functional guys  
are minority here...)



You have a very clear idea of what you want to do, so why do you not just
simply write something to do it?

something like this (untested):

def woofer(thefunc,thelist,thething):
theanswers = []
for x in thelist:
theanswers.append(thefunc(x,thething))
return theanswers

And the advantage is that you do not have to remember what map does...


This block:

theanswers = []
for x in thelist:
theanswers.append(thefunc(x,thething))

is formally the same as this one:

theanswers = [thefunc(x,thething) for x in thelist]

but the list comprehension is faster. So the function becomes:

def woofer(thefunc,thelist,thething):
return [thefunc(x,thething) for x in thelist]

and may be inlined (it's usually easier to read).


*ducks away from the inevitable flames*


*fights back to back with you against heretics*

--
Gabriel Genellina

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


Re: map

2009-08-31 Thread Piet van Oostrum
> Hendrik van Rooyen  (HvR) wrote:

>HvR> On Monday 31 August 2009 06:55:52 elsa wrote:
>HvR> 8< - map question 

>>> 
>>> (Ultimately, I want to call myFunc(myList[0], 'booHoo'), myFunc(myList
>>> [1], 'booHoo'), myFunc(myList[2], 'booHoo') etc. However, I might want
>>> to call myFunc(myList[0], 'woo'), myFunc(myList[1], 'woo'), myFunc
>>> (myList[2], 'woo') some other time).

>HvR> Here is some heretical advice:

>HvR> Do not use stuff like map and reduce unless they fit what you want to do 
>HvR> perfectly, and "JustWorks" the first time.

>HvR> You have a very clear idea of what you want to do, so why do you not just 
>HvR> simply write something to do it?

>HvR> something like this (untested):

>HvR> def woofer(thefunc,thelist,thething):
>HvR>   theanswers = []
>HvR>   for x in thelist:
>HvR>   theanswers.append(thefunc(x,thething))
>HvR>   return theanswers

>HvR> And the advantage is that you do not have to remember what map does...

Map should be in every good programmer's toolbox. So (s)he presumably
knows already what map does. In order to follow your advise (s)he must
first forget what map does :=)

Agreed on the part that map shouldn't be used indiscriminately. Neither
should loops. Your woofer is much harder to follow than map, I think.

[myFunc(elt, 'booHoo') for elt in myList] is also a good candidate and
in this case I think it is preferable to both the loop and the map with
a partial or lambda in terms of clarity.

On the other hand when you just want to call a function on each element
of a list and you don't need to collect the result a simple loop is
often preferable.

But ultimately it is also very much a matter of taste, preference and habit.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


starting a client remotely

2009-08-31 Thread jacopo
I am playing with multiprocessing and I would like to have a python
script on one machine which initialize my whole system, in other
words, this script should start the server (a python script) on my
local machine and the clients (python scripts) on the other machines
in my local network.

Would you have any suggestion?

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


Re: starting a client remotely

2009-08-31 Thread Diez B. Roggisch
jacopo wrote:

> I am playing with multiprocessing and I would like to have a python
> script on one machine which initialize my whole system, in other
> words, this script should start the server (a python script) on my
> local machine and the clients (python scripts) on the other machines
> in my local network.
> 
> Would you have any suggestion?

This isn't possible witout some kind of service running on the remote
machine. You don't write what OS you are using, on unix'ish machines this
can be easily accomplished using SSH to invoke a remote-command that starts
your server. I've used that + Pyro in the past to create distributed
systems.

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


Re: Return value of multiprocessing manager registerred function

2009-08-31 Thread jacopo
Hi Terry,
I have just started working on similar things and I am strugling to
find examples or documentations. So far I have found only the official
documentation of the multiprocessing package. Would you be able to
recommend me some good reference or a book. I dont want to overwhelm
this newsgroup with questions... yet :)
Regards, Jacopo

On Aug 26, 4:22 am, Terry  wrote:
> Hi,
>
> I'm using the multiprocessing.manager to run proceduresremotely. It
> all worked fine except I hope to have a different return value type.
>
> The remote function calls always return a proxy, which when I need to
> get the value it need to connect to the manager again to fetch it. But
> I just need the value, not the proxy.
>
> Can I just return the value instead of a proxy from a manager?
>
> br, Terry

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


Re: Is behavior of += intentional for int?

2009-08-31 Thread Piet van Oostrum
> Derek Martin  (DM) wrote:

>DM> On Sun, Aug 30, 2009 at 03:42:06AM -0700, Paul McGuire wrote:

>>> Is it any odder that 3 is an object than that the string literal
>>> "Hello, World!" is an object?  

>DM> Yes.  Because 3 is a fundamental bit of data that the hardware knows
>DM> how to deal with, requiring no higher level abstractions for the
>DM> programmer to use it (though certainly, a programming language can
>DM> provide them, if it is convenient).  "Hello, World!" is not.  They are
>DM> fundamentally different in that way.

How the semantics of Python is defined is not dependent of the hardware.
You could imagine a computer where strings are as much built into the
hardware as ints are. On the other hand you could also imagine a
computer that only knows about bits and where int arithmetic has to be
done in software. In fact early microprocessors only could operate
directly on bytes and arithmetic of larger ints was in software. And
even nowadays there are processors in use that don't have built-in
floating point hardware. Would you say that considering whether 3.14 is
an object in Python or whether that is to be considered strange should
depend on the availability of a floating point unit in the hardware
where the program runs? Would that make floating point numbers
"fundamentally different" from ints in the sense described above?
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: starting a client remotely

2009-08-31 Thread jacopo
thank you Diez,
unfortunatelly I am on Windows NT.
Did you use SSH in a python script?
Isn't multiprocessing.managers already doing something like Pyro?


thanks
Jacopo


On Aug 31, 12:47 pm, "Diez B. Roggisch"  wrote:
> jacopo wrote:
> > I am playing with multiprocessing and I would like to have a python
> > script on one machine which initialize my whole system, in other
> > words, this script should start the server (a python script) on my
> > local machine and the clients (python scripts) on the other machines
> > in my local network.
>
> > Would you have any suggestion?
>
> This isn't possible witout some kind of service running on the remote
> machine. You don't write what OS you are using, on unix'ish machines this
> can be easily accomplished using SSH to invoke a remote-command that starts
> your server. I've used that + Pyro in the past to create distributed
> systems.
>
> Diez

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


[ANN] PyYAML-3.09: YAML parser and emitter for Python

2009-08-31 Thread Kirill Simonov


 Announcing PyYAML-3.09


A new bug fix release of PyYAML is now available:

http://pyyaml.org/wiki/PyYAML

Note that PyYAML supports both Python 2 and Python 3.  For
compatibility notes, please see

http://pyyaml.org/wiki/PyYAMLDocumentation#Python3support


Changes
===

* Fixed compatibility issues with Python 3.1.
* Fixed use of uninitialized memory when emitting anchors with
  LibYAML bindings (Thank to cegner(at)yahoo-inc(dot)com).
* Fixed emitting incorrect BOM characters for UTF-16 (Thank to
  Valentin Nechayev)
* Fixed the emitter for folded scalars not respecting the preferred
  line width (Thank to Ingy).
* Fixed a subtle ordering issue with emitting '%TAG' directives
  (Thank to Andrey Somov).
* Fixed performance regression with LibYAML bindings.


Resources
=

PyYAML homepage: http://pyyaml.org/wiki/PyYAML
PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation

TAR.GZ package: http://pyyaml.org/download/pyyaml/PyYAML-3.09.tar.gz
ZIP package: http://pyyaml.org/download/pyyaml/PyYAML-3.09.zip
Windows installers:
http://pyyaml.org/download/pyyaml/PyYAML-3.09.win32-py2.3.exe
http://pyyaml.org/download/pyyaml/PyYAML-3.09.win32-py2.4.exe
http://pyyaml.org/download/pyyaml/PyYAML-3.09.win32-py2.5.exe
http://pyyaml.org/download/pyyaml/PyYAML-3.09.win32-py2.6.exe
http://pyyaml.org/download/pyyaml/PyYAML-3.09.win32-py3.0.exe
http://pyyaml.org/download/pyyaml/PyYAML-3.09.win32-py3.1.exe

PyYAML SVN repository: http://svn.pyyaml.org/pyyaml
Submit a bug report: http://pyyaml.org/newticket?component=pyyaml

YAML homepage: http://yaml.org/
YAML-core mailing list: 
http://lists.sourceforge.net/lists/listinfo/yaml-core



About PyYAML


YAML is a data serialization format designed for human readability and
interaction with scripting languages.  PyYAML is a YAML parser and
emitter for Python.

PyYAML features a complete YAML 1.1 parser, Unicode support, pickle
support, capable extension API, and sensible error messages.  PyYAML
supports standard YAML tags and provides Python-specific tags that allow
to represent an arbitrary Python object.

PyYAML is applicable for a broad range of tasks from complex
configuration files to object serialization and persistance.


Example
===

>>> import yaml

>>> yaml.load("""
... name: PyYAML
... description: YAML parser and emitter for Python
... homepage: http://pyyaml.org/wiki/PyYAML
... keywords: [YAML, serialization, configuration, persistance, pickle]
... """)
{'keywords': ['YAML', 'serialization', 'configuration', 'persistance',
'pickle'], 'homepage': 'http://pyyaml.org/wiki/PyYAML', 'description':
'YAML parser and emitter for Python', 'name': 'PyYAML'}

>>> print yaml.dump(_)
name: PyYAML
homepage: http://pyyaml.org/wiki/PyYAML
description: YAML parser and emitter for Python
keywords: [YAML, serialization, configuration, persistance, pickle]


Copyright
=

The PyYAML module is written by Kirill Simonov .

PyYAML is released under the MIT license.
--
http://mail.python.org/mailman/listinfo/python-list


Re: starting a client remotely

2009-08-31 Thread Diez B. Roggisch
jacopo wrote:

> thank you Diez,
> unfortunatelly I am on Windows NT.
> Did you use SSH in a python script?

Via subprocess, yes. Paramiko would be a way, too.

> Isn't multiprocessing.managers already doing something like Pyro?

I never used it, so I don't know - but it appears to be, yes. Doesn't change
the overall problem though - without an inroad to another server, you can't
spawn processes on remote machines.

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


Re: starting a client remotely

2009-08-31 Thread Gabriel Genellina

On Aug 31, 12:47 pm, "Diez B. Roggisch"  wrote:

jacopo wrote:
> I am playing with multiprocessing and I would like to have a python
> script on one machine which initialize my whole system, in other
> words, this script should start the server (a python script) on my
> local machine and the clients (python scripts) on the other machines
> in my local network.


En Mon, 31 Aug 2009 07:08:04 -0300, jacopo   
escribió:



thank you Diez,
unfortunatelly I am on Windows NT.


NT 4.0???
I was going to say "use the rexec command" but I think it's posterior to  
the Triasic-Jurasic extinction event :)


--
Gabriel Genellina

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


Re: Object's nesting scope

2009-08-31 Thread Bruno Desthuilliers

zaur a écrit :

On 28 авг, 16:07, Bruno Desthuilliers  wrote:

zaur a écrit :




On 26 авг, 17:13, "Diez B. Roggisch"  wrote:

Whom am we to judge? Sure if you propose this, you have some usecases in
mind - how about you present these

Ok. Here is a use case: object initialization.
For example,
person = Person():
  name = "john"
  age = 30
  address = Address():
 street = "Green Street"
 no = 12
vs.
person = Person()
person.name = "john"
person.age = 30
address = person.address = Address()
address.street = "Green Street"
address.no = 12



Err... Looks like you really should read the FineManual(tm) -
specifically, the parts on the __init__ method.

class Person(object):
def __init__(self, name, age, address):
self.name = name
self.age = age
self.address = address

class Address(object):
def __init__(self, street, no):
self.no = no
self.street = street

person = Person(
name="john",
age=30,
address = Address(
street="Green Street",
no=12
)
)


What are you doing if 1) classes Person and Address imported from
foreign module 2) __init__ method is not defined as you want?


Either 1/write an alternate initializer and bind it to the appropriate 
classes or 2/write factory functions:


1/

from foreign_module import Person, Address

def my_init(self, **kw):
for k, v in kw.items():
setattr(self, k, v)
return self

Person.init = my_init
Address.init = my_init

person = Person().init(
 name="john",
 age=30,
 address = Address().init(
 street="Green Street",
 no=12
 )
 )


2/

from functools import partial
import foreign_module

def my_factory(cls, **kw):
obj = cls()
for k, v in kw.items():
setattr(obj, k, v)
return obj

Person = partial(my_factory, foreign_module.Person)
Address = partial(my_factory, foreign_module.Address)

person = Person(
 name="john",
 age=30,
 address = Address(
 street="Green Street",
 no=12
 )
 )

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


Re: map

2009-08-31 Thread Steven D'Aprano
On Mon, 31 Aug 2009 10:43:07 +0200, Hendrik van Rooyen wrote:

> Here is some heretical advice:
> 
> Do not use stuff like map and reduce unless they fit what you want to do
> perfectly, and "JustWorks" the first time.
> 
> You have a very clear idea of what you want to do, so why do you not
> just simply write something to do it?

That's not heretical advice -- that's pretty standard, vanilla, boring 
advice. It's probably good advice, if you care more about Getting the Job 
Done than about learning the language.


> And the advantage is that you do not have to remember what map does...

map() is probably the simplest, most straightforward of the functional 
tools in Python. It's harder for me to remember it's name than to 
remember what it does: it applies a function to each element of a list, 
instead of two the entire list as a single argument. Easy-peasy.

> *ducks away from the inevitable flames*

You'll have to try harder than that to get flamed :)



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


Re: map

2009-08-31 Thread Hendrik van Rooyen
On Monday 31 August 2009 11:31:34 Piet van Oostrum wrote:

> But ultimately it is also very much a matter of taste, preference and
> habit.

This is true, but there is another reason that I posted - I have noticed that 
there seems to be a tendency amongst newcomers to the group to go to great 
lengths to find something that will do exactly what they want, irrespective 
of the inherent complexity or lack thereof of that which they are trying to 
do.

Now I cannot understand why this is - one could say that it is caused by an 
eagerness to understand all the corners of the tool that is python, but 
somehow it does not feel like that to me - I see it almost as a crisis of 
confidence - as if the newbie lacks the self confidence to believe that he or 
she is capable of doing anything independently.  

So whenever I can, I try to encourage people to just do it their way, and to 
see what happens, and to hack using the interactive interpreter, to build 
confidence by experimenting and making mistakes, and realizing that when you 
have made a mistake, it is not the end of the world,  - you can fix it and 
move on.

Don't know if this rant makes any sense...

- Hendrik

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


Re: An assessment of Tkinter and IDLE

2009-08-31 Thread Kevin Walzer

On 8/28/09 8:11 PM, r wrote:

On Aug 28, 5:48 pm, Mark Roseman  wrote:
(snip)

Thewww.tkdocs.comsite is 'language neutral' - currently the tutorial
covers Tcl, Perl, Ruby and yes Python, and allows you to switch between
any of those languages (or show all of them).


True, however the coverage is incomplete. I would back this site if we
can get a complete coverage of all widgets in the Python language.

+0.1


Are you certain the site is incomplete? Its coverage of the basic Tk and 
Ttk  widgets is spectacular. . Its coverage of layout techinques and 
best practices for organizing complex interfaces with Tk is also 
extremely valuable. I wish this site had been around when I was learning 
Tk five years ago. I've looked at just about every Tk and Tkinter 
tutorial site out there, and this one surpasses them all. Mark 
Roseman--a professional, independent software developer whose commercial 
products almost all incorporate Tk into their GUI's--has spent a couple 
of years putting together this site with input from various users and 
developers (myself included). It's now an absolutely indispensible 
resource for beginners and more experienced developers.


The reason the site does not cover 'all widgets in the Python language' 
is threefold:


1. It's a site about Tk, a tookit that has Python bindings and bindings 
to other languages also (Ruby, Perl, Tcl, etc.).
2. It omits additional Python-specific, Tkinter-based widget sets such 
as PMW, Tix, etc. because once you understand the basics of Tk, then 
grokking these other megawidget sets (which all build on top of Tk) 
should be pretty straightforward.
3. Finally, 'all widgets in the Python language' gets into other tookits 
as well, which is obviously unfeasible for a website.


If the site by itself isn't enough for you, or is a bit too basic in its 
coverage of Python techniques, then there are other options. Couple the 
TkDocs site with effbot's more advanced walk through the various Tkinter 
classes, and perhaps one or two of the other Tkinter-specific tutorials, 
and you'll have learned a lot. But I think the TkDocs site is essential, 
especially in its more advanced discussion of how to put together an 
attractive, polished user interface with Tk. Tk has a long-standing 
reputation of being the toolkit of choice for quick, simple, ugly 
interfaces, and the other resources I've mentioned do nothing to to 
change this. The practices that Mark Roseman discusses will allow one to 
eventually put together a UI that matches anything that the other big 
toolkits (wxPython, PyQt, PyObjC, PyGtk, etc.) can do.


Hope this helps,
Kevin

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
--
http://mail.python.org/mailman/listinfo/python-list


Math Notations, Computer Languages, and the “Form ” in Formalism

2009-08-31 Thread Xah Lee
• Math Notations, Computer Languages, and the “Form” in Formalism
  http://xahlee.org/cmaci/notation/index.html

plain text version follows. (lacks links)

-
Math Notations, Computer Languages, and the “Form” in Formalism

Xah Lee, 2009-08-31

This page is a collection of essays and expositions on the subjects of
nomenclature and notations in math and computer languages, in the
context of facilitating human communication and theorem proving
systems.

Most of these essays here are originally from email, blogs, or rants.
They are not of publication quality, and they are not a coherent
exposition the subject. Here's a very brief summary of of these
essays's central thesis:

• Traditional math notations are very inconsistent. Edsger Dijkstra is
a leader in a movement of what's called Calculational Proofs. That is,
using a notation that is consistent and facilitates the calculation
aspects when doing math by humans.

• Today, especially since 1990s, tremendous advances are made in
computer algebra systems and theorem proving systems. In these
languages, a coherent syntax, grammar, are needed for math
expressions.

• In computer algebra or theorem proving systems, they are intimately
tied to the math philosophies of formalism and logicism. In a sense,
formalism and logicism today are tied together as a single subject,
and using computer languages as foundation.

• Math expressions/syntax in computer languages are intimately tied to
math notations for human reading. (e.g. Mathematical, MathML are
technologies that combine the two.)

• The syntax and grammar of today's computer languages, such as Java,
C, Python, SQL, Lisp, are ad-hoc and their communities have little
understanding of the knowledge gained in math related fields such as
computer algebra or theorem proving languages. (This applies to
functional langs such as Haskell as well, but to a lesser degree.) On
the other hand, mathematicians in general are illiterate about
programing or using computer languages.

All of the above considered together, computer language designers and
mathematicians, should be made aware of these issues, so that when
they design or use computer languages, may it be math oriented or not,
the language's syntax and grammar can move towards a consistent syntax
system with solid foundation (as opposed to ad-hoc), and such language
should have build-in markup or simple mapping to 2-dimensional
notations for human reading (such as done with Mathematica or Semantic
MathML), and this computer language should be in fact as a basis of
theorem prover or computer algebra system (as in OCaml, Haskell,
Mathematica). The languages of computer algebra and theorem prover
would in fact merge together into one single subject if it is not
already slowly happening today.

Progress in the above issues are made in different fields but there
are little unification going on.

For example, there's Edsger Dijkstra's Calculational Proofs movement.
It improves math notations towards consistency and formalism. However,
people in Calculational Proofs movement are mostly math pedagogy
community i think. They are not programers interested in computer
languages, nor logicians interested in math formalism, or industrial
and commercial organizations interested in math notation
representation systems.

There's the computer algebra community, such as Mathematica, Maple,
Matlab, which requires a syntax and grammar for mathematical concepts.
There's the theorem proving community, such as OCaml, Coq, HOL, which
not only requires a syntax for math concepts, but also made major
understanding about math as a system of forms, i.e. formal systems.
Both computer algebra and theorem proving systems require math
notations and computer language syntax that are consistent and can
represent math concepts. However, the 2 camps are largely separate
communities. For example, there is as far as i know no tool that is
both a practical computer algebra system as well as a theorem proving
language.

Common computer languages, such as C, Java, Python, requires a good
syntax, parsers, and compilers, but their community, including
computer scientists and programers, are usually illiterate in typical
topics of of mathematics proper. Functional languages, such as Scheme
Lisp, APL, OCaml, Haskell, are more based on logic foundations (lambda
calculus) but their syntax and grammar has little to do with the math
notations as a logic or formal system. (these languages do not have a
formal spec in the sense of Formlism, i.e. transformation of forms. In
fact, almost no languages has a formal spec, formalism or not.)

There's math notation representation needs, such as TeX, MathCAD,
MathML, Mathematica. These are typically commercial organizations in
the computing industry. They can render math notations. In the case of
MathML and Mathematica, the language also represent the semantic
content of math notations. These two made major understanding about
the relation of math 

Re: Suggestion

2009-08-31 Thread Nitebirdz
On Sat, Aug 29, 2009 at 02:42:36PM +0530, Thangappan.M wrote:
> Dear all,
> 
>  I am in the process of learning Python programming language. I know
> Perl,PHP. Compare to both the language Python impressed me because here
> there is no lexical variables and all.Now I need suggestion saying that ,
> What online book can I follow?
> 
>  I have not yet learnt any advanced programming stuffs in Python.
> Please suggest some book? or tutorial. net net my goal is that I will be
> able to do the project in any languages(Python,Perl,PHP).So I need to learn
> more depth knowledge of Python.
> 
> So Please help me?
> 

Thangappan,


I'm no expert, but perhaps the following book will be of some help:

http://diveintopython.org/


There are plenty of tutorials on the web too.  Just do a quick search
for something like "python tutorial".  


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


Re: An assessment of the Unicode standard

2009-08-31 Thread Nigel Rantor

Hendrik van Rooyen wrote:

On Sunday 30 August 2009 22:46:49 Dennis Lee Bieber wrote:


Rather elitist viewpoint... Why don't we just drop nukes on some 60%
of populated landmasses that don't have a "western" culture and avoid
the whole problem?


Now yer talking, boyo!  It will surely help with the basic problem which is 
the heavy infestation of people on the planet!

:-)



On two conditions:

1) We drop some "test" bombs on Slough to satisfy Betjeman.

2) We strap both Xah and r to aforementioned bombs.



Also, I'm surprised no-one has mentioned Esperanto yet. Sounds like 
something r and Xah would *love*.


Slightly off-topic - does anyone have a good recipe for getting 
thunderbird to kill whole threads for good? Either based on a rule or 
just some extension I can use?


The Xah/r threads are like car crashes, I can't help but watch but my 
time could be better spent and I don't want to unsub the whole list.



Cheers,

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


Re: a popen command line question

2009-08-31 Thread Nitebirdz
On Sat, Aug 29, 2009 at 01:13:12PM -0700, Joni Lee wrote:
> Hi all,
> 
> I write a small script
> 
> status = os.popen('top').readlines()
> print status
> 
> It calls the command line "top" and will print out the status.
> But I have to press the keyboard "q" to quit "top", then the status
> will be printed, otherwise it just stands by with blank.
> 
> Question is. Do you know how to give "q" into my python script so that
> "top" is automatically quit immediately or maybe after 1s (for
> gathering information)
> 

Why not run the actual 'top' command in batch mode with only one
iteration?  It's in the man page.  I'm referring to this:

  status = os.popen('top -b -n 1').readlines()


Also, the following approach seems to display a nicer output:

-
#!/usr/bin/env python

import os

status=os.popen('top -b -n 1')
for i in status.readlines():
  print i
-


Or how about the following?

-
#!/usr/bin/env python

import commands

status=commands.getoutput('top -b -n 1')
print status
-


Mind you, I'm just suggesting different approaches.  I'm new to Python
and don't necessarily know what I'm doing.  Other more experienced
people may be able to suggest something better.


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


Re: IDE for Python

2009-08-31 Thread Mike Driscoll
On Aug 29, 1:08 pm, [email protected] wrote:
> 29.08.2009 4:14 пользователь "Thangappan.M"   
> написал:
>
> > Dear all,
> > Please suggest some good IDE for python.I am working in linux platform.
> > --
> > Regards,
> > Thangappan.M
>
> You can use Eclipse + PyDev or Emacs+PythonMode . Also there are Anjuta and  
> Code:Blocks, but they are designed mainly for C++ (but still can be used).

Don't forget Wingware IDE. Admittedly, it's not free (except for a
limited version), but it's pretty good. There's also SPE (Stani's
Python Editor). If you want a nigh-complete list, check the Python
wiki:

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

---
Mike Driscoll

Blog:   http://blog.pythonlibrary.org

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


Re: IDE for Python

2009-08-31 Thread Che M
On Aug 31, 10:53 am, Mike Driscoll  wrote:
> On Aug 29, 1:08špm, [email protected] wrote:
>
> > 29.08.2009 4:14 ÐÏÌØÚÏ×ÁÔÅÌØ "Thangappan.M"  š
> > ÎÁÐÉÓÁÌ:
>
> > > Dear all,
> > > Please suggest some good IDE for python.I am working in linux platform.
> > > --
> > > Regards,
> > > Thangappan.M
>
> > You can use Eclipse + PyDev or Emacs+PythonMode . Also there are Anjuta and 
> > š
> > Code:Blocks, but they are designed mainly for C++ (but still can be used).
>
> Don't forget Wingware IDE. Admittedly, it's not free (except for a
> limited version), but it's pretty good. There's also SPE (Stani's
> Python Editor). If you want a nigh-complete list, check the Python
> wiki:
>
> http://wiki.python.org/moin/PythonEditors

Not sure when an editor gets to be called an IDE, but while on the
site
that OP should check out this related page:

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

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


Re: An assessment of Tkinter and IDLE

2009-08-31 Thread Terry Reedy

Kevin Walzer wrote:
www.tkdocs.com

[snip]

and you'll have learned a lot. But I think the TkDocs site is essential, 
especially in its more advanced discussion of how to put together an 
attractive, polished user interface with Tk. Tk has a long-standing 
reputation of being the toolkit of choice for quick, simple, ugly 
interfaces, and the other resources I've mentioned do nothing to to 
change this. The practices that Mark Roseman discusses will allow one to 
eventually put together a UI that matches anything that the other big 
toolkits (wxPython, PyQt, PyObjC, PyGtk, etc.) can do.


Hope this helps,


It persuaded me to go and start reading. A couple of things of interest.

"It would be a great help if you could have a look around, provide any 
comments, corrections or suggestions, or even help fill in some of the 
missing pieces. "


so no pretense of completeness yet.

"In the near future, the plan is to continue refining the tutorial, 
mainly finishing up the rest of the Perl and Python examples."


And from the linked blog

"July 09, 2009
Python material in progress.

While not yet complete, I've managed to add a very hefty chunk of Python 
material to the tutorial. I should be able to complete the rest over the 
next week or so. Would definitely appreciate feedback from any 
Pythonistas on the existing material.


While I hadn't used it before, I think Tkinter may very well be the 
nicest interface to Tk next to Tcl's (for which Tk was originally 
designed of course, so you'd expect a bit of an advantage). For people 
unfamiliar with either language, I think Python's more conventional use 
of parentheses for functions, the "option=value" syntax, plus other 
language features it takes advantage of are very attractive and win out 
over Tcl. The two main parts that I think Tcl does in a nicer way are 
event bindings and the fact you can create and geometry manage a widget 
in one statement, while still keeping a handle to a widget around.


UPDATE July 17/2009: Most of the rest of the Python examples and code 
snippets have been added.

"

tjr

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


Re: map

2009-08-31 Thread Paul Rubin
elsa  writes:
> map(myFunc(b='booHoo'), myList)
> 
> Why doesn't this work? is there a way to make it work?

You can use functools.partial but a listcomp might be simpler:

   list(myfunc(a, b='booHoo') for a in myList)

There is another listcomp syntax with square brackets, but I try to
avoid it because it has broken behavior (leaks the index variable) in
Python 2.x.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda functions

2009-08-31 Thread Paul Rubin
Pierre  writes:
> s_minus_1 = lambda s : for index in range(0, len(s)) : s[index] = s
> [index]-1

What are you trying to do here anyway?  That looks broken. 
Maybe you want the list.insert method.
-- 
http://mail.python.org/mailman/listinfo/python-list


executable path finding

2009-08-31 Thread koranthala
Hi,
I am creating a python application using py2exe. I am facing a
problem which I am not sure how to solve.
The application contains many other files associated with it -
like icons, config files etc. The executable can be in any directory.
If the user creates a shortcut to the executable to run in desktop,
the program fails - saying that the icon image cannot be found. But I
can run the application properly, if I run it from application
directory - where all the other icons, config files etc are kept.
How is such issues usually solved? I do not want to hardcode the
paths of icons and store the icons in those paths. I guess, we can
change the directory to the application directory before running the
application. (in __init__.py ???) But how do we find the current
directory in that case? I am completely at sea in solving this.
This looks to be a very common issue. How is this usually solved?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: executable path finding

2009-08-31 Thread Diez B. Roggisch
koranthala wrote:

> Hi,
> I am creating a python application using py2exe. I am facing a
> problem which I am not sure how to solve.
> The application contains many other files associated with it -
> like icons, config files etc. The executable can be in any directory.
> If the user creates a shortcut to the executable to run in desktop,
> the program fails - saying that the icon image cannot be found. But I
> can run the application properly, if I run it from application
> directory - where all the other icons, config files etc are kept.
> How is such issues usually solved? I do not want to hardcode the
> paths of icons and store the icons in those paths. I guess, we can
> change the directory to the application directory before running the
> application. (in __init__.py ???) But how do we find the current
> directory in that case? I am completely at sea in solving this.
> This looks to be a very common issue. How is this usually solved?

You can get the location of a module via

 module.__file__

This can be used to find a file relative to e.g. the toplevel module/package
of your application.

The pkg_resources-module of setuptools encapsulates that even into a stream
and file-name api.

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


find free hard disk space remote windows host

2009-08-31 Thread Daniel
Hello,

I'm trying to determine the amount of free hard disk space on a remote
windows host.  Seems like this should be simple, but it's giving me
grief.  Here's what I've tried:

>>> mystat = os.stat('//remotehost/share/')
>>> mystat
(16895, 0L, 0, 0, 0, 0, 0L, 1251731920, 1251731289, 1249399952)

For some reason it doesn't show the details about space on the remote
path.

Next I tried this:

subprocess.call('dir //remotehost/share/ | find "bytes free"',
shell=True)

But this only returns the status, not the output, which is what I
need.

How can I determine the amount of free hard drive space on a remote
windows host using python?

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


Efficient way to sum a product of numbers...

2009-08-31 Thread vsoler
Hi,

After simplifying my problem, I can say that I want to get the sum of
the product of two culumns:

Say
 m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
 r={'a':4, 'b':5, 'c':6}

What I need is the calculation

 1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26

That is, for each row list in variable 'm' look for its first element
in variable 'r' and multiply the value found by the second element in
row 'm'. After that, sum all the products.

What's an efficient way to do it? I have thousands of these
calculations to make on a big data file.

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


Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Tim Chase

After simplifying my problem, I can say that I want to get the sum of
the product of two culumns:

Say
 m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]

assuming you meant ['c', 3] here...^

 r={'a':4, 'b':5, 'c':6}

What I need is the calculation

 1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26
and you mean "3*6" here instead of "3*4", which is 18 instead of 
12, making the whole sum 4+10+18=32



Then it sounds like you could do something like

 result = sum(v * r[k] for k,v in m)

where "m" is any arbitrary iterable of tuples.  If the keys (the 
letters) aren't guaranteed to be in "r", then you can use 
defaults (in this case "0", but could just as likely be "1" 
depending on your intent):


 result = sum(v * r.get(k,0) for k,v in m)


If the conditions above don't hold, you'll have to introduce me 
to your new math. ;-)


-tkc



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


Re: An assessment of the Unicode standard

2009-08-31 Thread Rami Chowdhury
No need to feed the troll by actually trying to engage in the discussion,  
but just FYI:



   Sanskrit is mostly written in Devanagari these days which is also
useful for selling things to people who speak Hindi and other Indian
languages.


Devanagari is what's used for Hindi and a handful of other languages, yes,  
but most Indian languages (Gujarati, Punjabi, Bengali, and Tamil just to  
name a few) use different scripts.


On Sat, 29 Aug 2009 20:07:17 -0700, Neil Hodgson  
 wrote:



Benjamin Peterson:


Like Sanskrit or Snowman language?


   Sanskrit is mostly written in Devanagari these days which is also
useful for selling things to people who speak Hindi and other Indian
languages.

   Not sure if you are referring to the ☃ snowman character or Arctic
region languages like Canadian Aboriginal syllabic writing like ᐲᐦᒑᔨᕽ
which were added to Unicode 8 years after the initial version. I'd guess
that was added from political rather than marketing motives. ☃ was
required since it was present in Japanese character sets.

   Neil




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: executable path finding

2009-08-31 Thread koranthala
On Aug 31, 9:07 pm, "Diez B. Roggisch"  wrote:
> koranthala wrote:
> > Hi,
> >     I am creating a python application using py2exe. I am facing a
> > problem which I am not sure how to solve.
> >     The application contains many other files associated with it -
> > like icons, config files etc. The executable can be in any directory.
> > If the user creates a shortcut to the executable to run in desktop,
> > the program fails - saying that the icon image cannot be found. But I
> > can run the application properly, if I run it from application
> > directory - where all the other icons, config files etc are kept.
> >     How is such issues usually solved? I do not want to hardcode the
> > paths of icons and store the icons in those paths. I guess, we can
> > change the directory to the application directory before running the
> > application. (in __init__.py ???) But how do we find the current
> > directory in that case? I am completely at sea in solving this.
> >     This looks to be a very common issue. How is this usually solved?
>
> You can get the location of a module via
>
>  module.__file__
>
> This can be used to find a file relative to e.g. the toplevel module/package
> of your application.
>
> The pkg_resources-module of setuptools encapsulates that even into a stream
> and file-name api.
>
> Diez

Thank you Diez. It was what I was looking for.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: rcond in numpy :

2009-08-31 Thread Robert Kern

On 2009-08-31 04:02 AM, Pierre wrote:


Hello,

Anyone knows the numpy equivalent of the matlab function : rcond
(Matrix reciprocal condition number estimate) ?


You will want to ask numpy questions on the numpy mailing list:

  http://www.scipy.org/Mailing_Lists

numpy.linalg.cond() will give you the condition number of the matrix. Invert it 
to get the reciprocal.


--
Robert Kern

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

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


Re: Efficient way to sum a product of numbers...

2009-08-31 Thread vsoler
On Aug 31, 6:30 pm, Tim Chase  wrote:
> > After simplifying my problem, I can say that I want to get the sum of
> > the product of two culumns:
>
> > Say
> >          m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
>
> assuming you meant ['c', 3] here...    ^>          r={'a':4, 'b':5, 'c':6}
>
> > What I need is the calculation
>
> >          1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26
>
> and you mean "3*6" here instead of "3*4", which is 18 instead of
> 12, making the whole sum 4+10+18=32
>
> Then it sounds like you could do something like
>
>   result = sum(v * r[k] for k,v in m)
>
> where "m" is any arbitrary iterable of tuples.  If the keys (the
> letters) aren't guaranteed to be in "r", then you can use
> defaults (in this case "0", but could just as likely be "1"
> depending on your intent):
>
>   result = sum(v * r.get(k,0) for k,v in m)
>
> If the conditions above don't hold, you'll have to introduce me
> to your new math. ;-)
>
> -tkc

Hello Tim,

There is no mistake in my original post, so I really meant [ 'a', 3]

Imagine that m contains time sheets of suppliers

   supplier 'a' has worked for you 1 hour
   supplier 'b' has worked for you 2 hour
   supplier 'a' has worked for you 3 hour

Now

   supplier 'a' charges $4 per hour
   supplier 'b' charges $5 per hour
   supplier 'c' charges $6 per hour

I want to know how much I will be charged this month by my pannel of
suppliers.

   1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26

This is what I am after.
I expect all my suppliers to have handed me in advance the per hour
fee. If at least one hasn't, I must know that the result is undefined.

Hope this helps


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


Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Tim Chase

vsoler wrote:

On Aug 31, 6:30 pm, Tim Chase  wrote:

After simplifying my problem, I can say that I want to get the sum of
the product of two culumns:
Say
 m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]

assuming you meant ['c', 3] here...^>  r={'a':4, 'b':5, 'c':6}


What I need is the calculation
 1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26

and you mean "3*6" here instead of "3*4", which is 18 instead of
12, making the whole sum 4+10+18=32

Then it sounds like you could do something like

  result = sum(v * r[k] for k,v in m)

where "m" is any arbitrary iterable of tuples.  If the keys (the
letters) aren't guaranteed to be in "r", then you can use
defaults (in this case "0", but could just as likely be "1"
depending on your intent):

  result = sum(v * r.get(k,0) for k,v in m)

If the conditions above don't hold, you'll have to introduce me
to your new math. ;-)



There is no mistake in my original post, so I really meant [ 'a', 3]


Ah...that makes more sense of the data.  My answer still holds 
then.  Use the r[k] version instead of the r.get(...) version, 
and it will throw an exception if the rate doesn't exist in your 
mapping.  (a KeyError if you want to catch it)


-tkc


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


Re: An assessment of Tkinter and IDLE

2009-08-31 Thread r
Kevin and Terry,


Kevin.
I respectfully disagree that the site is ready for prime time
*However* i do not wish to undermine the great work that Mark Roseman
has done here and i thank him for his contribution. He has put much
work into covering all the major languages and i think this site
*could* turn out to be the best one-stop-shop for Tk coding no matter
what language you come use. And Actually of all the sites that i know
of, his is by far the most professional/modern looking of all!

My only beef with Mark's site is lack of detailed information OR a
reference manual of sorts in the Python language. We have too many
places around the net one must go to get this information when
starting the road to Tkinter.

The Effbot site is great with much detail but is not a good reference.
John's NMT site is a great reference but lacks the extensive tutorial
style details of effbot. Mark's site is the shiny new corvette,
however the engine is on back order?

We need to compile this info into one beautiful orgy of Tkinter
learning material. Here are the three sites that i mentioned above,
they would compress well into one...

http://effbot.org/tkinterbook/
http://infohost.nmt.edu/tcc/help/pubs/tkinter/
http://www.tkdocs.com/


[TERRY SAID..]
While I hadn't used it before, I think Tkinter may very well be the
nicest interface to Tk next to Tcl's (for which Tk was originally
designed of course, so you'd expect a bit of an advantage). For people
unfamiliar with either language, I think Python's more conventional
use of parentheses for functions, the "option=value" syntax, plus
other
language features it takes advantage of are very attractive and win
out over Tcl.
[/TERRY]

Well put Terry! I could not agree more with this assessment! Pythons
wrapping of Tk is so beautiful next to the other languages i can bet a
lot of Ruby, Tcl, and Perl guys are going to feel like ugly ducklings
at a Ms america pageant! (but i may be partial to Python code... just
a little)  ;-)

When it comes to using Tkinter I think a lot of people let ego get in
the way. Yes the name may sound synonymous with "Tinker Toys" however,
TEE-KAY-ENTER is a great (albeit simple) GUI toolkit. I use it quite
often and reach for the power of wx only when i need the extra
functionality -- which the gap is starting to close. Anyhow, welcome
to Tkinter Terry, i only wished you would had dropped by
sooner...??? :)

psst: maybe you can use your influence and convince others that Tk is
not so bad?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is behavior of += intentional for int?

2009-08-31 Thread Carl Banks
On Aug 31, 10:21 am, zaur  wrote:
> On 29 авг, 16:45, zaur  wrote:
>
>
>
>
>
> > Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
> > [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
> > Type "copyright", "credits" or "license()" for more information.>>> a=1
> > >>> x=[a]
> > >>> id(a)==id(x[0])
> > True
> > >>> a+=1
> > >>> a
> > 2
> > >>> x[0]
>
> > 1
>
> > I thought that += should only change the value of the int object. But
> > += create new.
> > Is this intentional?
>
> As a result of this debate is not whether we should conclude that
> there should be two types of integers in python: 1) immutable numbers,
> which behave as constant value; 2) mutable numbers, which behave as
> variable value?

You are free to use third-party modules (such as numpy) which provide
mutable numbers.

I see no reason to include any mutable number type standard library,
as not many people will require the performance benefits and/or
indirection of mutable numbers, and those who do are free to use third-
party modules that provide them.


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


Re: IDE for Python

2009-08-31 Thread Chris Colbert
I'm a big fan of wing. Pay for the non-free version and you get all
the goodies, plus PHENOMENAL support. Really. They answer support
emails within a few minutes.

Its has the best code completion i've seen in any python editor/ide
and is also the most stable, fastest (for ide's), and customizable.

I am not affiliated with Wingware or their parent company in any way.


On Mon, Aug 31, 2009 at 11:32 AM, Che M wrote:
> On Aug 31, 10:53 am, Mike Driscoll  wrote:
>> On Aug 29, 1:08špm, [email protected] wrote:
>>
>> > 29.08.2009 4:14 ÐÏÌØÚÏ×ÁÔÅÌØ "Thangappan.M"  š
>> > ÎÁÐÉÓÁÌ:
>>
>> > > Dear all,
>> > > Please suggest some good IDE for python.I am working in linux platform.
>> > > --
>> > > Regards,
>> > > Thangappan.M
>>
>> > You can use Eclipse + PyDev or Emacs+PythonMode . Also there are Anjuta 
>> > and š
>> > Code:Blocks, but they are designed mainly for C++ (but still can be used).
>>
>> Don't forget Wingware IDE. Admittedly, it's not free (except for a
>> limited version), but it's pretty good. There's also SPE (Stani's
>> Python Editor). If you want a nigh-complete list, check the Python
>> wiki:
>>
>> http://wiki.python.org/moin/PythonEditors
>
> Not sure when an editor gets to be called an IDE, but while on the
> site
> that OP should check out this related page:
>
> http://wiki.python.org/moin/IntegratedDevelopmentEnvironments
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Paul Rubin
vsoler  writes:
>  m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
>  r={'a':4, 'b':5, 'c':6}
> 
> What I need is the calculation
> 
>  1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26

sum(r[k]*w for k,w in m)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient way to sum a product of numbers...

2009-08-31 Thread vsoler
On Aug 31, 6:59 pm, Tim Chase  wrote:
> vsoler wrote:
> > On Aug 31, 6:30 pm, Tim Chase  wrote:
> >>> After simplifying my problem, I can say that I want to get the sum of
> >>> the product of two culumns:
> >>> Say
> >>>          m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
> >> assuming you meant ['c', 3] here...    ^>          r={'a':4, 'b':5, 'c':6}
>
> >>> What I need is the calculation
> >>>          1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26
> >> and you mean "3*6" here instead of "3*4", which is 18 instead of
> >> 12, making the whole sum 4+10+18=32
>
> >> Then it sounds like you could do something like
>
> >>   result = sum(v * r[k] for k,v in m)
>
> >> where "m" is any arbitrary iterable of tuples.  If the keys (the
> >> letters) aren't guaranteed to be in "r", then you can use
> >> defaults (in this case "0", but could just as likely be "1"
> >> depending on your intent):
>
> >>   result = sum(v * r.get(k,0) for k,v in m)
>
> >> If the conditions above don't hold, you'll have to introduce me
> >> to your new math. ;-)
> > There is no mistake in my original post, so I really meant [ 'a', 3]
>
> Ah...that makes more sense of the data.  My answer still holds
> then.  Use the r[k] version instead of the r.get(...) version,
> and it will throw an exception if the rate doesn't exist in your
> mapping.  (a KeyError if you want to catch it)
>
> -tkc

It works!!!

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


Re: Is behavior of += intentional for int?

2009-08-31 Thread zaur
On 29 авг, 16:45, zaur  wrote:
> Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
> [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
> Type "copyright", "credits" or "license()" for more information.>>> a=1
> >>> x=[a]
> >>> id(a)==id(x[0])
> True
> >>> a+=1
> >>> a
> 2
> >>> x[0]
>
> 1
>
> I thought that += should only change the value of the int object. But
> += create new.
> Is this intentional?

As a result of this debate is not whether we should conclude that
there should be two types of integers in python: 1) immutable numbers,
which behave as constant value; 2) mutable numbers, which behave as
variable value?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Logging contents of IRC channel

2009-08-31 Thread Paul Rubin
devaru  writes:
> I am new to Python. I want to log the activities in an IRC channel.
> Any pointers regarding this would be of great help.

http://science.slashdot.org/science/04/04/13/1356216.shtml
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An assessment of Tkinter and IDLE

2009-08-31 Thread r
On Aug 28, 11:12 am, Mark Roseman  wrote:
> Would it be useful to link to this from the main Python Tkinter
> documentation?
>
> Mark

Sorry Mark,
i did not realize when i replied to you that YOU are the Mark of
tkdoc.com. For some reason i only saw Tcl code when i visted the site,
and that prompted my slightly grumpy rant. After looking a second time
(and actually reading more) i see this site has much promise. I hope
my post did not seem condescending of your efforts. I think your site
is beautiful and just wish we could add MORE Python specific info to
it like i covered in my last post. And also I would like to see a
complete coverage of all the widgets.

We more experienced guys already know how and where to find the
thousand or so sites for this or that Python info, but the new users
are going to be lost in the wilderness. I love that Python has so much
info out there, i just hate that is so spread out! We must do
something about this in a way that all doc/tut creators can be happy.

PS: and i would like to contribute to your site.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: find free hard disk space remote windows host

2009-08-31 Thread Tim Golden

Daniel wrote:

Hello,

I'm trying to determine the amount of free hard disk space on a remote
windows host.  Seems like this should be simple, but it's giving me
grief.  Here's what I've tried:


mystat = os.stat('//remotehost/share/')
mystat

(16895, 0L, 0, 0, 0, 0, 0L, 1251731920, 1251731289, 1249399952)


Assuming you have the necessary security levels,
WMI's quite good at this kind of thing. See this
example:

 http://timgolden.me.uk/python/wmi_cookbook.html#percentage_free

and just add "remotehost" as the first parameter to the
wmi.WMI () call. (And I recommend find_classes=False) for
speed.

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


Re: Logging contents of IRC channel

2009-08-31 Thread Jonathan Gardner
On Aug 31, 10:23 am, devaru  wrote:
> I am new to Python. I want to log the activities in an IRC channel.
> Any pointers regarding this would be of great help.

How are you going to plug into the chat server to obtain the data?

How will you store the data?

The in between parts are really easy.
-- 
http://mail.python.org/mailman/listinfo/python-list


win32ui DLL Load Failed

2009-08-31 Thread MikeC
I have a python executable that's failing to load on a user's machine
running Windows XP. My developer machine is also running Windows XP. I
have determined that it is failing when it attempts to load win32ui.

I have Python 2.6 on my developer machine and am using the pywin
support (Mark Hammonds???) for Python 2.6.

In order to make the problem smaller and more managable I created an
executable (with pytoexe) of a 1 one-line python script which does the
following:

import win32ui

Running the one-line script on my machine from python source as well
as from the executable created from the one-line source works fine on
my machine. But when I attempt to run the executable on a target
Windows/XP user machine (without Python) it fails with the following
traceback

Traceback (most recent call last):
  File "CheckScan.py", line 7, in 
  File "PrintImage.pyc", line 1, in 
  File "win32ui.pyc", line 12, in 
  File "win32ui.pyc", line 10, in __load
ImportError: DLL load failed: This application has failed to start
because the application configuration is incorrect. Reinstalling the
application may fix this problem.

The only thing I can think of regarding the difference between my
machine and the target machine is that I have the .NET framework on my
machine. Is it possible that that is the problem? Running Depends
didn't get me anywhere. I would appreciate any help you can offer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Unexpected 411 error response using httplib

2009-08-31 Thread John Gordon
I'm writing some code that queries a Microsoft Exchange Web Services server.
The server is responding with a 411 Length Required error, which is strange
because I am definitely sending a Content-Length header.

Here's the code:

-
import httplib
import base64

SoapMessage = """\

http://schemas.xmlsoap.org/soap/envelope/";
   
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types";>
  
http://schemas.microsoft.com/exchange/services/2006/messages";
  
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types";
  Traversal="Shallow">
  
Default

  
  
  

  
  

  

  
\
"""

host = "some.host.com"

username = "myUsername"
password = "myPassword"
auth = base64.encodestring(username + ":" + password)

conn = httplib.HTTPSConnection(host)
conn.set_debuglevel(5)
conn.putrequest("POST", "/EWS/Exchange.asmx")
conn.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
conn.putheader("Proxy-Authorization", "Basic %s" % auth)
conn.putheader("Content-Length", "%d" % len(SoapMessage))
conn.putheader("User-Agent", "Python post")
conn.endheaders()
conn.send(SoapMessage)

resp = conn.getresponse()

body= resp.read()
headers = resp.msg
version = resp.version
status  = resp.status
reason  = resp.reason

conn.close()

print "Response: ", status, reason
print "Headers: ", headers
print body
-

As you can see, I am including the call to putheader() for Content-Length,
and the debugging output confirms that the header is present in the outgoing
message.

So why am I getting a 411 Length Required error?

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: An assessment of the Unicode standard

2009-08-31 Thread Emile van Sebille

On 8/31/2009 10:41 AM Dennis Lee Bieber said...

On Mon, 31 Aug 2009 15:36:46 +0100, Nigel Rantor 


Also, I'm surprised no-one has mentioned Esperanto yet. Sounds like 
something r and Xah would *love*.



Hmmm, thought I had mentioned Esperanto (and Klingon)


Just curious -- has anyone mentioned autocoding?  :)

Emile

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


pyjamas in action?

2009-08-31 Thread kj



At work we want to implement a webapp using Google's GWT, and we're
debating whether to use the standard GWT approach with Java, or to
try Pyjamas.  There's no great love here for Java, but there's the
concern that Pyjamas will not be able to deliver the full power
and/or convenience of standard Java-based GWT.  (Why-oh-why did
Google pick Java for this?  Couldn't Guido twist some arms?  Just
kidding.)

Are there any examples of real production websites implemented with
Pyjamas?

TIA!

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


Re: win32ui DLL Load Failed

2009-08-31 Thread Mike Driscoll
On Aug 31, 2:43 pm, MikeC  wrote:
> I have a python executable that's failing to load on a user's machine
> running Windows XP. My developer machine is also running Windows XP. I
> have determined that it is failing when it attempts to load win32ui.
>
> I have Python 2.6 on my developer machine and am using the pywin
> support (Mark Hammonds???) for Python 2.6.
>
> In order to make the problem smaller and more managable I created an
> executable (with pytoexe) of a 1 one-line python script which does the
> following:
>
> import win32ui
>
> Running the one-line script on my machine from python source as well
> as from the executable created from the one-line source works fine on
> my machine. But when I attempt to run the executable on a target
> Windows/XP user machine (without Python) it fails with the following
> traceback
>
> Traceback (most recent call last):
>   File "CheckScan.py", line 7, in 
>   File "PrintImage.pyc", line 1, in 
>   File "win32ui.pyc", line 12, in 
>   File "win32ui.pyc", line 10, in __load
> ImportError: DLL load failed: This application has failed to start
> because the application configuration is incorrect. Reinstalling the
> application may fix this problem.
>
> The only thing I can think of regarding the difference between my
> machine and the target machine is that I have the .NET framework on my
> machine. Is it possible that that is the problem? Running Depends
> didn't get me anywhere. I would appreciate any help you can offer.

Did you install PyWin32? If so, which version? Here's a link:

http://sourceforge.net/projects/pywin32/

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


Re: win32ui DLL Load Failed

2009-08-31 Thread Chris Kaynor
You likely need to install the Microsoft Visual C++ 2008 SP1 Redistributable
Package on the target machine. If you search Google for this, you should
find it (make sure to grab the correct version of x86 or x64 depending upon
the Python version).


Chris


On Mon, Aug 31, 2009 at 12:43 PM, MikeC  wrote:

> I have a python executable that's failing to load on a user's machine
> running Windows XP. My developer machine is also running Windows XP. I
> have determined that it is failing when it attempts to load win32ui.
>
> I have Python 2.6 on my developer machine and am using the pywin
> support (Mark Hammonds???) for Python 2.6.
>
> In order to make the problem smaller and more managable I created an
> executable (with pytoexe) of a 1 one-line python script which does the
> following:
>
> import win32ui
>
> Running the one-line script on my machine from python source as well
> as from the executable created from the one-line source works fine on
> my machine. But when I attempt to run the executable on a target
> Windows/XP user machine (without Python) it fails with the following
> traceback
>
> Traceback (most recent call last):
>  File "CheckScan.py", line 7, in 
>  File "PrintImage.pyc", line 1, in 
>  File "win32ui.pyc", line 12, in 
>  File "win32ui.pyc", line 10, in __load
> ImportError: DLL load failed: This application has failed to start
> because the application configuration is incorrect. Reinstalling the
> application may fix this problem.
>
> The only thing I can think of regarding the difference between my
> machine and the target machine is that I have the .NET framework on my
> machine. Is it possible that that is the problem? Running Depends
> didn't get me anywhere. I would appreciate any help you can offer.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: map

2009-08-31 Thread Nobody
On Sun, 30 Aug 2009 21:55:52 -0700, elsa wrote:

> say I have a list, myList. Now say I have a function with more than
> one argument:
> 
> myFunc(a, b='None')
> 
> now, say I want to map myFunc onto myList, with always the same
> argument for b, but iterating over a:
> 
> map(myFunc(b='booHoo'), myList)
> 
> Why doesn't this work?

You're passing the result of (incorrectly) calling myFunc to map(), but
you need to pass a function.

> is there a way to make it work?

If you need to construct a simple function on-the-fly, you can use a
lambda form:

map(lambda x: myFunc(x, b='booHoo'), myList)

Or you could use a list comprehension:

[myFunc(x, b='booHoo') for x in myList]

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


Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Jan Kaliszewski

31-08-2009 o 18:19:28 vsoler  wrote:


Say
 m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]]
 r={'a':4, 'b':5, 'c':6}

What I need is the calculation

 1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26

That is, for each row list in variable 'm' look for its first element
in variable 'r' and multiply the value found by the second element in
row 'm'. After that, sum all the products.

What's an efficient way to do it? I have thousands of these
calculations to make on a big data file.



31-08-2009 o 18:30:27 Tim Chase  wrote:


  result = sum(v * r[k] for k,v in m)



You can also check if this isn't more efficient:

  from itertools import starmap
  from operator import mul

  result = sum(starmap(mul, ((r[name], hour) for name, hour in m)))


Or, if you had m in form of two lists:

  names = ['a', 'b', 'a']
  hours = [1, 2, 3]

...then you could do:

  from itertools import imap as map  # <- remove if you use Py3.x
  from operator import mul

  result = sum(map(mul, map(r.__getitem__, names), hours))


Cheers,
*j

PS. I've done a quick test on my computer (Pentium 4, 2.4Ghz, Linux):

setup = "from itertools import starmap, imap ; from operator import  
mul; import random, string; names =  
[rndom.choice(string.ascii_letters) for x in xrange(1)]; hours =  
[random.randint(1, 12) for x in xrange(1000)]; m = zip(names, hours);  
workers = set(names); r = dict(zip(workers, (random.randint(1, 10) for  
x in xrange(en(workers)"

tests = (

... 'sum(v * r[k] for k,v in m)',
... 'sum(starmap(mul, ((r[name], hour) for name, hour in m)))',
... 'sum(imap(mul, imap(r.__getitem__, names), hours))',
... )

for t in tests:

... print t
... timeit.repeat(t, setup, number=1000)
... print
...
sum(v * r[k] for k,v in m)
[6.2493009567260742, 6.1892399787902832, 6.2634339332580566]

sum(starmap(mul, ((r[name], hour) for name, hour in m)))
[9.3293819427490234, 10.280816078186035, 9.2766909599304199]

sum(imap(mul, imap(r.__getitem__, names), hours))
[5.7341709136962891, 5.5898380279541016, 5.7318859100341797]


--
Jan Kaliszewski (zuo) 
--
http://mail.python.org/mailman/listinfo/python-list


Re: pyjamas in action?

2009-08-31 Thread André
On Aug 31, 4:46 pm, kj  wrote:
> At work we want to implement a webapp using Google's GWT, and we're
> debating whether to use the standard GWT approach with Java, or to
> try Pyjamas.  There's no great love here for Java, but there's the
> concern that Pyjamas will not be able to deliver the full power
> and/or convenience of standard Java-based GWT.  (Why-oh-why did
> Google pick Java for this?  Couldn't Guido twist some arms?  Just
> kidding.)
>
> Are there any examples of real production websites implemented with
> Pyjamas?
>
> TIA!
>
> kynn

Perhaps you might get answers faster if you posted to the pyjamas
group: http://groups.google.com/group/pyjamas-dev

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


Re: win32ui DLL Load Failed

2009-08-31 Thread MikeC
On Aug 31, 12:43 pm, MikeC  wrote:
> I have a python executable that's failing to load on a user's machine
> running Windows XP. My developer machine is also running Windows XP. I
> have determined that it is failing when it attempts to load win32ui.
>
> I have Python 2.6 on my developer machine and am using the pywin
> support (Mark Hammonds???) for Python 2.6.
>
> In order to make the problem smaller and more managable I created an
> executable (with pytoexe) of a 1 one-line python script which does the
> following:
>
> import win32ui
>
> Running the one-line script on my machine from python source as well
> as from the executable created from the one-line source works fine on
> my machine. But when I attempt to run the executable on a target
> Windows/XP user machine (without Python) it fails with the following
> traceback
>
> Traceback (most recent call last):
>   File "CheckScan.py", line 7, in 
>   File "PrintImage.pyc", line 1, in 
>   File "win32ui.pyc", line 12, in 
>   File "win32ui.pyc", line 10, in __load
> ImportError: DLL load failed: This application has failed to start
> because the application configuration is incorrect. Reinstalling the
> application may fix this problem.
>
> The only thing I can think of regarding the difference between my
> machine and the target machine is that I have the .NET framework on my
> machine. Is it possible that that is the problem? Running Depends
> didn't get me anywhere. I would appreciate any help you can offer.

I assume you're asking about my development machine. Yes I have it
installed. When I bring up PythonWin.exe, here is what is displayed at
the top of the main dialog.

PythonWin 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit
(Intel)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin'
for further copyright information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Jan Kaliszewski

31-08-2009 o 22:28:56 Jan Kaliszewski  wrote:


>>> setup = "from itertools import starmap, imap ; from operator
import mul; import random, string; names = [rndom.choice(string.
ascii_letters) for x in xrange(1)]; hours = [random.randint(
1, 12) for x in xrange(1000)]; m = zip(names, hours); workers = 
set(names); r = dict(zip(workers, (random.randint(1, 10) for x i

n xrange(en(workers)"


Erratum -- should be:

  >>> setup = (
  ... 'from itertools import starmap, imap;'
  ... 'from operator import mul;'
  ... 'import random, string; names'
  ... ' = [random.choice(string.ascii_letters)'
  ... 'for x in xrange(1)];'
  ... 'hours = [random.randint(1, 12)'
  ...   for x in xrange(1)];'
  ... 'm = zip(names, hours);'
  ... 'workers = set(names);'
  ... 'r = dict(zip(workers, (random.randint(1, 10)'
  ... '   for x in xrange(len(workers)'
  ... )

--
Jan Kaliszewski (zuo) 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Object Reference question

2009-08-31 Thread Ethan Furman

josef wrote:

On Aug 27, 1:35 pm, Ethan Furman  wrote:


josef wrote:


Thanks to everyone who responded.



I will be going with some sort of a = MyClass(name = 'a') format. It's
the Python way.



For me, it was very hard to accept that EVERYTHING is an object
reference. And that there are no object reference names, just string
entries in dictionaries. But I think it all makes sense now.



Thanks again,



Josef


My apologies if I missed it, but what *exactly* are you planning on
doing with your 'name' attribute?  From the posts I've seen so far, I
think you are only setting yourself up for failure.

~Ethan~



I'm going to use it for printing purposes. dk = MyClass(name='dk')
When I need a name dk.name. There will only ever be one dk defined.

Does that read like I'm setting myself up for failure?


I was hoping someone with more expertise than myself would answer that. 
 :)  Oh well.


The best answer I can give is that you do not want to use 'name' to 
reference the object itself, but only for printing/debugging purposes. 
'name' is just a label for your object, and not necessarily the only 
label;  that particular label may also be lost... Consider:


In [5]: class MyClass(object):
   ...: def __init__(self, name):
   ...: self.name = name
   ...: def __repr__(self):
   ...: return "MyClass(name='%s')" % self.name
   ...:

In [6]: dk = MyClass(name='dk')

In [7]: dk
Out[7]: MyClass(name='dk')

In [8]: se = dk

In [9]: del dk

In [10]: se
Out[10]: MyClass(name='dk')

In [11]: dk
---
NameError Traceback (most recent call last)

C:\pythonlib\ in ()

NameError: name 'dk' is not defined

As you can see, just because you have saved the original name does not 
gaurantee that same name will always reference that same object, or any 
object.


Hope this helps!

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


Re: lambda functions

2009-08-31 Thread Rhodri James
On Mon, 31 Aug 2009 08:41:57 +0100, Pierre   
wrote:



Hello,

I would like to know if it is possible to define a loop in a lambda
function

How to manage the indents ? Example :
s_minus_1 = lambda s : for index in range(0, len(s)) : s[index] = s
[index]-1


You can't use commands in a lambda function, only expressions.  The nearest
thing I can think of to what you want here is to use a list comprehension:

  s_minus_1 = lambda s : [i-1 for i in s]
  my_list = s_minus_1(my_list)

On the other hand, giving a name to an anonymous function rather defeats
the point of it being an *anonymous* function!  What are you actually
trying to do here?  There's almost certainly a better way to do it than
this.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Python installation

2009-08-31 Thread Vo, Trinh (388C)
Hello Python Users,

I am new to Python.  I have errors message when I installed Python.  I 
appreciate if you can help.

I download Python-2.6-2.  I then did the following steps:
./configure
make

In the second step "make", I had the following message:


Failed to find the necessary bits to build these modules:
_bsddb _curses_curses_panel
_hashlib   _sqlite3   _ssl
_tkinter   bsddb185   bz2
dbmdl gdbm
imageopreadline   sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the 
module's name.
I however still saw the binary python was installed in /usr/local/Python-2.6.2. 
 I tested, and it till run OK.  However, I am worried if the above message can 
cause any problem in  the future.  I have on my cluster:
X86_64
GCC version 4.1.2  (Red Hat 4.1.2-42)

Thank you,

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


Re: Python installation

2009-08-31 Thread Benjamin Kaplan
On Mon, Aug 31, 2009 at 9:32 PM, Vo, Trinh (388C) wrote:
> Hello Python Users,
>
>
>
> I am new to Python.  I have errors message when I installed Python.  I
> appreciate if you can help.
>
>
>
> I download Python-2.6-2.  I then did the following steps:
>
> ./configure
>
> make
>
>
>
> In the second step “make”, I had the following message:
>
>
>
>
>
> Failed to find the necessary bits to build these modules:
>
> _bsddb _curses    _curses_panel
>
> _hashlib   _sqlite3   _ssl
>
> _tkinter   bsddb185   bz2
>
> dbm    dl gdbm
>
> imageop    readline   sunaudiodev
>
> To find the necessary bits, look in setup.py in detect_modules() for the
> module's name.
>
> I however still saw the binary python was installed in
> /usr/local/Python-2.6.2.  I tested, and it till run OK.  However, I am
> worried if the above message can cause any problem in  the future.  I have
> on my cluster:
>
> X86_64
>
> GCC version 4.1.2  (Red Hat 4.1.2-42)
>
It's only a problem if you want to use those modules. Personally, I
would rebuild it with some more of those (just install those libraries
and the dev versions if red hat keeps them separate) but Python can
run fine without them.

>
>
> Thank you,
>
>
>
> Trinh Vo
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An assessment of the Unicode standard

2009-08-31 Thread Byung-Hee HWANG
Nigel Rantor  writes:

> Hendrik van Rooyen wrote:
>> On Sunday 30 August 2009 22:46:49 Dennis Lee Bieber wrote:
>>
>>> Rather elitist viewpoint... Why don't we just drop nukes on some 60%
>>> of populated landmasses that don't have a "western" culture and avoid
>>> the whole problem?
>>
>> Now yer talking, boyo!  It will surely help with the basic problem
>> which is the heavy infestation of people on the planet!
>> :-)
>
> 
> On two conditions:
>
> 1) We drop some "test" bombs on Slough to satisfy Betjeman.
>
> 2) We strap both Xah and r to aforementioned bombs.
> 
>
> 
> Also, I'm surprised no-one has mentioned Esperanto yet. Sounds like
> something r and Xah would *love*.
>
> Slightly off-topic - does anyone have a good recipe for getting
> thunderbird to kill whole threads for good? Either based on a rule or
> just some extension I can use?
>
> The Xah/r threads are like car crashes, I can't help but watch but my
> time could be better spent and I don't want to unsub the whole list.
> 

Please do not insult Xah. He spoke nothing in this threads. 

-- 
"After the divorce I gave Ginny and the kids more than the courts said I 
should."
-- Johnny Fontane, "Chapter 1", page 36
-- 
http://mail.python.org/mailman/listinfo/python-list


Executing python script stored as a string

2009-08-31 Thread Ecir Hana
Hello,

please, how to execute a python script stored as a string? But let me
impose several limitations, so simple "exec" wont work:

- if I understood it correctly defining a function in the string and
exec-ing it created the function in current scope. This is something I
really don't want

- simple exec also blocks the rest of the program

- I also would like the string to be able to use and return some parts
of the caller

So to give an example what I try to achieve:

result = []
def up(s):
  result.append(s.upper())

code = '''
up("abc")
print 'hello'
i = i + 3
def x(s):
  up(s)
x('def')
print i
'''

somehow_execute(code)

Couple of points:

- the script in string should behave just like any other ordinary
python script executed in separate process, except it should also know
about a function caller "up". Nothing else. (I read that something
similar is possible while embedding python into your C project - that
you could invoke the VM and provide some default "imports")

- if the other script runs in separate process how should it call the
remote function? And how to pass its arguments? I really hope I don't
have to serialize every communication, maybe I should use threading
instead of process? All I want is that running it wont block the
caller and that it cannot modify callers code/variables/scope (apart
from calling the predefined callers' functions). Or maybe even better,
let it block the caller but provide a way to stop its execution?

- how to know that the script finished? I was thinking about atexit()
- could it work here?

Think of it as a text editor with a special ability to execute its
content, while providing access of some of its functionality to the
script.

The reason I *think* I cannot just simple import the "editor" module
into the script is that the"editor" is GUI application and script
should have access to just this instance of editor.

Anyway, I hope I was not too confusing. Thanks for any help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is behavior of += intentional for int?

2009-08-31 Thread Steven D'Aprano
On Mon, 31 Aug 2009 10:21:22 -0700, zaur wrote:

> As a result of this debate is not whether we should conclude that there
> should be two types of integers in python: 1) immutable numbers, which
> behave as constant value; 2) mutable numbers, which behave as variable
> value?

What can you do with mutable numbers that you can't do with immutable 
ones, and why do you want to do it?



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


Re: a popen question. Please help

2009-08-31 Thread Aahz
In article ,
Tim Chase   wrote:
>
>Darn "standards" :-/

The wonderful thing about standards is that there are so many to choose
from.
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"I support family values -- Addams family values" --www.nancybuttons.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Overriding iadd for dictionary like objects

2009-08-31 Thread Aahz
In article ,
RunThePun   wrote:
>On Aug 30, 10:33=A0pm, [email protected] (Aahz) wrote:
>> In article .com>,
>> RunThePun =A0 wrote:
>>>
>>>I made a DictMixin where the keys are filenames and the values are the
>>>file contents. It was very simple and easy to do thanks to DictMixin.
>>>
>>>For example this code writes "abc" in a file named "temp.txt" and
>>>prints the contents of the file named "swallow", these files are
>>>looked up/created/deleted in the directory "spam":
>> d =3D3D FilesDict('spam')
>> d['temp.txt'] =3D3D 'abc'
>> print(d['swallow'])
>>>
>>>My problem arose when I wanted to append a string to a file which
>>>using open(..., 'ab') would have been miles more efficient because I
>>>wouldn't have to read the entire file (__getitem__) and then write the
>>>entire file back (__setitem__). The files are expected to be as big as
>>>600 KB which will be appended 30 bytes at a time about 3 times a
>>>second. Performance-wise the system would probably work without open
>>>(..., 'ab') but it would be a real thrashing so the current solution
>>>uses a method "AddTo" as Robert suggested, sacrificing the neat
>>>getitem/setitem syntax.
>>
>> You can do mostly what you want, I think, by having __setitem__()
>> convert string values into FileProxy() objects that have an appropriate
>> __iadd__() method. =A0That brings a whole new set of problems, of course.
>
>I'm guessing you meant __getitem__, which is what Jan Kaliszewski
>suggested, but as you noted, would be a bit cumbersome in this case.

Actually, what I meant was __setitem__.  The idea is that you create the
proxy item when you add the data to the dict (wrapping the original
data), and the proxy has an __iadd__ method, which would allow you to do
the file append.
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

"I support family values -- Addams family values" --www.nancybuttons.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Return value of multiprocessing manager registerred function

2009-08-31 Thread Terry
On Aug 31, 5:58 pm, jacopo  wrote:
> Hi Terry,
> I have just started working on similar things and I am strugling to
> find examples or documentations. So far I have found only the official
> documentation of the multiprocessing package. Would you be able to
> recommend me some good reference or a book. I dont want to overwhelm
> this newsgroup with questions... yet :)
> Regards, Jacopo
>
> On Aug 26, 4:22 am, Terry  wrote:
>
>
>
> > Hi,
>
> > I'm using the multiprocessing.manager to run proceduresremotely. It
> > all worked fine except I hope to have a different return value type.
>
> > The remote function calls always return a proxy, which when I need to
> > get the value it need to connect to the manager again to fetch it. But
> > I just need the value, not the proxy.
>
> > Can I just return the value instead of a proxy from a manager?
>
> > br, Terry
Hi Jacopo,
Well, I also have had a hard time to find any examples or document
except the official document. I had to read the multiprocessing source
code (they are all in python except the network connection parts). And
I found I need to hack it a little to get it work.
You can share your questions, and maybe it's common to most of us.

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


Re: multiprocessing managers and socket connection.

2009-08-31 Thread Terry
On Aug 26, 7:25 pm, Chris  wrote:
> On Aug 25, 9:11 pm, Terry  wrote:
>
>
>
>
>
> > On Aug 25, 10:14 pm, Chris  wrote:
>
> > > I've been using multiprocessing managers and I really like the
> > > functionality.
>
> > > I have a question about reconnecting to a manager. I have a situation
> > > where I start on one machine (A) a manager that is listening and then
> > > on another machine (B) connects to that manager and uses its proxy
> > > object to call functions on the manager's computer; this all works as
> > > expected. But, if the manager from A shuts down, B's application won't
> > > notice because in the MP code it ignores socket error
> > > errno.ECONNREFUSED. If A becomes available again or is restarted, B
> > > doesn't automatically reconnect either and continue its operation.
> > > It's function is basically stopped.
>
> > > Here is the code from connection.py:
> > > while 1:
> > >         try:
> > >             s.connect(address)
> > >         except socket.error, e:
> > >             if e.args[0] != errno.ECONNREFUSED: # connection refused
> > >                 debug('failed to connect to address %s', address)
> > >                 raise
> > >             time.sleep(0.01)
> > >         else:
> > >             break
>
> > > How can I have B automatically reconnect to A and continue its work
> > > once A is available again?
>
> > I think you need to retry repeatedly until successfully connected.
>
> > br, Terry
>
> I'm having issue after once connected. If the server goes down during
> a long-running connection. I would want to be notified so I could try
> to reconnect. I'm doing more experimenting now and will try to post an
> example.

Hi Chris,

Are you sure that the proxy object keeps a permanent connection to the
server?

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


Re: Why does this group have so much spam?

2009-08-31 Thread r
On Aug 31, 2:04 pm, David <[email protected]> wrote:
(snip)
> It's a question of point of view: in italy if a thief steals a car and
> causes an accident the car's owner's assurance (having a car assurance is
> mandatory) must refund the victims. That's because protections of victims is
> first priority.
> Obviously the owner can not be charged

Is the car owner not a victim too? :). i am ok with the filthy
insurance company paying as long as the owners rates don't increase.
But why can't we force the criminal into hard labor to pay back the
lost monies? Seems like that would serve justice to all parties...

> That's a problem of the computer owner. Why should the rest of the world be
> charged of *his* problem while keeping him safe from suffering any
> consequence?

No, why should spammers feel safe while doing their crimes? I say put
the pressure on criminals, and NOT the victims. I really doubt much is
being done to fight spam now that is why it is so prevalent. Two FBI
hackers can't keep up with billions of spams.

> Madness, you say? Let's examine the situation a bit moore deeply.
>
> First, the mail-tax would is not for rebuilding the destroyed building after
> the attack but, at the opposite, to prevent the attack. Wouldn't you pay a
> small tax to prevent terrorist's attacks?

Only if that tax was given to highly trained US Marines who where
given a green light to use any and all methods to brutally kill the
enemy and make an example of him with no worry of prosecution by their
own government.

> The mail-tax would be really small, if you send 1000 mails at month (a real
> huge traffic, for a non spammer!) the bill would be about 10 cents.
> Do you really think this is too much to get rid of most of the spam?

I don't think that will stop most spammers since they must be making
more that a 10c a month profit or they would starve to death! I say
why not put a 1000.00 fine on any idiot that responds to a spam! What
about that?

> We are paying and hidden tax in terms of HW and human resources needed by
> ISPs to manage that huge (~90%) useless/malicius traffic. (I don't mention
> const related to dalays, denial of services, theft of informations...)
(...snip)

The system is definitely flawed. I am no internet expert so i don't
really know what we could do to fix it. I do fear goverment or
corporations taking over of the internet and robbing use of our
freedom of speech under the pretense that they will *somehow* save us
from the spammers. Something must be done however.

I *do* know however that M$ windows ships with its back doors wide
open and you could put a lot of blame of M$ for this stupidity! And
since their product is meant for computing morons why do they still
ship it in such a vulnerable state... complete madness!

> Finally a little criticims: spam and related malware is a problem growing
> day by day. I am proposing a solution and if somebody doest't like it, well,
> he should propose a better one. Just saying "NO!" and turning head aside
> hoping that the problem will solve by itsef is no more acceptable.
(snip)

I agree with you, we must do something...




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


Re: Executing python script stored as a string

2009-08-31 Thread Steven D'Aprano
On Mon, 31 Aug 2009 16:29:45 -0700, Ecir Hana wrote:

> Hello,
> 
> please, how to execute a python script stored as a string? But let me
> impose several limitations, so simple "exec" wont work:
> 
> - if I understood it correctly defining a function in the string and
> exec-ing it created the function in current scope. This is something I
> really don't want


You can pass in a global and local namespaces to exec as arguments:

>>> x = 4
>>> ns = {'x': 4}
>>> exec "x += 1" in ns
>>> x
4
>>> ns['x']
5


See the docs for details.


> - simple exec also blocks the rest of the program


Run it in a thread.


> - I also would like the string to be able to use and return some parts
> of the caller

You can copy the parts of the current scope into the namespace you pass 
to exec, then later copy the revised values out again.

But are you sure you really want to take this approach? exec is up to ten 
times slower than just executing the code directly. And if the string is 
coming from an untrusted source, it is a *huge* security risk.



> Couple of points:
> 
> - the script in string should behave just like any other ordinary python
> script executed in separate process, except it should also know about a
> function caller "up". Nothing else. (I read that something similar is
> possible while embedding python into your C project - that you could
> invoke the VM and provide some default "imports")

If you want it to execute in a separate *process*, that's a whole 
different question. If you do that, you get separation of code for free, 
as well as separate namespaces. My approach would be to have a special 
module "common" which subprocesses can import, to get access to the 
shared functions. You will probably need to create some sort of message 
passing infrastructure to get results out of the subprocess into the 
parent process. 


> - if the other script runs in separate process how should it call the
> remote function? And how to pass its arguments? I really hope I don't
> have to serialize every communication, maybe I should use threading
> instead of process? 

If you want separate processes, they're *separate*. Threads are not.


> All I want is that running it wont block the caller
> and that it cannot modify callers code/variables/scope (apart from
> calling the predefined callers' functions). Or maybe even better, let it
> block the caller but provide a way to stop its execution?

As far as I know, you can't kill threads, you can only ask them to kill 
themselves.


> - how to know that the script finished? I was thinking about atexit() -
> could it work here?

I doubt it. You would need to poll each thread to see if it has completed.



> Think of it as a text editor with a special ability to execute its
> content, while providing access of some of its functionality to the
> script.

Something like this?

In the text editor, you have contents:

text goes here
and more text
# Python script starts here
x = 'a'
up(x)
print "foo"
# Python script stops here
more text again


and the user selects lines 4 and 5 and chooses the command "Execute". The 
script executes, and its output (foo) is appended to the end of the file:

text goes here
and more text
# Python script starts here
x = 'a'
up(x)
print "foo"
# Python script stops here
more text again
foo

Is this what you mean?

If so, I think you are making this much too complicated for such a simple 
use-case. Just publish an API which the script can use, and have the main 
text editor application specify a "script" namespace containing only that 
API. That could be a module:

>>> import math  # pretend this is your API shared module
>>> exec "myvalue = 42" in math.__dict__
>>> math.myvalue
42



Then execute the text using exec, but don't bother about putting it into 
a thread or subprocess. That just makes it harder to implement, and you 
have to worry about concurrency issues.



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


Re: map

2009-08-31 Thread alex23
Piet van Oostrum  wrote:
> [myFunc(elt, 'booHoo') for elt in myList] is also a good candidate and
> in this case I think it is preferable to both the loop and the map with
> a partial or lambda in terms of clarity.

>From memory, a listcomp with a non-builtin function is also faster
than map with the same.

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