ANN: ActivePython 2.6.4.10 is now available

2010-02-05 Thread Sridhar Ratnakumar
I'm happy to announce that ActivePython 2.6.4.10 is now available for download 
from:

http://www.activestate.com/activepython/

This is a minor release with several updates and fixes.

Changes in 2.6.4.10
---

- PyPM is now included in 64-bit Windows and Linux builds
- Include Distribute instead of setuptools
- Include pip
- Upgrade to Tcl/Tk 8.5.8
- [Windows] Upgrade to Pywin32 CVS (2009-11-10)
- [Windows] Support for OpenSSL in 64-bit
- [Windows] Include Tcl/Tk header files 
- [Windows] Fix broken IDLE on the 64-bit build 

See the release notes for full details:

http://docs.activestate.com/activepython/2.6/relnotes.html#changes


What is ActivePython?
-

ActivePython is ActiveState's binary distribution of Python. Builds
for Windows, Mac OS X, Linux are made freely available. Builds
for Solaris, HP-UX and AIX, and access to older versions are
available with ActivePython Business Edition:

http://www.activestate.com/business_edition/

ActivePython includes the Python core and the many core extensions:
zlib and bzip2 for data compression, the Berkeley DB (bsddb) and SQLite
(sqlite3) database libraries, OpenSSL bindings for HTTPS
support, the Tix GUI widgets for Tkinter, ElementTree for XML
processing, ctypes (on supported platforms) for low-level library
access, and others. The Windows distribution ships with PyWin32 -- a
suite of Windows tools developed by Mark Hammond, including bindings
to the Win32 API and Windows COM. 

Beginning with the 2.6.3.7 release, ActivePython includes a binary package
manager for Python (PyPM) that can be used to install packages much
easily. For example:

pypm install pylons

See this page for full details:

http://docs.activestate.com/activepython/2.6/whatsincluded.html

As well, ActivePython ships with a wealth of documentation for both
new and experienced Python programmers. In addition to the core Python
docs, ActivePython includes the What's New in Python series, Dive
into Python, the Python FAQs  HOWTOs, and the Python Enhancement
Proposals (PEPs).

An online version of the docs can be found here:

http://docs.activestate.com/activepython/2.6/

We would welcome any and all feedback to:

activepython-feedb...@activestate.com

Please file bugs against ActivePython at:

http://bugs.activestate.com/query.cgi?set_product=ActivePython


On what platforms does ActivePython run?


ActivePython includes installers for the following platforms:

- Windows/x86
- Windows/x64 (aka AMD64)
- Mac OS X
- Linux/x86
- Linux/x86_64 (aka AMD64)
- Solaris/SPARC (Business Edition only)
- Solaris/x86 (Business Edition only)
- HP-UX/PA-RISC (Business Edition only)
- AIX/PowerPC (Business Edition only)
- AIX/PowerPC 64-bit (Business Edition only)

Custom builds are available in Enterprise Edition:

http://www.activestate.com/activepython/enterprise/

Thanks, and enjoy!

The Python Team

--
Sridhar Ratnakumar
sridharr at activestate.com
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


pyclutter anyone?

2010-02-05 Thread donn
Hi, this is a little bit of a cross-post. I posted to the clutter list, 
but there's little activity there.


I am trying to make sense of pyClutter 1.0. Could anyone point me to an
example (or post one) that shows clipping from a path applied to child
objects?

For example: A star shape that contains a bunch of moving rectangles
which will travel/size/rotate with the star, but are clipped to the
shape of the star.

I suspect this will involve a custom clutter.Group class of some kind,
with cogl paths and an on_paint() method, but I can find no headway on
the web so far.

Hope someone can help!
\d

--
Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software

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


C:\Python25\Lib\IDLELIB\idle.pyw won't start

2010-02-05 Thread Anthra Norell

Hi,

  I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle window.

This is the command I have been using:
  C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c 
execfile('C:\\Python24\\i')


And this is the command that doesn't start anything:
  C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c 
execfile('C:\\Python25\\i')


The command is exactly the same with the digit 5 in the place of 4. All 
paths and names are correct. C:\\Python25\\i sets up sys.path but seems 
irrelevant, as taking the execfile () part out doesn't change anything. 
The OS is Windows ME. The download of 2.5 finished with a warning saying 
that 2.5 was the highest version for Windows 9* Any tips?


Thanks

Frederic







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


Re: Common area of circles

2010-02-05 Thread Shashwat Anand
Here is my approach:
# input circles, remove duplicates, store them
# check whether all circle intersect:
if no: print '0.0'
if yes:
# calculate intersection points of two circles.
# check if that point lies in rest all circles
if yes: store it as polygon-coordinates (hull)
calculate area of curve from the given two points
# calculate final area : net area of curve + area of polygon
Here is my final code :
It's still Buggy (the logic I believe is correct, The implementation is
Buggy I guess
Code

import math

def catch_point(x, y):
# checks for points which lie inside all the circles
# stores all such point in hull
kount = True
for i in range(n):
if (x - circle[i][0])**2 + (y - circle[i][1])**2 - 1.0  0:
kount = False
if kount == True:
hull.append((x, y))

def curve_area(x0, y0, x1, y1, x2, y2):
k = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
area_c = math.pi * (math.degrees(math.acos(1.0 - k*k/2.0))/360) #TODO
Verify
area_t = 0.5 * ( x0*(y1 - y2) - x1*(y0 - y2) + x2*(y0 - y1) )
if area_t  0:  area_t = -area_t
area = area_c - area_t
#print area
return area

def polygon_area(p):
# calculate area of the polygon given the co-ordinates
return 0.5 * abs(sum(x0*y1 - x1*y0 for ((x0, y0), (x1, y1)) in
segments(p)))

def segments(p):
return zip(p, p[1:] + [p[0]])

def intersect_circles(l):
# check whether all circle intersects or not
for i in l:
for j in l:
if (i[0] - j[0])**2 + (i[1] - j[1])**2 = 4.0:
sol = 0.0
return sol
break
return 1.0

def intersect_coordinates(l):
sol = 0.0   # initialisation of final result
for i in range(n):
for j in range(n):
# find all intersecting co-ordinates for each circle
xa, xb = circle[i][0], circle[j][0]
ya, yb = circle[i][1], circle[j][1]
d = math.sqrt((xa - xb)**2 + (ya - yb)**2)
if d == 0:  continue
x1 = 0.5*(xa + xb) + 0.5*(yb - ya)*math.sqrt(4 - d*d) / d
y1 = 0.5*(yb + ya) - 0.5*(xb - xa)*math.sqrt(4 - d*d) / d
catch_point(x1, y1) # first intersection point
x2 = 0.5*(xa + xb) - 0.5*(yb - ya)*math.sqrt(4 - d*d) / d
y2 = 0.5*(yb + ya) + 0.5*(xb - xa)*math.sqrt(4 - d*d) / d
catch_point(x2, y2) # second intersection point
sol += curve_area(circle[i][0], circle[i][1], hull[-1][0],
hull[-1][1], hull[-2][0], hull[-2][1])
# add up the value of curves
return sol

t = int(raw_input())# total no. of test cases
for test in range(t):
n = int(raw_input())# total no. of circles
circle = [] # a blank list which will contain center of
circles
hull = []   # a blank list which will consist of points on
convex polygon
for i in range(n):
x,y = [float(i) for i in raw_input().split()]
circle.append((x,y))# storing the value

circle = list(set(circle))  # removing duplicates
n = len(circle) # calculating no. of non-duplicate circle
sol = intersect_circles(circle) #intersect_circles() check whether
all circle intersect
if sol == 0.0:  # if sol == 0.0 means all circle do not
intersect
print 0.00# solution = 0.00 in this case
elif n == 1:# if only 1 circle present, the solution is PI
print %.6f %(math.pi)
else:
sol = intersect_coordinates(circle)# for rest cases we need
to calculate intersection co-ordinates of circle
print %.6f %(sol + polygon_area(hull))   # final solution

/Code

sample output :
4
2
0 0
1 0
1.228370
3
0 0
0 0
0 0
3.141593
3
0 0
0 1
10 12
0.00
3
0 0
1 0
0 1
0.192972

Either there is a redundency or there is some issue with this line : sol +=
curve_area(circle[i][0], circle[i][1], hull[-1][0], hull[-1][1],
hull[-2][0], hull[-2][1])

Still trying to fix it.
~l0nwlf

On Fri, Feb 5, 2010 at 11:48 AM, John Nagle na...@animats.com wrote:

 Chris Rebert wrote:

 On Thu, Feb 4, 2010 at 2:39 AM, Shashwat Anand anand.shash...@gmail.com
 wrote:

 Given 'n' circles and the co-ordinates of their center, and the radius of
 all being equal i.e. 'one', How can I take out the intersection of their
 area.


 How is this at all specific to Python?

 This also sounds suspiciously like homework, which you should know
 this list is unlikely to give direct answers to, though you might be
 able to get a few pointers or some general suggestions.


Good point.

This is actually a problem in what's called constructive geometry.
 Usually, this is a 3D problem, for which the term constructive solid
 geometry, or CSG, is used.  That's where to look for algorithms.

Yes, there are efficient algorithms and near-exact solutions.
 The basic idea is that you find all the points at which circles
 intersect, sort those by one coordinate, and advance across that
 coordinate, from one 

Re: C:\Python25\Lib\IDLELIB\idle.pyw won't start

2010-02-05 Thread Alf P. Steinbach

* Anthra Norell:

Hi,

  I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle window.

This is the command I have been using:
  C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c 
execfile('C:\\Python24\\i')


And this is the command that doesn't start anything:
  C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c 
execfile('C:\\Python25\\i')


The command is exactly the same with the digit 5 in the place of 4. All 
paths and names are correct. C:\\Python25\\i sets up sys.path but seems 
irrelevant, as taking the execfile () part out doesn't change anything. 
The OS is Windows ME. The download of 2.5 finished with a warning saying 
that 2.5 was the highest version for Windows 9* Any tips?


Don't know, but the '-n' option, is that passed to IDLE?

Perhaps try removing that.


Cheers  hth.,

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


Re: xmlrpc slow in windows 7 if hostnames are used

2010-02-05 Thread News123
Yhanks  a lot I'll check whether this is the root cause.

Currently my machine could live without IPV6


bye

N


Gabriel Genellina wrote:
 En Thu, 04 Feb 2010 19:34:20 -0300, News123 news...@free.fr escribió:
 
 I wrote a small xmlrpc client on Windows 7 with python 2.6

 srv = xmlrpclib.Server('http://localhost:80')

 I was able to perform about 1 rpc call per second


 After changing to
 srv = xmlrpclib.Server('http://127.0.0.1:80')

 I was able to perform about 10 to 16 rpc calls per second.

 So it seems, that under windows 7 the host name lookup occurs for every
 RPC call
 
 Not necesarily. There is another difference: 127.0.0.1 is an IPv4
 address, localhost maps to both IPv4 and IPv6 addresses (::1)
 
 I vaguely remember a problem with that - IPv6 is tried first, doesn't
 work, only then IPv4, and that slows down the whole process.
 Try disabling completely the IPv6 stack, if you don't need it.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Ruby

2010-02-05 Thread Ethan Furman

Robert Kern wrote:

On 2010-02-04 14:55 PM, Jonathan Gardner wrote:

On Feb 3, 3:39 pm, Steve Holdenst...@holdenweb.com  wrote:

Robert Kern wrote:

On 2010-02-03 15:32 PM, Jonathan Gardner wrote:



I can explain all of Python in an hour; I doubt anyone will understand
all of Python in an hour.


With all respect, talking about a subject without a reasonable 
chance of

your audience understanding the subject afterwards is not explaining.
It's just exposition.


I agree. If the audience doesn't understand then you haven't 
explained it.


On the contrary, that explanation would have everything you need. It
would take an hour to read or listen to the explanation, but much more
than that time to truly understand everything that was said.


Like I said, that's exposition, not explanation. There is an important 
distinction between the two words. Simply providing information is not 
explanation. If it takes four hours for your audience to understand it, 
then you explained it in four hours no matter when you stopped talking.




And if it takes six months?  Would you seriously say it took you six 
months to explain something because it took that long for your audience 
to understand it?


At some point you have to make the transition from person A explaining 
and person(s) B understanding -- they don't necessarily happen 
synchronously.


As a real-life example, I've read several Python books, tutorials, and 
this list for quite some time, some of which has very good explanatory 
material, and yet some of the points I didn't fully comprehend until 
much, much later.  Every time, though, it's still the same reaction:  I 
*love* Python!  :D


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


Re: Your beloved python features

2010-02-05 Thread Ethan Furman

Julian wrote:

Hello,

I've asked this question at stackoverflow a few weeks ago, and to make
it clear: this should NOT be a copy of the stackoverflow-thread
hidden features of Python.

I want to design a poster for an open source conference, the local
usergroup will have a table there, and in the past years there were
some people that came to the python-table just to ask why should I
use python?.

For those guys would be a poster quite cool which describes the most
popular and beloved python features.

So, may you help me please? If there's a similar thread/blogpost/
whatever, please give it to me, google couldn't.

Regards
Julian


http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf
--
http://mail.python.org/mailman/listinfo/python-list


Re: xmlrpc slow in windows 7 if hostnames are used

2010-02-05 Thread Jean-Michel Pichavant

News123 wrote:

Yhanks  a lot I'll check whether this is the root cause.

Currently my machine could live without IPV6


bye

N


Gabriel Genellina wrote:
  

En Thu, 04 Feb 2010 19:34:20 -0300, News123 news...@free.fr escribió:



I wrote a small xmlrpc client on Windows 7 with python 2.6

srv = xmlrpclib.Server('http://localhost:80')

I was able to perform about 1 rpc call per second


After changing to
srv = xmlrpclib.Server('http://127.0.0.1:80')

I was able to perform about 10 to 16 rpc calls per second.

So it seems, that under windows 7 the host name lookup occurs for every
RPC call
  

Not necesarily. There is another difference: 127.0.0.1 is an IPv4
address, localhost maps to both IPv4 and IPv6 addresses (::1)

I vaguely remember a problem with that - IPv6 is tried first, doesn't
work, only then IPv4, and that slows down the whole process.
Try disabling completely the IPv6 stack, if you don't need it.


Or you can simply use an explicit external address. Most of the time 
xmlRPC server/clients are used between distant machines.
If your are using localhost for test purpose, then binding your server 
on its external IP instead of the local one could solve your problem 
(wihtout removing the IPV6 stack).


import socket

# server
server = SimpleXMLRPCServer((socket.gethostname(), 5000), 
logRequests=False, allow_none=True)



# client
xmlrpclib.ServerProxy(http://%s.yourdomain.com:%s; % 
(socket.gethostname(), 5000))


JM

PS : please don't top post :o)
PS : just wondering if using the port 80 is legal
--
http://mail.python.org/mailman/listinfo/python-list


Re: Your beloved python features

2010-02-05 Thread Martin P. Hellwig

On 02/04/10 23:03, Julian wrote:
cut


For those guys would be a poster quite cool which describes the most
popular and beloved python features.


That it is ego-orientated programming ;-)
http://mail.python.org/pipermail/python-announce-list/2009-April/007419.html

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


Re: Your beloved python features

2010-02-05 Thread Jean-Michel Pichavant

Ethan Furman wrote:

Julian wrote:

Hello,

I've asked this question at stackoverflow a few weeks ago, and to make
it clear: this should NOT be a copy of the stackoverflow-thread
hidden features of Python.

I want to design a poster for an open source conference, the local
usergroup will have a table there, and in the past years there were
some people that came to the python-table just to ask why should I
use python?.

For those guys would be a poster quite cool which describes the most
popular and beloved python features.

So, may you help me please? If there's a similar thread/blogpost/
whatever, please give it to me, google couldn't.

Regards
Julian


http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf 


Choose metaclasses if you don’t value your sanity.

That remembers me the time when it took me 4 hours to write a ten lines 
metaclass :o)


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


Re: Building a multiline string

2010-02-05 Thread lallous
@Ulrich:

On Feb 4, 1:09 pm, Ulrich Eckhardt eckha...@satorlaser.com wrote:
 Just for the record: Neither of the below methods actually produce a
 multiline string. They only spread a string containing one line over
 multiple lines of source code.


I meant:
Note - Note: I don't want to use new lines

I did not want a multi line string


Thanks guys, method 3 seems to be good enough.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C:\Python25\Lib\IDLELIB\idle.pyw won't start

2010-02-05 Thread Duncan Booth
Anthra Norell anthra.nor...@bluewin.ch wrote:

 Hi,
 
I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle
window. 
 
 This is the command I have been using:
C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c 
 execfile('C:\\Python24\\i')
 
 And this is the command that doesn't start anything:
C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c 
 execfile('C:\\Python25\\i')
 
 The command is exactly the same with the digit 5 in the place of 4.
 All paths and names are correct. C:\\Python25\\i sets up sys.path but
 seems irrelevant, as taking the execfile () part out doesn't change
 anything. The OS is Windows ME. The download of 2.5 finished with a
 warning saying that 2.5 was the highest version for Windows 9* Any
 tips? 
 
 Thanks
 
Does 'unable to start a 2.5 idle window' mean you get some sort of error
or simply that nothing happens? 

What happens if you simply run C:\Python25\Lib\IDLELIB\idle.bat
Does that work or not?

What about running this from a command prompt:

 C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.py

Does that run idle or do you get any error messages?
What about this?

 C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.pyw

Using pythonw.exe will start the program with all error output dumped in
the bit bucket. Running from a command prompt with python.exe will at
least let you see if there are any errors. 

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


Re: Your beloved python features

2010-02-05 Thread Daniel Fetchinson
 I've asked this question at stackoverflow a few weeks ago, and to make
 it clear: this should NOT be a copy of the stackoverflow-thread
 hidden features of Python.

 I want to design a poster for an open source conference, the local
 usergroup will have a table there, and in the past years there were
 some people that came to the python-table just to ask why should I
 use python?.

 For those guys would be a poster quite cool which describes the most
 popular and beloved python features.

 So, may you help me please? If there's a similar thread/blogpost/
 whatever, please give it to me, google couldn't.

 Regards
 Julian

 http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf

This is effin hilarious! Should be either linked or stored on python.org

Cheers,
Daniel


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


Repost: Read a running process output

2010-02-05 Thread Ashok Prabhu
Hi,

I very badly need this to work. I have been googling out for a week
with no significant solution. I open a process p1 which does keeps
running for 4+ hours. It gives some output in stdout now and then. I
open this process with subprocess.Popen and redirect the stdout to
PIPE. However when I read the output with readline it blocks waiting
forever. I need to read from p1.stdout till what it has in the PIPE.
Can someone help me out with the exact code change that can accomplish
the task.

from subprocess import *

p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True)

while 1:
line=p1.stdout.readline()
print line

Thanks in advance,
~Ashok.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Ruby

2010-02-05 Thread mk

Steve Holden wrote:

Jeez, Steve, you're beginning to sound like some kind of fallacy
zealot... ;)
Death to all those who confuse agumentum ad populum with argumentum ad 
verecundiam!!!




Yeah, what did the zealots ever do for us?


They produced Python?

.
.
.


Oh Python! Shut up!


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


Re: Repost: Read a running process output

2010-02-05 Thread Alain Ketterlin
Ashok Prabhu ashokprab...@gmail.com writes:

 from subprocess import *
 p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True)

Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell.

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


Re: Your beloved python features

2010-02-05 Thread bartc


R Fritz rfritz...@gmail.com wrote in message 
news:e97ff208-d08e-4934-8e38-a40d668cd...@l24g2000prh.googlegroups.com...

My favorite feature is its readability.  It's as near to pseudo-code
as any language we have, and that's valuable in open source projects
or when I return to code to modify it.


That might be true when used to code actual algorithms using basic features.

But a lot of Pythonisms would appear mysterious to someone who doesn't know 
the language (for example, what does :: mean in an array index).


Or perhaps pseudo-code is much more advanced these days...

--
bartc 


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


Simple question about Queue.Queue and threads

2010-02-05 Thread Frank Millman

Hi all

Assume you have a server process running, a pool of worker threads to 
perform tasks, and a Queue.Queue() to pass the tasks to the workers.


In order to shut down the server cleanly, you want to ensure that the 
workers have all finished their tasks. I like the technique of putting a 
None onto the queue, and have each worker check for None, put None back onto 
the queue, and terminate itself.


The main program would look something like this -

   q.put(None)
   for worker in worker_threads:
   worker.join()

At this point you can be sure that each thread has completed its tasks and 
terminated itself.


However, the queue is not empty - it still has the final None in it.

Is it advisable to finalise the cleanup like this? -

   while not q.empty():
   q.get()
   q.task_done()
   q.join()

Or is this completely redundant?

Thanks

Frank Millman


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


Re: Repost: Read a running process output

2010-02-05 Thread Ashok Prabhu
On Feb 5, 5:12 pm, Alain Ketterlin al...@dpt-info.u-strasbg.fr
wrote:
 Ashok Prabhu ashokprab...@gmail.com writes:
  from subprocess import *
  p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True)

 Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell.

 -- Alain.

Hi Alain,

Thanks for the response. However it throws an error. Please find
below.

 from subprocess import *
 p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE)
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /usr/lib/python2.4/subprocess.py, line 543, in __init__
errread, errwrite)
  File /usr/lib/python2.4/subprocess.py, line 975, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

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


Re: Repost: Read a running process output

2010-02-05 Thread Alain Ketterlin
Ashok Prabhu ashokprab...@gmail.com writes:

  p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True)

 Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell.

 -- Alain.

 Thanks for the response. However it throws an error. Please find
 below.

 from subprocess import *
 p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE)

You forgot to change the monolithic command into a list of words. Since
you don't use the shell anymore you have to give Popen a pre-parsed
command line.

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


Re: C:\Python25\Lib\IDLELIB\idle.pyw won't start

2010-02-05 Thread Anthra Norell
Thank you both (Alf and Duncan) for your comments. I answer Duncan's 
questions interleaved:


Duncan Booth wrote:

Anthra Norell anthra.nor...@bluewin.ch wrote:

  

Hi,

   I upgraded from 2.4 to 2.5 and am unable to start an 2.5 idle
   window. 


This is the command I have been using:
   C:\Python24\pythonw.exe C:\Python24\Lib\IDLELIB\idle.pyw -n -c 
execfile('C:\\Python24\\i')


And this is the command that doesn't start anything:
   C:\Python25\pythonw.exe C:\Python25\Lib\IDLELIB\idle.pyw -n -c 
execfile('C:\\Python25\\i')


The command is exactly the same with the digit 5 in the place of 4.
All paths and names are correct. C:\\Python25\\i sets up sys.path but
seems irrelevant, as taking the execfile () part out doesn't change
anything. The OS is Windows ME. The download of 2.5 finished with a
warning saying that 2.5 was the highest version for Windows 9* Any
tips? 


Thanks



Does 'unable to start a 2.5 idle window' mean you get some sort of error
or simply that nothing happens? 
  
Nothing happens and no error message shows. The disk head stepper makes 
a brief attempt at something then goes silent and that's it.

What happens if you simply run C:\Python25\Lib\IDLELIB\idle.bat
Does that work or not?
  

Same thing: Nothing happens

What about running this from a command prompt:

 C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.py
  

Same thing: Nothing!

Does that run idle or do you get any error messages?
What about this?

 C:\Python25\python.exe C:\Python25\Lib\IDLELIB\idle.pyw

  

Nothing!

Using pythonw.exe will start the program with all error output dumped in
the bit bucket. Running from a command prompt with python.exe will at
least let you see if there are any errors. 
  
python.exe from the command line works all right in a DOS window. The 
problem must be with  idle.pyw. I tried the old idle.pyw (2.4) with the 
new python.exe. (2.5) and that didn't work either.
What is the bit bucket? If I had a clue, I could go from there. What 
puzzles me is that version 2.4 has been working fine and one wouldn't 
think that the changes from 2.4 to 2.5 would be so extensive as to cause 
a major malfunction. For the time being 2.4 works fine. I'd much prefer 
2.5, though, because it includes the image library (PIL), whereas 2.4 
cannot even use it.


Frederic

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


Re: Repost: Read a running process output

2010-02-05 Thread Ashok Prabhu
On Feb 5, 5:58 pm, Alain Ketterlin al...@dpt-info.u-strasbg.fr
wrote:
 Ashok Prabhu ashokprab...@gmail.com writes:
   p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True)

  Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell.

  -- Alain.
  Thanks for the response. However it throws an error. Please find
  below.

  from subprocess import *
  p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE)

 You forgot to change the monolithic command into a list of words. Since
 you don't use the shell anymore you have to give Popen a pre-parsed
 command line.

 -- Alain.

Here is the error again

 p1=Popen('/usr/sunvts/bin/64/vtsk','-d',stdout=PIPE)
Traceback (most recent call last):
  File stdin, line 1, in ?
  File /usr/lib/python2.4/subprocess.py, line 494, in __init__
raise TypeError(bufsize must be an integer)
TypeError: bufsize must be an integer


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


Re: Repost: Read a running process output

2010-02-05 Thread Ashok Prabhu
On Feb 5, 6:33 pm, Ashok Prabhu ashokprab...@gmail.com wrote:
 On Feb 5, 5:58 pm, Alain Ketterlin al...@dpt-info.u-strasbg.fr
 wrote:



  Ashok Prabhu ashokprab...@gmail.com writes:
p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True)

   Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell.

   -- Alain.
   Thanks for the response. However it throws an error. Please find
   below.

   from subprocess import *
   p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE)

  You forgot to change the monolithic command into a list of words. Since
  you don't use the shell anymore you have to give Popen a pre-parsed
  command line.

  -- Alain.

 Here is the error again

  p1=Popen('/usr/sunvts/bin/64/vtsk','-d',stdout=PIPE)

 Traceback (most recent call last):
   File stdin, line 1, in ?
   File /usr/lib/python2.4/subprocess.py, line 494, in __init__
     raise TypeError(bufsize must be an integer)
 TypeError: bufsize must be an integer

 ~Ashok.

Oops i missed the braces. But still no output.


 p1=Popen(['/usr/sunvts/bin/64/vtsk','-d'],stdout=PIPE)
 while 1:
...  a=p1.stdout.readline()
...  print a
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Your beloved python features

2010-02-05 Thread Roald de Vries

On Feb 5, 2010, at 12:03 AM, Julian wrote:


Hello,

I've asked this question at stackoverflow a few weeks ago, and to make
it clear: this should NOT be a copy of the stackoverflow-thread
hidden features of Python.

I want to design a poster for an open source conference, the local
usergroup will have a table there, and in the past years there were
some people that came to the python-table just to ask why should I
use python?.

For those guys would be a poster quite cool which describes the most
popular and beloved python features.

So, may you help me please? If there's a similar thread/blogpost/
whatever, please give it to me, google couldn't.


My reasoning: I needed a language more powerful than bash, but more  
portable and faster to develop (at least small scripts) than C/C++. So  
I needed a scripting language. Python, Ruby, Perl, Tcl, ...?


Python seems to be the language with the most libraries available,  
programs written in it, OS-support (even runs on my smartphone), has a  
good data-model, has a good interactive shell (iPython).




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


Re: Your beloved python features

2010-02-05 Thread Bruno Desthuilliers

Julian a écrit :

Hello,

I've asked this question at stackoverflow a few weeks ago, and to make
it clear: this should NOT be a copy of the stackoverflow-thread
hidden features of Python.

I want to design a poster for an open source conference, the local
usergroup will have a table there, and in the past years there were
some people that came to the python-table just to ask why should I
use python?.

For those guys would be a poster quite cool which describes the most
popular and beloved python features.


My all-time favorite Python feature : it fits my brain.
--
http://mail.python.org/mailman/listinfo/python-list


Re: C:\Python25\Lib\IDLELIB\idle.pyw won't start

2010-02-05 Thread Duncan Booth
Anthra Norell anthra.nor...@bluewin.ch wrote:

 Using pythonw.exe will start the program with all error output dumped in
 the bit bucket. Running from a command prompt with python.exe will at
 least let you see if there are any errors. 
   
 python.exe from the command line works all right in a DOS window. The 
 problem must be with  idle.pyw. I tried the old idle.pyw (2.4) with the 
 new python.exe. (2.5) and that didn't work either.
 What is the bit bucket? If I had a clue, I could go from there. What 
 puzzles me is that version 2.4 has been working fine and one wouldn't 
 think that the changes from 2.4 to 2.5 would be so extensive as to cause 
 a major malfunction. For the time being 2.4 works fine. I'd much prefer 
 2.5, though, because it includes the image library (PIL), whereas 2.4 
 cannot even use it.

Bit bucket: http://en.wikipedia.org/wiki/Bit_bucket

If you are seeing nothing at all when running it with python.exe instead of 
pythonw.exe then something bizarre must be happening.

My guess would have been that you had a problem importing something: e.g. 
if Tkinter isn't installed properly then running Idle under pythonw.exe 
would exit with an error message but you wouldn't see the error message. 
However since you don't see an error message when running it with 
python.exe it isn't that.

Sorry, I'm out of ideas for now.

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


which

2010-02-05 Thread mk


if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)
else:
self.cmd = cmd

or

self.cmd = cmd
if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)


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


Re: YAML (was: Python and Ruby)

2010-02-05 Thread Lou Pecora
In article 00f4bb3a$0$15566$c3e8...@news.astraweb.com,
 Steven D'Aprano st...@remove-this-cybersource.com.au wrote:

 On Thu, 04 Feb 2010 09:57:59 -0500, Lou Pecora wrote:
 
  Well, that looks a bit more complicated than I would like, but maybe
  it's doing more stuff than I can grok.  Here's what I needed and how I
  did it in Python:
 [...]
  # Reading same list in:
  instr=fp.readline()
  inlist=eval(instr)
  x1,y1,astr1,z1= inlist
  
  
  That's what I needed.  3 lines to write or read a inhomogeneous
  collection of variables. 
 
 Easy, but also quick and dirty -- good enough for small scripts, but not 
 really good enough for production applications.
 
 
  I can add more variables, shuffle the order,
  whatever without messing with formatting, etc. 
 
 This is nice and easy. But there are at least four catches:
 
 
 * you can't safely treat the data file as human-editable
 (although a sufficiently careful and Python-aware user could edit it)
 
 * you can't use any data that isn't a built-in, or that contains 
 something that is not a built-in
 
 * there may be reliability issues with floats - you're at the mercy of 
 changes to the underlying repr of float objects, and it almost certainly 
 will blow up in your face if you get an inf or nan (at least prior to 
 Python 2.6)
 
 * you're using eval, which is a security risk if you can't trust the 
 source of the data file.
 
 However, be aware that neither marshal nor pickle guarantees to be safe 
 against malicious data either. The docs for both warn against using them 
 on untrusted data. YAML or JSON *might* be safer, I haven't looked.

I understand where you are coming from: Production Code.  I was just 
making a point about Python and my code is only used by me.  I can edit 
the file for the simple I/O I do.  I am not recommending this way for 
everyone. Just an example.

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


Re: which

2010-02-05 Thread KDr2
cmd= isinstance(cmd,str) and c.replace('${ADDR}',ip) or cmd


Best Regards,
 -- KDr2 http://kdr2.net




On Fri, Feb 5, 2010 at 10:21 PM, mk mrk...@gmail.com wrote:


 if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)
 else:
self.cmd = cmd

 or

 self.cmd = cmd
 if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)


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

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


Pickling an extension type subclasses problems

2010-02-05 Thread Gaetan de Menten
Hi all,

I am trying to write an (optional!) C extension for SQLAlchemy, and I
am struggling to make an extension type picklable *and* using the same
format as the pure Python version (so that computers with the C
extension can unpickle pickles from computers without it and
vice-versa). Also the extension type (MyBase in the example code
below) only serves as a base class for the type that get pickled
(MyPythonType). MyPythonType also has further subclasses and those
should be picklable too.

My setup is as follow:

On the Python side:


try:
from cextension import MyBase
except ImportError:
class MyBase(object):
__slots__ = ('a', 'b', 'c')
def __init__(self, a, b, c):
self.a, self.b, self.c = a, b, c

def __getstate__(self):
...

def __setstate__(self, state):
...
...


class MyPythonType(MyBase):
...

On the .c side:
===
I implemented a reduce method, which returns

Py_BuildValue((O(s)N), Py_TYPE(self), __state__, state);

and in my BaseRowProxy_init method, I check the number of arguments,
whether the __state__ marker is present and unpack the state if it
is. This makes the type nicely pickleable, but this is obviously not
the same pickle format as the Python version.

What would you recommend in this kind of situation? I'm a bit tired of
trial and error... My last hope is to define __reduce__ on the Python
side too, and make it use a module-level reconstructor function as
follow:

def mypythontype_reconstructor(cls, state):
obj = object.__new__(cls, state):

return obj

Will this work? Any other idea?

Thanks in advance,
-- 
Gaëtan de Menten
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which

2010-02-05 Thread Steve Holden
mk wrote:
 
 if isinstance(cmd, str):
 self.cmd = cmd.replace(r'${ADDR}',ip)
 else:
 self.cmd = cmd
 
 or
 
 self.cmd = cmd
 if isinstance(cmd, str):
 self.cmd = cmd.replace(r'${ADDR}',ip)
 
 
My own preference is for the latter, but I am sure you will find that
opinions are mixed on this. In recent versions of Python you might want
to take the possibility that cmd is Unicode into account by using

  id isinstance(cmd, basestring):

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: which

2010-02-05 Thread Jean-Michel Pichavant

mk wrote:


if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)
else:
self.cmd = cmd

or

self.cmd = cmd
if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)


I would vote for the first one. But I could use the second as well, I 
would'nt fight for it.


What is worrying me the most in your code sample is that self.cmd can 
hold diferrent types (str, and something else). That is usually a bad 
thing to do (putting None aside).
However, my remark could be totally irrelevant of course, that depends 
on the context.


JM

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


Re: Your beloved python features

2010-02-05 Thread Jean-Michel Pichavant

Bruno Desthuilliers wrote:

Julian a écrit :

Hello,

I've asked this question at stackoverflow a few weeks ago, and to make
it clear: this should NOT be a copy of the stackoverflow-thread
hidden features of Python.

I want to design a poster for an open source conference, the local
usergroup will have a table there, and in the past years there were
some people that came to the python-table just to ask why should I
use python?.

For those guys would be a poster quite cool which describes the most
popular and beloved python features.


My all-time favorite Python feature : it fits my brain.

Python is simple ... no offense Bruno :D

JM

(sorry couldn't help)
--
http://mail.python.org/mailman/listinfo/python-list


method to intercept string formatting % operations

2010-02-05 Thread bradallen
Hello,

For container class derived from namedtuple, but which also behaves
like a dictionary by implementing __getitem__ for non-integer index
values, is there a special reserved method which allows intercepting %
string formatting operations? I would like for my container type to
behave appropriately depending on whether the string formatting
operation has a string like this :

whatever %s yadayada % mycontainer  # needs to act like a tuple

whatever %(key)s yadayada % mycontainer  # needs to act like a
dictionary

I looked through the Python data model docs at http://docs.python.org/
reference/datamodel.html#emulating-container-types but only found
this:

If the left operand of a % operator is a string or Unicode object, no
coercion takes place and the string formatting operation is invoked
instead.

Thanks!

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


Re: which

2010-02-05 Thread mk

Jean-Michel Pichavant wrote:


What is worrying me the most in your code sample is that self.cmd can 
hold diferrent types (str, and something else). That is usually a bad 
thing to do (putting None aside).
However, my remark could be totally irrelevant of course, that depends 
on the context.


That's a valid criticism - but I do not know how to handle this 
otherwise really, because the program can be called with cmd to run, 
or a script to run (or a directory to copy) and in those cases cmd is None.


I guess I could use

if cmd:
self.cmd = ...


But. Suppose that under some circumstances cmd is not string. What then?

I know that isinstance is typically not recommended, but I don't see 
better solution here.



Regards,
mk


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


Re: which

2010-02-05 Thread mk

KDr2 wrote:

cmd= isinstance(cmd,str) and c.replace('${ADDR}',ip) or cmd


Perlish, but I like that. :-)

Regards,
mk

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


Re: Your beloved python features

2010-02-05 Thread Grant Edwards
On 2010-02-04, Julian maili...@julianmoritz.de wrote:

 I've asked this question at stackoverflow a few weeks ago, and
 to make it clear: this should NOT be a copy of the
 stackoverflow-thread hidden features of Python.

 I want to design a poster for an open source conference, the
 local usergroup will have a table there, and in the past years
 there were some people that came to the python-table just to
 ask why should I use python?.

 For those guys would be a poster quite cool which describes
 the most popular and beloved python features.

In the fine old tradition:



Python:  It sucks less.


  A lot less.

  
-- 
Grant Edwards   grante Yow! You should all JUMP
  at   UP AND DOWN for TWO HOURS
   visi.comwhile I decide on a NEW
   CAREER!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which

2010-02-05 Thread Jean-Michel Pichavant

mk wrote:

Jean-Michel Pichavant wrote:


What is worrying me the most in your code sample is that self.cmd can 
hold diferrent types (str, and something else). That is usually a bad 
thing to do (putting None aside).
However, my remark could be totally irrelevant of course, that 
depends on the context.


That's a valid criticism - but I do not know how to handle this 
otherwise really, because the program can be called with cmd to run, 
or a script to run (or a directory to copy) and in those cases cmd is 
None.


I guess I could use

if cmd:
self.cmd = ...


But. Suppose that under some circumstances cmd is not string. What then?

I know that isinstance is typically not recommended, but I don't see 
better solution here.



Regards,
mk


If you can change your program interface, then do it, if not then you're 
right you don't have much choice as you are suffering from the program 
poor interface.
You can fix this problem by explicitly asking for the thing you want to 
do, instead of guessing by inspecting the argument nature.


myProg --help

usage : myProg command [args]
   command list:
  - cmd: execute the given arg1 command line
  - exec: execute the given script file named arg1
  - copy: copy arg1 to arg2

example:
myProg cmd echo that's cool
myProg exec /etc/init.d/myDaemon
myProg copy /tmp /tmp2

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


Terminating threaded programs

2010-02-05 Thread mk

Hello everyone,

I have a problem with a threaded program: it frequently hangs on sys.exit.

The problem is that my program uses threads which in turn use paramiko 
library, which itself is threaded.


I try to gracefully close the threads (below), but it doesn't always 
work, if paramiko calls happen to be at stage of negotiating ssh 
connection or smth similar.


The only workable solution I have is a program sending itself SIGKILL, 
which makes it terminated by OS (I think so).


Is there any way to brutally close the threads? I know that normally 
that should not be done, but shutdown when you don't care about writing 
out to disk is the only situation where it doesn't apply.


def ctrlchandler(signal, frame):
print
print ENDC + Terminating on Ctrl-C, closing threads for:,
while queue:
for ip, th in queue:
print ip,
try:
lock.acquire()
th.abort = True
lock.release()
except RuntimeError:
pass
queue.remove((ip,th))
print
pid = os.getpid()
print Finished closing threads.
# suicide - it's the only way of preventing frequent hangup on sys.exit
os.kill(pid, SIGTERM)
os.kill(pid, SIGKILL)
sys.exit(0)

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


Re: ANN: ActivePython 2.6.4.10 is now available

2010-02-05 Thread Tommy Grav

On Feb 5, 2010, at 12:01 AM, Sridhar Ratnakumar wrote:

 I'm happy to announce that ActivePython 2.6.4.10 is now available for 
 download from:

 On what platforms does ActivePython run?
 
 
 ActivePython includes installers for the following platforms:
 
 - Windows/x86
 - Windows/x64 (aka AMD64)
 - Mac OS X

Is the Mac OS X version still only 32 bit? If so does ActiveState plan to make 
binaries for 64bit builds
for Snow Leopard?

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


Drawing a zig-zag Trail in Python?

2010-02-05 Thread W. eWatson
I'd like to draw something like an animal track. Between each point is a 
line. Perhaps the line would have an arrow showing the direction of 
motion. There should be x-y coordinates axises. PIL? MatPlotLib, ??

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


Re: which

2010-02-05 Thread John Posner

On 2/5/2010 9:21 AM, mk wrote:


if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)
else:
self.cmd = cmd

or

self.cmd = cmd
if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)




(lunatic fringe?)

Last August [1], I offered this alternative:

  self.cmd = (cmd.replace(r'${ADDR}',ip)
  if isinstance(cmd, str) else
  cmd)

But it didn't get much love in this forum!


[1] 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/6876917a4d579d59/1f700586f4c4614d?lnk=gstq=Posner#1f700586f4c4614d

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


Re: method to intercept string formatting % operations

2010-02-05 Thread Jean-Michel Pichavant

bradallen wrote:

Hello,

For container class derived from namedtuple, but which also behaves
like a dictionary by implementing __getitem__ for non-integer index
values, is there a special reserved method which allows intercepting %
string formatting operations? I would like for my container type to
behave appropriately depending on whether the string formatting
operation has a string like this :

whatever %s yadayada % mycontainer  # needs to act like a tuple

whatever %(key)s yadayada % mycontainer  # needs to act like a
dictionary

I looked through the Python data model docs at http://docs.python.org/
reference/datamodel.html#emulating-container-types but only found
this:

If the left operand of a % operator is a string or Unicode object, no
coercion takes place and the string formatting operation is invoked
instead.

Thanks!

  

class toto:
   def __getitem__(self, key):
   return 'paf'
   def __str__(self):
   return 'pif'
   def toTuple(self):
   return (1,2,3)


1/ print '%s %s %s' % toto().toTuple()
'1 2 3'
2/ print '%(key)s ' % toto()
'paf'
3/ print '%s' % toto()
'pif'


1/ I don't know how to spare the explicit toTuple conversion, supporting 
tuple() would be tedious

2/ thanks to __getitem__ (duck typing)
3/ thanks to __str__

Anyway why would you want to use the tuple form ? it's beaten in every 
aspect by the dictionary form.



JM

If you need something call me, I'll tell you how to live without it 
(Coluche, about politicians)

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


Re: Your beloved python features

2010-02-05 Thread Bruno Desthuilliers

Jean-Michel Pichavant a écrit :

Bruno Desthuilliers wrote:


My all-time favorite Python feature : it fits my brain.

Python is simple ... no offense Bruno :D


!-)

But FWIW, that's exactly the point : even a stoopid like me can manage 
to learn and use Python, and proceed to write working apps without 
spending more time reading the doc than actually solving the problem.

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


Re: which

2010-02-05 Thread mk

Jean-Michel Pichavant wrote:
If you can change your program interface, then do it, if not then you're 
right you don't have much choice as you are suffering from the program 
poor interface.
You can fix this problem by explicitly asking for the thing you want to 
do, instead of guessing by inspecting the argument nature.


myProg --help

usage : myProg command [args]
   command list:
  - cmd: execute the given arg1 command line
  - exec: execute the given script file named arg1
  - copy: copy arg1 to arg2

example:
 myProg cmd echo that's cool
 myProg exec /etc/init.d/myDaemon
 myProg copy /tmp /tmp2



I sure can change the interface since I'm the author of the entire 
program. But I don't see how I can arrange program in a different way: 
the program is supposed to be called with -c parameter (command to run), 
-s script to run, or -y file_or_dir_to_copy.


Then, I start instances of SSHThread class to do precisely that, 
separately for each ip/hostname:



class SSHThread(threading.Thread):
def __init__(self, lock, cmd, ip, username, sshprivkey=None, 
passw=None, port=22, script=None, remotedir=None):


threading.Thread.__init__(self)

self.lock = lock
if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)
else:
self.cmd = cmd
self.ip = ip
self.username = username
self.sshprivkey = sshprivkey
self.passw = passw
self.port = port
self.conobj = None
self.conerror = ''
self.msgstr = ''
self.confailed = True
if script:
self.setpathinfo(script, remotedir=remotedir)
self.sentbytes = 0
self.finished = False
self.abort = False

It gets called like this:

th = SSHThread(lock, opts.cmd, ip, username=username, 
sshprivkey=opts.key, passw=passw, port=port, script=opts.script, 
remotedir=opts.remotedir)



..where all the options are parsed by ConfigParser.OptionParser(). So 
they are either strings, or Nones.


So in this context this is fine. But I wanted to make the class more 
robust. Perhaps I should do smth like this before setting self.cmd?


assert isinstance(cmd, basestring) or cmd is None, cmd should be string 
or None


and then:

if cmd:
self.cmd = cmd.replace..


?

Entire source code is here:

http://python.domeny.com/cssh.py

regards,
mk







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


Re: which

2010-02-05 Thread Jean-Michel Pichavant

John Posner wrote:

On 2/5/2010 9:21 AM, mk wrote:


if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)
else:
self.cmd = cmd

or

self.cmd = cmd
if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)




(lunatic fringe?)

Last August [1], I offered this alternative:

  self.cmd = (cmd.replace(r'${ADDR}',ip)
  if isinstance(cmd, str) else
  cmd)

But it didn't get much love in this forum!


[1] 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/6876917a4d579d59/1f700586f4c4614d?lnk=gstq=Posner#1f700586f4c4614d 


Heresy !

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


Re: list.extend([]) Question

2010-02-05 Thread Aahz
In article 088e7a24-b0d0-4d43-bee7-193e5eaef...@b7g2000pro.googlegroups.com,
Dan Brown  fsenz...@gmail.com wrote:

Why does extending a list with the empty list result in None?  It
seems very counterintuitive to me, at least --- I expected ['a'].extend
([]) to result in ['a'], not None.

http://www.python.org/doc/faq/general/#why-doesn-t-list-sort-return-the-sorted-list
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

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


xmlrcp - how to marshall objects

2010-02-05 Thread Jean-Michel Pichavant
Deos anyone knows where to find an code sample describing how to 
implement the interface to marshall one object into XMLRPC compliant 
structures ?


I googled without any success, and what google does not find does not exist.

Let say I have this very simple class:

class Point:
   def __init__(self, x, y):
   self.x = x
   self.y = y


I've looked into xmlrpc code, I see  2 options:
1/ override the Marshaller class of client and server
2/ looks like the lib is supporting a WRAPPER list system, it uses to 
Marshall Datetime  Binary object. Can it be possible to add its own 
class (could require to emplement the 'encode' method)


I sense I will spend much more time than required unless someone is 
pointing me in the right direction.


JM

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


Re: which

2010-02-05 Thread Bruno Desthuilliers

mk a écrit :
(snip)
So in this context this is fine. But I wanted to make the class more 
robust. Perhaps I should do smth like this before setting self.cmd?


assert isinstance(cmd, basestring) or cmd is None, cmd should be string 
or None


and then:

if cmd:
self.cmd = cmd.replace..


And what if cmd happens to be the empty string ?-)

ok, me ---[]
--
http://mail.python.org/mailman/listinfo/python-list


Re: which

2010-02-05 Thread Gerald Britton
[snip]

 Last August [1], I offered this alternative:

  self.cmd = (cmd.replace(r'${ADDR}',ip)
              if isinstance(cmd, str) else
              cmd)

 But it didn't get much love in this forum!

I'd probably go for that one as well though I might consider removing
the outer parentheses.

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


Re: which

2010-02-05 Thread Bruno Desthuilliers

mk a écrit :


if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)
else:
self.cmd = cmd


What could cmd be except a string ? From other posts here, I guess 
it's either a string or None ? If yes, then I'd go for this:


if cmd:
  cmd = cmd.replace(r'${ADDR}',ip)

self.cmd = cmd



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


Import question

2010-02-05 Thread Andrew Degtiariov
Code of our project has split into several packages and we deploy the
project using buildout.
All worked fine until I need to dynamically inspect python modules.

Here is structure of our src directory


├───project.api.config
│   ├───project
│   │   └───api
│   │   └───config
│   │   └───settings
│   └───project.api.config.egg-info
├───project.api.contacts
│   ├───project
│   │   └───api
│   │   └───contacts
│   │   ├───importer
│   │   └───views
│   └───project.api.contacts.egg-info
├───project.api.core
│   ├───project
│   │   └───api
│   │   └───core
│   │   ├───js
│   │   ├───lib
│   │   ├───management
│   │   │   └───commands
│   │   ├───middleware
│   │   ├───sessions
│   │   └───users
│   └───project.api.core.egg-info


Buildout by itself generates bin/python which look like:
import sys

sys.path[0:0] = [
  'c:\\users\\ad\\project\\src\\project.api.core',
  'c:\\users\\ad\\project\\src\\project.api.config',
  'c:\\users\\ad\\project\\src\\project.api.contacts',
  'c:\\users\\ad\\project\\eggs\\lockfile-0.8-py2.6.egg',
  'c:\\users\\ad\\project\\parts\\django',
  'c:\\users\\ad\\project\\eggs\\web.py-0.33-py2.6.egg',


Regular code like import project.api.config worked fine, but now I'm tryed
__import__('project.api.config'):

$ bin/python

 import project.api.config
 __import__('project.api.config')
module 'project from
'c:\users\ad\project\src\project.api.contacts\project\__init__.pyc'


What's wrong?
Ok, I'm trying imp:
 import imp
 imp.find_module('project.api.config')
Traceback (most recent call last):
  File console, line 1, in module
ImportError: No module named project.api.config
 import sys
 sys.path[1]
'c:\\users\\ad\\project\\src\\project.api.config'
 imp.find_module('project.api.config', sys.path[1])
Traceback (most recent call last):
  File console, line 1, in module
ImportError: No frozen submodule named
c:\users\ad\project\src\project.api.config.project.api.config


There is setup.py for project.api.config:

import os
from setuptools import setup, find_packages

name = project.api.config
install_requires = [
'zc.buildout',
'setuptools',
'web.py=0.33',
'project.api.core',
'Django=1.1.0',
'lockfile'
]

if sys.platform != 'win32':
install_requires.append('python-daemon')

setup(
name = name,
version = 1.0,
author = Andrew Degtiariov,
author_email = andrew.degtiar...@gmail.com,
description = ...,
license = Commercial,
packages=find_packages(os.path.dirname(__file__), exclude=['ez_setup']),
namespace_packages=['project, 'project.api'],
include_package_data=True,
zip_safe=False,
install_requires = install_requires
)

What's wrong? We really need to split the code for several eggs and want
that all of our package's names starts from 'project.api'

--
Andrew Degtiariov
DA-RIPE
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which

2010-02-05 Thread John Posner

On 2/5/2010 11:06 AM, Gerald Britton wrote:

[snip]


Last August [1], I offered this alternative:

  self.cmd = (cmd.replace(r'${ADDR}',ip)
  if isinstance(cmd, str) else
  cmd)

But it didn't get much love in this forum!


I'd probably go for that one as well though I might consider removing
the outer parentheses.


Agreed ... except that you *need* the outer parentheses if the statement 
occupies multiple source lines.


-John


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


Re: Wrap a function

2010-02-05 Thread Aahz
In article mailman.1944.1265367378.28905.python-l...@python.org,
Dennis Lee Bieber  wlfr...@ix.netcom.com wrote:
On 4 Feb 2010 16:18:04 -0800, a...@pythoncraft.com (Aahz) declaimed the
following in gmane.comp.python.general:
 
 But in bash scripting, you'd just use rsync or cp or rm -- maybe an
 example would make clearer how REXX differs from bash.

   I suspect the only really good examples would have to written under
OS/VMS (where it originated, written to be a more powerful  friendlier
replacement for the EXEC scripting language) or AmigaOS -- to
demonstrate the switching interaction of command handlers. REXX
implementations for Windows and Linux pretty much only support the
shell as a command handler, whereas the two named OS could address
editors (and on the Amiga, word processors, desktop publishing programs,
terminal emulators/comm programs, system editor).

   My Amiga's been in storage since Win95 days, so this is a fictitious
example based on the reference manuals.

address command/* use normal command shell to process commands */
file = 'some.file'
'run ed' file  /* start ED editor in background, editing 'file'*/
address ED /* send commands to the ED instance */
'b'/* go to bottom of file */
'i /text to be inserted before bottom line/'
't'/* to to top */
'a /text inserted after first line/'
find = 'needle'
replace = 'thorn'
'rpe /' || find || '/' || replace '/'
'x'/* save  exit */
address command
'type' file/* type file to screen */
'filenote' file edited via AREXX script

IOW, kinda like AppleScript?
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

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


Re: Drawing a zig-zag Trail in Python?

2010-02-05 Thread mk

W. eWatson wrote:
I'd like to draw something like an animal track. Between each point is a 
line. Perhaps the line would have an arrow showing the direction of 
motion. There should be x-y coordinates axises. PIL? MatPlotLib, ??


Pycairo?

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


Re: list.extend([]) Question

2010-02-05 Thread Gerald Britton
I think it's because when you do ['a'].extend([]) or whatever, the
result is whatever the method extend returns.  But extend has no
return value, hence you will see None if you do this interactively.

On Fri, Feb 5, 2010 at 10:55 AM, Aahz a...@pythoncraft.com wrote:
 In article 088e7a24-b0d0-4d43-bee7-193e5eaef...@b7g2000pro.googlegroups.com,
 Dan Brown  fsenz...@gmail.com wrote:

Why does extending a list with the empty list result in None?  It
seems very counterintuitive to me, at least --- I expected ['a'].extend
([]) to result in ['a'], not None.

 http://www.python.org/doc/faq/general/#why-doesn-t-list-sort-return-the-sorted-list
 --
 Aahz (a...@pythoncraft.com)           *         http://www.pythoncraft.com/

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




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


Re: which

2010-02-05 Thread mk

Bruno Desthuilliers wrote:

if cmd:
self.cmd = cmd.replace..


And what if cmd happens to be the empty string ?-)

ok, me ---[]


Right, I didn't think much when I wrote that. Anyway, that's back to 
square one.


I will probably go for this anyway:

assert isinstance(cmd, basestring) or cmd is None, 'cmd has to 
be string or None'

if cmd:
cmd = cmd.replace(r'${ADDR}',ip)
self.cmd = cmd

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


Re: Python's Reference And Internal Model Of Computing Languages

2010-02-05 Thread David Thole
I read thisand am a tiny bit confused about the actual problem.

It's not exactly complex to realize that something like:
a = b = array
that a and b both point to the array.

Logically speaking, I'm not sure how one could assume that the same
assignment would yield a and b point to the same duplicate array.  If
that was the case, why not do:
a = array..
b = array..

I know with what you were complaining about a few days ago, .clear makes
perfect sense.  If a and b point to the same array, clear should clear
both arrays.  Again, if you didn't want that to happen, create a
duplicate array.

Personally I feel that this complexity doesn't hamper programming
process, and yes while its good for efficiency it also just makes sense.

Also, I wouldn't look at PHP on the right way to do something
programming wise.  I have ~5 years experience in this language, and I
dislike it a whole lot.  There's a lot of things it should do right that
it doesn't out of convenience.

-David
www.thedarktrumpet.com

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


Re: Repost: Read a running process output

2010-02-05 Thread Helmut Jarausch
On 02/05/10 14:39, Ashok Prabhu wrote:
 On Feb 5, 6:33 pm, Ashok Prabhu ashokprab...@gmail.com wrote:
 On Feb 5, 5:58 pm, Alain Ketterlin al...@dpt-info.u-strasbg.fr
 wrote:



 Ashok Prabhu ashokprab...@gmail.com writes:
 p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE,shell=True)

 Use Popen(['/usr/...','-d'],stdout=PIPE), i.e., no shell.

 -- Alain.
 Thanks for the response. However it throws an error. Please find
 below.

 from subprocess import *
 p1=Popen('/usr/sunvts/bin/64/vtsk -d',stdout=PIPE)

 You forgot to change the monolithic command into a list of words. Since
 you don't use the shell anymore you have to give Popen a pre-parsed
 command line.

 -- Alain.

 Here is the error again

 p1=Popen('/usr/sunvts/bin/64/vtsk','-d',stdout=PIPE)

 Traceback (most recent call last):
   File stdin, line 1, in ?
   File /usr/lib/python2.4/subprocess.py, line 494, in __init__
 raise TypeError(bufsize must be an integer)
 TypeError: bufsize must be an integer

 ~Ashok.
 
 Oops i missed the braces. But still no output.
 
 
 p1=Popen(['/usr/sunvts/bin/64/vtsk','-d'],stdout=PIPE)
 while 1:
 ...  a=p1.stdout.readline()
 ...  print a
 ...

I've tried

#!/usr/bin/python
import subprocess
p1= subprocess.Popen(['/bin/ls','/LOCAL/'],stdout=subprocess.PIPE)
for line in p1.stdout :
  print ,line

which works just fine.

Are you sure, your /usr/sunvts/bin/64/vtsk writes a newline character (readline 
is waiting for that)?

Helmut.

-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which

2010-02-05 Thread Jean-Michel Pichavant

mk wrote:

Jean-Michel Pichavant wrote:
If you can change your program interface, then do it, if not then 
you're right you don't have much choice as you are suffering from the 
program poor interface.
You can fix this problem by explicitly asking for the thing you want 
to do, instead of guessing by inspecting the argument nature.


myProg --help

usage : myProg command [args]
   command list:
  - cmd: execute the given arg1 command line
  - exec: execute the given script file named arg1
  - copy: copy arg1 to arg2

example:
 myProg cmd echo that's cool
 myProg exec /etc/init.d/myDaemon
 myProg copy /tmp /tmp2



I sure can change the interface since I'm the author of the entire 
program. But I don't see how I can arrange program in a different way: 
the program is supposed to be called with -c parameter (command to 
run), -s script to run, or -y file_or_dir_to_copy.


Then, I start instances of SSHThread class to do precisely that, 
separately for each ip/hostname:



class SSHThread(threading.Thread):
def __init__(self, lock, cmd, ip, username, sshprivkey=None, 
passw=None, port=22, script=None, remotedir=None):


threading.Thread.__init__(self)

self.lock = lock
if isinstance(cmd, str):
self.cmd = cmd.replace(r'${ADDR}',ip)
else:
self.cmd = cmd
self.ip = ip
self.username = username
self.sshprivkey = sshprivkey
self.passw = passw
self.port = port
self.conobj = None
self.conerror = ''
self.msgstr = ''
self.confailed = True
if script:
self.setpathinfo(script, remotedir=remotedir)
self.sentbytes = 0
self.finished = False
self.abort = False

It gets called like this:

th = SSHThread(lock, opts.cmd, ip, username=username, 
sshprivkey=opts.key, passw=passw, port=port, script=opts.script, 
remotedir=opts.remotedir)



..where all the options are parsed by ConfigParser.OptionParser(). So 
they are either strings, or Nones.


So in this context this is fine. But I wanted to make the class more 
robust. Perhaps I should do smth like this before setting self.cmd?


assert isinstance(cmd, basestring) or cmd is None, cmd should be 
string or None


and then:

if cmd:
self.cmd = cmd.replace..


?

Entire source code is here:

http://python.domeny.com/cssh.py

regards,
mk



To be honest I have not enough courrage to dive into yout 1000 lines of 
script :-)


What I can say however:

1/ your interface is somehow broken. You ask actions through options (-c 
-y -s), meaning one can possibly use all these 3 options  together. Your 
code won't handle it (you are using elif statements). What happens if I 
use no option at all ? As the the optparse doc states : if an option is 
not optional, then it is not an option (it's a positional argument).


2/ executing a script, or copying a directory are both commands as well.
myProg -s /tmp/myscript.sh
is nothing more than
myProg -c '/bin/sh myscript.sh'

myProg -y file1
is nothing more than
myProg -c 'cp file1 towhatever'

3/ check your user parameters before creating your SSHThread, and create 
your SSHThread with already validated parameters. You don't want to 
pollute you SSHThread code with irrelevant user error check.



my humble conclusion:

1/ rewrite your interface with
prog command args [options]

2/ Simplify your SSHThread by handling only  shell commands

3/ at the CLI level (right after parameter validation), mute you copy  
script

command to a shell command and pass it to SSHThread.

Cheers,

JM

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


Re: Drawing a zig-zag Trail in Python?

2010-02-05 Thread Jean-Michel Pichavant

mk wrote:

W. eWatson wrote:
I'd like to draw something like an animal track. Between each point 
is a line. Perhaps the line would have an arrow showing the direction 
of motion. There should be x-y coordinates axises. PIL? MatPlotLib, ??


Pycairo?


turtle

http://docs.python.org/library/turtle.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python's Reference And Internal Model Of Computing Languages

2010-02-05 Thread J�rgen Exner
David Thole dth...@gmail.com wrote in comp.lang.perl.misc:
I read thisand am a tiny bit confused about the actual problem.

It's not exactly complex to realize that something like:
a = b = array
that a and b both point to the array.

???
What are you talking about? First of all you should post actual code,
not pseudo-code because pseudo-code leads to misunderstandings. Did you
mean
@a = @b = @array

Second what do you mean by pointing? That is a very ambiguous term. if
you do the assignment as written above then @a and @b will be _copies_
of @array. If you want two additional references to the same array
insted then you have to create that reference first and assign that
reference to $a and $b instead of copying the array, see perldoc
perlref for details. And remember, references are scalars, no matter if
they reference other scalars or arrays.

Logically speaking, I'm not sure how one could assume that the same
assignment would yield a and b point to the same duplicate array.  If

Now what? The same array or a duplicate array? Two very different and
mutually exclusive things.

that was the case, why not do:
a = array..
b = array..

Which, after correcting the obvious syntax errors is the same as the
code above.

I know with what you were complaining about a few days ago, .clear makes
perfect sense.  If a and b point to the same array, clear should clear

They don't point, they are copies. And what do you mean by clear?

both arrays.  Again, if you didn't want that to happen, create a
duplicate array.

But that is what that code above does. If you want references then
create references.

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


Re: ANN: ActivePython 2.6.4.10 is now available

2010-02-05 Thread Sridhar Ratnakumar

On 2010-02-05, at 6:31 AM, Tommy Grav wrote:

 
 On Feb 5, 2010, at 12:01 AM, Sridhar Ratnakumar wrote:
 
 I'm happy to announce that ActivePython 2.6.4.10 is now available for 
 download from:
 
 On what platforms does ActivePython run?
 
 
 ActivePython includes installers for the following platforms:
 
 - Windows/x86
 - Windows/x64 (aka AMD64)
 - Mac OS X
 
 Is the Mac OS X version still only 32 bit?

Yes.

 If so does ActiveState plan to make binaries for 64bit builds
 for Snow Leopard?

No concrete plans yet, but we do intend to make 64 bit for Mac available 
eventually.

-srid

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


Re: which

2010-02-05 Thread John Posner

On 2/5/2010 11:26 AM, Gerald Britton wrote:

sure, but it will fit nicely on one line if you like

On Fri, Feb 5, 2010 at 11:22 AM, John Posnerjjpos...@optimum.net  wrote:
   

On 2/5/2010 11:06 AM, Gerald Britton wrote:
 

[snip]

   

Last August [1], I offered this alternative:

  self.cmd = (cmd.replace(r'${ADDR}',ip)
  if isinstance(cmd, str) else
  cmd)

But it didn't get much love in this forum!
 

I'd probably go for that one as well though I might consider removing
the outer parentheses.
   

Agreed ... except that you *need* the outer parentheses if the statement
occupies multiple source lines.

-John



 



   
Did you mean to take this off-list?  Also, I'm contractually obligated 
to admonish you not to top post.


At any rate, I proposed the 3-line format specifically because it 
separates the data values from the if-then-else machinery, making it 
easier (for me) to read. But there was considerable resistance to 
spending so much vertical space in the source code.


-John

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


Re: which

2010-02-05 Thread Gerald Britton

 Did you mean to take this off-list?

Nope -- just hit the wrong key

 Also, I'm contractually obligated to
 admonish you not to top post.

Contract?


 At any rate, I proposed the 3-line format specifically because it separates
 the data values from the if-then-else machinery, making it easier (for me)
 to read. But there was considerable resistance to spending so much vertical
 space in the source code.

Weird!  It's three lines and the original was four lines was it not?

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


Re: xmlrcp - how to marshall objects

2010-02-05 Thread Adam Tauno Williams
On Fri, 2010-02-05 at 17:03 +0100, Jean-Michel Pichavant wrote:
 Deos anyone knows where to find an code sample describing how to 
 implement the interface to marshall one object into XMLRPC compliant 
 structures ?
 I googled without any success, and what google does not find does not exist.
 Let say I have this very simple class:
 class Point:
 def __init__(self, x, y):
 self.x = x
 self.y = y

You have to be more specific about what you want to do; marshall is a
fairly generic term.  XML-RPC isn't CORBA; typically you don't remote
persistent objects you just make individual calls.

 I've looked into xmlrpc code, I see  2 options:
 1/ override the Marshaller class of client and server
 2/ looks like the lib is supporting a WRAPPER list system, it uses to 
 Marshall Datetime  Binary object. Can it be possible to add its own 
 class (could require to emplement the 'encode' method)
 I sense I will spend much more time than required unless someone is 
 pointing me in the right direction.

You can use the loads and dumps methods to process the XML-RPC call
anyway you like.
http://coils.hg.sourceforge.net/hgweb/coils/coils/file/22c023c8e0f5/src/coils/net/xmlrpc.py
-- 
OpenGroupware developer: awill...@whitemice.org
http://whitemiceconsulting.blogspot.com/
OpenGroupare  Cyrus IMAPd documenation @
http://docs.opengroupware.org/Members/whitemice/wmogag/file_view

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


Re: xmlrcp - how to marshall objects

2010-02-05 Thread mk

Jean-Michel Pichavant wrote:

Why not dump the whole thing and use Pyro, which works beautifully and 
handles all the serialization business by itself, you get a Python 
object on the other side? Unless xmlrpc has to be at the other end, that is.



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


Re: which

2010-02-05 Thread mk

Jean-Michel Pichavant wrote:

 To be honest I have not enough courrage to dive into yout 1000 lines of
 script :-)

Understandable.

 What I can say however:

 1/ your interface is somehow broken. You ask actions through options (-c
 -y -s), meaning one can possibly use all these 3 options  together. Your
 code won't handle it (you are using elif statements). What happens if I
 use no option at all ?

You get this:

Linux RH [17:35] root ~ # cssh.py -c ps|wc -s /tmp/s.sh

Following options that you specified are mutually exclusive:
-s / --script (value: /tmp/s.sh)
-c / --cmd (value: ps|wc)
You have to specify exactly one of options -c / --cmd, or -s / --script, 
or -y / --copy.


I wrote additional logic to handle such situations, I don't rely 
entirely on optparse.


 2/ executing a script, or copying a directory are both commands as well.
 myProg -s /tmp/myscript.sh
 is nothing more than
 myProg -c '/bin/sh myscript.sh'

True. But you have to copy the script to remote machine in the first 
place. It's more convenient to do this using one option (copy to remote 
machine  execute there).


 myProg -y file1
 is nothing more than
 myProg -c 'cp file1 towhatever'

Err but this is command to copy a local file/dir to *remote* machine. 
Like scp (in fact it uses scp protocol internally).



 3/ check your user parameters before creating your SSHThread, and create
 your SSHThread with already validated parameters. You don't want to
 pollute you SSHThread code with irrelevant user error check.


 my humble conclusion:

 1/ rewrite your interface with
 prog command args [options]

 2/ Simplify your SSHThread by handling only  shell commands

 3/ at the CLI level (right after parameter validation), mute you copy 
 script
 command to a shell command and pass it to SSHThread.

 Cheers,

 JM



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


Re: Drawing a zig-zag Trail in Python?

2010-02-05 Thread mk

Jean-Michel Pichavant wrote:

mk wrote:

W. eWatson wrote:
I'd like to draw something like an animal track. Between each point 
is a line. Perhaps the line would have an arrow showing the direction 
of motion. There should be x-y coordinates axises. PIL? MatPlotLib, ??


Pycairo?


turtle

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


It's in standard library, and therefore Not Cool.

duck


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


Re: pyclutter anyone?

2010-02-05 Thread donn

No one uses pyClutter?
I have some code, it does not work, but maybe this will start to help 
solve the problem:


import clutter
from clutter import cogl

x,y=0,0

def boo(tl,frame,obj):#,evt):
global x,y
obj.set_position(x, y)

def xy(obj,evt):
global x,y
x,y = evt.x,evt.y

class G(clutter.Group):

Attempt to make a Group that can clip its children to a path.

def __init__(self,*args):
clutter.Group.__init__(self,*args)
#self.set_clip(0,0,10,10)
self.connect(paint,self.do_paint)
self._color = clutter.Color(255,200,100)
def do_paint(self, args):
width,height=200,200
cogl.path_move_to(width / 2, 0)
cogl.path_line_to(width, height)
cogl.path_line_to(0, height)
cogl.path_line_to(width / 2, 0)
cogl.path_close()
#cogl.set_source_color(self._color)
#cogl.path_fill()

## Colour me lost from here...
cogl.clip_push_from_path()
clutter.Group.do_paint(self)
cogl.clip_pop()

def main():
global group1
stage = clutter.Stage()
stage.set_size(500, 500)
stage.set_color(clutter.color_from_string(#FFF))

	rect1, rect2, rect3 = clutter.Rectangle(), clutter.Rectangle(), 
clutter.Rectangle()

group1, group2, group3 = G(), clutter.Group(), clutter.Group()

group1.add(rect1, group2)
group2.add(rect2, group3)
group3.add(rect3)

group1.set_position(100, 100)
group2.set_position(100, 100)
group3.set_position(100, 100)

rect1.set_position(0, 0)
rect2.set_position(0, 0)
rect3.set_position(0, 0)

rect1.set_size(150, 150)
rect2.set_size(150, 150)
rect3.set_size(150, 150)

rect1.set_color(clutter.color_from_string(#FF90))
rect2.set_color(clutter.color_from_string(#00FF0090))
rect3.set_color(clutter.color_from_string(#FF90))

stage.add(group1)

stage.show_all()
group1.show_all()
group2.show_all()
group3.show_all()

stage.connect(key-press-event, clutter.main_quit)
stage.connect('destroy', clutter.main_quit)
stage.connect('motion-event', xy)

path = clutter.Path('M 0 0 L 300 0 L 300 300 L 0 300z')
timeline = clutter.Timeline(4000)
timeline.set_loop(True)
alpha = clutter.Alpha(timeline,clutter.EASE_OUT_SINE)
p_behaviour = clutter.BehaviourPath(alpha, path)
path.add_move_to(0, 0)
p_behaviour.apply(group3)   

timeline.add_marker_at_time(foo,2000)

timeline.start()

t=clutter.Timeline(1000)
t.set_loop(True)
t.connect('new-frame', boo, group1)
t.start()

clutter.main()

if __name__ == '__main__':
main()

\d

--
Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software
--
http://mail.python.org/mailman/listinfo/python-list


timer for a function

2010-02-05 Thread mk

I have the following situation:

1.

self.conobj = paramiko.SSHClient()

self.conobj.connect(self.ip, username=self.username, 
key_filename=self.sshprivkey, port=self.port, timeout=opts.timeout)


2. very slow SSH host that is hanging for 30+ seconds on key exchange.

The timeout in the options regards only a socket timeout, not further 
stages of connection negotiation, so it doesn't work there.


On paramiko mailing list I got the suggestion to build a timer and then 
quit this by myself:



The timeout option in connect() is for the socket, not for the entire
operation. You are connected, so that timeout is no longer relevant.
You would probably have to wrap the transport.connect() method in a
timer to break out of this early.


Question: how can I do that? Use another threaded class? Is there some 
other way?



Additional snag is SSHClient() is a class that internally uses threads. 
How do I kill brutally its threads? Is there any way to do it?


Regards,
mk

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


Re: xmlrcp - how to marshall objects

2010-02-05 Thread Jean-Michel Pichavant

Jean-Michel Pichavant wrote:
Deos anyone knows where to find an code sample describing how to 
implement the interface to marshall one object into XMLRPC compliant 
structures ?


I googled without any success, and what google does not find does not 
exist.


Let say I have this very simple class:

class Point:
   def __init__(self, x, y):
   self.x = x
   self.y = y


I've looked into xmlrpc code, I see  2 options:
1/ override the Marshaller class of client and server
2/ looks like the lib is supporting a WRAPPER list system, it uses to 
Marshall Datetime  Binary object. Can it be possible to add its own 
class (could require to emplement the 'encode' method)


I sense I will spend much more time than required unless someone is 
pointing me in the right direction.


JM

I realized I gave a poor example, actually the Point object is marshable 
(marshallable ? like to invent new words), xmlrpc will try to marshall 
using __dict__ if possible.


import os

class Point:
  def __init__(self, x, y):
  self.x = x
  self.y = y
  self.notMarshallable = os


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


Re: Dreaming of new generation IDE

2010-02-05 Thread Arnaud Delobelle
Robert Kern robert.k...@gmail.com writes:

 I prefer Guido's formulation (which, naturally, I can't find a direct
 quote for right now): if you expect that a boolean argument is only
 going to take *literal* True or False, then it should be split into
 two functions.

So rather than three boolean arguments, would you have eight functions?

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


Re: Your beloved python features

2010-02-05 Thread mk

Ethan Furman wrote:

http://www1.american.edu/academic.depts/cas/econ/faculty/isaac/choose_python.pdf 



Choose to get your difficult questions about threads in Python ignored. 
Oh well..


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


Re: Python's Reference And Internal Model Of Computing Languages

2010-02-05 Thread Tad McClellan
[Followup-To: header set to comp.lang.perl.misc.]

Jürgen Exner jurge...@hotmail.com wrote:
 David Thole dth...@gmail.com wrote in comp.lang.perl.misc:
I read thisand am a tiny bit confused about the actual problem.

It's not exactly complex to realize that something like:
a = b = array
that a and b both point to the array.

 ???
 What are you talking about? First of all you should post actual code,


First of all, we should not be feeding the troll!

actual code in one of Perl, Python or Lisp?


-- 
Tad McClellan
email: perl -le print scalar reverse qq/moc.liamg\100cm.j.dat/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xmlrcp - how to marshall objects

2010-02-05 Thread Jean-Michel Pichavant

mk wrote:

Jean-Michel Pichavant wrote:

Why not dump the whole thing and use Pyro, which works beautifully and 
handles all the serialization business by itself, you get a Python 
object on the other side? Unless xmlrpc has to be at the other end, 
that is.




Company stuff. We are all using the xmlrpc standard for our network code.

JM


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


Re: Drawing a zig-zag Trail in Python?

2010-02-05 Thread Grant Edwards
On 2010-02-05, W. eWatson wolftra...@invalid.com wrote:

 I'd like to draw something like an animal track. Between each
 point is a line. Perhaps the line would have an arrow showing
 the direction of motion. There should be x-y coordinates
 axises. PIL? MatPlotLib, ??

I'd probably use gnuplot-py, but I'm probably biased since I've
been using gnuplot since way before I learned Python.

-- 
Grant Edwards   grante Yow! Hello, GORRY-O!!
  at   I'm a GENIUS from HARVARD!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which

2010-02-05 Thread mk

mk wrote:


  What I can say however:
 
  1/ your interface is somehow broken. You ask actions through options (-c
  -y -s), meaning one can possibly use all these 3 options  together. Your
  code won't handle it (you are using elif statements). What happens if I
  use no option at all ?



Arrgh this is my bad day. You get this:

Linux RH [17:35] root ~ # cssh.py -i linux

You have to specify exactly one of the following:
 - command to run remotely, using -c command / --cmd command, or
 - script to run remotely, using -s scriptfile / --script scriptfile, or
 - file/directory to copy, using -y file_or_dir / --copy file_or_dir

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


Re: Your beloved python features

2010-02-05 Thread mk

Julian wrote:


For those guys would be a poster quite cool which describes the most
popular and beloved python features.


Dictionaries.

A workhorse of Python, by far the most useful data structure.


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


Re: method to intercept string formatting % operations

2010-02-05 Thread Brad Allen
On Fri, Feb 5, 2010 at 9:49 AM, Jean-Michel Pichavant
jeanmic...@sequans.com wrote:

 Anyway why would you want to use the tuple form ? it's beaten in every
 aspect by the dictionary form.

I'm subclassing a namedtuple, and adding some additional functionality
such as __getitem__, __setitem__, so that the namedtuple also behaves
like a dict.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modules failing to add runtime library path info at link time

2010-02-05 Thread cjblaine
On Feb 1, 11:35 pm, cjblaine cjbla...@gmail.com wrote:
 On Feb 1, 11:04 pm, cjblaine cjbla...@gmail.com wrote:



  On Feb 1, 8:00 pm, Christian Heimes li...@cheimes.de wrote:

   cjblaine wrote:
Where/how can I configure the appropriate portion of our Python
install to do 100% the right thing instead of just 50% (-L)?

   Python's distutils doesn't alter the library search path unless you tell
   it explicitly.

A specific example -- note the -L and lack of -R (Solaris build):

% python setup.py build

gcc -shared build/temp.solaris-2.10-sun4u-2.6/pgmodule.o -L/afs/rcf/
apps/catchall/lib -lpq -o build/lib.solaris-2.10-sun4u-2.6/_pg.so
%

   The Extension() class supports the rpath argument. Simply add
   rpath=/path/to/library/dir and you are good.

   Christian

  Thanks for the reply.

  So, python setup.py build rpath=/whatever/lib ?

 Replying to myself:

 No.  Actually, Christian, it looks like it's runtime_library_dirs?

 class Extension:
 ...
       runtime_library_dirs : [string]
         list of directories to search for C/C++ libraries at run time
         (for shared extensions, this is when the extension is loaded)

 So, how does one inject that into, I assume, setup.cfg ?  Ideally it
 could be done via the build command-line, but I don't see a way to do
 that when browsing python setup.py build --help

 ( there is no setup.cfg provided in the PyGreSQL source tree, to )
 ( continue that example case                                     )

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


Editor for Python

2010-02-05 Thread Laszlo Nagy


  Hi All,

I know that this question was put up on this list a thousand times. I 
know that most of the editors are listed here: 
http://wiki.python.org/moin/PythonEditors


I already tried most of them. But still, I need something that is not 
listed there. Requirements:


   * starts and works fast
   * has code folding, displays identation guides
   * auto completion
   * class browser
   * source code browser (e.g. a list of definitions, when you click it
 jumps to the definition
   * integration with pychecker or pylint
   * UTF-8 files
   * free, or not-so-expensive
   * works on linux and windows

The one I'm using now is Geany. It does everything, except class browser 
and pychecker/pylint. Now maybe, I can install (or write??) a geany 
extension that would allow me to use pychecker. But I could not find 
information on that. There where others I tried (PyPE, DrPython, 
KomodoEdit, Editra etc.) but all of them failed for some reason. Can you 
please suggest another editor that I could try? Or send me a link that 
tells how to write or install pychecked plugin for Geany.


Thanks,

   Laszlo

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


Re: xmlrcp - how to marshall objects

2010-02-05 Thread MRAB

Jean-Michel Pichavant wrote:

Jean-Michel Pichavant wrote:
Deos anyone knows where to find an code sample describing how to 
implement the interface to marshall one object into XMLRPC compliant 
structures ?


I googled without any success, and what google does not find does not 
exist.


Let say I have this very simple class:

class Point:
   def __init__(self, x, y):
   self.x = x
   self.y = y


I've looked into xmlrpc code, I see  2 options:
1/ override the Marshaller class of client and server
2/ looks like the lib is supporting a WRAPPER list system, it uses to 
Marshall Datetime  Binary object. Can it be possible to add its own 
class (could require to emplement the 'encode' method)


I sense I will spend much more time than required unless someone is 
pointing me in the right direction.


JM

I realized I gave a poor example, actually the Point object is marshable 
(marshallable ? like to invent new words), xmlrpc will try to marshall 
using __dict__ if possible.



marshallable. Just pick a verb and add -able.

There was an advertisement by British Gas in which someone said that his
gas central heating was very turn-off-and-on-able! :-)


import os

class Point:
  def __init__(self, x, y):
  self.x = x
  self.y = y
  self.notMarshallable = os


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


Re: which

2010-02-05 Thread John Posner

On 2/5/2010 11:53 AM, Gerald Britton wrote:

  Also, I'm contractually obligated to

admonish you not to top post.


Contract?


Joke. (I know it's hard to tell.)





At any rate, I proposed the 3-line format specifically because it separates
the data values from the if-then-else machinery, making it easier (for me)
to read. But there was considerable resistance to spending so much vertical
space in the source code.


Weird!  It's three lines and the original was four lines was it not?


Yes, but most people (including you, right?) seemed to think that 
conditional expressions are best confined to a single line.


I proposed my 3-line alternative for expressions that *cannot* 
reasonably be confined to a single line.


-John




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


Re: Editor for Python

2010-02-05 Thread Gerald Britton
2010/2/5 Laszlo Nagy gand...@shopzeus.com:

   Hi All,

 I know that this question was put up on this list a thousand times. I know
 that most of the editors are listed here:
 http://wiki.python.org/moin/PythonEditors

 I already tried most of them. But still, I need something that is not listed
 there. Requirements:

 starts and works fast
 has code folding, displays identation guides
 auto completion
 class browser
 source code browser (e.g. a list of definitions, when you click it jumps to
 the definition
 integration with pychecker or pylint
 UTF-8 files
 free, or not-so-expensive
 works on linux and windows

 The one I'm using now is Geany. It does everything, except class browser and
 pychecker/pylint. Now maybe, I can install (or write??) a geany extension
 that would allow me to use pychecker. But I could not find information on
 that. There where others I tried (PyPE, DrPython, KomodoEdit, Editra etc.)
 but all of them failed for some reason. Can you please suggest another
 editor that I could try? Or send me a link that tells how to write or
 install pychecked plugin for Geany.

 Thanks,

    Laszlo


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



I use Geany too.  It lets me see the classes in my module, though not
within a package (Is that what you mean)?  You'd probably have to
write a plugin to support pychecker or pylint though I believe that
its not too difficult.  Who knows?  Perhaps someone already has such a
plugin that you can use.

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


Exception class documentation

2010-02-05 Thread Charles Yeomans
I am so far unable to find the information I want about the Exception  
class.  Information like the signature of __init__ seems to be  
unavailable.  Any suggestions where I might find such information?



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


Re: How Uninstall MatPlotLib?

2010-02-05 Thread W. eWatson

On 2/5/2010 8:17 AM, W. eWatson wrote:

See Subject.
I'm working in IDLE in Win7. It seems to me it gets stuck in 
site-packages under C:\Python25. Maybe this is as simple as deleting the 
entry?


Well, yes there's a MPL folder under site-packages and an info MPL file 
of 540 bytes. There  are  also pylab.py, pyc,and py0 files under site.

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


Re: Exception class documentation

2010-02-05 Thread Gerald Britton
On Fri, Feb 5, 2010 at 12:55 PM, Charles Yeomans char...@declaresub.com wrote:
 I am so far unable to find the information I want about the Exception class.
  Information like the signature of __init__ seems to be unavailable.  Any
 suggestions where I might find such information?


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


Though not documented, some silly tests indicate that it will accept
pretty much anything:

 Exception(1,2,4,54)
Exception(1, 2, 4, 54)
 Exception(*range(10))
Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
 Exception(*range(50))
Exception(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49)
 Exception('a','b','c','d','e')
Exception('a', 'b', 'c', 'd', 'e')
 Exception(Exception(1))
Exception(Exception(1,),)

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


method names nounVerb or verbNoun

2010-02-05 Thread Wanderer
Which is the more accepted way to compose method names nounVerb or
verbNoun?

For example voltageGet or getVoltage? getVoltage sounds more normal,
but voltageGet is more like voltage.Get. I seem to mix them and I
should probably pick one way and stick with it.

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


Re: Dreaming of new generation IDE

2010-02-05 Thread Steve Holden
Arnaud Delobelle wrote:
 Robert Kern robert.k...@gmail.com writes:
 
 I prefer Guido's formulation (which, naturally, I can't find a direct
 quote for right now): if you expect that a boolean argument is only
 going to take *literal* True or False, then it should be split into
 two functions.
 
 So rather than three boolean arguments, would you have eight functions?
 
If there's genuinely a need for that functionality, yes.

I statement that calls one of two functions depending on the value of a
Boolean is normally considered to be better coupling than calling a
single function with the Boolean as an argument.

As with everything else you have to apply a certain amount of common sense.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: method names nounVerb or verbNoun

2010-02-05 Thread Gerald Britton
On Fri, Feb 5, 2010 at 2:53 PM, Wanderer wande...@dialup4less.com wrote:
 Which is the more accepted way to compose method names nounVerb or
 verbNoun?

 For example voltageGet or getVoltage? getVoltage sounds more normal,
 but voltageGet is more like voltage.Get. I seem to mix them and I
 should probably pick one way and stick with it.

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


I'd say noun_verb (note the underscore in accordance with the style
guide in PEP 8):

http://www.python.org/dev/peps/pep-0008/

Function Names

  Function names should be lowercase, with words separated by underscores
  as necessary to improve readability.

  mixedCase is allowed only in contexts where that's already the
  prevailing style (e.g. threading.py), to retain backwards compatibility.

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


Re: How to guard against bugs like this one?

2010-02-05 Thread John Nagle

kj wrote:
...


Through a *lot* of trial an error I finally discovered that the
root cause of the problem was the fact that, in the same directory
as buggy.py, there is *another* innocuous little script, totally
unrelated, whose name happens to be numbers.py. 


   The right answer to this is to make module search return an
error if two modules satisfy the search criteria.  First find
isn't a good solution.

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


Last M digits of expression A^N

2010-02-05 Thread mukesh tiwari
Hello everyone. I am kind of new to python so pardon me if i sound
stupid.
I have to find out the last M digits of expression.One thing i can do
is (A**N)%M but my  A and N are too large (10^100) and M is less than
10^5. The other approach   was  repeated squaring and taking mod of
expression. Is there any other way to do this in python more faster
than log N.

def power(A,N,M):
ret=1
while(N):
if(N%2!=0):ret=(ret*A)%M
A=(A*A)%M
N=N//2
return ret
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xmlrcp - how to marshall objects

2010-02-05 Thread Adam Tauno Williams
On Fri, 2010-02-05 at 18:24 +0100, Jean-Michel Pichavant wrote:
 Jean-Michel Pichavant wrote:
  Deos anyone knows where to find an code sample describing how to 
  implement the interface to marshall one object into XMLRPC compliant 
  structures ?
  I googled without any success, and what google does not find does not 
  exist.
  Let say I have this very simple class:
  class Point:
 def __init__(self, x, y):
 self.x = x
 self.y = y
  I've looked into xmlrpc code, I see  2 options:
  1/ override the Marshaller class of client and server
  2/ looks like the lib is supporting a WRAPPER list system, it uses to 
  Marshall Datetime  Binary object. Can it be possible to add its own 
  class (could require to emplement the 'encode' method)
  I sense I will spend much more time than required unless someone is 
  pointing me in the right direction.
 I realized I gave a poor example, actually the Point object is marshable 
 (marshallable ? like to invent new words), xmlrpc will try to marshall 
 using __dict__ if possible.
 import os
 class Point:
def __init__(self, x, y):
self.x = x
self.y = y
self.notMarshallable = os

This example doesn't make any sense.  Why would you set a variable equal
to an important module in a class named Point?

What is it you are actually trying to accomplish?  If you are trying to
create an object publishing environment then maybe something like -

rpc = xmlrpclib.loads(payload, use_datetime=True)
method = rpc[1].split('.')
classname   = method[0]
methodname = method[1]
parameters  = rpc[0]
classclass = eval(classname)
handler = classclass()
call = getattr(handler, method_name)
result = apply(call, parameters)
result = xmlrpclib.dumps(tuple([result]), methodresponse=True)

Obviously add copious amounts of exception handling and a security
model.
-- 
OpenGroupware developer: awill...@whitemice.org
http://whitemiceconsulting.blogspot.com/
OpenGroupare  Cyrus IMAPd documenation @
http://docs.opengroupware.org/Members/whitemice/wmogag/file_view

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


Re: How to guard against bugs like this one?

2010-02-05 Thread Stephen Hansen
On Fri, Feb 5, 2010 at 12:16 PM, John Nagle na...@animats.com wrote:

 kj wrote:

 Through a *lot* of trial an error I finally discovered that the
 root cause of the problem was the fact that, in the same directory
 as buggy.py, there is *another* innocuous little script, totally
 unrelated, whose name happens to be numbers.py.


   The right answer to this is to make module search return an
 error if two modules satisfy the search criteria.  First find
 isn't a good solution.


And thereby slowdown every single import and application startup time as the
common case of finding a module in one of the first couple entries in
sys.path now has to search it in every single item on that path. Its not
uncommon to have a LOT of things on sys.path.

No thanks. First Find is good enough, especially with PEP328 and
absolute_import being on in Python 3 (and presumably 2.7). It doesn't really
help older Python versions unfortunately, but changing how import works
wouldn't help them anyways. Yeah, there might be two paths on sys.path which
both have a 'numbers.py' at the top level and First Find might return the
wrong one, but... people making poor decisions on code organization and not
using packages isn't something the language really needs to fix.

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


Re: Last M digits of expression A^N

2010-02-05 Thread Mark Dickinson
On Feb 5, 8:14 pm, mukesh tiwari mukeshtiwari.ii...@gmail.com wrote:
 Hello everyone. I am kind of new to python so pardon me if i sound
 stupid.
 I have to find out the last M digits of expression.One thing i can do
 is (A**N)%M but my  A and N are too large (10^100) and M is less than
 10^5. The other approach   was  repeated squaring and taking mod of
 expression. Is there any other way to do this in python more faster
 than log N.

 def power(A,N,M):
     ret=1
     while(N):
         if(N%2!=0):ret=(ret*A)%M
         A=(A*A)%M
         N=N//2
     return ret

The built-in pow function does exactly this, if you give it three
arguments:

 pow(12345, 67891, 17)
10
 12345 ** 67891 % 17
10L

(Though this won't work for negative N.)

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


Re: Last M digits of expression A^N

2010-02-05 Thread Gerald Britton
On Fri, Feb 5, 2010 at 3:14 PM, mukesh tiwari
mukeshtiwari.ii...@gmail.com wrote:
 Hello everyone. I am kind of new to python so pardon me if i sound
 stupid.
 I have to find out the last M digits of expression.One thing i can do
 is (A**N)%M but my  A and N are too large (10^100) and M is less than
 10^5. The other approach   was  repeated squaring and taking mod of
 expression. Is there any other way to do this in python more faster
 than log N.

 def power(A,N,M):
    ret=1
    while(N):
        if(N%2!=0):ret=(ret*A)%M
        A=(A*A)%M
        N=N//2
    return ret
 --
 http://mail.python.org/mailman/listinfo/python-list


http://docs.python.org/3.1/library/decimal.html#decimal.Context.power

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


Re: method names nounVerb or verbNoun

2010-02-05 Thread Chris Rebert
On Fri, Feb 5, 2010 at 11:53 AM, Wanderer wande...@dialup4less.com wrote:
 Which is the more accepted way to compose method names nounVerb or
 verbNoun?

 For example voltageGet or getVoltage? getVoltage sounds more normal,
 but voltageGet is more like voltage.Get. I seem to mix them and I
 should probably pick one way and stick with it.

Use properties[1] and just call it `voltage`. Python is not Java [2];
explicit getters/setters are unpythonic.

[1] http://docs.python.org/library/functions.html#property
[2] http://dirtsimple.org/2004/12/python-is-not-java.html

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


Re: method names nounVerb or verbNoun

2010-02-05 Thread MRAB

Wanderer wrote:

Which is the more accepted way to compose method names nounVerb or
verbNoun?

For example voltageGet or getVoltage? getVoltage sounds more normal,
but voltageGet is more like voltage.Get. I seem to mix them and I
should probably pick one way and stick with it.


I would use the 'normal' order, which in this case is 'get_voltage'.
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >