BayPIGgies at OSCON: 7/23 8-9:30pm

2009-07-10 Thread Aahz
NOTE: time change AND location change

The July BayPIGgies meeting will be held at OSCON in the San Jose
Convention Center as one of the BoF (Birds of a Feather) sessions from
8pm to 9:30pm Thursday July 23.  Everyone is welcome: you do NOT need to
be an OSCON member to attend a BoF.

Wesley Chun will have a newbie-oriented What is Python? BoF from 7-8pm
in the same room as BayPIGgies (we don't know which room yet).

The July meeting is supposed to have a Django focus, but the program
hasn't been settled yet, either.

For more information, see
http://baypiggies.net/

Discussion of details will take place on the BayPIGgies list:
http://mail.python.org/mailman/listinfo/baypiggies
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


way for a function to understand whether it's being run through a OnCreate callback or not

2009-07-10 Thread slamdunk
is there a way for a function to understand whether it's being run
through a OnCreate callback or not?
I have working functions that I want to recycle through the OnCreate
but need to catch the nuke.thisNode() bit inside them so they can
still function when called manually through other scripts functions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AP -- MeAmI.org Paces Google

2009-07-10 Thread Bruce C. Baker

Floetry scribe...@yahoo.com wrote in message 
news:803a7f06-8e43-4ff5-86a6-9fd9d2eee...@2g2000prl.googlegroups.com...
On Jul 9, 8:33 pm, Bruce C. Baker b...@undisclosedlocation.net
wrote:
 scribe...@yahoo.com wrote in message

 news:defacf35-6149-485a-8f03-15472d63d...@a39g2000pre.googlegroups.com...

 ka-snip

 Oh, puh-LEEZ, Martin! A two-year-old wouldn't be fooled by this!

Any reason ka-snip?

Binomial Theorem: page 3. http://MeAmI.org/pversusnp.pdf

_

Well, *Martin*, since you think I'm dead, it could only have been my ka 
that did the snipping. Surely a polymath of your vast accomplishments will 
have no problem with the religio-historical reference, eh, *Martin*? (I'm 
predicting that not only will you *not* recognize it, you'll find it beneath 
your notice. No fair googling, *Martin*!)




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


Re: way for a function to understand whether it's being run through a OnCreate callback or not

2009-07-10 Thread Chris Rebert
On Thu, Jul 9, 2009 at 11:18 PM, slamdunks.de...@gmail.com wrote:
 is there a way for a function to understand whether it's being run
 through a OnCreate callback or not?
 I have working functions that I want to recycle through the OnCreate
 but need to catch the nuke.thisNode() bit inside them so they can
 still function when called manually through other scripts functions.

Your question lacks context. What's an OnCreate callback?

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


Re: way for a function to understand whether it's being run through a OnCreate callback or not

2009-07-10 Thread Gary Herron

slamdunk wrote:

is there a way for a function to understand whether it's being run
through a OnCreate callback or not?
I have working functions that I want to recycle through the OnCreate
but need to catch the nuke.thisNode() bit inside them so they can
still function when called manually through other scripts functions.
  
You've given us almost *NO* clue what you are talking about.   I suppose 
I could Google onCreate, and perhaps nuke and thisNode, and see 
what falls out.  But why would I?  If you want our help, *you* take the 
time to tell is what you are asking about. 

You may want to start here:  
http://www.catb.org/~esr/faqs/smart-questions.html#intro


Gary Herron

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


Re: Examples of Python driven Microsoft UI Automation wanted

2009-07-10 Thread Kelie
On Jul 9, 5:50 pm, Tim Roberts t...@probo.com wrote:
 The University of North Carolina at Chapel Hill has a great Python package
 called pyAA that does exactly this:

 http://www.cs.unc.edu/Research/assist/developer.shtmlhttp://mindtrove.info/articles/gui-automation-with-pyaa/
 --
 Tim Roberts, t...@probo.com

Thanks Tim. From this page http://sourceforge.net/projects/uncassist/files/,
there isn't a installer for Python2.5 or higher. Didn't find the
source code there either.

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


Re: AP -- MeAmI.org Paces Google

2009-07-10 Thread Musatov
On Jul 9, 11:21 pm, Bruce C. Baker b...@undisclosedlocation.net
wrote:
 Floetry scribe...@yahoo.com wrote in message

 news:803a7f06-8e43-4ff5-86a6-9fd9d2eee...@2g2000prl.googlegroups.com...
 On Jul 9, 8:33 pm, Bruce C. Baker b...@undisclosedlocation.net
 wrote:

  scribe...@yahoo.com wrote in message

 news:defacf35-6149-485a-8f03-15472d63d...@a39g2000pre.googlegroups.com...

  ka-snip

  Oh, puh-LEEZ, Martin! A two-year-old wouldn't be fooled by this!

 Any reason ka-snip?

 Binomial Theorem: page 3.http://MeAmI.org/pversusnp.pdf

 _

 Well, *Martin*, since you think I'm dead, it could only have been my ka
 that did the snipping. Surely a polymath of your vast accomplishments will
 have no problem with the religio-historical reference, eh, *Martin*? (I'm
 predicting that not only will you *not* recognize it, you'll find it beneath
 your notice. No fair googling, *Martin*!)

I did not Google.

ka in ancient Egypt, the supposed spiritual part of an individual
human being or god, which survived (with the soul) after death and
could reside in a statue of the person.

ELIZABETH KNOWLES. ka. The Oxford Dictionary of Phrase and Fable.
Oxford University Press. 2006. Encyclopedia.com. 10 Jul. 2009 http://
www.encyclopedia.com.

In a third class of religion—usually heavily interlaced with fetishism—
magic, momentary and special deities, nature gods, and deities
personifying natural functions (such as the Egyptian solar god Ra, the
Babylonian goddess of fertility Ishtar, the Greek sea-god Poseidon,
and the Hindu goddess of death and destruction *Ka*li) emerge and are
incorporated into a system of mythology and ritual. Sometimes they
take on distinctively human characteristics (see anthropomorphism).

The axis of reason - equinox, mass, and time - the orbits of ...Et a
basso profundo hashi-hashi-brek-a-time todo ka tiempo.  Vozacka
dozvola macarana lambada ... (⋯@⋮⋱⋮@⋯)) P. -- Musatov http://MeAmI.org
...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: way for a function to understand whether it's being run through a OnCreate callback or not

2009-07-10 Thread Martin Vilcans
On Fri, Jul 10, 2009 at 8:18 AM, slamdunks.de...@gmail.com wrote:
 is there a way for a function to understand whether it's being run
 through a OnCreate callback or not?
 I have working functions that I want to recycle through the OnCreate
 but need to catch the nuke.thisNode() bit inside them so they can
 still function when called manually through other scripts functions.

I suppose you're programming for The Foundry's Nuke. Python is used in
lots of different contexts, and most people on this list use Python
for something totally unrelated to video.

As an attempt at answering your question, you can add a parameter to
your function that tells from where it's called. I.e. you put True in
the parameter when it is called from OnCreate, False when it is not.
But that isn't a very good design. A function should not need to care
from where it is called. You probably want to have the node as a
parameter to the function instead of calling nuke.thisNode inside of
it.

I can't find documentation for the OnCreate function online. Do you
mean that you can only call nuke.thisNode() from inside OnCreate?

Here's my guess of what I think you want to do:

def OnCreate():
# call your function with the current node as argument
your_function(nuke.thisNode())

def your_function(node):
# The function takes a node as an argument.
# Do whatever you want here

For more Nuke-specific questions, you'd probably get better results by
asking on the Nuke-python mailing list:

http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python


-- 
mar...@librador.com
http://www.librador.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for the right library for a simple HTTP client

2009-07-10 Thread David Stanek
On Fri, Jul 10, 2009 at 1:29 AM,
scriptlear...@gmail.comscriptlear...@gmail.com wrote:
 I am trying to implement a simple client that can do the following:
 1)to send the following kinds of HTTP requests and validate responses
 1.1 GET
 1.2 POST with application/x-www-form-urlencoded encoding
 1.3 POST with multipart/form-data encoding

 2)to set any number of (even duplicate) headers.  For example, I may
 intentionally add the following Cookie: headers to a request:
 Cookie: id_1=v1;Domain=sample.com;Path=/
 Cookie: id_1=v1;Domain=sample.com;Path=/ --same as the one above
 Cookie: id_2=v1;Domain=sample.com;Path=/

 3)to set proxy cfg so requests can go through a proxy server to reach
 the target server.

 4)to send multiple requests simultaneously.


 I have Python 2.4.1 on Solaris 9 and 10, and I don't have any plan to
 upgrade to latest version of Python.

 I looked around and I found httplib and urllib.  Are they sufficient
 for my tasks 1 to 3 above?  Any good sample codes will be great.
 Thanks.
 --
 http://mail.python.org/mailman/listinfo/python-list


I like urllib2. The examples[1] are pretty good.

[1] http://www.python.org/doc/2.4.1/lib/urllib2-examples.html

-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
-- 
http://mail.python.org/mailman/listinfo/python-list


Httplib issues

2009-07-10 Thread jayesh bhardwaj
Hi,
i was trying to download file frm a terminal having apache with
httplib manipulation. It worked, now i want to upload file to the
terminal. Can this b done by httplib too?
-- 
http://mail.python.org/mailman/listinfo/python-list


need to write a assembly progrm

2009-07-10 Thread m.reddy prasad reddy
my aim is to run the assembly programs in python.by that we can use that in
the any labs.because we can run the python in the mobiles also.if we write
assembly programs in the mobile ,the mobile act as a tool kit for the
lab.tell me any other solutions for this
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AP -- MeAmI.org Paces Google

2009-07-10 Thread The Masked Logician
On Jul 9, 6:18 pm, Bruce C. Baker b...@undisclosedlocation.net
wrote:
 Musatov marty.musa...@gmail.com wrote in message

 news:fe9969b0-3c6a-49f7-8f38-0ed89dc9a...@x6g2000prc.googlegroups.com...

 [snip-a-rooney]

  violator. Google could not be reached for comment.

 Possibly because they were laughing so hard they couldn't hear their cell
 phones ringing ...?

Thank you for your comment Bruce C. Baker. Are you aware you're dead?

http://wcc.dli.mt.gov/B/BAKER_BRUCE_SJ_DECISION.htm

http://MeAmI.org

The Best Search Engine for Fat Dead Guys named Bruce
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AP -- MeAmI.org Paces Google

2009-07-10 Thread Bruce C. Baker
Musatov marty.musa...@gmail.com wrote in message 
news:fe9969b0-3c6a-49f7-8f38-0ed89dc9a...@x6g2000prc.googlegroups.com...

[snip-a-rooney]

 violator. Google could not be reached for comment.

Possibly because they were laughing so hard they couldn't hear their cell 
phones ringing ...? 


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


Re: gett error message: TypeError: 'int' object is not callable

2009-07-10 Thread Lie Ryan
Friðrik Már Jónsson wrote:
 Hi Rhodri,
 
 It's only really a pitfall if you try to use the built-in after you've
 redefined it.  That's the thing to keep an eye open for.
 
 You're right, but in cases where you're editing a codebase which you
 didn't author entirely by yourself you may not be aware of that.
 
 That said, if the codebase you're working on is structured (short,
 concise methods) you should be working with small, consumable scopes you
 can inhale in entirety before modifying.
 
 Regards,
 Friðrik Már

But if you are responsible for a large codebase that you don't write
yourself, it is doubtful that you're a real newbie.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gett error message: TypeError: 'int' object is not callable

2009-07-10 Thread Lie Ryan
Simon Forman wrote:
 On Thu, Jul 9, 2009 at 9:42 AM, Nicknleio...@gmail.com wrote:
 snip
fields = line.split()
for i in range(len(fields)):
fields[i] = float(fields[i])
 
 
 instead of the above code you could say:
 
 fields = [float(n) for n in in line.split()]
 
 Have fun getting back into python! :]  (A lot has changed in the last few 
 years)

 fields = [float(n) for n in in line.split()]
  File stdin, line 1
fields = [float(n) for n in in line.split()]
 ^
SyntaxError: invalid syntax

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


Re: Package for fast plotting of many data points in Python?

2009-07-10 Thread Jeremy Sanders
tt-industries wrote:

 Hi,
 
 I am programming a oscilloscope module in Python. For this reason, I
 want to plot very many data points as fast as possible. This can be
 more than 100 000 at once. So far I have been using the ploting module
 of wxPython. However, it becomes unstable for more than 25000 points.
 Can someone recommend me a faster plotting library? It would be really
 cool if one could embed this in wxPython. If someone has an idea I
 would be very glad about answer.

Veusz can plot a line with that many points with that many points in a 
couple of seconds on my system. It's a bit faster without antialiasing, 
slower if you want to actually plot markers at each position.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/

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


Re: Httplib issues

2009-07-10 Thread Diez B. Roggisch

jayesh bhardwaj schrieb:

Hi,
i was trying to download file frm a terminal having apache with
httplib manipulation. It worked, now i want to upload file to the
terminal. Can this b done by httplib too?


Upload file to the terminal makes no sense to me. You can upload 
something to a server. You can run a terminal. You can run a ssh-session 
to a server in a terminal. You can't upload to a terminal.


But you can use httplib (or better urllib2) to make http-post-requests 
to webservers.


And last but not least the ubiquious

http://catb.org/esr/faqs/smart-questions.html

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


Re: Clarity vs. code reuse/generality

2009-07-10 Thread Jean-Michel Pichavant

Nobody wrote:

On Thu, 09 Jul 2009 04:57:15 -0300, Gabriel Genellina wrote:

  
Nobody says you shouldn't check your data. Only that assert is not the  
right way to do that.



assert is not the right way to check your *inputs*. It's a perfectly
reasonable way to check data which should be valid, as well as a way to
document what variables are supposed to contain.

  
Maybe, one of the assert problem is a semantic issue. Assert is a 
convenient way to write in the code This is a requirement, get lost if 
you don't fit in. However it seems we often forget that builtin asserts 
can be disabled.
One possible solution for those who prefer to write assertions instead a 
'if A then Exception' is to write their own assertion statement and 
**raise an exception** that will not be disabled at runtime.


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


Re: Colour of output text

2009-07-10 Thread garabik-news-2005-05
Tim Harig user...@ilthio.net wrote:
 On 2009-07-09, Alex Rosslyn black.line...@gmail.com wrote:
 I would like to learn a way of changing the colour of a particular
 part of the output text. I've tried the following

 On Unix operating systems this would be done through the curses interface:
 
 http://docs.python.org/library/curses.html

Or using ANSI colour codes:

colours = {
'none'   :,
'default':\033[0m,
'bold'   :\033[1m,
'underline'  :\033[4m,
'blink'  :\033[5m,
'reverse':\033[7m,
'concealed'  :\033[8m,

'black'  :\033[30m,
'red':\033[31m,
'green'  :\033[32m,
'yellow' :\033[33m,
'blue'   :\033[34m,
'magenta':\033[35m,
'cyan'   :\033[36m,
'white'  :\033[37m,

'on_black'   :\033[40m,
'on_red' :\033[41m,
'on_green'   :\033[42m,
'on_yellow'  :\033[43m,
'on_blue':\033[44m,
'on_magenta' :\033[45m,
'on_cyan':\033[46m,
'on_white'   :\033[47m,

'beep'   :\007,

# non-standard attributes, supported by some terminals 
'dark' :\033[2m,
'italic'   :\033[3m,
'rapidblink'   :\033[6m,
'strikethrough':\033[9m,
}

print colours['red'], 'this is red', colours['blue'], 'blue', 
colours['on_green'], 'and with a green background', colours['default']

-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


the ultimate logging facility for debugging code

2009-07-10 Thread Jean-Michel Pichavant

Greetings,

Sorry for the dubious title :o). I was wandering if there is a standard 
(or reliable) python module that implements the following feature:


http://code.activestate.com/recipes/198078/
Recipe 198078: Wrapping method calls (meta-class example)

A metaclass is used to wrap all (or just some) methods for logging 
purposes. The underlying mechanism can be used as well to check pre/post 
conditions, attribute access,... The basic point is, that the actual 
class must not be changed in any way to achive the desired effect.
  

I had to adapt the code to some of my needs, but now it's almost 
working, by simply defining a metaclass for any of my class, I get the 
class methods calls logged with the instance that called the method, the 
method name, the call line in the file, the parameter **value**  passed 
to the method and the returned value.
It just saved me from hours of ipython interactive debugging with the 
old print way, and to beauty of it: I don't have to write any 
self._log('Please log me') line.


As it is so useful, I bet there is a module that is doing this in a more 
reliable way that I did. Anyone has heard of it ?


Jean-Michel

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


help me to find the error

2009-07-10 Thread jhinak sen
hi,
i am a beginner in python language,

i am trying with this programme :
to find the addition and mean from a data set in a file and writing the mean
and sum in some other file :

*#! /usr/bin/env python

import re
import cPickle as p
import math
from numpy import *

f0= open(temp9,r+).readlines()
f2= open(out1,r+)
add_1=[ ];
for i in range(0, len(f0)):
f1=f0[i].split()
add= float(f1[1])+float(f1[2])
mean= float(add)/2
print (f1[1]).ljust(6) ,(f1[2]).ljust(6),repr(add).ljust(7),
repr(mean).ljust(7)
add_1.append(add)
add_1.append(mean)
f2.write(%s % repr(add).ljust(7)),f2.write(%s %
repr(mean).ljust(7))
print printing from file
for i in range(0, len(add_1),2):
print add_1[i],, add_1[i+1]

f0.close()
f2.close()*




and this programme is givving me this error :

*Traceback (most recent call last):
  File ./temporary1.py, line 24, in module
f0.close()
AttributeError: 'list' object has no attribute 'close'*


please help to to find the error.
or suggest some simpler or better way

note:
1)file temp9 is already exist
2)this programme is giving me all my outputs, but at the end of the out
..its giving me that error.
-- 
http://mail.python.org/mailman/listinfo/python-list


A zlib question

2009-07-10 Thread Roland Hedberg

Hi!

I have a problem with zlib and compressing/decompressing according to  
RFC 1951.


It seems like I can decompress, something compressed according to RFC  
1951 by someone else, provided I set wbits to something negative (used  
-8 but I guess any negative number would work?).


But how can I compress using zlib so it doesn't add a gzip header ?

-- Roland 
--

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


Re: help me to find the error

2009-07-10 Thread Xavier Ho
I'm new to Python myself, but I think it's because the method readlist()
returns a list. Hence, f0 is typed 'list'. And lists can't be closed.

If you leave it to:

*f0= open(temp9,r+)

*and then assign another variable to the readlist, such as:

*lines = f0.readlines()*

Then in the for loop, change f1 to

*f1=lines[i].split()*

That may just stop it from complaining.

Untested, but logically it's sound.

Hope that works,

Ching-Yun Xavier Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: cont...@xavierho.com
Website: http://xavierho.com/


On Fri, Jul 10, 2009 at 5:41 PM, jhinak sen jhinak@gmail.com wrote:

 hi,
 i am a beginner in python language,

 i am trying with this programme :
 to find the addition and mean from a data set in a file and writing the
 mean and sum in some other file :
 
 *#! /usr/bin/env python

 import re
 import cPickle as p
 import math
 from numpy import *

 f0= open(temp9,r+).readlines()
 f2= open(out1,r+)
 add_1=[ ];
 for i in range(0, len(f0)):
 f1=f0[i].split()
 add= float(f1[1])+float(f1[2])
 mean= float(add)/2
 print (f1[1]).ljust(6) ,(f1[2]).ljust(6),repr(add).ljust(7),
 repr(mean).ljust(7)
 add_1.append(add)
 add_1.append(mean)
 f2.write(%s % repr(add).ljust(7)),f2.write(%s %
 repr(mean).ljust(7))
 print printing from file
 for i in range(0, len(add_1),2):
 print add_1[i],, add_1[i+1]

 f0.close()
 f2.close()*


 

 and this programme is givving me this error :

 *Traceback (most recent call last):
   File ./temporary1.py, line 24, in module
 f0.close()
 AttributeError: 'list' object has no attribute 'close'*
 

 please help to to find the error.
 or suggest some simpler or better way

 note:
 1)file temp9 is already exist
 2)this programme is giving me all my outputs, but at the end of the out
 ..its giving me that error.

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


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


Re: Concatenating images (numpy arrays), but they look like HSV images

2009-07-10 Thread Sebastian Schabe

Robert Kern schrieb:
Probably, you need to use zeros(..., dtype=uint8). When you use 
dtype=int, that will result in dtype=int arrays. I suspect that 
matplotlib is then interpreting that to mean that you want it to treat 
the input as scalar data (which it will pass through a colormap) rather 
than an RGB image.




Thanks Robert, that was exactly the problem. Now I'am really wondering 
how one can know such details. Well, with your answer I searched again 
in the mathplotlib documentation and under the function imshow(X, ...) I 
indeed found the hint, that X has to be an uint8 or float array or PIL 
image, but before I hadn't known where to search.


So again, thank you

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


Re: hoe to build a patched socketmodule.c

2009-07-10 Thread jacopo mondi
Roger Binns wrote:
 jacopo mondi wrote:
 Hi all, I need to patch socketmodule.c (the _socket module) in order to
 add support to an experimental socket family.
 
 You may find it considerably easier to use ctypes since that will avoid
 the need for any patching.  You'll also be able to control how read and
 write are done (eg read vs recvfrom vs recvmsg vs readv).  You can use
 os.fdopen to convert your raw file descriptor into a Python file object
 if appropriate.
 
 If you do use ctypes then you'll only need to distribute pure Python
 source code.
 
 Roger
Thanks a lot, I'll give it a try..

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


Re: property using a classmethod

2009-07-10 Thread Bruno Desthuilliers

Lie Ryan a écrit :

Bruno Desthuilliers wrote:

Lie Ryan a écrit :

Emanuele D'Arrigo wrote:

(snip)

Ultimately all I want is a non-callable class-level attribute
MyClass.myProperty that gives the result of MyClass.myClassMethod().

This works like what you seem to want (it's ugly):

Ugly, indeed. And an extreme case of arbitrary overcomplexification too :-/

(snip rube goldberg code)



Can't think of anything simpler than that without meddling with
descriptor.


Hmmm... Rereading the OP's spec, I guess you understood it better than I 
did - seems the OP wants to be able to call the property on the class 
object itself - which won't work with the builtin property type. So my 
own proposed solution won't do :-/


But still, meddling with descriptor is *way* simpler than your 
proposed solution. Here's a simple non-binding descriptor that do the job:


class ClsProperty(object):
def __init__(self, fget):
if not isinstance(fget, (classmethod, staticmethod)):
raise ValueError(
  fget must be a classmethod or staticmethod
  )
self.fget = fget

def __get__(self, obj, cls=None):
if cls is None:
assert obj is not None
cls = type(obj)
return self.fget.__get__(obj, cls)()


# example use
class Foo(object):
@classmethod
def bar(cls):
return %s.bar % cls.__name__

quux = ClsProperty(bar)



I'm not even sure descriptor can help here as it seems
descriptor needs an instance?


wrt/ descriptors, no, they don't need an instance, at least for 
non-binding descriptors. Else, MyClass.MyMethod would return the 
MyClass.__dict__['MyMethod'] function, not an unbound method object !-)



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


Re: Python-list Digest, Vol 70, Issue 142

2009-07-10 Thread jhinak sen
hey Xavier

thnx a lot :)
its working and ya.. i got your pont regarding typecasting .

jhinak

On Fri, Jul 10, 2009 at 3:30 PM, python-list-requ...@python.org wrote:

 Send Python-list mailing list submissions to
python-list@python.org

 To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
 or, via email, send a message with subject or body 'help' to
python-list-requ...@python.org

 You can reach the person managing the list at
python-list-ow...@python.org

 When replying, please edit your Subject line so it is more specific
 than Re: Contents of Python-list digest...

 Today's Topics:

   1. A zlib question (Roland Hedberg)
   2. Re: help me to find the error (Xavier Ho)
   3. Re: Concatenating images (numpy arrays), but they look like
  HSV images (Sebastian Schabe)


 -- Forwarded message --
 From: Roland Hedberg rol...@catalogix.se
 To: python-list@python.org
 Date: Fri, 10 Jul 2009 11:33:25 +0200
 Subject: A zlib question
 Hi!

 I have a problem with zlib and compressing/decompressing according to RFC
 1951.

 It seems like I can decompress, something compressed according to RFC 1951
 by someone else, provided I set wbits to something negative (used -8 but I
 guess any negative number would work?).

 But how can I compress using zlib so it doesn't add a gzip header ?

 -- Roland


 -- Forwarded message --
 From: Xavier Ho cont...@xavierho.com
 To: python-list@python.org
 Date: Fri, 10 Jul 2009 17:53:15 +0800
 Subject: Re: help me to find the error
 I'm new to Python myself, but I think it's because the method readlist()
 returns a list. Hence, f0 is typed 'list'. And lists can't be closed.

 If you leave it to:

 *f0= open(temp9,r+)

 *and then assign another variable to the readlist, such as:

 *lines = f0.readlines()*

 Then in the for loop, change f1 to

 *f1=lines[i].split()*

 That may just stop it from complaining.

 Untested, but logically it's sound.

 Hope that works,

 Ching-Yun Xavier Ho, Technical Artist

 Contact Information
 Mobile: (+61) 04 3335 4748
 Skype ID: SpaXe85
 Email: cont...@xavierho.com
 Website: http://xavierho.com/


 On Fri, Jul 10, 2009 at 5:41 PM, jhinak sen jhinak@gmail.com wrote:

 hi,
 i am a beginner in python language,

 i am trying with this programme :
 to find the addition and mean from a data set in a file and writing the
 mean and sum in some other file :
 
 *#! /usr/bin/env python

 import re
 import cPickle as p
 import math
 from numpy import *

 f0= open(temp9,r+).readlines()
 f2= open(out1,r+)
 add_1=[ ];
 for i in range(0, len(f0)):
 f1=f0[i].split()
 add= float(f1[1])+float(f1[2])
 mean= float(add)/2
 print (f1[1]).ljust(6) ,(f1[2]).ljust(6),repr(add).ljust(7),
 repr(mean).ljust(7)
 add_1.append(add)
 add_1.append(mean)
 f2.write(%s % repr(add).ljust(7)),f2.write(%s %
 repr(mean).ljust(7))
 print printing from file
 for i in range(0, len(add_1),2):
 print add_1[i],, add_1[i+1]

 f0.close()
 f2.close()*


 

 and this programme is givving me this error :

 *Traceback (most recent call last):
   File ./temporary1.py, line 24, in module
 f0.close()
 AttributeError: 'list' object has no attribute 'close'*
 

 please help to to find the error.
 or suggest some simpler or better way

 note:
 1)file temp9 is already exist
 2)this programme is giving me all my outputs, but at the end of the out
 ..its giving me that error.

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




 -- Forwarded message --
 From: Sebastian Schabe sebastian.sch...@gmx.de
 To: python-list@python.org
 Date: Fri, 10 Jul 2009 12:01:51 +0200
 Subject: Re: Concatenating images (numpy arrays), but they look like HSV
 images
 Robert Kern schrieb:

 Probably, you need to use zeros(..., dtype=uint8). When you use dtype=int,
 that will result in dtype=int arrays. I suspect that matplotlib is then
 interpreting that to mean that you want it to treat the input as scalar data
 (which it will pass through a colormap) rather than an RGB image.


 Thanks Robert, that was exactly the problem. Now I'am really wondering how
 one can know such details. Well, with your answer I searched again in the
 mathplotlib documentation and under the function imshow(X, ...) I indeed
 found the hint, that X has to be an uint8 or float array or PIL image, but
 before I hadn't known where to search.

 So again, thank you

 Sebastian


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

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


Re: tough-to-explain Python

2009-07-10 Thread Hendrik van Rooyen
Steven D'Aprano st...@remove-this-cye.com.au wrote:

On Wed, 08 Jul 2009 22:05:57 -0700, Simon Forman wrote:

 persistent idea out there that programming is a very accessible
 skill, like cooking or gardening, anyone can do it, and even profit
 from it, monetarily or otherwise, etc., and to some extent I am
 
 Programming is not like any other human activity.

In practice? In principle? Programming in principle is not the same as it 
is performed in practice.

But in either case, programming requires both the logical reasoning of 
mathematics and the creativity of the arts. Funnily enough, 

I do not buy this arty creativity stuff. - or are you talking about
making a website look pretty?

mathematicians will tell you that mathematics requires the same, and so 
will the best artists. I think mathematicians, engineers, artists, even 
great chefs, will pour scorn on your claim that programming is not like 
any other human activity.

So a chef is now an authority on programming?

Programming is actually kind of different - almost everything else is 
just done, at the time that you do it.

Programming is creating stuff that is completely useless until it is
fed into something that uses it, to do something else, in conjuction
with the thing it is fed into, at a later time.

This is a highly significant difference, IMHO.




[...]
 He talks about how when all is said and done, the only thing computers
 can do for us is to manipulate symbols and produce results of such
 manipulations and he emphasises the uninterpreted nature of
 mechanical symbol manipulation, i.e. that the machine is doing it
 mindlessly.

Manipulate symbols is so abstract as to be pointless. By that 
reasoning, I can build a computer consisting of a box open at the top. 
I represent a symbol by an object (say, a helium-filled balloon, or a 
stone), instead of a pattern of bits. I manipulate the symbol by holding 
the object over the box and letting go. If it flies up into the sky, that 
represents the symbol Love is War, if it falls into the box, it 
represents the symbol Strength is Blue, and if it just floats there, it 
represents Cheddar Cheese. This is a deterministic, analog computer 
which manipulates symbols. Great.

And utterly, utterly useless. So what is my computer lacking that real 
computers have? When you have answered that question, you'll see why 
Dijkstra's claim is under-specified.


So if computers do not manipulate symbols, what is it that they do?
They sure cannot think,
or drink,
or reason,
or almost any verb you can think of.

Manipulating symbols is actually an elegant definition.
Try coming up with a better one and you will see.

And calling an abstraction pointless kind of contradicts
what you say later...

8--- camel humps and other stuff ---

- Hendrik



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


Re: subprocess + python-daemon - bug/problem?

2009-07-10 Thread Ben Finney
Andy  Clegg andy...@gmail.com writes:

 import daemon
 import subprocess
 
 daemon.DaemonContext(stderr = open(fakeConsole.txt,w+)).open()
 subprocess.Popen(['echo','1']).wait()
 
 However the error remains the same.

The error appears in the file specified for the stderr output of the
DaemonContext. Here it is without the unwanted extra line-wrapping that
seems to plague all Google Mail users (seriously, folks: get a real mail
provider that won't mangle your messages)::

Traceback (most recent call last):
  File /home/bignose/Projects/python/python-daemon/bin/andy-clegg-test, 
line 7, in module
subprocess.Popen(['echo', '1']).wait()
  File /usr/lib/python2.5/subprocess.py, line 1184, in wait
pid, sts = self._waitpid_no_intr(self.pid, 0)
  File /usr/lib/python2.5/subprocess.py, line 1014, in _waitpid_no_intr
return os.waitpid(pid, options)
OSError: [Errno 10] No child processes

I confirm that I'm getting the same error; Python 2.5.4.

My first thought was perhaps it's related to the fact that the process
has no stdout? But setting ‘stdout’ and ‘stderr’ to the same file::

#! /usr/bin/python

import daemon
import subprocess

fake_console = open(fake_console.txt, w+)
daemon.DaemonContext(stdout=fake_console, stderr=fake_console).open()
subprocess.Popen(['echo', '1']).wait()

still gives the same error::

1
Traceback (most recent call last):
  File /home/bignose/Projects/python/python-daemon/bin/andy-clegg-test, 
line 8, in module
subprocess.Popen(['echo', '1']).wait()
  File /usr/lib/python2.5/subprocess.py, line 1184, in wait
pid, sts = self._waitpid_no_intr(self.pid, 0)
  File /usr/lib/python2.5/subprocess.py, line 1014, in _waitpid_no_intr
return os.waitpid(pid, options)
OSError: [Errno 10] No child processes

I'm not familiar enough with the nuances of the ‘subprocess’ module to
know what might be going wrong here. I'd like to know whether it might
be a problem in the ‘python-daemon’ library.

-- 
 \ “Whatever a man prays for, he prays for a miracle. Every prayer |
  `\   reduces itself to this: “Great God, grant that twice two be not |
_o__)   four.”” —Ivan Turgenev |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: property using a classmethod

2009-07-10 Thread Bruno Desthuilliers

Bruno Desthuilliers a écrit :
(snip)
You could write your own custom descriptor. Or just use an additional 
level of indirection, ie:


   myProperty = property(lambda self: self.myClassMethod())



Sorry, looks like I didn't read carefully enough. The above code won't 
work if you intend to lookup the property directly on the class object, 
ie MyClass.myProperty. If that was your intention, you'll need a 
custom descriptor. The following code should do the job, or at least get 
you started:


# python 2.5.x

# the custom (non binding) descriptor
class ClsProperty(object):
def __init__(self, fget):
if not isinstance(fget, (classmethod, staticmethod)):
# XXX better error message
raise ValueError(
  fget must be a classmethod or staticmethod
)
self.fget = fget

def __get__(self, obj, cls=None):
if cls is None:
assert obj is not None
cls = type(obj)
return self.fget.__get__(obj, cls)()

# helper - a simple decorator
def classproperty(func):
if not isinstance(func, (classmethod, staticmethod)):
func = classmethod(func)
return ClsProperty(func)


# example use
class Foo(object):

# the hard way
@classmethod
def bar(cls):
return %s.bar % cls.__name__

quux = ClsProperty(bar)

# the simple way
@classproperty
def baaz(cls):
return %s.baaz % cls


Given your example, this should be enough. If you need a binding 
descriptor (one with a setter), you'll have to implement the __set__ 
method (and possibly __del__). Google for python descriptor to find 
more doc about the descriptor protocol.


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


Re: can i write a assemly language programs in python

2009-07-10 Thread Dave Angel

Terry Reedy wrote:
div class=moz-text-flowed style=font-family: -moz-fixedDave 
Angel wrote:

m.reddy prasad reddy wrote:
can any one tell me how to write assembly language programs in 
python...if

no is there any other way to write the programs in python

Reddi prasad reddy
ph.no:09958083797

  
Assembly language is a different programming language than Python.  
You can use both in the same process, much in the same way you can 
use C or C++ with Python.  In fact, some of the system DLL's are 
written (partly) in assembler, though mostly in C or C++.


It is possible that he meant how to write assembly *with* python.
Or how to translate python to assembly.

As it turns out, CPython translates Python to byte code and has a dis 
(assembly) module that produces very nice assembly code ;-)

So that is one answer to his question.


You'll need to tell us what your real goal is.


Definitely.

tjr


/div

If you mean dis.dis() that only gives you byte code.  I assumed he was 
referring to native code assembly.


I guess I'd better stop guessing grin.

DaveA

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


Query regarding set([])?

2009-07-10 Thread vox
Hi,
I'm contsructing a simple compare-script and thought I would use set
([]) to generate the difference output. But I'm obviosly doing
something wrong.

file1 contains 410 rows.
file2 contains 386 rows.
I want to know what rows are in file1 but not in file2.

This is my script:
s1 = set(open(file1))
s2 = set(open(file2))
s3 = set([])
s1temp = set([])
s2temp = set([])

s1temp = set(i.strip() for i in s1)
s2temp = set(i.strip() for i in s2)
s3 = s1temp-s2temp

print len(s3)

Output is 119. AFAIK 410-386=24. What am I doing wrong here?

BR,
Andy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Query regarding set([])?

2009-07-10 Thread Peter Otten
vox wrote:

 I'm contsructing a simple compare-script and thought I would use set
 ([]) to generate the difference output. But I'm obviosly doing
 something wrong.
 
 file1 contains 410 rows.
 file2 contains 386 rows.
 I want to know what rows are in file1 but not in file2.
 
 This is my script:
 s1 = set(open(file1))
 s2 = set(open(file2))

Remove the following three lines:

 s3 = set([])
 s1temp = set([])
 s2temp = set([])

 
 s1temp = set(i.strip() for i in s1)
 s2temp = set(i.strip() for i in s2)
 s3 = s1temp-s2temp
 
 print len(s3)
 
 Output is 119. AFAIK 410-386=24. What am I doing wrong here?

You are probably misinterpreting len(s3). s3 contains lines occuring in 
file1 but not in file2. Duplicate lines are only counted once, and the 
order doesn't matter. 

So there are 119 lines that occur at least once in file2, but not in 
file1.

If that is not what you want you have to tell us what exactly you are 
looking for.

Peter

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


Re: psyco V2 beta2 benchmark

2009-07-10 Thread Paul Boddie
On 10 Jul, 04:54, Zac Burns zac...@gmail.com wrote:
 Where do you get this beta? I heard that Psyco V2 is coming out but
 can't find anything on their site to support this.

I found the Subversion repository from the Psyco site:

http://psyco.sourceforge.net/

- http://codespeak.net/svn/psyco/dist/

- http://codespeak.net/svn/psyco/v2/

It's not widely advertised, but I imagine that this is the correct
repository. Navigating around on the codespeak.net site took me to the
ViewVC instance which gives some date/time information that would
confirm my suspicions:

https://codespeak.net/viewvc/psyco/

A log of the development can be viewed here:

https://codespeak.net/viewvc/psyco/v2/dist/?view=log

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


Re: help me to find the error

2009-07-10 Thread Rhodri James
On Fri, 10 Jul 2009 10:41:03 +0100, jhinak sen jhinak@gmail.com  
wrote:



hi,
i am a beginner in python language,

i am trying with this programme :
to find the addition and mean from a data set in a file and writing the  
mean

and sum in some other file :

*#! /usr/bin/env python

import re
import cPickle as p
import math
from numpy import *

f0= open(temp9,r+).readlines()
f2= open(out1,r+)
add_1=[ ];
for i in range(0, len(f0)):
f1=f0[i].split()
add= float(f1[1])+float(f1[2])
mean= float(add)/2
print (f1[1]).ljust(6) ,(f1[2]).ljust(6),repr(add).ljust(7),
repr(mean).ljust(7)
add_1.append(add)
add_1.append(mean)
f2.write(%s % repr(add).ljust(7)),f2.write(%s %
repr(mean).ljust(7))
print printing from file
for i in range(0, len(add_1),2):
print add_1[i],, add_1[i+1]

f0.close()
f2.close()*




and this programme is givving me this error :

*Traceback (most recent call last):
  File ./temporary1.py, line 24, in module
f0.close()
AttributeError: 'list' object has no attribute 'close'*



As the error message tells you, 'f0' is a list.  readlines()
returns a list of the lines in the file object, rather than the
file object itself.  Since you promptly (and entirely reasonably)
discard the file object, you haven't got any way to close() it.

You don't actually need to do that, though.  You can use a file
object as something you use a 'for' loop over, and be given one
line at a time.  So instead you can write your code like this:

snippet
f0 = open(temp9, r)
for line in f0:
f1 = line.split()
# ... and so on
/snippet

Notice that I only opened the file as r -- you are only
reading it, not updating it, and giving yourself more permission
than you need is a bad habit to get into.  Opening the file this
way means that if you accidentally write f0.write(something)
instead of f2.write(something), Python will stop you with an
exception rather than silently trash your data.

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


Re: need to write a assembly progrm

2009-07-10 Thread Rhodri James
On Thu, 09 Jul 2009 11:52:44 +0100, m.reddy prasad reddy  
reddy@gmail.com wrote:


my aim is to run the assembly programs in python.by that we can use that  
in
the any labs.because we can run the python in the mobiles also.if we  
write

assembly programs in the mobile ,the mobile act as a tool kit for the
lab.tell me any other solutions for this


Please define what you mean by assembly.

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


Re: language analysis to enforce code standards

2009-07-10 Thread Jean-Michel Pichavant

Steven D'Aprano wrote:

On Fri, 10 Jul 2009 02:06:35 +, Jason S. Friedman wrote:

  

Hello, I administer the Informatica ETL tool at my company.  Part of
that role involves creating and enforcing standards.  I want the
Informatica developers to add comments to certain key objects and I want
to be able to verify (in an automated fashion) that they have done so.

I cannot merely check for non-emptiness; that is trivial to circumvent.
  On the other hand, I probably do not need to be able to catch
developers who are determined to not create comments.  There are not too
many of them and perhaps they will find it is easier to write a (useful)
comment than to game the system.

Any thoughts on how I might proceed?  Stated plainly, how can I tell
when a string more-or-less forms at least one phrase?



Define phrase.


if len(s)  0:
print at least one character
if len(s.split())  0:
print at least one word
if len(s.split('\n')  0:
print at least one line



  
You could also verify there are at least N different characters used in 
the sentence:


N = 5 # must contains at least 5 different characters
record = []
for c in s:
   if c not in record:
   record += [c]
if len(record) = N:
   print at least %s different characters % N


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


Re: Examples of Python driven Microsoft UI Automation wanted

2009-07-10 Thread Mark
Hi,

I am the author of pywinauto (http://pywinauto.openqa.org/).

It doesn't have specific functionality built in for winforms - but
many winforms controls are built on top of win32 functionality and
pywinauto can work with them for that.

On Jul 9, 4:41 pm, Paul McGuire pt...@austin.rr.com wrote:
 On Jul 9, 1:50 pm, DuaneKaufman duane.kauf...@gmail.com wrote:

   I have used pywinauto to drive a Flash game running inside of an
   Internet Explorer browser - that's pretty GUI!


Wow - cool :)


   -- Paul

  Hi,

  Could you share some code examples?


You might have a look at http://pywinauto.pbworks.com/ (the site is no
longer used - but there is a cool movie giving an example of using
pywinauto at the interactive prompt)

Other examples (Notepad, mspaint) are included with the install.

PyPi - http://pypi.python.org/pypi/pywinauto/0.3.8


  Thanks,
  Duane (duanek (at) chorus (dot) net)


Good luck! :)
  Mark

 I just went on a brief fishing expedition through two disk backups,
 and no luck.  I guess it's been a while since I worked on this.

 The work I did was entirely graphical, which is to say, my script
 interacted with the Flash program by using PIL to take image snapshots
 of the window, and then sifting through the bitmap looking for the
 status of a time remaining thermometer-style gauge in the game.
 Then the script could click on X-Y coordinates within the window,
 which would get picked up by the Flash game, and the script would
 monitor the time remaining gauge some more, and so on.

 I'm not sure how well pywinauto would work in allowing you to access
 controls such as textboxes within a form.  I remember that I had to
 access the IE window using a caption name, and then found the embedded
 Flash program as an embedded control of some sort, again, I probably
 needed to indicate that it was some sort of Adobe.FlashWidget1
 object or something.

 I may have another, older disk backup at home, I can look for it later
 this evening.

 -- Paul

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


Re: can i write a assemly language programs in python

2009-07-10 Thread Tim Chase

m.reddy prasad reddy wrote:

can any one tell me how to write assembly language programs in python...if
no is there any other way to write the programs in python


Bah, writing assembly language is easy in Python:

  print(MOV EAX, [EBX])
  print(XOR EBX, EBX)

Just adjust the strings for your favorite processor architecture 
and Python will produce the assembly code you want.


Now compiling assembly to *machine* code...or calling between 
Python and assembly...that's another matter.  But writing 
assembly language programs in Python?  Easy. ;-)


-tkc



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


Re: language analysis to enforce code standards

2009-07-10 Thread Peter Otten
Jason S. Friedman wrote:

 Hello, I administer the Informatica ETL tool at my company.  Part of
 that role involves creating and enforcing standards.  I want the
 Informatica developers to add comments to certain key objects and I want
 to be able to verify (in an automated fashion) that they have done so.
 
 I cannot merely check for non-emptiness; that is trivial to circumvent.
   On the other hand, I probably do not need to be able to catch
 developers who are determined to not create comments.  There are not too
 many of them and perhaps they will find it is easier to write a (useful)
 comment than to game the system.
 
 Any thoughts on how I might proceed?  Stated plainly, how can I tell
 when a string more-or-less forms at least one phrase?

Don't be a fool. Have someone other than the author read the comment.

Peter

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


Re: Query regarding set([])?

2009-07-10 Thread vox
On Jul 10, 2:04 pm, Peter Otten __pete...@web.de wrote:
 You are probably misinterpreting len(s3). s3 contains lines occuring in
 file1 but not in file2. Duplicate lines are only counted once, and the
 order doesn't matter.

 So there are 119 lines that occur at least once in file2, but not in
 file1.

 If that is not what you want you have to tell us what exactly you are
 looking for.

 Peter

Hi,
Thanks for the answer.

I am looking for a script that compares file1 and file2, for each line
in file1, check if line is present in file2. If the line from file1 is
not present in file2, print that line/write it to file3, because I
have to know what lines to add to file2.

BR,
Andy



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


Re: Query regarding set([])?

2009-07-10 Thread David Robinow
On Fri, Jul 10, 2009 at 8:52 AM, voxvox2...@gmail.com wrote:
 I am looking for a script that compares file1 and file2, for each line
 in file1, check if line is present in file2. If the line from file1 is
 not present in file2, print that line/write it to file3, because I
 have to know what lines to add to file2.
  Just copy file1 to file2.
(I'm pretty sure that's not what you want, but in explaining why it
should become clearer what you're trying to do.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hoe to build a patched socketmodule.c

2009-07-10 Thread jacopo mondi
Roger Binns wrote:
 jacopo mondi wrote:
 Hi all, I need to patch socketmodule.c (the _socket module) in order to
 add support to an experimental socket family.
 
 You may find it considerably easier to use ctypes since that will avoid
 the need for any patching.  You'll also be able to control how read and
 write are done (eg read vs recvfrom vs recvmsg vs readv).  You can use
 os.fdopen to convert your raw file descriptor into a Python file object
 if appropriate.
 
 If you do use ctypes then you'll only need to distribute pure Python
 source code.
 
 Roger

Wait a minute, am I confused or ctypes seems to be unusless for my needs?
Ctypes wraps a system shared object (as libc is) and gives you the
possibility to access its functions. What have I to wrap? the
fuctionalities I need to use are those exposed by the kernel via
sys/socket.h haeder (socket, bind, connect etc.).
Maybe I could wrapp _socket.so (I think it's possible) but seems to be
unuseless because I need to modify, for example, the parameters that
_socket.so passes to the socket() function in order to create a socket
owned by the new socket family I'm actualy experimenting.
Hope it's clear what I'm trying to explain...

Thanks anyway, but ctypes doen't seem to fit my needs..

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


Re: tough-to-explain Python

2009-07-10 Thread Steven D'Aprano
On Fri, 10 Jul 2009 12:54:21 +0200, Hendrik van Rooyen wrote:

 Steven D'Aprano st...@remove-this-cye.com.au wrote:
 
On Wed, 08 Jul 2009 22:05:57 -0700, Simon Forman wrote:

 persistent idea out there that programming is a very accessible
 skill, like cooking or gardening, anyone can do it, and even profit
 from it, monetarily or otherwise, etc., and to some extent I am
 
 Programming is not like any other human activity.

In practice? In principle? Programming in principle is not the same as
it is performed in practice.

But in either case, programming requires both the logical reasoning of
mathematics and the creativity of the arts. Funnily enough,
 
 I do not buy this arty creativity stuff. - or are you talking about
 making a website look pretty?

I must admit, it never crossed my mind that anyone here would claim that 
there was no creativity involved in programming, that it was all a 
mindless, algorithmic process capable of being done by a simple 
mechanical device.

This is certainly the accusation made against *bad* programmers -- that 
they can't actually solve new, unique problems, but just apply recipes 
they learned without any insight or intelligence. The sort of people who 
program so poorly that a trained monkey could do what they do.

Do you really think that applies to good programmers too? If so, then a 
good code generator should be able to replace any programmer. Is that 
what you believe?


 
mathematicians will tell you that mathematics requires the same, and so
will the best artists. I think mathematicians, engineers, artists, even
great chefs, will pour scorn on your claim that programming is not like
any other human activity.
 
 So a chef is now an authority on programming?

Did I say that?

Chefs are authorities on OTHER HUMAN ACTIVITIES.



 Programming is actually kind of different - almost everything else is
 just done, at the time that you do it.
 
 Programming is creating stuff that is completely useless until it is fed
 into something that uses it, to do something else, in conjuction with
 the thing it is fed into, at a later time.

Somebody should teach Hendrik that human beings have been creating TOOLS 
for hundreds of thousands of years. People have been creating tools to 
build tools for thousands of years. Software is just more of the same.

Even *soup stock* fits the same profile as what Hendrik claims is almost 
unique to programming. On its own, soup stock is totally useless. But you 
make it, now, so you can you feed it into something else later on.

Or instant coffee.

No, Henrik, if that's the best you can do, it's not very good. It is 
rather sad, but also hilarious, that the most different thing you have 
noticed about software is that it's just like instant coffee.


 This is a highly significant difference, IMHO.


[...]
 He talks about how when all is said and done, the only thing
 computers can do for us is to manipulate symbols and produce results
 of such manipulations and he emphasises the uninterpreted nature of
 mechanical symbol manipulation, i.e. that the machine is doing it
 mindlessly.

Manipulate symbols is so abstract as to be pointless. By that
reasoning, I can build a computer consisting of a box open at the top.
I represent a symbol by an object (say, a helium-filled balloon, or a
stone), instead of a pattern of bits. I manipulate the symbol by holding
the object over the box and letting go. If it flies up into the sky,
that represents the symbol Love is War, if it falls into the box, it
represents the symbol Strength is Blue, and if it just floats there,
it represents Cheddar Cheese. This is a deterministic, analog computer
which manipulates symbols. Great.

And utterly, utterly useless. So what is my computer lacking that real
computers have? When you have answered that question, you'll see why
Dijkstra's claim is under-specified.


 So if computers do not manipulate symbols, what is it that they do?

Did I say they don't manipulate symbols?


 They
 sure cannot think,
 or drink,
 or reason,

They can't reason? Then what are they doing when they manipulate symbols?

Yet again, it didn't even cross my mind that somebody would make this 
claim. My entire point is that it's not enough to just manipulate 
symbols, you have to manipulate symbols the correct way, following laws 
of logic, so that the computer can *mindlessly* reason.


 or almost any verb you can think of.

If you're going to take that argument, then I'll remind you that there 
are no symbols inside a computer. There are only bits. And in fact, there 
aren't even any bits -- there are only analog voltages, and analog 
magnetic fields.


 Manipulating symbols is actually an elegant definition. Try coming up
 with a better one and you will see.

As I said above, it's not enough to just manipulate symbols. Here's a set 
of rules to manipulate symbols:

X = 0

or in English, Any symbol becomes the zero symbol.

That's symbol manipulation. Utterly useless. This is why it's not 

Re: AP -- MeAmI.org Paces Google

2009-07-10 Thread David Bernier

Musatov wrote:

Los Angeles (AP) --MeAmI.org now has users in 50 countries following
its adopted use in Pakistan.  The search engine has grown in
popularity 10,000 fold following its Beta test launch three months ago
in April, 2009. Supporters of the site claim it is better than rival
Google upon which platform it is based. Controversy arose after
MeAmI.org search code allowed users to search other users Google
results with no advertising. It is truly an innovative thing we are
doing, said Founder and CEO, Martin Musatov. Letting users search
the results of other Google users immediately results in a level of
accuracy and relevance above and beyond Google. Google changed their
API following the launch or MeAmI.org and explored the possibility of
blocking site access from MeAmI.org to Google search results but was
unable to do so. Critics of MeAmI.org say what it is doing is
tantamount to intellectual theft. When asked about this topper Musatov
exclaimed, The Internet was made for people, not companies. An
analyst at Goldman Sachs says, requesting to remain anonymous,
MeAmI.org has a strong presence in promoting itself as a vehicle for
global activism and to tell you the truth, this makes it much more
likely an acquisition target than potential intellectual property
violator. Google could not be reached for comment.


Mr. Musatov, is it you who removed the post
quoted above from the Google Groups archive?

Thank you.

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


Re: The meaning of = (Was: tough-to-explain Python)

2009-07-10 Thread Aahz
[excessive quoting ahead, I'm too tired to trim]

In article h32i2o$eo...@reader1.panix.com, kj  no.em...@please.post wrote:
In h32fon$26...@panix3.panix.com a...@pythoncraft.com (Aahz) writes:
In article h32eoh$ql...@reader1.panix.com, kj  no.em...@please.post wrote:

OK, so, scratching from my original post the case

identifier.identifier = expression

(as being a special case of identifier = expression), still,
to the extent that I understand your post, the = in

  x = 1

means something fundamentally different (in terms of Python's
underlying implementation) from the = in

  y[0] = 1

No?

No.  ;-)

No???  Just when I thought I finally understood all this!

What's different is not the ``=`` but the construction of the
assignment target before ``=`` gets executed.

Hmm.  OK, I went to the link you posted in your other message
(http://docs.python.org/reference/simple_stmts.html#assignment-statements)
and I find this (my emphasis):

Assignment of an object to a single target is recursively defined as 
 follows.

* If the target is an identifier (name):

 o If the name does not occur in a global statement in
   the current code block: the name is bound to the object
^
   in the current local namespace.

 o Otherwise: the name is bound to the object in the
   ^
   current global namespace.

  The name is rebound if it was already bound. This may cause
  the reference count for the object previously bound to the
  name to reach zero, causing the object to be deallocated and
  its destructor (if it has one) to be called.

* If the target is a target list enclosed in parentheses or in
  square brackets... (I'LL IGNORE THIS FOR NOW)

* If the target is an attribute reference: The primary expression
  in the reference is evaluated. It should yield an object with
  assignable attributes; if this is not the case, TypeError is
  raised. That object is then asked to assign the assigned
  
  object to the given attribute; if it cannot perform the
  ^^
  assignment, it raises an exception (usually but not necessarily
  AttributeError).

* If the target is a subscription: The primary expression in
  the reference is evaluated. It should yield either a mutable
  sequence object (such as a list) or a mapping object (such
  as a dictionary). Next, the subscript expression is evaluated.

  If the primary is a mutable sequence object (such as a
  list),...  [CONDITIONS ON THE INDEX EXPRESSION OMITTED]...
  the sequence is asked to assign the assigned object to its
  ^^^
  item with that index

  If the primary is a mapping object (such as a dictionary),...
  [CONDITIONS ON THE SUBSCRIPT EXPRESSION OMITTED]... the
  ^^^
  mapping is then asked to create a key/datum pair which maps
  ^^^
  the subscript to the assigned object.
  

* If the target is a slicing: [INDEX STUFF OMITTED]... the
   ^^^
  sequence object is asked to replace the slice with the items
  
  of the assigned sequence...
  

OK, I originally interpreted what Lundh wrote in his two articles
that the binding described at the very beginning (i.e. when the
target is an identifier), which I take to make an entry or modify
such an entry in a namespace, is a *categorically different*
operation from the remaining operations underlined above.

I interpreted Paul Boddie's correction in his response to me as
saying that the assignment mentioned for the case when the target
is an attribute reference is actually a special case of the
assignment to simple identifiers (i.e. it also means binding).

But that still leaves all the other assignments (or the like)
underlined above.  I don't think that the full definitions of these
remaining cases are covered by the same rule, even though the rule
is described as recursive.  I think that the writer has something
else in mind, and in particular, something *other* than binding,
but the author remains vague on exactly what this means.

Clearly, both Lundh and the documentation draw some distinction
between binding and some other forms of assignment (which remain
ill-defined throughout).  This distinction is what I was referring
to when I said that = means different things in different contexts.

Consider this:

x = 1
globals()['x'] = 1
locals()[1] = 1

What's the difference between the three?  Although there's a lot of
machinery amenable to manipulation, with the 

Re: help me to find the error

2009-07-10 Thread Dave Angel

jhinak sen wrote:

hi,
i am a beginner in python language,

i am trying with this programme :
to find the addition and mean from a data set in a file and writing the mean
and sum in some other file :

*#! /usr/bin/env python

import re
import cPickle as p
import math
from numpy import *

f0= open(temp9,r+).readlines()
f2= open(out1,r+)
add_1=[ ];
for i in range(0, len(f0)):
f1=f0[i].split()
add= float(f1[1])+float(f1[2])
mean= float(add)/2
print (f1[1]).ljust(6) ,(f1[2]).ljust(6),repr(add).ljust(7),
repr(mean).ljust(7)
add_1.append(add)
add_1.append(mean)
f2.write(%s % repr(add).ljust(7)),f2.write(%s %
repr(mean).ljust(7))
print printing from file
for i in range(0, len(add_1),2):
print add_1[i],, add_1[i+1]

f0.close()
f2.close()*




and this programme is givving me this error :

*Traceback (most recent call last):
  File ./temporary1.py, line 24, in module
f0.close()
AttributeError: 'list' object has no attribute 'close'*


please help to to find the error.
or suggest some simpler or better way

note:
1)file temp9 is already exist
2)this programme is giving me all my outputs, but at the end of the out
..its giving me that error.

  
Others have pointed out the specific problem that gives you this error.  
But I'd like to point out a few other things to consider:


1) Don't mix tabs and spaces.  Best practice is to bind tab to (4) 
spaces in your editor, and never have a tab in a Python source file.
2) Think about your variable names.  As it stands, f0 is a list of 
lines, f1 is a list of word within a line, and f2 is a file.  No 
wonder you accidentally tried to close the list.  I'd suggest things like:

 infile = open()
 lines = infile.readlines()
 outfile = open()

 for line in lines:
words = line.split( ) or  even   val1, val2 = 
lines.split( )


  Then of course the last two lines become
  infile.close()
  outfile.close()

3) Learn to use the for statement directly on a list, rather than using 
len() on the list to make an index, then using the index to find the value

4) On the open() calls, get your modes right.  Looks like you really want
  infile = open(infilename, r)
  outfile = open(outfilename, w)
5) Consider using tuples in your add_1 list, rather than separate 
elements.  That way, each element of the list would contain both sum and 
mean.

  add_1.append((add, mean))

  and the final print would become

   for item in add_1:
   print item[0],, item[1]

6) Put anything over three lines into a function, instead of doing it at 
module scope.  That way, you'll be clearer about what things are local 
to this code, and what might be useful to other code in the same module.
In this case,  infilename, and outfilename might be arguments to that 
function.


There are lots of other refinements, but these are all within your 
reach, and would make the program much clearer.


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


Re: Colour of output text

2009-07-10 Thread Tim Harig
On 2009-07-10, garabik-news-2005...@kassiopeia.juls.savba.sk 
garabik-news-2005...@kassiopeia.juls.savba.sk wrote:
 Tim Harig user...@ilthio.net wrote:
 On 2009-07-09, Alex Rosslyn black.line...@gmail.com wrote:
 I would like to learn a way of changing the colour of a particular
 part of the output text. I've tried the following
 On Unix operating systems this would be done through the curses interface:
 http://docs.python.org/library/curses.html
 Or using ANSI colour codes:

Which will only work for ANSI terminals.
-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter only: table widget with canvas...

2009-07-10 Thread Thomas Lehmann
My intention is to keep dependencies low that means using python and
tkinter
as base package is quite easy because it's available on nearly every
system.

There is good documentation on Tkinter but going into the depth I'm
missing
many details. As an example...

Using the Tkinter.Canvas class I should be able to create a nice
table.
The missing informations are:

a) Assume I would have some different widgets to add per row. How
do I get the maximum row height?

b) Assume something like a label in one column. The length of all
texts
in a column will differ. How do I choose the maxium column width?

c) Placing headers in a canvas does not look like a good idea because
I don't want to scroll the headers. Am I right?
c.1) How do I place a none scrollable header in a canvas?  or
c.2) How do I place all headers outside the canvas correctly above
the relating column?

best regards
Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Implementing a cache

2009-07-10 Thread Nikolaus Rath
Hello,

I want to implement a caching data structure in Python that allows me
to:

 1. Quickly look up objects using a key
 2. Keep track of the order in which the objects are accessed (most
recently and least recently accessed one, not a complete history)
 3. Quickly retrieve and remove the least recently accessed object.


Here's my idea for the implementation:

The objects in the cache are encapsulated in wrapper objects:

class OrderedDictElement(object):
__slots__ = [ next, prev, key, value ]

These wrapper objects are then kept in a linked lists and in an ordinary
dict (self.data) in parallel. Object access then works as follows:

def __setitem__(self, key, value):
if key in self.data:
# Key already exists, just overwrite value
self.data[key].value = value
else:
# New key, attach at head of list
with self.lock:
el = OrderedDictElement(key, value, next=self.head.next, 
prev=self.head)
self.head.next.prev = el
self.head.next = el
self.data[key] = el

def __getitem__(self, key):
return self.data[key].value

To 'update the access time' of an object, I use

def to_head(self, key):
with self.lock:
el = self.data[key]
# Splice out
el.prev.next = el.next
el.next.prev = el.prev

# Insert back at front
el.next = self.head.next
el.prev = self.head

self.head.next.prev = el
self.head.next = el


self.head and self.tail are special sentinel objects that only have a
.next and .prev attribute respectively.


While this is probably going to work, I'm not sure if its the best
solution, so I'd appreciate any comments. Can it be done more elegantly?
Or is there an entirely different way to construct the data structure
that also fulfills my requirements?


I already looked at the new OrderedDict class in Python 3.1, but
apparently it does not allow me to change the ordering and is therefore
not suitable for my purpose. (I can move something to one end by
deleting and reinserting it, but I'd like to keep at least the option of also
moving objects to the opposite end).


Best,


   -Nikolaus

-- 
 »Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Query regarding set([])?

2009-07-10 Thread Dave Angel

vox wrote:

On Jul 10, 2:04 pm, Peter Otten __pete...@web.de wrote:
  

You are probably misinterpreting len(s3). s3 contains lines occuring in
file1 but not in file2. Duplicate lines are only counted once, and the
order doesn't matter.

So there are 119 lines that occur at least once in file2, but not in
file1.

If that is not what you want you have to tell us what exactly you are
looking for.

Peter



Hi,
Thanks for the answer.

I am looking for a script that compares file1 and file2, for each line
in file1, check if line is present in file2. If the line from file1 is
not present in file2, print that line/write it to file3, because I
have to know what lines to add to file2.

BR,
Andy


  
There's no more detail in that response.  To the level of detail you 
provide, the program works perfectly.  Just loop through the set and 
write the members to the file.


But you have some unspecified assumptions:
   1) order doesn't matter
   2) duplicates are impossible in the input file, or at least not 
meaningful.  So the correct output file could very well be smaller than 
either of the input files.


And a few others that might matter:
   3) the two files are both text files, with identical line endings 
matching your OS default
   4) the two files are ASCII, or at least 8 bit encoded, using the 
same encoding  (such as both UTF-8)

   5) the last line of each file DOES have a trailing newline sequence



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


Re: Implementing a cache

2009-07-10 Thread Steven D'Aprano
On Fri, 10 Jul 2009 09:22:29 -0400, Nikolaus Rath wrote:

 Hello,
 
 I want to implement a caching data structure in Python that allows me
 to:
 
  1. Quickly look up objects using a key 2. Keep track of the order in
  which the objects are accessed (most
 recently and least recently accessed one, not a complete history)
  3. Quickly retrieve and remove the least recently accessed object.

Google for python LRU cache.

Here are the first three hits:

http://code.activestate.com/recipes/498245/
http://code.activestate.com/recipes/252524/
http://www.algorithm.co.il/blogs/index.php/programming/python/small-python-challenge-no-2-lru-cache/




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


Re: Where does setuptools live?

2009-07-10 Thread Chris Withers

Inky 788 wrote:

Currently, distutils itself is being actively developed. More info
about this here: http://tarekziade.wordpress.com/

My (albeit anonymous) advice is: use distutils. Manually download
packages as-needed from PyPI and install manually using standard
distutils.


No thanks. I'm a big fan of buildout. Making it possible for packages to 
specify their dependencies is a big win...


Chris

--
Simplistix - Content Management, Zope  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: Query regarding set([])?

2009-07-10 Thread vox
On Jul 10, 4:17 pm, Dave Angel da...@ieee.org wrote:
 vox wrote:
  On Jul 10, 2:04 pm, Peter Otten __pete...@web.de wrote:

  You are probably misinterpreting len(s3). s3 contains lines occuring in
  file1 but not in file2. Duplicate lines are only counted once, and the
  order doesn't matter.

  So there are 119 lines that occur at least once in file2, but not in
  file1.

  If that is not what you want you have to tell us what exactly you are
  looking for.

  Peter

  Hi,
  Thanks for the answer.

  I am looking for a script that compares file1 and file2, for each line
  in file1, check if line is present in file2. If the line from file1 is
  not present in file2, print that line/write it to file3, because I
  have to know what lines to add to file2.

  BR,
  Andy

 There's no more detail in that response.  To the level of detail you
 provide, the program works perfectly.  Just loop through the set and
 write the members to the file.

 But you have some unspecified assumptions:
     1) order doesn't matter
     2) duplicates are impossible in the input file, or at least not
 meaningful.  So the correct output file could very well be smaller than
 either of the input files.

 And a few others that might matter:
     3) the two files are both text files, with identical line endings
 matching your OS default
     4) the two files are ASCII, or at least 8 bit encoded, using the
 same encoding  (such as both UTF-8)
     5) the last line of each file DOES have a trailing newline sequence

Thanks all for the input!
I have guess I have to think it through a couple times more. :)

BR,
Andy
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clarity vs. code reuse/generality

2009-07-10 Thread Tim Rowe
2009/7/9 kj no.em...@please.post:

 Thanks for the encouragement.

[snip]

 into code.  And by this I mean not only assumptions about the
 correctness of their code (the typical scope of assertions), but
 also, more broadly, assumptions about the data that they are dealing
 with (which often comes from external sources with abysmal quality
 control).

There we diverge. A lot. If correctness of the code trumps everything
else (in fact, if it matters at all) and the external data has
abysmal quality control then it *must* be checked for correctness
before it is used. If it is not, you have no idea whether your output
is correct or not. And assertions *will* *not* reliably provide that
checking (because they may not be executed). You *must* actively check
the data, using good old-fasioned if statements and so on, because
not to do so is to declare that you *don't* care about correctness.
You *know* the input is often wrong, but you're not bothering to check
it?

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


Re: Query regarding set([])?

2009-07-10 Thread Peter Otten
vox wrote:

 On Jul 10, 4:17 pm, Dave Angel da...@ieee.org wrote:
 vox wrote:
  On Jul 10, 2:04 pm, Peter Otten __pete...@web.de wrote:

  You are probably misinterpreting len(s3). s3 contains lines occuring
  in file1 but not in file2. Duplicate lines are only counted once,
  and the order doesn't matter.

  So there are 119 lines that occur at least once in file2, but not in
  file1.

  If that is not what you want you have to tell us what exactly you are
  looking for.

  Peter

  Hi,
  Thanks for the answer.

  I am looking for a script that compares file1 and file2, for each line
  in file1, check if line is present in file2. If the line from file1 is
  not present in file2, print that line/write it to file3, because I
  have to know what lines to add to file2.

  BR,
  Andy

 There's no more detail in that response.  To the level of detail you
 provide, the program works perfectly.  Just loop through the set and
 write the members to the file.

 But you have some unspecified assumptions:
 1) order doesn't matter
 2) duplicates are impossible in the input file, or at least not
 meaningful.  So the correct output file could very well be smaller than
 either of the input files.

 And a few others that might matter:
 3) the two files are both text files, with identical line endings
 matching your OS default
 4) the two files are ASCII, or at least 8 bit encoded, using the
 same encoding  (such as both UTF-8)
 5) the last line of each file DOES have a trailing newline sequence
 
 Thanks all for the input!
 I have guess I have to think it through a couple times more. :)

Indeed. Note that others thinking through related problems have come up with

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

Peter

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


Re: PyGtk Depends on Numeric

2009-07-10 Thread Aahz
In article 1ebe9314-9434-459a-bd3e-2b2386a35...@n11g2000yqb.googlegroups.com,
dieter  vel.ac...@gmail.com wrote:

Get with the times people and port to numpy. :P
Don't you think its about time?

Are you trying to get something to happen or just posting a random
drive-by?
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AP -- MeAmI.org Paces Google

2009-07-10 Thread Fran�ois Grondin

David Bernier david...@videotron.ca a écrit dans le message de news: 
h36ki102...@news5.newsguy.com...
 Musatov wrote:
 On Jul 9, 7:54 pm, David Bernier david...@videotron.ca wrote:
 Musatov wrote:
 Los Angeles (AP) --MeAmI.org now has users in 50 countries following
 its adopted use in Pakistan.  The search engine has grown in
 popularity 10,000 fold following its Beta test launch three months ago
 in April, 2009. Supporters of the site claim it is better than rival
 Google upon which platform it is based. Controversy arose after
 MeAmI.org search code allowed users to search other users Google
 results with no advertising. It is truly an innovative thing we are
 doing, said Founder and CEO, Martin Musatov. Letting users search
 the results of other Google users immediately results in a level of
 accuracy and relevance above and beyond Google. Google changed their
 API following the launch or MeAmI.org and explored the possibility of
 blocking site access from MeAmI.org to Google search results but was
 unable to do so. Critics of MeAmI.org say what it is doing is
 tantamount to intellectual theft. When asked about this topper Musatov
 exclaimed, The Internet was made for people, not companies. An
 analyst at Goldman Sachs says, requesting to remain anonymous,
 MeAmI.org has a strong presence in promoting itself as a vehicle for
 global activism and to tell you the truth, this makes it much more
 likely an acquisition target than potential intellectual property
 violator. Google could not be reached for comment.
 Mr. Musatov,  do you know who originally wrote the
 article above?

 Thank you.

 David Bernier- Hide quoted text -

 - Show quoted text -

 Yes.

 Mr. Musatov, do you know the name of the person who
 originally wrote the article above?

 Thank you.

 David Bernier

Maybe Mr. Musatov should answer the following questions instead :
1. Did you write the article above?
2. If not, who did? And I don't want AP as the answer, but the name of the 
journalist.

David, don't take it bad, but he answered your question with an accurate 
answer (yes), You gave him the opportunity to avoid the real answer and he 
took it. Based on Musatov's strange behavior and logic, don't expect more 
from him. Ask anyone else the same question and you'd get a real answer.

BTW, my guess for question 2 would be the Masked Logician, Floetry, 
scriber77, or Professor X.

Francois 


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


Re: language analysis to enforce code standards

2009-07-10 Thread Aahz
In article mailman.2948.1247229186.8015.python-l...@python.org,
Jean-Michel Pichavant  jeanmic...@sequans.com wrote:

You could also verify there are at least N different characters used in 
the sentence:

N = 5 # must contains at least 5 different characters
record = []
for c in s:
if c not in record:
record += [c]
if len(record) = N:
print at least %s different characters % N

Much simpler and *way* more efficient with a set:

if len(set(s))  N:
print Must have at least %s different characters % N
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


problem with keys combination!

2009-07-10 Thread Alex
Hi at all,
  I made a simple program that make a screenshot of Desktop and use it
as fullscreen background and then a ball erase image making illusion
that erase Desktop. The program working fine and I succesfully blocked
all keys but I have a problem with hotkey combination Ctrl-Alt-
Del...that bypass my FullScreen Application. Reading in google I
understood that if I want disable this keys I have to operate in more
low level. But I'm a newbe and I don't know how to make it(operate
with api is very hard 4 me).I tried several days to find a workaround
like replace one of that keys but doesn't work :-((
Plus..I can't install pyHook because there isn't a 2.6 version :-((
Can someone help me ??
thanks in advance
Alex

This is a piece of my code:
while True:
pg.event.pump()
keyinput = pg.key.get_pressed()
# press ESC to exit
if keyinput[pg.K_ESCAPE]
raise SystemExit
if  keyinput[pygame.K_LALT] and keyinput[pygame.K_LCTRL] and
keyinput[pygame.K_DELETE]:
 win32api.keybd_event(win32con.VK_ESCAPE,0)
 #shell = win32com.client.Dispatch(WScript.Shell)
#shell.SendKeys({ESC})
#ignore keyboard input
def IgnoreKeyboardInterrupt():
return signal.signal(signal.SIGINT,signal.SIG_IGN)
-- 
http://mail.python.org/mailman/listinfo/python-list


Threading.Condition problem

2009-07-10 Thread Gabriel Rossetti

Hello everyone,

I wrote a small example that listens for xmpp msgs in a thread. The main 
program calls a function that blocks (using Condition.wait) until a msg 
has been received and then returns the msg. When a msg arrives, it is 
put in a variable in the thread's object, it then calls the notify() 
attr on the Condition object. For some reason, this doesn't work, the 
thread gets the msg, tries to notify the Condition object, fails because 
the lock has not been acquired yet and blocks. I tried ignoring the 
failure, thinking that since it has not been acquired yet then when it 
is, it will get the msg right away and never call Condition.wait, thus 
not causing any problems, but this does not work either. Does someone 
know what I am doing wrong? I attached the code to this msg.


Thank you,
Gabriel
# Copyright (c) 2001-2006 Twisted Matrix Laboratories.
# See LICENSE for details.

import sys
from twisted.internet import reactor
from twisted.names.srvconnect import SRVConnector
from twisted.words.xish import domish, xpath
from twisted.words.protocols.jabber import xmlstream, client, jid

PRESENCE = '/presence' # this is an global xpath query to use in an observer
MESSAGE = '/message'   # message xpath
IQ = '/iq' # iq xpath

class XMPPClientConnector(SRVConnector):
def __init__(self, reactor, domain, factory):
SRVConnector.__init__(self, reactor, 'xmpp-client', domain, factory)


def pickServer(self):
host, port = SRVConnector.pickServer(self)

if not self.servers and not self.orderedServers:
# no SRV record, fall back..
port = 5222

return host, port



class Client(object):

def __init__(self, client_jid, secret, dest=None):


self.dest = dest
f = client.XMPPClientFactory(client_jid, secret)
f.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, self.connected)
f.addBootstrap(xmlstream.STREAM_END_EVENT, self.disconnected)
f.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authenticated)
f.addBootstrap(xmlstream.INIT_FAILED_EVENT, self.init_failed)
connector = XMPPClientConnector(reactor, client_jid.host, f)
connector.connect()

def rawDataIn(self, buf):
print RECV: %s % unicode(buf, 'utf-8').encode('ascii', 'replace')

def rawDataOut(self, buf):
print SEND: %s % unicode(buf, 'utf-8').encode('ascii', 'replace')

def connected(self, xs):


print 'Connected.'

self.xmlstream = xs

# Log all traffic
xs.rawDataInFn = self.rawDataIn
xs.rawDataOutFn = self.rawDataOut


def disconnected(self, xs):


print 'Disconnected.'
try:
reactor.stop()
except:
pass

def authenticated(self, xs):


def sendPresence():
presence = domish.Element((None, 'presence'))
xs.send(presence)

def sendMsg(user, res=None):
msg = domish.Element((jabber:client, message))
msg[to] = %...@localhost%s % (user, / + res if res else )
body = msg.addElement(body, content = Hello world %s % res if res else )
subject = msg.addElement(subject, content = will this be displayed?)
thread = msg.addElement(thread, content = this shouldn't be displayed)
xs.send(msg)


print Authenticated.

xs.addObserver(PRESENCE, self.onPresence, 1)
#xs.addObserver(IQ, self.onIq, 1)
xs.addObserver(MESSAGE, self.onMessage, 1)

reactor.callLater(0, sendPresence)

if(self.dest):
reactor.callLater(2, sendMsg, self.dest, toto)
reactor.callLater(4, sendMsg, self.dest, titi)

#msg = domish.Element((jabber:client, message))
#msg[to] = grosse...@localhost
#body = msg.addElement(body, content = Hello world)
#subject = msg.addElement(subject, content = will this be displayed?)
#thread = msg.addElement(thread, content = this shouldn't be displayed)
#xs.send(msg)

#msg = domish.Element((jabber:client, iq))
#msg[to] = ser...@localhost
#msg[id] = 666
#xs.send(msg)

#msg = domish.Element((jabber:client, presence))
#msg[to] = grosse...@localhost
#msg[type] = subscribe
#xs.send(msg)

#reactor.callLater(5, xs.sendFooter)

def onMessage(self, msg):

Act on the message stanza that has just been received.

# return to sender
#msg = create_reply(msg)
#self.xmlstream.send(msg) # send the modified domish.Element
pass

#def onIq(self, iq):
#
#Act on the iq stanza that has just been received.

#
#iq = create_reply(iq)
#self.xmlstream.send(iq)

def onPresence(self, prs):

Act on the presence stanza that has just been received.

t = 

Re: Threading.Condition problem

2009-07-10 Thread Gabriel Rossetti
The previous msg w/ attached code is the wrong code, please use the code 
attached to this msg, thank you and sorry for this.


Gabriel


Gabriel Rossetti wrote:

Hello everyone,

I wrote a small example that listens for xmpp msgs in a thread. The 
main program calls a function that blocks (using Condition.wait) until 
a msg has been received and then returns the msg. When a msg arrives, 
it is put in a variable in the thread's object, it then calls the 
notify() attr on the Condition object. For some reason, this doesn't 
work, the thread gets the msg, tries to notify the Condition object, 
fails because the lock has not been acquired yet and blocks. I tried 
ignoring the failure, thinking that since it has not been acquired yet 
then when it is, it will get the msg right away and never call 
Condition.wait, thus not causing any problems, but this does not work 
either. Does someone know what I am doing wrong? I attached the code 
to this msg.


Thank you,
Gabriel
from __future__ import with_statement
import xmpp, sys
from threading import Thread, Condition, Event


class Listener(Thread):
def __init__(self, ws):
Thread.__init__(self)
self.interrupt = Event()
self.message = None
self._cv = ws._cv
self.client = ws._client
self.client.RegisterHandler('message', self.onMessage)

def onMessage(self, conn, msg):
self.message = msg
try:
self._cv.notify()
except RuntimeError:
print self._cv has not acquired the lock yet

def getMsg(self):
return self.message

def run(self):
try:
while(not self.interrupt.isSet()):
self.client.Process(1)
except KeyboardInterrupt:
return 0

class WS(object):
def __init__(self, username, password, res):
self._jid = xmpp.protocol.JID(username)
self._client = xmpp.Client(self._jid.getDomain())
self._cv = Condition()

if(self._client.connect(server=(localhost, 5222)) == ):
raise Exception(Error while connecting!)

if(self._client.auth(self._jid.getNode(), password, res) is None):
raise Exception(Authentication failed!)

self._client.sendInitPresence()

self._listener = Listener(self)
self._listener.start()

def getMsg(self, mid=None):


with self._cv:
res = self._listener.getMsg()
while not res:
self._cv.wait()
res = self._listener.getMsg()
return res

if(__name__ == __main__):
ws = WS(t...@localhost, 123, test)
res = ws.getMsg()
print I just received : %s % str(res)
sys.exit(0)
-- 
http://mail.python.org/mailman/listinfo/python-list


Threading.Condition problem

2009-07-10 Thread Gabriel Rossetti
Sorry if this appears twice, I sent it once with an attachment and it 
never arrived so maybe the attachment is posing problems. I inlined the 
code this time (at the bottom), thank you,


Gabriel

## Original message 

Hello everyone,

I wrote a small example that listens for xmpp msgs in a thread. The main
program calls a function that blocks (using Condition.wait) until a msg
has been received and then returns the msg. When a msg arrives, it is
put in a variable in the thread's object, it then calls the notify()
attr on the Condition object. For some reason, this doesn't work, the
thread gets the msg, tries to notify the Condition object, fails because
the lock has not been acquired yet and blocks. I tried ignoring the
failure, thinking that since it has not been acquired yet then when it
is, it will get the msg right away and never call Condition.wait, thus
not causing any problems, but this does not work either. Does someone
know what I am doing wrong? I attached the code to this msg.

Thank you,
Gabriel



 Example code 

from __future__ import with_statement
import xmpp, sys
from threading import Thread, Condition, Event


class Listener(Thread):
def __init__(self, ws):
Thread.__init__(self)
self.interrupt = Event()
self.message = None
self._cv = ws._cv
self.client = ws._client
self.client.RegisterHandler('message', self.onMessage)

def onMessage(self, conn, msg):
self.message = msg
try:
self._cv.notify()
except RuntimeError:
print self._cv has not acquired the lock yet

def getMsg(self):
return self.message

def run(self):
try:
while(not self.interrupt.isSet()):
self.client.Process(1)
except KeyboardInterrupt:
return 0

class WS(object):
def __init__(self, username, password, res):
self._jid = xmpp.protocol.JID(username)
self._client = xmpp.Client(self._jid.getDomain())
self._cv = Condition()

if(self._client.connect(server=(localhost, 5222)) == ):
raise Exception(Error while connecting!)

if(self._client.auth(self._jid.getNode(), password, res) is None):
raise Exception(Authentication failed!)

self._client.sendInitPresence()

self._listener = Listener(self)
self._listener.start()

def getMsg(self, mid=None):


with self._cv:
res = self._listener.getMsg()
while not res:
self._cv.wait()
res = self._listener.getMsg()
return res

if(__name__ == __main__):
ws = WS(t...@localhost, 123, test)
res = ws.getMsg()
print I just received : %s % str(res)
sys.exit(0)


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


Re: tough-to-explain Python

2009-07-10 Thread Steven D'Aprano
On Fri, 10 Jul 2009 08:28:29 -0700, Scott David Daniels wrote:

 Steven D'Aprano wrote:
 Even *soup stock* fits the same profile as what Hendrik claims is
 almost unique to programming. On its own, soup stock is totally
 useless. But you make it, now, so you can you feed it into something
 else later on.
 
 Or instant coffee.
 
 I think I'll avoid coming to your house for a cup of coffee. :-)


I meant the instant coffee powder is prepared in advance. It's useless on 
it's own, but later on you feed it into boiling water, add sugar and 
milk, and it's slightly less useless.



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


Re: help me to find the error

2009-07-10 Thread Dave Angel

jhinak sen wrote:

hey,
thanx a lot :)
i got ur points .. and it really helps..

and please also tell me ...
where i can get more basic and detail knowledge of python.. as i am
beginners in this , i need more examples  of python programmes so that i can
understand better.
also if you know of any gud pdf file or book please let me know

thnx a lot
jhinak

On Fri, Jul 10, 2009 at 7:25 PM, Dave Angel da...@ieee.org wrote:

  

jhinak sen wrote:



hi,
i am a beginner in python language,

i am trying with this programme :
to find the addition and mean from a data set in a file and writing the
mean
and sum in some other file :

*#! /usr/bin/env python

import re
import cPickle as p
import math
from numpy import *

f0= open(temp9,r+).readlines()
f2= open(out1,r+)
add_1=[ ];
for i in range(0, len(f0)):
   f1=f0[i].split()
   add= float(f1[1])+float(f1[2])
   mean= float(add)/2
   print (f1[1]).ljust(6) ,(f1[2]).ljust(6),repr(add).ljust(7),
repr(mean).ljust(7)
   add_1.append(add)
   add_1.append(mean)
   f2.write(%s % repr(add).ljust(7)),f2.write(%s %
repr(mean).ljust(7))
print printing from file
for i in range(0, len(add_1),2):
   print add_1[i],, add_1[i+1]

f0.close()
f2.close()*




and this programme is givving me this error :

*Traceback (most recent call last):
 File ./temporary1.py, line 24, in module
   f0.close()
AttributeError: 'list' object has no attribute 'close'*


please help to to find the error.
or suggest some simpler or better way

note:
1)file temp9 is already exist
2)this programme is giving me all my outputs, but at the end of the out
..its giving me that error.



  

Others have pointed out the specific problem that gives you this error.
 But I'd like to point out a few other things to consider:

1) Don't mix tabs and spaces.  Best practice is to bind tab to (4) spaces
in your editor, and never have a tab in a Python source file.
2) Think about your variable names.  As it stands, f0 is a list of lines,
f1 is a list of word within a line, and f2 is a file.  No wonder you
accidentally tried to close the list.  I'd suggest things like:
infile = open()
lines = infile.readlines()
outfile = open()

for line in lines:
   words = line.split( ) or  even   val1, val2 =
lines.split( )

 Then of course the last two lines become
 infile.close()
 outfile.close()

3) Learn to use the for statement directly on a list, rather than using
len() on the list to make an index, then using the index to find the value
4) On the open() calls, get your modes right.  Looks like you really want
 infile = open(infilename, r)
 outfile = open(outfilename, w)
5) Consider using tuples in your add_1 list, rather than separate elements.
 That way, each element of the list would contain both sum and mean.
 add_1.append((add, mean))

 and the final print would become

  for item in add_1:
  print item[0],, item[1]

6) Put anything over three lines into a function, instead of doing it at
module scope.  That way, you'll be clearer about what things are local to
this code, and what might be useful to other code in the same module.
In this case,  infilename, and outfilename might be arguments to that
function.

There are lots of other refinements, but these are all within your reach,
and would make the program much clearer.





  
Please don' t top-post.  Putting your reply out of order makes it harder 
for others to see the sequences of things.  Some people top-post 
everything, but on this mailing list (and maybe most), the standard is 
to add to bottom, or inline where appropriate.


Anyway,
http://docs.python.org/tutorial/
http://diveintopython.org/
http://www.openbookproject.net/thinkCSpy/

are all good, depending on your experience with other languages, and 
with your computer's OS.


You could also check out
http://code.activestate.com/recipes/ or
http://code.activestate.com/recipes/langs/python/  for Python specifically


which has a large set of relatively small modules of code.
For a examples that might stretch your thought process:
   http://code.activestate.com/recipes/576755/
   http://code.activestate.com/recipes/576647/


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


Re: tough-to-explain Python

2009-07-10 Thread D'Arcy J.M. Cain
On 10 Jul 2009 15:48:47 GMT
Steven D'Aprano st...@remove-this-cybersource.com.au wrote:
 I meant the instant coffee powder is prepared in advance. It's useless on 
 it's own, but later on you feed it into boiling water, add sugar and 
 milk, and it's slightly less useless.

I don't know about that.  I find instant coffee pretty useless no
matter what it is fed to.  :-)

-- 
D'Arcy J.M. Cain da...@druid.net |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Automate rsync w/ authentication

2009-07-10 Thread Bryan
I am trying to automate rsync to backup server A from server B.  I
have set up a private/public key between the two servers so I don't
have to enter a password when using rsync.  Running rsync manually
with the following command works fine:
rsync -av --dry-run -e /usr/bin/ssh -i /home/bry/keys/brybackup.key
r...@10.0.45.67:/home/bry/jquery.lookup /home/bry/tmp

But when I try to do it with python, the subprocess simply returns the
ssh -h output on stderr like I am passing some invalid syntax.  What
is wrong in my translation of rsync's -e command from shell to
pythyon?

#! /usr/bin/python
from subprocess import Popen, PIPE
rsyncExec = '/usr/bin/ssh'
source = 'r...@10.0.45.67:/home/bry/jquery.lookup'
dest = '/home/bry/tmp'
rshArg = '-e /usr/bin/ssh -i /home/bry/keys/brybackup.key'
args = [rsyncExec, '-a', '-v', '--dry-run', rshArg, source, dest]
try:
p = Popen(args, stdout=PIPE, stderr=PIPE)
print 'rsync running with pid %s' % p.pid
out, err = p.communicate()
print 'Errors: %s' % err
print 'Output: %s' % out
except Exception:
print 'Error running rsync'

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


Re: problem with keys combination!

2009-07-10 Thread Steven D'Aprano
On Fri, 10 Jul 2009 08:33:18 -0700, Alex wrote:

 Hi at all,
   I made a simple program that make a screenshot of Desktop and use it
 as fullscreen background and then a ball erase image making illusion
 that erase Desktop. The program working fine and I succesfully blocked
 all keys but I have a problem with hotkey combination Ctrl-Alt-
 Del...that bypass my FullScreen Application.


What operating system are you using? Windows?

As I understand it, you can't block, modify, or otherwise access Ctrl-Alt-
Del while running under Windows: it is the Secure Attention Key, and is 
designed to be virtually impossible to interfere with. It's not *quite* 
impossible, but it is the deepest, darkest black magic. Microsoft makes 
it close enough to impossible as makes no difference even for experienced 
developers.

As a newbie, well, put it this way: it's like somebody saying Hi guys, I 
have a shiny new Swiss Army Knife, the one with the screwdriver and the 
corkscrew. I'd like to build my own Space Shuttle -- what do I do?

http://stackoverflow.com/questions/886076/how-can-i-intercept-all-key-events-including-ctrlaltdel-and-ctrltab

http://en.wikipedia.org/wiki/Control-Alt-Delete

You should also read this:

http://blogs.msdn.com/oldnewthing/archive/2004/02/16/73780.aspx



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


Re: DBI module deprecated at Python 2.5--what to use in its place?

2009-07-10 Thread M.-A. Lemburg
dana wrote:
 I have a variety of Python 2.4 scripts that utilitize the DBI and ODBC
 modules together. Although I don't have Python 2.5, I've been informed
 the DBI module has been deprecated at 2.5. A few questions:
 
 1) Although deprecated, will it work at all in 2.5? Does the fact that
 it is deprecrated mean it has been removed entirely, or does Python
 2.5 simply issuing a warning?
 
 2) What do I use in place of DBI for my Python 2.4. scripts that
 import modules DBI and ODBC together. I don't use DBI directly. It was
 simply a dependency for the ODBC module as best I knew.

If you're looking for a stable and maintained ODBC for Python,
have a look at our mxODBC extension or mxODBC Connect package:

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

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 10 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Remoting over SSH

2009-07-10 Thread M.-A. Lemburg
Lucas Carvalho wrote:
 Hussein B wrote:
 Hey,
 I want to perform commands on a remote server over SSH.
 What do I need?
 Thanks.
   
 Hi,
 If you want to use the SSH2 protocol into a python code, you should
 take a look at this module: paramiko [1].
 
 [1] http://www.lag.net/paramiko/

If you're looking for remote Python execution over SSH have
a look at http://codespeak.net/py/dist/execnet.html

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jul 10 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help me to find the error

2009-07-10 Thread Steven D'Aprano
On Fri, 10 Jul 2009 11:57:21 -0400, Dave Angel wrote:

[...]
 Please don' t top-post.  Putting your reply out of order makes it harder
 for others to see the sequences of things.  Some people top-post
 everything, but on this mailing list (and maybe most), the standard is
 to add to bottom, or inline where appropriate.

Inline is nearly always appropriate. Please trim your replies, leaving 
only what you need for context and what you are replying to directly, not 
the entire every-growing collection of quoted-quoted-quoted-quoted-quotes.

Thank you.


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


Re: tough-to-explain Python

2009-07-10 Thread pdpi
On Jul 10, 2:11 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 On Fri, 10 Jul 2009 12:54:21 +0200, Hendrik van Rooyen wrote:
  Steven D'Aprano st...@remove-this-cye.com.au wrote:

 On Wed, 08 Jul 2009 22:05:57 -0700, Simon Forman wrote:

  persistent idea out there that programming is a very accessible
  skill, like cooking or gardening, anyone can do it, and even profit
  from it, monetarily or otherwise, etc., and to some extent I am

  Programming is not like any other human activity.

 In practice? In principle? Programming in principle is not the same as
 it is performed in practice.

 But in either case, programming requires both the logical reasoning of
 mathematics and the creativity of the arts. Funnily enough,

  I do not buy this arty creativity stuff. - or are you talking about
  making a website look pretty?

 I must admit, it never crossed my mind that anyone here would claim that
 there was no creativity involved in programming, that it was all a
 mindless, algorithmic process capable of being done by a simple
 mechanical device.

 This is certainly the accusation made against *bad* programmers -- that
 they can't actually solve new, unique problems, but just apply recipes
 they learned without any insight or intelligence. The sort of people who
 program so poorly that a trained monkey could do what they do.

I wholeheartedly agree. Coming up with Duff's device is nothing if not
creative. My mind still reels at trying to grok it.
http://www.lysator.liu.se/c/duffs-device.html

 Even *soup stock* fits the same profile as what Hendrik claims is almost
 unique to programming. On its own, soup stock is totally useless. But you
 make it, now, so you can you feed it into something else later on.

 Or instant coffee.

I've always found cooking an apt metaphor for programming.

You've got your well-limited for loops (cook for x minutes), your less
straightforward while/until loops (roast until golden), you have your
subprocedures (prepare sauce in advance/in parallel), you have some
conditionals (tenderize the steak if the meat isn't really that
tender), etc etc.

The complexities of assignment can be easily visualized in terms of
containers and mixing stuff together. Nothing makes a += b more
obvious than having a bowl of cream (a), an egg (b), and adding the
egg to the bowl of cream (a += b). Well, except for the part where
that in that case evaluating b is destructive ;)

 They can't reason? Then what are they doing when they manipulate symbols?

Computers aren't intelligent. They only think they are. Or, more to
the point: the typical definition of reasoning tends to involve more
of what defines humans as self-aware, animate beings than what is
usually ascribed to computers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Clarity vs. code reuse/generality

2009-07-10 Thread Charles Yeomans


On Jul 9, 2009, at 10:57 PM, Steven D'Aprano wrote:


On Fri, 10 Jul 2009 03:28:04 +0100, Nobody wrote:


On Thu, 09 Jul 2009 04:57:15 -0300, Gabriel Genellina wrote:


Nobody says you shouldn't check your data. Only that assert is not
the right way to do that.


assert is not the right way to check your *inputs*. It's a  
perfectly
reasonable way to check data which should be valid, as well as a  
way

to document what variables are supposed to contain.


Where are those variables coming from?

The distinction really boils down to this:

* asserts should never fail. If there is any chance that an assertion
might fail outside of test suites, then don't use assert.


You can't control what input the caller provides to a function, so  
unless

the data is generated inside the function, a caller might provide
something unexpected. Therefore, assert is inappropriate for checking
function parameters, even if that function is private and only  
called

by your own functions.

(1) So-called private or internal functions have a habit of  
becoming

public, and then you have asserts in public functions.

(2) If public() calls _private(x), and _private uses assert to check  
the

value of x, there is a risk that if public() is buggy and supplies an
invalid x, the assertion will never be checked and _private() will  
return

incorrect results.

(3) assert is absolutely unsuitable for enforcing pre-conditions and  
post-
conditions, unless such conditions are mere guidelines, because  
assert

can be switched off at runtime.



Unless, of course, you want to switch off such checking at runtime, as  
you might when using a design-by-contract approach.


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


BayPIGgies at OSCON: 7/23 8-9:30pm

2009-07-10 Thread Aahz
NOTE: time change AND location change

The July BayPIGgies meeting will be held at OSCON in the San Jose
Convention Center as one of the BoF (Birds of a Feather) sessions from
8pm to 9:30pm Thursday July 23.  Everyone is welcome: you do NOT need to
be an OSCON member to attend a BoF.

Wesley Chun will have a newbie-oriented What is Python? BoF from 7-8pm
in the same room as BayPIGgies (we don't know which room yet).

The July meeting is supposed to have a Django focus, but the program
hasn't been settled yet, either.

For more information, see
http://baypiggies.net/

Discussion of details will take place on the BayPIGgies list:
http://mail.python.org/mailman/listinfo/baypiggies
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


problem with subprocess

2009-07-10 Thread gabrielmonnerat

Hi all,

I need start a openoffice in Xvfb, but when I call with the DISPLAY 
occurs this error:


[r...@localhost oood]# Xvfb :99 -screen 0 1024x768x24 

In [9]: subprocess.call('/opt/ooo-dev3/program/soffice.bin')
Out[9]: 0

In [10]: subprocess.call('DISPLAY=:99 /opt/ooo-dev3/program/soffice.bin')
---
OSError   Traceback (most recent call last)

/home/gabriel/ipython console in module()

/usr/lib/python2.6/subprocess.pyc in call(*popenargs, **kwargs)
   442 retcode = call([ls, -l])
   443 
-- 444 return Popen(*popenargs, **kwargs).wait()
   445
   446

/usr/lib/python2.6/subprocess.pyc in __init__(self, args, bufsize, 
executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, 
env, universal_newlines, startupinfo, creationflags)

   593 p2cread, p2cwrite,
   594 c2pread, c2pwrite,
-- 595 errread, errwrite)
   596
   597 # On Windows, you cannot just redirect one or two 
handles: You



/usr/lib/python2.6/subprocess.pyc in _execute_child(self, args, 
executable, preexec_fn, close_fds, cwd, env, universal_newlines, 
startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, 
errread, errwrite)

  1104 os.waitpid(self.pid, 0)
  1105 child_exception = pickle.loads(data)
- 1106 raise child_exception
  1107
  1108

OSError: [Errno 2] No such file or directory

I am using subprocess because I need store the pid. Any suggestions?

thanks in advance,

Gabriel M. Monnerat

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


Re: Where does setuptools live?

2009-07-10 Thread Inky 788
On Jul 10, 10:26 am, Chris Withers ch...@simplistix.co.uk wrote:
 Inky 788 wrote:
  Currently, distutils itself is being actively developed. More info
  about this here:http://tarekziade.wordpress.com/

  My (albeit anonymous) advice is: use distutils. Manually download
  packages as-needed from PyPI and install manually using standard
  distutils.

 No thanks. I'm a big fan of buildout. Making it possible for packages to
 specify their dependencies is a big win...

Yup, it's a big win. But package installation for Python is a bit of a
mess right now. Neither setuptools nor buildout (nor pip for that
matter) are a standard part of Python. It's rather silly that although
Python is a batteries-included language, and it's mid-2009, and Python
3.1 has been released, that Python *still* doesn't have a standard
built-in way to handle package installation (including dependencies
and uninstallation).

My guess is that once distutils finishes getting spruced up, some
intrepid hacker is going to:

* take the best parts of pip and the best parts of setuptools (I don't
know anything about buildout),

* stir vigorously,

* ruthlessly remove the excess pieces,

* write good documentation for it,

* throw the result up on github/launchpad/bitbucket/whatever,

and then *that's* what everyone's going to start using and which will
eventually make it into the Python std lib.

But that's just my anon 2 cents.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter problem

2009-07-10 Thread Paul Simon

David Smith d...@cornell.edu wrote in message 
news:h35f78$pt...@ruby.cit.cornell.edu...
 Paul Simon wrote:
 Peter Otten __pete...@web.de wrote in message
 news:h3481q$d95$0...@news.t-online.com...
 Paul Simon wrote:

 Chris Rebert c...@rebertia.com wrote in message
 news:mailman.2863.1247095339.8015.python-l...@python.org...
 On Wed, Jul 8, 2009 at 4:18 PM, Paul Simonpsi...@sonic.net wrote:
 I have the tkinter problem and need some assistance to straighten it
 out.
 From the web page http://wiki.python.org/moin/TkInter; I tested as 
 in
 step
 1 and cannot import _tkinter. I do not have that file on my 
 computer,
 but
 do have tkinter.py in /usr/local/lib/python2.6/lib-tk. as well as the
 directories /usr/lib/tk8.5 and /usr/lib/tcl8.5.
 This python stuff is great, but the documentation frequently
 feels like it is just a bit out of my grasp. I realize that all of 
 this
 is free but I understand the instructions on the web page to repair 
 only
 to the
 point of confusion. I'm not an expert. How do I modify my python
 configuration? Is there a file that needs to be edited? Which setup.py
 file
 do I use? Make? or python setup.py build and python setup.py install?
 Thanks. I appreciate your help.
 - How did you install Python?
 - What Linux distro are you using?

 Cheers,
 Chris
 http://blog.rebertia.com
 Im using Mandriva 2008.1.  I have to tell you honestly that I'm not 
 sure
 exactly how I installed Python.  Originally I had installed 2.5 from 
 RPM
 but 2.6 was not available for my distro (2008.1) in RPM.  I downloaded
 something from python.org and installed.  Not sure if it was tarball or
 zip file.
 Zip or tar doesn't matter, you are installing from source.

 Python has to find the necessary include files for tcl/tk. These are in
 separate packages that you have to install before you invoke Python's
 configure script.

 I don't know what they are called on your system -- look for tk-dev.rpm,
 tcl-dev.rpm or similar.

 You may run into the same problem with other modules like readline.

 Peter


 Thank you Peter.  I understand what you are saying but don't know how to 
 do
 it.  Although I installed from source, I followed a cookbook recipe.
 Could you tell me what files to execute, where they might be, and file
 arguments?  I'm just ignorant, not stupid. ;-).

 Paul



 Just install the tkinter package from the Mandriva Linux Control
 Center's Software Management system.  I just did it, doing a search for
 tkinter brought it right up.  All done.

 --David

Thanks to all for your patient help.  I have made some progress, but still 
no success.  I installed Active Tcl-8.5.7 and corrected the PATH 
accordingly.  However I still get a missing message on building Python. 
Failed to find the necessary bits (!) to build these modules:


_tkinter (among others)
To find the necessary bits, look in setup.py in detect_modules() for teh 
module's name.

Not sure what bits are, euphemism?  but am about to wipe the disk and 
reinstall linux, etc.

Paul 


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


Re: Clarity vs. code reuse/generality

2009-07-10 Thread J. Cliff Dyer
On Fri, 2009-07-10 at 02:57 +, Steven D'Aprano wrote:
 On Fri, 10 Jul 2009 03:28:04 +0100, Nobody wrote:
 
  On Thu, 09 Jul 2009 04:57:15 -0300, Gabriel Genellina wrote:
  
  Nobody says you shouldn't check your data. Only that assert is not
  the right way to do that.
  
  assert is not the right way to check your *inputs*. It's a perfectly
  reasonable way to check data which should be valid, as well as a way
  to document what variables are supposed to contain.
 
 Where are those variables coming from?
 
 The distinction really boils down to this:
 
 * asserts should never fail. If there is any chance that an assertion 
 might fail outside of test suites, then don't use assert.
 

I'm no expert, but the more I read this thread, and the more I think on
it, the more I believe that asserts don't really need to exist outside
of test suites.  The function that assertions provide is handled in a
far more robust and maintainable way by unit tests and doctests.
Anything else should be handled by more descriptive exceptions.  

The use of assertions in regular code may just be a historical baby step
on the way to real code testing.

To play devils advocate for a moment, one possible use case for assert
statements is if you need to test something that you can't easily get
under a proper unittest or doctest.  Maybe you need to know the value of
a variable halfway through a method.  A judicious assertion can help
supplement your test suite  A better solution would be to refactor so
you can get the needed value under test, but if time constraints won't
allow it, then make your assertion and move on, but only to help you
debug the code, not to protect your code at runtime.  Even then, why not
use a proper Exception (unless speed is a major issue)?

Even if it is only used internally in a module, I would still prefer a
ValueError to an AssertionError.  It tells you what's happening more
clearly.  And it protects you if another caller (even one internal to
the class) calls it with a different set of assumptions.

At minimum, I think there's a heavy burden on an author to justify the
use of AssertionErrors rather than other kinds of Exceptions. 

Cheers,
Cliff

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


Re: problem with keys combination!

2009-07-10 Thread Alex
Hi Steven,

 As I understand it, you can't block, modify, or otherwise access Ctrl-Alt-
 Del while running under Windows: it is the Secure Attention Key, and is
 designed to be virtually impossible to interfere with. It's not *quite*
 impossible, but it is the deepest, darkest black magic. Microsoft makes
 it close enough to impossible as makes no difference even for experienced
 developers.

No, is possible but for my level is quite impossible:

http://www.codeproject.com/KB/winsdk/AntonioWinLock.aspx

...in this article the author move a lot a functions in a dll  and
make a demonstration with a VB and C code to use it...plus...there is
his program that make it :-
I thought that python can read dll via ctypes...but it's very hard for
me :-((


 As a newbie, well, put it this way: it's like somebody saying Hi guys, I
 have a shiny new Swiss Army Knife, the one with the screwdriver and the
 corkscrew. I'd like to build my own Space Shuttle -- what do I do?

:-))but yes We cannn

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


Re: problem with subprocess

2009-07-10 Thread gabrielmonnerat

gabrielmonnerat wrote:

Hi all,

I need start a openoffice in Xvfb, but when I call with the DISPLAY 
occurs this error:


[r...@localhost oood]# Xvfb :99 -screen 0 1024x768x24 

In [9]: subprocess.call('/opt/ooo-dev3/program/soffice.bin')
Out[9]: 0

In [10]: subprocess.call('DISPLAY=:99 /opt/ooo-dev3/program/soffice.bin')
--- 

OSError   Traceback (most recent call 
last)


/home/gabriel/ipython console in module()

/usr/lib/python2.6/subprocess.pyc in call(*popenargs, **kwargs)
   442 retcode = call([ls, -l])
   443 
-- 444 return Popen(*popenargs, **kwargs).wait()
   445
   446

/usr/lib/python2.6/subprocess.pyc in __init__(self, args, bufsize, 
executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, 
env, universal_newlines, startupinfo, creationflags)

   593 p2cread, p2cwrite,
   594 c2pread, c2pwrite,
-- 595 errread, errwrite)
   596
   597 # On Windows, you cannot just redirect one or two 
handles: You



/usr/lib/python2.6/subprocess.pyc in _execute_child(self, args, 
executable, preexec_fn, close_fds, cwd, env, universal_newlines, 
startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, 
c2pwrite, errread, errwrite)

  1104 os.waitpid(self.pid, 0)
  1105 child_exception = pickle.loads(data)
- 1106 raise child_exception
  1107
  1108

OSError: [Errno 2] No such file or directory

I am using subprocess because I need store the pid. Any suggestions?

Sorry, I was forgot the parameter shell=True.
i.e
In [20]: subprocess.call('DISPLAY=:99 
/opt/ooo-dev3/program/soffice.bin',shell=True)


lack of attention mine


thanks in advance,

Gabriel M. Monnerat



Gabriel M. Monnerat
--
http://mail.python.org/mailman/listinfo/python-list


Re: Clarity vs. code reuse/generality

2009-07-10 Thread Robert Kern

On 2009-07-10 11:50, J. Cliff Dyer wrote:

On Fri, 2009-07-10 at 02:57 +, Steven D'Aprano wrote:

On Fri, 10 Jul 2009 03:28:04 +0100, Nobody wrote:


On Thu, 09 Jul 2009 04:57:15 -0300, Gabriel Genellina wrote:


Nobody says you shouldn't check your data. Only that assert is not
the right way to do that.

assert is not the right way to check your *inputs*. It's a perfectly
reasonable way to check data which should be valid, as well as a way
to document what variables are supposed to contain.

Where are those variables coming from?

The distinction really boils down to this:

* asserts should never fail. If there is any chance that an assertion
might fail outside of test suites, then don't use assert.



I'm no expert, but the more I read this thread, and the more I think on
it, the more I believe that asserts don't really need to exist outside
of test suites.


Actually, there is a good argument that one shouldn't use an assert statement in 
test suites: code can have bugs that only show up under -O so you want to be 
able to run your test suite under -O.


--
Robert Kern

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

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


Re: Where does setuptools live?

2009-07-10 Thread Inky 788
On Jul 10, 10:26 am, Chris Withers ch...@simplistix.co.uk wrote:
 Inky 788 wrote:
  Currently, distutils itself is being actively developed. More info
  about this here:http://tarekziade.wordpress.com/

  My (albeit anonymous) advice is: use distutils. Manually download
  packages as-needed from PyPI and install manually using standard
  distutils.

 No thanks. I'm a big fan of buildout. Making it possible for packages to
 specify their dependencies is a big win...

Read this: 
http://tarekziade.wordpress.com/2009/07/03/dropping-pep-386-versions-comparison/

So, again, I don't know anything about buildout, and it might be a
nice interim solution, but there are some new and exciting
developments in distutils coming down the pike, and whatever becomes
the standard Python package management system will very likely be
based on those new developments.

I just hope it all happens sooner than later. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Nested Classes and Instances

2009-07-10 Thread Manuel Graune

Hello,

as an example of what I would like to achieve, think of a street
where each house has a door and a sign with a unique (per house)
number on it. I tried to model this like this:

class House(object):
class Door(object):
def __init__(self,color):
 self.color=color
class Sign(object):
def __init__(self,text):
 self.text=text
def __init__(self, doorcolor,housenumber):
self.housenumber=housenumber
self.door=House.Door(doorcolor)
self.sign=House.Sign(housenumber)

house1=House(red,1)
house2=House(blue,2)

Well, so far, so good. Now, what I'd like to achive is that the text of
the sign changes whenever the variable housenumber of the
parent-instance changes or  that
house1.sign.text is a reference/pointer to house1.housenumber

Thanks in advance,

Manuel



-- 
A hundred men did the rational thing. The sum of those rational choices was
called panic. Neal Stephenson -- System of the world
http://www.graune.org/GnuPG_pubkey.asc
Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A  5828 5476 7E92 2DB4 3C99
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with subprocess

2009-07-10 Thread Christian Heimes
gabrielmonnerat wrote:
 I am using subprocess because I need store the pid. Any suggestions?
 Sorry, I was forgot the parameter shell=True.
 i.e
 In [20]: subprocess.call('DISPLAY=:99
 /opt/ooo-dev3/program/soffice.bin',shell=True)

You should avoid using the shell=True parameter. It may result in
security issues and it consumes more resources. Try this:

env = os.environ.copy()
env[DISPLAY] = :99
subprocess.call(['opt/ooo-dev3/program/soffice.bin', env=env)

Christian

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


Re: can i write a assemly language programs in python

2009-07-10 Thread member thudfoo
On Fri, Jul 10, 2009 at 5:37 AM, Tim Chasepython.l...@tim.thechases.com wrote:
 m.reddy prasad reddy wrote:

 can any one tell me how to write assembly language programs in python...if
 no is there any other way to write the programs in python

 Bah, writing assembly language is easy in Python:

  print(MOV EAX, [EBX])
  print(XOR EBX, EBX)

 Just adjust the strings for your favorite processor architecture and Python
 will produce the assembly code you want.

 Now compiling assembly to *machine* code...or calling between Python and
 assembly...that's another matter.  But writing assembly language programs in
 Python?  Easy. ;-)


PyASM is a full-featured dynamic assembler written entirely in
Python. By dynamic, I mean that it can be used to generate and execute
machine code in python at runtime without requiring the generation of
object files and linkage. It essentially allow 'inline' assembly in
python modules on x86 platforms.

PyASM can also generate object files (for windows) like a traditional
standalone assembler, although you're probably better off using one of
the many freely available assemblers if this is you primary goal.

http://members.verizon.net/~olsongt/usersGuide.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gett error message: TypeError: 'int' object is not callable

2009-07-10 Thread Nick
On Jul 9, 8:22 pm, Paul Rubin http://phr...@nospam.invalid wrote:
 Nick nleio...@gmail.com writes:
  text = file.readlines()
  len = len(text)
  fields = text[1].split()

 Is that intended to split the first line of the file?  Remember
 that arrays in python begin at index 0.

no the '1st line' is garbled meta data, but thanks man
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested Classes and Instances

2009-07-10 Thread Peter Otten
Manuel Graune wrote:

 as an example of what I would like to achieve, think of a street
 where each house has a door and a sign with a unique (per house)
 number on it. I tried to model this like this:
 
 class House(object):
 class Door(object):
 def __init__(self,color):
  self.color=color
 class Sign(object):
 def __init__(self,text):
  self.text=text
 def __init__(self, doorcolor,housenumber):
 self.housenumber=housenumber
 self.door=House.Door(doorcolor)
 self.sign=House.Sign(housenumber)
 
 house1=House(red,1)
 house2=House(blue,2)
 
 Well, so far, so good. Now, what I'd like to achive is that the text of
 the sign changes whenever the variable housenumber of the
 parent-instance changes or  that
 house1.sign.text is a reference/pointer to house1.housenumber

Python doesn't support C-style pointers, but you can work around it to some 
degree:

 class House(object):
... def __init__(self, housenumber):
... self.housenumber = housenumber
... self.sign = Sign(self)
...
 class Sign(object):
... def __init__(self, house):
... self.house = house
... @property
... def text(self): return self.house.housenumber
...
 house = House(42)
 house.sign.text
42
 house.housenumber = 42b
 house.sign.text
'42b'

If you are concerned about the tight coupling between House and Sign you can 
modify Sign to accept a function that gets the housenumber:

 class House(object):
... def __init__(self, n): self.housenumber = n
...
 class Sign(object):
... def __init__(self, gettext):
... self._gettext = gettext
... @property
... def text(self): return self._gettext()
...
 house = House(7)
 house.sign = Sign(lambda house=house: house.housenumber)
 house.sign.text
7

Peter

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


Re: tough-to-explain Python

2009-07-10 Thread Wesley Chun
On Jul 7, 1:04 pm, kj no.em...@please.post wrote:
 I'm having a hard time coming up with a reasonable way to explain
 certain things to programming novices.
 :
 How do I explain to rank beginners (no programming experience at
 all) why x and y remain unchanged above, but not z?
 :
 What do you say to that?

 I can come up with much mumbling about pointers and stacks and
 heaps and much hand-waving about the underlying this-and-that, but
 nothing that sounds even remotely illuminating.

 Your suggestions would be much appreciated!


kj,

i don't have too much to add to everyone else's response except to
describe how i deal with this. i teach Python courses several times a
year and realized long ago that conveying the concept of mutable vs.
immutable is a key to getting up-to-speed quickly with Python as well
as helping beginners.

so, although techically, this is more of an intermediate topic rather
than beginner material, i still teach it anyway, with the hopes of
producing better Python programmers out of the gate, and hopefully,
less frustrated ones. in fact, i dedicated an entire chapter (4) in
Core Python Programming just to address this important issue. to top
it all off, i end this module in the class by giving 2 quizzes, just
to make sure they understood what i just told them. i put the 1st one
online, so if you're curious, the PDF is at 
http://roadkill.com/~wesc/cyberweb/introQuiz.pdf
... the 2nd quiz is harder and involves the discussion of the
differences between shallow and deep copies. so yes, not very beginner-
ish stuff, hence the reason why i (re)named my course Intro
+Intermediate Python.

finally, rather than the paper tag or alex's hotel statue analogy, i
just say that variables are like Post-Itreg; or sticky notes on
objects. i can tag objects anytime, tag objects more than once, remove
tags, or switch them to another object, etc.

just my $0.02,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Core Python Programming, Prentice Hall, (c)2007,2001
Python Fundamentals, Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a script to build docs from setup.py

2009-07-10 Thread Tony Houghton
On Fri, 10 Jul 2009 11:06:34 +1000
Ben Finney ben+pyt...@benfinney.id.au wrote:

 Tony Houghton h...@realh.co.uk writes:
 
  I've looked through the manual but I can't find any hooks in distutils
  for generating files at install time other than extension modules and
  .pyc files. Should I just run the script from somewhere in my setup.py
  before calling distutils' setup function?
 
 Indirectly related: Ian Bicking's article on using Python's ‘setup.py’
 as a ‘Makefile’ replacement:
 
 URL:http://blog.ianbicking.org/pythons-makefile.html

Thanks, but I don't think that adds much to the distutils manual.

 If one is writing a ‘setup.py’ anyway, I think it makes sense to use
 that as the build program for the whole project if possible. Good
 hunting!

Yes. Really I only want to write a setup.py because it makes it easier
to make a debian package, but the more of the installation that's done
by setup.py the better I suppose, then other people might find it
useful.

-- 
TH * http://www.realh.co.uk

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


python make dies :libtk8.5.so: cannot open shared object file: No such file or directory

2009-07-10 Thread Lay, Tony
Trying to build python-2.6.2

 

./configure --prefix=/usr/local --exec-prefix=/usr/local
LDFLAGS=-L/usr/local

(runs through happily, had to make some libs local)

 

make runs most of the way until.

 

building '_tkinter' extension

gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall
-Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11R6/include -I.
-I/tmp/meld/Python-2.6.2/./Include -I. -IInclude -I./Include
-I/usr/local/include -I/tmp/meld/Python-2.6.2/Include
-I/tmp/meld/Python-2.6.2 -c /tmp/meld/Python-2.6.2/Modules/_tkinter.c -o
build/temp.linux-i686-2.6/tmp/meld/Python-2.6.2/Modules/_tkinter.o

gcc -pthread -fPIC -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall
-Wstrict-prototypes -DWITH_APPINIT=1 -I/usr/X11R6/include -I.
-I/tmp/meld/Python-2.6.2/./Include -I. -IInclude -I./Include
-I/usr/local/include -I/tmp/meld/Python-2.6.2/Include
-I/tmp/meld/Python-2.6.2 -c /tmp/meld/Python-2.6.2/Modules/tkappinit.c -o
build/temp.linux-i686-2.6/tmp/meld/Python-2.6.2/Modules/tkappinit.o

gcc -pthread -shared
build/temp.linux-i686-2.6/tmp/meld/Python-2.6.2/Modules/_tkinter.o
build/temp.linux-i686-2.6/tmp/meld/Python-2.6.2/Modules/tkappinit.o
-L/usr/X11R6/lib64 -L/usr/X11R6/lib -L/usr/local/lib -ltk8.5 -ltcl8.5 -lX11
-o build/lib.linux-i686-2.6/_tkinter.so

*** WARNING: renaming _tkinter since importing it failed: libtk8.5.so:
cannot open shared object file: No such file or directory

 

Failed to find the necessary bits to build these modules:

_sqlite3   bsddb185   sunaudiodev

To find the necessary bits, look in setup.py in detect_modules() for the
module's name.

 

 

Failed to build these modules:

_tkinter

 

running build_scripts

# cd /usr/local/lib

# ls -la | grep libtk8.5.so

-r-xr-xr-x   1 root root  1112606 Jul 10 13:28 libtk8.5.so

Am I missing something, it's there?

 

Regards,

 

Tony Lay

UNIX Administration 

407-306-6559

Lockheed Martin - EBS 

One Company, One Team

 

BEGIN:VCARD
VERSION:2.1
N:Lay;Anthony (Tony)
FN:Anthony (Tony) Lay (tony@lmco.com)
ORG:Lockheed Martin
TITLE:Computer Network Supprt SrSpec
TEL;WORK;VOICE:407/306-6559
TEL;PAGER;VOICE:321/297-0122
ADR;WORK:;;12506 Lake Underhill Rd;Orlando;FL;32825;US
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:12506 Lake Underhill Rd=0D=0AOrlando, FL 32825=0D=0AUS
EMAIL;PREF;INTERNET:tony@lmco.com
REV:20090424T165829Z
END:VCARD


smime.p7s
Description: S/MIME cryptographic signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: language analysis to enforce code standards

2009-07-10 Thread Tim Rowe
2009/7/10 Peter Otten __pete...@web.de:

 Don't be a fool. Have someone other than the author read the comment.

That's the winning answer as far as I'm concerned. Automated tools are
good for picking up some types of accidental mistakes, but for
checking that comments are meaningful (and variable names, for that
matter) you can't do without peer review.

Think about it. What's the purpose of enforcing standards. Just a
tick in some assurance box to say we meet these standards? Ot to
ensure something about the product quality?

No automated tool -- not for a while yet, anyway -- is going to pick
up comments such as:

# increment x
x += 1

or

# You are not expected to understand this.

The former is the sort of thing that any programmer might produce when
against a deadline and forced to comment their code. The latter is a
classic from a programming guru of old. An automatic checker that just
checks that the comment exists without understanding its contents
simply is not adding value but is rather petty bureaucracy that will
annoy the programmers.


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


Re: Automate rsync w/ authentication

2009-07-10 Thread Chris Rebert
On Fri, Jul 10, 2009 at 9:13 AM, Bryanbryanv...@gmail.com wrote:
 I am trying to automate rsync to backup server A from server B.  I
 have set up a private/public key between the two servers so I don't
 have to enter a password when using rsync.  Running rsync manually
 with the following command works fine:
 rsync -av --dry-run -e /usr/bin/ssh -i /home/bry/keys/brybackup.key
 r...@10.0.45.67:/home/bry/jquery.lookup /home/bry/tmp

 But when I try to do it with python, the subprocess simply returns the
 ssh -h output on stderr like I am passing some invalid syntax.  What
 is wrong in my translation of rsync's -e command from shell to
 pythyon?

 #! /usr/bin/python
 from subprocess import Popen, PIPE
 rsyncExec = '/usr/bin/ssh'
 source = 'r...@10.0.45.67:/home/bry/jquery.lookup'
 dest = '/home/bry/tmp'
 rshArg = '-e /usr/bin/ssh -i /home/bry/keys/brybackup.key'
 args = [rsyncExec, '-a', '-v', '--dry-run', rshArg, source, dest]

Like many problems involving the subprocess module, I think you've
tokenized the arguments incorrectly. Try:

rshArg = '/usr/bin/ssh -i /home/bry/keys/brybackup.key'
args = [rsyncExec, '-av', '--dry-run', '-e', rshArg, source, dest]

Note that the -e switch and its operand are separate arguments for the
purposes of POSIX shell tokenization.

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


Re: tough-to-explain Python

2009-07-10 Thread Scott David Daniels

Steven D'Aprano wrote:

On Fri, 10 Jul 2009 08:28:29 -0700, Scott David Daniels wrote:

Steven D'Aprano wrote:

Even *soup stock* fits the same profile as what Hendrik claims is
almost unique to programming. On its own, soup stock is totally
useless. But you make it, now, so you can you feed it into something
else later on.
Or instant coffee.

I think I'll avoid coming to your house for a cup of coffee. :-)
I meant the instant coffee powder is prepared in advance. It's useless on 
it's own, but later on you feed it into boiling water, add sugar and 
milk, and it's slightly less useless.


I know, but the image of even a _great_ soup stock with instant
coffee poured in, both appalled me and made me giggle.  So, I
thought I'd share.

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


Re: Clarity vs. code reuse/generality

2009-07-10 Thread J. Cliff Dyer
On Fri, 2009-07-10 at 11:57 -0500, Robert Kern wrote:
 On 2009-07-10 11:50, J. Cliff Dyer wrote:
  On Fri, 2009-07-10 at 02:57 +, Steven D'Aprano wrote:
  On Fri, 10 Jul 2009 03:28:04 +0100, Nobody wrote:
 
  On Thu, 09 Jul 2009 04:57:15 -0300, Gabriel Genellina wrote:
 
  Nobody says you shouldn't check your data. Only that assert is not
  the right way to do that.
  assert is not the right way to check your *inputs*. It's a perfectly
  reasonable way to check data which should be valid, as well as a way
  to document what variables are supposed to contain.
  Where are those variables coming from?
 
  The distinction really boils down to this:
 
  * asserts should never fail. If there is any chance that an assertion
  might fail outside of test suites, then don't use assert.
 
 
  I'm no expert, but the more I read this thread, and the more I think on
  it, the more I believe that asserts don't really need to exist outside
  of test suites.
 
 Actually, there is a good argument that one shouldn't use an assert statement 
 in 
 test suites: code can have bugs that only show up under -O so you want to be 
 able to run your test suite under -O.
 

That's an interesting point.  Presumably TestCase.assert_() doesn't
suffer from this defect?  Otherwise the entire unittest suite is
essentially broken by your argument.  I suppose I should have said one
should only raise AssertionErrors in test suites.  Practically speaking,
that's what a test suite is:  The place where you assert what the code
does.



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


Re: gett error message: TypeError: 'int' object is not callable

2009-07-10 Thread J. Cliff Dyer
On Thu, 2009-07-09 at 13:53 +, Friðrik Már Jónsson wrote:
 Look at:
 
len = len(text)
 
 You're overriding `len` (a built-in method), with an integer  
 (`len(text)`).  You then call:
 
for i in range(len(fields)):
 
 But `len` is no longer a callable, but merely an integer.
 
 Regards,
 Friðrik Már
 
 P.S. While this is a fairly obvious problem it's usually a good idea  
 to post working code and a traceback when requesting help.

While we're on the subject of good question posting form:  The body of
your post should contain all relevant information.  Please don't make
readers look back at the subject heading for the statement of the
problem.  Duplicating the statement of the problem in the subject and
the body is ok, but it really ought to be in the body.

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


ANN: Leo 4.6 rc1 released

2009-07-10 Thread Edward K Ream
Leo 4.6 rc1 is now available at:
http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106

Leo is a text editor, data organizer, project manager and much more. See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.6:
--

- Cached external files *greatly* reduces the time to load .leo files.
- Leo now features a modern Qt interface by default.
  Leo's legacy Tk interface can also be used.
- New --config, --file and --gui command-line options.
- Leo tests syntax of .py files when saving them.
- Leo can now open any kind of file into @edit nodes.
- @auto-rst nodes allow easy editing of reStructuredText files.
- Properties of commanders, positions and nodes simplify programming.
- Improved Leo's unit testing framework.
- Leo now requires Python 2.5 or later.
- Dozens of small improvements and bug fixes.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Forum:http://groups.google.com/group/leo-editor
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
Bzr:  http://code.launchpad.net/leo-editor/
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward K. Ream   email:  edream...@yahoo.com
Leo: http://webpages.charter.net/edreamleo/front.html



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


Re: Clarity vs. code reuse/generality

2009-07-10 Thread Robert Kern

On 2009-07-10 13:56, J. Cliff Dyer wrote:

On Fri, 2009-07-10 at 11:57 -0500, Robert Kern wrote:

On 2009-07-10 11:50, J. Cliff Dyer wrote:

On Fri, 2009-07-10 at 02:57 +, Steven D'Aprano wrote:

On Fri, 10 Jul 2009 03:28:04 +0100, Nobody wrote:


On Thu, 09 Jul 2009 04:57:15 -0300, Gabriel Genellina wrote:


Nobody says you shouldn't check your data. Only that assert is not
the right way to do that.

assert is not the right way to check your *inputs*. It's a perfectly
reasonable way to check data which should be valid, as well as a way
to document what variables are supposed to contain.

Where are those variables coming from?

The distinction really boils down to this:

* asserts should never fail. If there is any chance that an assertion
might fail outside of test suites, then don't use assert.


I'm no expert, but the more I read this thread, and the more I think on
it, the more I believe that asserts don't really need to exist outside
of test suites.

Actually, there is a good argument that one shouldn't use an assert statement in
test suites: code can have bugs that only show up under -O so you want to be
able to run your test suite under -O.



That's an interesting point.  Presumably TestCase.assert_() doesn't
suffer from this defect?  Otherwise the entire unittest suite is
essentially broken by your argument.


It explicitly raises AssertionErrors. It does not use the assert statement.


I suppose I should have said one
should only raise AssertionErrors in test suites.  Practically speaking,
that's what a test suite is:  The place where you assert what the code
does.


Yup.

--
Robert Kern

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

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


Re: Colour of output text

2009-07-10 Thread Chris Rebert
On Fri, Jul 10, 2009 at 2:23 AM,
garabik-news-2005...@kassiopeia.juls.savba.sk wrote:
 Tim Harig user...@ilthio.net wrote:
 On 2009-07-09, Alex Rosslyn black.line...@gmail.com wrote:
 I would like to learn a way of changing the colour of a particular
 part of the output text. I've tried the following

 On Unix operating systems this would be done through the curses interface:

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

 Or using ANSI colour codes:

 colours = {
snip
            'beep'       :    \007,

Sound is a color? Maybe if you have synaesthesia...

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


Why not enforce four space indentations in version 3.x?

2009-07-10 Thread walterbyrd
I believe Guido himself has said that all indentions should be four
spaces - no tabs.

Since backward compatibility is being thrown away anyway, why not
enforce the four space rule?

At least that way, when I get python code from somebody else, I would
know what I am looking at, without having to do a hex dump, or
something.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AP -- MeAmI.org Paces Google

2009-07-10 Thread Musatov


François Grondin wrote:
 David Bernier david...@videotron.ca a �crit dans le message de news:
 h36ki102...@news5.newsguy.com...
  Musatov wrote:
  On Jul 9, 7:54 pm, David Bernier david...@videotron.ca wrote:
  Musatov wrote:
  Los Angeles (AP) --MeAmI.org now has users in 50 countries following
  its adopted use in Pakistan.  The search engine has grown in
  popularity 10,000 fold following its Beta test launch three months ago
  in April, 2009. Supporters of the site claim it is better than rival
  Google upon which platform it is based. Controversy arose after
  MeAmI.org search code allowed users to search other users Google
  results with no advertising. It is truly an innovative thing we are
  doing, said Founder and CEO, Martin Musatov. Letting users search
  the results of other Google users immediately results in a level of
  accuracy and relevance above and beyond Google. Google changed their
  API following the launch or MeAmI.org and explored the possibility of
  blocking site access from MeAmI.org to Google search results but was
  unable to do so. Critics of MeAmI.org say what it is doing is
  tantamount to intellectual theft. When asked about this topper Musatov
  exclaimed, The Internet was made for people, not companies. An
  analyst at Goldman Sachs says, requesting to remain anonymous,
  MeAmI.org has a strong presence in promoting itself as a vehicle for
  global activism and to tell you the truth, this makes it much more
  likely an acquisition target than potential intellectual property
  violator. Google could not be reached for comment.
  Mr. Musatov,  do you know who originally wrote the
  article above?
 
  Thank you.
 
  David Bernier- Hide quoted text -
 
  - Show quoted text -
 
  Yes.
 
  Mr. Musatov, do you know the name of the person who
  originally wrote the article above?
 
  Thank you.
 
  David Bernier

 Maybe Mr. Musatov should answer the following questions instead :
 1. Did you write the article above?
 2. If not, who did? And I don't want AP as the answer, but the name of the
 journalist.

 David, don't take it bad, but he answered your question with an accurate
 answer (yes), You gave him the opportunity to avoid the real answer and he
 took it. Based on Musatov's strange behavior and logic, don't expect more
 from him. Ask anyone else the same question and you'd get a real answer.

 BTW, my guess for question 2 would be the Masked Logician, Floetry,
 scriber77, or Professor X.

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


  1   2   >