functon invoke or not

2013-01-09 Thread skyworld
Hi,

I see someone's code as this:

class ABC: 
def __init__(self, env):
 ...
 self.jmpTable['batchQ']['submit_job']  = self.lsf_submit
 ...
def lsf_submit(self, cmd,env):
 .

what confused me is why there is no parentheses for self.lsf_submit in
"self.jmpTable['batchQ']['submit_job']  = self.lsf_submit"? what does
this piece of code mean? thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: functon invoke or not

2013-01-09 Thread Peter Otten
skyworld wrote:

> Hi,
> 
> I see someone's code as this:
> 
> class ABC: 
> def __init__(self, env):
>  ...
>  self.jmpTable['batchQ']['submit_job']  = self.lsf_submit

The bound method self.lsf_submit is not invoked in this line, it is stored 
for later use.

>  ...
> def lsf_submit(self, cmd,env):
>  .
> 
> what confused me is why there is no parentheses for self.lsf_submit in
> "self.jmpTable['batchQ']['submit_job']  = self.lsf_submit"? what does
> this piece of code mean? thanks.

Somewhere else in the code the is probably code similar to

var1 = ...
var2 = ...
self.jmpTable[var1][var2](some_command, some_env)

When var1 is "batchQ" and var2 is "submit_job" this will in effect call

self.lsf_submit(some_command, some_env)

A slightly simplified example with just a dict and two functions:

>>> def german(name):
... print "Guten Tag, Herr", name
... 
>>> def french(name):
... print "Bonjour, M.", name
... 
>>> lookup = {"fr": french, "de": german}
>>> lookup["fr"]("Hulot")
Bonjour, M. Hulot


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


Re: functon invoke or not

2013-01-09 Thread Mitya Sirenef

On Wed 09 Jan 2013 03:23:56 AM EST, skyworld wrote:

Hi,

I see someone's code as this:

class ABC: 
 def __init__(self, env):
  ...
  self.jmpTable['batchQ']['submit_job']  = self.lsf_submit
  ...
 def lsf_submit(self, cmd,env):
  .

what confused me is why there is no parentheses for self.lsf_submit in
"self.jmpTable['batchQ']['submit_job']  = self.lsf_submit"? what does
this piece of code mean? thanks.



Presumably it will be called at a later point:

def f(): print 'foo'

lst = [f]
# la la
lst[0]()


HTH,  -m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
--
http://mail.python.org/mailman/listinfo/python-list


Re: functon invoke or not

2013-01-09 Thread skyworld
On 1月9日, 下午4时46分, Mitya Sirenef  wrote:
> On Wed 09 Jan 2013 03:23:56 AM EST, skyworld wrote:
>
> > Hi,
>
> > I see someone's code as this:
>
> > class ABC: 
> >      def __init__(self, env):
> >           ...
> >           self.jmpTable['batchQ']['submit_job']  = self.lsf_submit
> >           ...
> >      def lsf_submit(self, cmd,env):
> >           .
>
> > what confused me is why there is no parentheses for self.lsf_submit in
> > "self.jmpTable['batchQ']['submit_job']  = self.lsf_submit"? what does
> > this piece of code mean? thanks.
>
> Presumably it will be called at a later point:
>
> def f(): print 'foo'
>
> lst = [f]
> # la la
> lst[0]()
>
> HTH,  -m
>
> --
> Lark's Tongue Guide to Python:http://lightbird.net/larks/

Thanks for both of your replies. I got it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: functon invoke or not

2013-01-09 Thread Jussi Piitulainen
skyworld writes:

> Hi,
> 
> I see someone's code as this:
> 
> class ABC: 
> def __init__(self, env):
>  ...
>  self.jmpTable['batchQ']['submit_job']  = self.lsf_submit
>  ...
> def lsf_submit(self, cmd,env):
>  .
> 
> what confused me is why there is no parentheses for self.lsf_submit in
> "self.jmpTable['batchQ']['submit_job']  = self.lsf_submit"? what does
> this piece of code mean? thanks.

Functions are objects. The above is storing the function lsf_submit in
a dict from where it can later be taken and invoked. The invocation is
indicated by the parentheses after an expression that denotes a
function.

Consider the following, and play with examples of your own in a Python
interpreter.

   >>> from math import acos
   >>> def foo(x): return acos, x
   ... 
   >>> foo(-1)
   (, -1)
   >>> foo(-1)[0]
   
   >>> foo(-1)[0](foo(-1)[1])
   3.141592653589793

Or simply:

   >>> acos
   
   >>> acos(-1)
   3.141592653589793
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-09 Thread Kurt Hansen

Den 08/01/13 16.31, chaouche yacine skrev:

Well tell me how do you use this script in gedit, are you using it as a
plugin ?


"Snippets" is a plugin, yes. It's included in the .app for Mac (v. 
2.30.2), but not activated af default.


Open "Tools" in the menu line and click "Manage snippets...". Here you 
can organize, add and edit snippets of texts. The feature olså has the 
ability to work with Python code inside the snippet content.


I am re-building a 15 years old homepage. The HTML code is handmade over 
the years and very varying, buggy etc., så I would like to renew the 
HTML for the table structure in an easy way.


Example: On this page: http://www.danacord.dk/frmsets/records/732-r.html 
I mark the content of the CD, copy it to the clipboard and paste it into 
the editing area in Gedit. cmd-a marks it all again and then I "run" the 
snippet upon the text, either using my self-defined hotkey or by pushing 
ctrl+space and select my snippet from a list.


The copied text is inserted as clean text without any HTML. The 
Python-snippet we are discussing recognizes tabs to separate the columns 
and adds the apprpriate HTML-code to it.

--
Regards
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-09 Thread Kurt Hansen

Den 06/01/13 15.20, Chris Angelico wrote:



That version should work.



Am 06.01.2013 15:30 schrieb Kurt Hansen:


It certainly does. I'll keep it and use it until at better solution is
found.


On 08/01/13 15.18, Thomas Rachel wrote:
>

That would be simple:

Replace

output += '' + item +
' '

with

if len(columns) >= 3:
 output += ''
else:
 output += ''
output += item + ' '

(untested as well; keep the indentation in mind!)


Thanks, Thomas, but ...

The script stops right bofore
= 3:
output += ''

This, and the rest of the script code is put out as the result, not my test.
--
Venlig hilsen
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the selected text of the webpage in chrome through python ?

2013-01-09 Thread Alister
On Mon, 07 Jan 2013 20:20:28 -0800, iMath wrote:

> How to get the selected text of the webpage in chrome through python ?

i think you need to explain your  requirement further
also what do you want to do to the text once you have it?




-- 
Genius is one percent inspiration and ninety-nine percent perspiration.
-- Thomas Alva Edison
-- 
http://mail.python.org/mailman/listinfo/python-list


Regex not matching a string

2013-01-09 Thread python . prog29
Hi All -


In the following code ,am trying to remove a multi line - comment that contains 
"This is a test comment" for some reason the regex is not matching.. can anyone 
provide inputs on why it is so?

import os
import sys
import re
import fnmatch

def find_and_remove(haystack, needle):
pattern = re.compile(r'/\*.*?'+ needle + '.*?\*/', re.DOTALL)
return re.sub(pattern, "", haystack)

for path,dirs,files in os.walk(sys.argv[1]):
for fname in files:
for pat in ['*.cpp','*.c','*.h','*.txt']:
if fnmatch.fnmatch(fname,pat):
fullname = os.path.join(path,fname)
# put all the text into f and read and replace...
f = open(fullname).read()
result = find_and_remove(f, r"This is a test comment") 
print result
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to modify this script?

2013-01-09 Thread chaouche yacine
I figrued it out. Copy/paste exactly these lines in the snippets tool. You can 
bind it to a key as you may know, I bound it to Ctrl-E. So paste it in a new 
snippet (keep the original in a safe place), bind to a key, select the text you 
want to html-tableize and hit the key binding. In my case it worked.

$<
def addline(line):
    return "%s\n" % line

def addcolumn(item,nb_columns):
    if nb_columns != 3:
    return "%s" % (3 - nb_columns + 1, item)
    return "%s" % item

output = "\n"
for line in """$GEDIT_SELECTED_TEXT""".split("\n"):
    items = line.strip().split("\t")
    columns = ""
    for item in items :
    columns += addcolumn(item,len(items))
    output  += addline(columns)


output += ""
return output>


Here's a screenshit, sorry screenshot :) http://h.dropcanvas.com/521xc/gedit.png


The python support in gedit snippets is very poor when it comes to debugging 
because there are traceback printed in the console, that means gedit actually 
breaks without even noticing the user about what went wrong (ex. : your snippet 
is malformed or has errors). I had to debug it using pdb.set_trace directly 
inside its source code to figure out what was wrong in the snippet.

If this doesn't work for you, please let me know.






 From: Kurt Hansen 
To: python-list@python.org 
Sent: Wednesday, January 9, 2013 10:07 AM
Subject: Re: How to modify this script?
 
Den 08/01/13 16.31, chaouche yacine skrev:
> Well tell me how do you use this script in gedit, are you using it as a
> plugin ?

"Snippets" is a plugin, yes. It's included in the .app for Mac (v. 2.30.2), but 
not activated af default.

Open "Tools" in the menu line and click "Manage snippets...". Here you can 
organize, add and edit snippets of texts. The feature olså has the ability to 
work with Python code inside the snippet content.

I am re-building a 15 years old homepage. The HTML code is handmade over the 
years and very varying, buggy etc., så I would like to renew the HTML for the 
table structure in an easy way.

Example: On this page: http://www.danacord.dk/frmsets/records/732-r.html I mark 
the content of the CD, copy it to the clipboard and paste it into the editing 
area in Gedit. cmd-a marks it all again and then I "run" the snippet upon the 
text, either using my self-defined hotkey or by pushing ctrl+space and select 
my snippet from a list.

The copied text is inserted as clean text without any HTML. The Python-snippet 
we are discussing recognizes tabs to separate the columns and adds the 
apprpriate HTML-code to it.
-- Regards
Kurt Hansen
-- http://mail.python.org/mailman/listinfo/python-list-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regex not matching a string

2013-01-09 Thread Steven D'Aprano
On Wed, 09 Jan 2013 02:08:23 -0800, python.prog29 wrote:

> Hi All -
> 
> 
> In the following code ,am trying to remove a multi line - comment that
> contains "This is a test comment" for some reason the regex is not
> matching.. can anyone provide inputs on why it is so?

It works for me.

Some observations:

Perhaps you should consider using the glob module rather than manually 
using fnmatch. That's what glob does.

Also, you never actually write to the files, is that deliberate?

Finally, perhaps your regex simply doesn't match what you think it 
matches. Do you actually have any files containing the needle 

"/* ... This is a test comment ... */"

(where the ... are any characters) exactly as shown?

Instead of giving us all the irrelevant code that has nothing to do with 
matching a regex, you should come up with a simple piece of example code 
that demonstrates your problem. Or, in this case, *fails* to demonstrate 
the problem.

import re
haystack = "aaa\naaa /*xxxThis is a test comment \nxxx*/aaa\naaa\n"
needle = "This is a test comment"
pattern = re.compile(r'/\*.*?'+ needle + '.*?\*/', re.DOTALL)
print haystack
print re.sub(pattern, "", haystack)


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


Re: Regex not matching a string

2013-01-09 Thread Peter Otten
python.pro...@gmail.com wrote:

> In the following code ,am trying to remove a multi line - comment that
> contains "This is a test comment" for some reason the regex is not
> matching.. can anyone provide inputs on why it is so?

> def find_and_remove(haystack, needle):
> pattern = re.compile(r'/\*.*?'+ needle + '.*?\*/', re.DOTALL)
> return re.sub(pattern, "", haystack)

If a comment does not contain the needle "/\*.*?" extends over the end of 
that comment:

>>> re.compile(r"/\*.*?xxx").search("/* xxx */").group()
'/* xxx'
>>> re.compile(r"/\*.*?xxx").search("/* yyy */ /* xxx */").group()
'/* yyy */ /* xxx'


One solution may be a substitution function:

>>> def sub(match, needle="xxx"):
... s = match.group()
... if needle in s:
... return ""
... else:
... return s
... 
>>> re.compile(r"/\*.*?\*/").sub(sub, "/* yyy */ /* xxx */")
'/* yyy */ '


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


Re: How to modify this script?

2013-01-09 Thread Kurt Hansen

Den 09/01/13 11.23, chaouche yacine skrev:

I figrued it out. Copy/paste exactly these lines in the snippets tool.
You can bind it to a key as you may know, I bound it to Ctrl-E. So paste
it in a new snippet (keep the original in a safe place), bind to a key,
select the text you want to html-tableize and hit the key binding. In my
case it worked.

$<

[cut]

def addline(line):


Spooky behavior. Yes, the green-apple-example also works for me with 
your new script, BUT ...!


Try to copy the table content on this page:
http://www.danacord.dk/frmsets/records/732-r.html
which is a realistic scenario. That's whar I am doing these days.

Pasting it into Gedit and running the snippet blanks the edit area (on 
MY Mac at least).


And yes: I have pasted your code excatly and I've double-checked for 
linewraps. Everything is okay.


For your cenvenience I have put borders on the table online (see link 
above). You may ommit the rows after track 14. Not that it makes any 
differerence, but that block is surposed to be formatted differerent. I 
do that manually afterwards ... if not ... ;-)

--
Regards
Kurt Hansen
--
http://mail.python.org/mailman/listinfo/python-list


socket.makefile raises ValueError when mode = 'rt'

2013-01-09 Thread Antoon Pardon
This is using python 3.2.

I am writing somekind of wrapper around the ftplib. So
that you can work with it as if you are working with
local files.

The idea is that you start with making a connection like

rmt = FTP(...)

and then do something like the following

rmtfl = rmt.open("rmtfilename", "rt")
for ln in rmtfl:
treat(ln)

This is part of the code:

class ftpfile:
def __init__(self, cn, rfn, mode, bound = False):
self.ftp = cn
self.bound = bound
if 'b' in mode:
self.ftp.voidcmd('TYPE I')
else:
self.ftp.voidcmd('TYPE A')
if 'r' in mode:
self.cnct =  self.ftp.transfercmd("RETR %s" % rfn)
self.fl = self.cnct.makefile(mode)
elif 'w' in mode:
self.cnct =  self.ftp.transfercmd("STOR %s" % rfn)
self.fl = self.cnct.makefile(mode, newline = '\r\n')
else:
raise ValueError("%s: invalide mode" % mode)

The problem is with makefile. If mode contains a "t" I get
the following traceback:

Traceback (most recent call last):
  File "ftputil.tpy", line 14, in test_textftp
rmtfl1 = rmt.open('ftp1.py', 'wt')
  File "/local/home/apardon/src/projecten/py3lib/ftputil.py", line 76,
in open
return ftpfile(ftp, fn, mode, True)
  File "/local/home/apardon/src/projecten/py3lib/ftputil.py", line 15,
in __init__
self.fl = self.cnct.makefile(mode, newline = '\r\n')
  File "/usr/lib/python3.2/socket.py", line 151, in makefile
raise ValueError("invalid mode %r (only r, w, b allowed)")
ValueError: invalid mode %r (only r, w, b allowed)

But the documentation states:
socket.makefile(mode='r', buffering=None, *, encoding=None, errors=None,
newline=None)
Return a file object associated with the socket. The exact returned
type depends on the arguments given to makefile(). These arguments are
interpreted the same way as by the built-in open() function.

And since 't' is allowed in the mode of the built-in open() function I
would consider this a bug.
Unless I am missing something?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket.makefile raises ValueError when mode = 'rt'

2013-01-09 Thread Dave Angel
On 01/09/2013 08:22 AM, Antoon Pardon wrote:
> This is using python 3.2.
>
> I am writing somekind of wrapper around the ftplib. So
> that you can work with it as if you are working with
> local files.
>
> The idea is that you start with making a connection like
>
> rmt = FTP(...)
>
> and then do something like the following
>
> rmtfl = rmt.open("rmtfilename", "rt")
> for ln in rmtfl:
> treat(ln)
>
> This is part of the code:
>
> class ftpfile:
> def __init__(self, cn, rfn, mode, bound = False):
> self.ftp = cn
> self.bound = bound
> if 'b' in mode:
> self.ftp.voidcmd('TYPE I')
> else:
> self.ftp.voidcmd('TYPE A')
> if 'r' in mode:
> self.cnct =  self.ftp.transfercmd("RETR %s" % rfn)
> self.fl = self.cnct.makefile(mode)
> elif 'w' in mode:
> self.cnct =  self.ftp.transfercmd("STOR %s" % rfn)
> self.fl = self.cnct.makefile(mode, newline = '\r\n')
> else:
> raise ValueError("%s: invalide mode" % mode)
>
> The problem is with makefile. If mode contains a "t" I get
> the following traceback:
>
> Traceback (most recent call last):
>   File "ftputil.tpy", line 14, in test_textftp
> rmtfl1 = rmt.open('ftp1.py', 'wt')
>   File "/local/home/apardon/src/projecten/py3lib/ftputil.py", line 76,
> in open
> return ftpfile(ftp, fn, mode, True)
>   File "/local/home/apardon/src/projecten/py3lib/ftputil.py", line 15,
> in __init__
> self.fl = self.cnct.makefile(mode, newline = '\r\n')
>   File "/usr/lib/python3.2/socket.py", line 151, in makefile
> raise ValueError("invalid mode %r (only r, w, b allowed)")
> ValueError: invalid mode %r (only r, w, b allowed)
>
> But the documentation states:
> socket.makefile(mode='r', buffering=None, *, encoding=None, errors=None,
> newline=None)
> Return a file object associated with the socket. The exact returned
> type depends on the arguments given to makefile(). These arguments are
> interpreted the same way as by the built-in open() function.
>
> And since 't' is allowed in the mode of the built-in open() function I
> would consider this a bug.
> Unless I am missing something?

I believe that 't' was a new addition to mode, for Python 3.x So
perhaps the socket library hasn't kept consistent with it.

I don't really know the socket library.  Does it even support text
mode?  Does that make sense?  Remember that text mode means a different
thing in 3.x than it did in 2.x



-- 

DaveA

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


Re: socket.makefile raises ValueError when mode = 'rt'

2013-01-09 Thread Antoon Pardon
Op 01/09/13 14:54, Dave Angel schreef:
> On 01/09/2013 08:22 AM, Antoon Pardon wrote:
>> This is using python 3.2.
...
>> But the documentation states:
>> socket.makefile(mode='r', buffering=None, *, encoding=None, errors=None,
>> newline=None)
>> Return a file object associated with the socket. The exact returned
>> type depends on the arguments given to makefile(). These arguments are
>> interpreted the same way as by the built-in open() function.
>>
>> And since 't' is allowed in the mode of the built-in open() function I
>> would consider this a bug.
>> Unless I am missing something?
> I believe that 't' was a new addition to mode, for Python 3.x So
> perhaps the socket library hasn't kept consistent with it.
>
> I don't really know the socket library.  Does it even support text
> mode?  Does that make sense?  Remember that text mode means a different
> thing in 3.x than it did in 2.x
As far as I understand the code, it does support text. This is part of
the makefile method.

   def makefile(self, mode="r", buffering=None, *,
 encoding=None, errors=None, newline=None):

for c in mode:
if c not in {"r", "w", "b"}:
raise ValueError("invalid mode %r (only r, w, b allowed)")
writing = "w" in mode
reading = "r" in mode or not writing
assert reading or writing
binary = "b" in mode
...
if binary:
return buffer
text = io.TextIOWrapper(buffer, encoding, errors, newline)
text.mode = mode
return text

So it seems that if the mode is not binary an io.TextIOWrapper is
returned. That indicates to me that
text mode is supported.

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


PIL or something to open EXIF Metadata with Python

2013-01-09 Thread Jose Trevino
I am trying to load the PIL module to manage exif metadata with Python but have 
had no success. I do some work relate with applescript, but for large files 
time increases exponentially. So I changed to Python with the intention of 
using PIL or something similar. I see that the last update of PIL is like 3 
years ago, so I don't know if it is still working. I downloaded the last 
version of PIL to my mac, but I can't get python to recognize PIL included 
commands. Does anybody has a suggestion?  Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL or something to open EXIF Metadata with Python

2013-01-09 Thread Tim Golden
On 09/01/2013 14:45, Jose Trevino wrote:
> I am trying to load the PIL module to manage exif metadata with
> Python but have had no success. 


Try pyexiv2:

  http://tilloy.net/dev/pyexiv2/

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


new to python and programming at large

2013-01-09 Thread kwakukwatiah
pls  I want to write a function that can compute for the sqrt root of any 
number.bt it not working pls help.
from math import sqrt
def squareroot(self):
x = sqrt(y)
print x-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PyDTLS

2013-01-09 Thread Neal Becker
A bit OT, but the widespread use of rfc 6347 could have a big impact on my 
work.  
I wonder if it's likely to see widespread use?  What are likely/possible use 
cases?

Thank.

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


new to python and programming at large

2013-01-09 Thread kwakukwatiah
pls  I want to write a function that can compute for the sqrt root of any 
number.bt it not working pls help.
from math import sqrt
def squareroot(self):
x = sqrt(y)
print x-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new to python and programming at large

2013-01-09 Thread Chris Angelico
On Thu, Jan 10, 2013 at 8:03 AM,   wrote:
> pls  I want to write a function that can compute for the sqrt root of any
> number.bt it not working pls help.
> from math import sqrt
> def squareroot(self):
> x = sqrt(y)
> print x

The 'self' argument is a convention used in classes. You probably want
to call your argument y:

def squareroot(y):

since that's what you then pass to math.sqrt.

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


Re: new to python and programming at large

2013-01-09 Thread Alister
On Thu, 10 Jan 2013 02:18:11 +1100, Chris Angelico wrote:

> On Thu, Jan 10, 2013 at 8:03 AM,   wrote:
>> pls  I want to write a function that can compute for the sqrt root of
>> any number.bt it not working pls help.
>> from math import sqrt def squareroot(self):
>> x = sqrt(y)
>> print x
> 
> The 'self' argument is a convention used in classes. You probably want
> to call your argument y:
> 
> def squareroot(y):
> 
> since that's what you then pass to math.sqrt.
> 
> Chris Angelico

why even do this when simply calling sqrt is all that is needed?




-- 
Outside of a dog, a book is man's best friend.  Inside of a dog, it is too
dark to read.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new to python and programming at large

2013-01-09 Thread Chris Angelico
On Thu, Jan 10, 2013 at 2:38 AM, Alister  wrote:
> On Thu, 10 Jan 2013 02:18:11 +1100, Chris Angelico wrote:
>
>> On Thu, Jan 10, 2013 at 8:03 AM,   wrote:
>>> pls  I want to write a function that can compute for the sqrt root of
>>> any number.bt it not working pls help.
>>> from math import sqrt def squareroot(self):
>>> x = sqrt(y)
>>> print x
>>
>> The 'self' argument is a convention used in classes. You probably want
>> to call your argument y:
>>
>> def squareroot(y):
>>
>> since that's what you then pass to math.sqrt.
>>
>> Chris Angelico
>
> why even do this when simply calling sqrt is all that is needed?

Good question. But without a lot more context from the OP, none of
this is really ponderable...

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


Interpolating/crossfading a stack of matrices

2013-01-09 Thread raphael
Hi,

I want to interpolate (with quadratic splines) a stack of 2D-arrays/matrices 
y1, y2, y3, ... in a third dimension (which I call x) e.g. for crossfading 
images. I already have a working code which unfortunately still contains two 
explicit loops over the rows and colums of the matrices. Inside these loops I 
simply use 'interp1d' from scipy suitable for 1D-interpolations. Is anybody 
here aware of a better, more efficient solution of my problem? Maybe somewhere 
out there a compiled routine for my problem already exists in a python 
library... :-)

My code:

--
from scipy.interpolate import interp1d
from numpy import array, empty_like, dstack

x = [0.0, 0.25, 0.5, 0.75, 1.0]

y1 = array([[1, 10, 100, 1000], [1,  10,   100,  1000]], float)
y2 = array([[2, 20, 200, 2000], [2,  20,   200,  2000]], float)
y3 = array([[3, 30, 300, 3000], [4,  40,   400,  4000]], float)
y4 = array([[4, 40, 400, 4000], [8,  80,   800,  8000]], float)
y5 = array([[5, 50, 500, 5000], [16, 160, 1600, 16000]], float)

y = dstack((y1, y2, y3, y4, y5))

y_interpol = empty_like(y[:, :, 0]) 
i_range, j_range = y.shape[:2]

for i in xrange(i_range):
for j in xrange(j_range):
# interpolated value for x = 0.2
y_interpol[i,j] = interp1d(x, y[i, j,:], kind='quadratic')(0.2)

print y_interpol
--

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


Re: ANN: PyDTLS

2013-01-09 Thread Guido van Rossum
On Tue, Jan 8, 2013 at 11:38 PM, rbit  wrote:
> On Tue, Jan 8, 2013 at 9:09 PM, Guido van Rossum  wrote:
>> But don't you have to deal with that when doing synchronous I/O as
>> well? It's a datagram protocol after all.
>
> No: when dealing with blocking sockets, the OpenSSL library activates its
> own retransmission timers, and the application never becomes aware of
> whether timeouts occurred. Since OpenSSL can't do this in the the case of
> non-blocking sockets, it becomes the application's problem to call back into
> OpenSSL at some point in the future (the very same time for which OpenSSL
> would have set its own timeout had the socket been blocking). OpenSSL
> exports functions DTLSv1_get_timeout and DTLSv1_handle_timeout to
> applications to address this case. The timeouts start at one second, and
> double for each encountered timeout, until the timeout ceiling of one
> minutes is reached. I'm using the term "application" here for any code that
> uses the OpenSSL library, but is not part of it.

Got it.

>>> One
>>> such situation occurs during DTLS's handshaking phase: if no response
>>> is received from the peer after some period of time, we must assume
>>> that our most recent datagram has been lost, and so we need to
>>> retransmit.
>>
>> Is this something the transport can handle, or does the protocol (and
>> hence the application) need to be involved here?
>
> Given my current understanding of the PEP, I think this can be handled in
> the transport. Maybe there's some pitfall here that I can't quite see yet -
> even more reason for me to try to implement it.

Yes -- I won't considered the PEP ready for acceptance until several
people have successfully implemented new protocols using it and agree
that they can do everything they need. (I want to get started with a
decent HTTP client and server myself.)

>>> The event loop interface as outlined in the PEP makes this
>>> a bit difficult (as did the asyncore module). One possible way to make
>>> things easier would be by adding two parameters to add_reader: a
>>> callable to retrieve the current timeout, and a callable that is
>>> invoked if that timeout expires before the descriptor becomes
>>> readable. Each loop iteration would then collect all given timeouts,
>>> and pass the minimum of that set to whatever polling facility it
>>> invokes. If that timeout expires, the corresponding timeout handler
>>> would be invoked prior to the next loop iteration.
>>
>> Hm, this would add a fair amount of complexity to the event loop. It's
>> true that I don't have the complete story for timeouts yet, but I am
>> hopeful that things like this can be implemented by using call_later()
>> with some callback that does the retransmit (and resets some internal
>> state), and cancelling that callback whenever a packet is received
>> (i.e. in the protocol's datagram_received() method).
>
> Yes, ok, I can see how that could work, too. I thought that it might make
> sense to centralize handling timeouts in the event loop in order to prevent
> proliferation in the transports (since there are multiple event loop
> implementations, perhaps a mix-in would be good?).

A mix-in for what? Each event loop presumably already has its own
timer implementation; call_later() and call_repeatedly() are supported
in one way or another by all other event loops I'm aware of.

We'll have to have more experience with writing transports and
protocols before we'll know what is really missing.

> I think one will want to
> contain handshake (vs. application data) timeout handling at least to the
> transport, though, and not let it spill over into various protocols. I'm not
> sure yet where the right place is for cancelling a timeout callback.

This seems pretty unique to your TLS-over-UDP use case. I am quite
sure that you can write a transport that suits your purpose with just
the socket, callback and timer primitives in the PEP.

>>> Implementing DTLS as a tulip transport sounds interesting. Is the
>>> tulip package available somewhere so that I can try it out?
>>
>> Absolutely -- it is very much in flux, but you can check out the
>> latest source from http://code.google.com/p/tulip/source/checkout
>> using Mercurial.
>
> All right, thanks, I'll check it out.

Looking forward to your feedback!

-- 
--Guido van Rossum (python.org/~guido)
-- 
http://mail.python.org/mailman/listinfo/python-list


wiki.python.org

2013-01-09 Thread Reed, Kevin
Hello,

I have been unable to access wiki.python.org for two days.  Is there a problem 
with the server, or is it me?

Thank you much,

Kevin C. Reed
New Python User
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new to python and programming at large

2013-01-09 Thread Ulrich Eckhardt

Am 09.01.2013 22:05, schrieb kwakukwat...@gmail.com:

pls  I want to write a function that can compute for the sqrt root of
any number.bt it not working pls help.


Whenever describing an error, be precise. In this particular case, we 
have some sourcecode (which is good!) but what is still missing is what 
exactly you see when running that code (output and error messages) and 
what you expected instead.




from math import sqrt
def squareroot(self):
 x = sqrt(y)
 print x


In this very case, I also wonder if the tutorial you are learning from 
assumes Python 2 while you are using Python 3. This is important, 
because "print" is a special statement in Python 2 but a normal function 
in Python 3.


That said, I see two errors here:
1. "self": This is customary used when you have a class function that 
takes an instance of that class. This instance is then the first 
parameter and called "self". Python doesn't enforce this, but you should 
adhere to this convention to avoid confusion. Since you are not writing 
a class, don't name this parameter "self".
2. There is no "y" in that code. I guess that if you renamed your "self" 
to "y", you would get what you wanted.


Good luck and welcome to Python!

Uli

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


RE: new to python and programming at large

2013-01-09 Thread Adrian Espinosa Moreno
Hello, you have to use the same parameter, not self which is used in classes

def squareroot(n):
return sqrt(n)


--
Adrián Espinosa.
Engineering Support, Wholesale Systems.
Jazztel.com


De: kwakukwat...@gmail.com [mailto:kwakukwat...@gmail.com]
Enviado el: miércoles, 09 de enero de 2013 22:06
Para: python-list@python.org
Asunto: new to python and programming at large

pls  I want to write a function that can compute for the sqrt root of any 
number.bt it not working pls help.
from math import sqrt
def squareroot(self):
x = sqrt(y)
print x





Este mensaje es privado y CONFIDENCIAL y se dirige exclusivamente a su 
destinatario. Si usted ha recibido este mensaje por error, no debe revelar, 
copiar, distribuir o usarlo en ningún sentido. Le rogamos lo comunique al 
remitente y borre dicho mensaje y cualquier documento adjunto que pudiera 
contener. El correo electrónico via Internet no permite asegurar la 
confidencialidad de los mensajes que se transmiten ni su integridad o correcta 
recepción. JAZZTEL no asume responsabilidad por estas circunstancias. Si el 
destinatario de este mensaje no consintiera la utilización del correo 
electrónico via Internet y la grabación de los mensajes, rogamos lo ponga en 
nuestro conocimiento de forma inmediata.Cualquier opinión expresada en este 
mensaje pertenece únicamente al autor remitente, y no representa necesariamente 
la opinión de JAZZTEL, a no ser que expresamente se diga y el remitente esté 
autorizado para hacerlo.





This message is private and CONFIDENTIAL and it is intended exclusively for its 
addressee. If you receive this message in error, you should not disclose, copy, 
distribute this e-mail or use it in any other way. Please inform the sender and 
delete the message and attachments from your system.Internet e-mail neither 
guarantees the confidentiality nor the integrity or proper receipt of the 
messages sent. JAZZTEL does not assume any liability for those circumstances. 
If the addressee of this message does not consent to the use of Internet e-mail 
and message recording, please notify us immediately.Any views or opinions 
contained in this message are solely those of the author, and do not 
necessarily represent those of JAZZTEL, unless otherwise specifically stated 
and the sender is authorised to do so.



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


Re: wiki.python.org

2013-01-09 Thread Matty Sarro
Wiki.python.org was compromised a few days ago, almost everything was wiped
per a previous email. Not sure what the recovery status is.


On Wed, Jan 9, 2013 at 11:05 AM, Reed, Kevin  wrote:

>  Hello,
>
> ** **
>
> I have been unable to access wiki.python.org for two days.  Is there a
> problem with the server, or is it me?
>
> ** **
>
> Thank you much,
>
> ** **
>
> Kevin C. Reed
>
> New Python User
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wiki.python.org

2013-01-09 Thread Ken
On Wed, Jan 09, 2013 at 04:05:31PM +, Reed, Kevin wrote:
> Hello,
> 
> I have been unable to access wiki.python.org for two days.  Is there a 
> problem with the server, or is it me?
> 
> Thank you much,
> 
> Kevin C. Reed
> New Python User

Well, I just tried it twice and could not get there, so I would say it
is a problem on the server's end.

Ken


-- 
Corruption is not the #1 priority of the Police Commissioner.  His job
is to enforce the law and fight crime.
-- P. B. A. President E. J. Kiernan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wiki.python.org

2013-01-09 Thread Ben Carleton
- Original Message - 

> From: "Kevin Reed" 
> To: python-list@python.org
> Sent: Wednesday, January 9, 2013 11:05:31 AM
> Subject: wiki.python.org

> Hello,

> I have been unable to access wiki.python.org for two days. Is there a problem
> with the server, or is it me?

> Thank you much,

> Kevin C. Reed
> New Python User

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

Hi Kevin,

There was a security issue with the Wiki and it was taken offline while they 
get it resolved. Take a look at this post on the list from earlier this month 
for more info: 
http://mail.python.org/pipermail/python-list/2013-January/638182.html

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


Re: wiki.python.org

2013-01-09 Thread Benjamin Kaplan
On Wed, Jan 9, 2013 at 8:30 AM, Ken  wrote:
> On Wed, Jan 09, 2013 at 04:05:31PM +, Reed, Kevin wrote:
>> Hello,
>>
>> I have been unable to access wiki.python.org for two days.  Is there a 
>> problem with the server, or is it me?
>>
>> Thank you much,
>>
>> Kevin C. Reed
>> New Python User
>
> Well, I just tried it twice and could not get there, so I would say it
> is a problem on the server's end.
>
> Ken
>
>

The server was compromised with a zero-day remote code exploit. It was
taken offline to prevent further damage.

http://mail.python.org/pipermail/python-list/2013-January/638182.html
-- 
http://mail.python.org/mailman/listinfo/python-list


new to python and programming at large.

2013-01-09 Thread kwakukwatiah
thanks for ur help I wz able to do it.but I wish to expand it by asking a user 
to input a number for the sqrt to be calculated it I dd it this way but its not 
working.


from math import sqrt
number = raw_input('enter a number:')
def number(y):
return number(Y)


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


Re: wiki.python.org

2013-01-09 Thread Evan Driscoll
On 01/09/2013 10:05 AM, Reed, Kevin wrote:
> I have been unable to access wiki.python.org for two days.  Is there a
> problem with the server, or is it me?

I can't speak to why, but it appears down for me as well. I also checked
http://www.downforeveryoneorjustme.com/ (which is just about the best
domain name ever) and it says it's down too.

Evan



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Previous Question Answered - Thank You All For Your Replies

2013-01-09 Thread Reed, Kevin
Hello,

My question concerning wiki.python.org unavailability has been answered.  Thank 
you all for your assistance!  You guys are awesome!

For those of you who don't know, here's the info.

http://mail.python.org/pipermail/python-list/2013-January/638182.html

Thanks again,

Kevin

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


Re: Previous Question Answered - Thank You All For Your Replies

2013-01-09 Thread Dave Angel
On 01/09/2013 12:11 PM, Reed, Kevin wrote:
> Hello,
>
> My question concerning wiki.python.org unavailability has been answered.  
> Thank you all for your assistance!  You guys are awesome!
>
> For those of you who don't know, here's the info.
>
> http://mail.python.org/pipermail/python-list/2013-January/638182.html
>
> Thanks again,
>
> Kevin
>
>
>

Please don't start a new thread, nor change the subject line, when
you're posting a followup on an existing thread.  It's like responding
to a letter by putting a note in a bottle and tossing it into the sea.

Just use reply to an existing message in the thread, and make sure
python-list@python.org is in the To or CC field.


-- 

DaveA

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


Re: new to python and programming at large.

2013-01-09 Thread John Gordon
In  kwakukwat...@gmail.com 
writes:

> thanks for ur help I wz able to do it.but I wish to expand it by asking
> a user to input a number for the sqrt to be calculated it I dd it this
> way but its not working.

> from math import sqrt
> number = raw_input('enter a number:')
> def number(y):
> return number(Y)

You're storing the user input in a variable called 'number', but then
you define a method also called 'number'.  Call them something different.

Within your method, you probably want to return sqrt(y) instead of calling
the method from itself.

The argument to your method is called 'y' in the definition, but you refer
to it as 'Y' in the return statement.  Variable names are case-sensitive.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: new to python and programming at large.

2013-01-09 Thread Dave Angel
On 01/09/2013 05:28 PM, kwakukwat...@gmail.com wrote:
> thanks for ur help I wz able to do it.but I wish to expand it by asking a 
> user to input a number for the sqrt to be calculated it I dd it this way but 
> its not working.
>
>
> from math import sqrt
> number = raw_input('enter a number:')
> def number(y):
> return number(Y)
>
>
>
>

Please don't keep posting new messages on the same topic.  When adding
to a thread, use Reply (and make sure python-list is in the to: or cc:
field).

This program has a pile of problems with it.

You've used the name 'number' for three different purposes.  Let me
explain what those lines do.

number = raw_input(...
Capture a string from the user.  Type is str.

def number(y):
 toss out the string the user entered, and bind that name instead to
a function definition that takes a parameter y.

return number(Y)
Attempt to call your own function recursively, but first crash since
Y is undefined.  Y is not the same as y.

Fortunately, you never actually call the function, by any name.

You never used the string you got from the user, but if you had fixed
everything else, you'd have discovered that sqrt() expects either an int
or a float.

Suggestions:
put your imports first
then put your function definitions and classes
only then put your initialization and calls to those functions and
classes.
Make sure you don't use the same name for two different purposes. 
It can frequently be okay, but it's certainly confusing for a beginner.
Watch the case of any names you use.  It matters.

You don't have a spec, but perhaps this is close to what you want
(untested):


from math import sqrt

def squareroot(y):
return sqrt(y)


number = float(raw_input('enter a number:'))
print squareroot(number)

 
-- 

DaveA

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


Re: How to modify this script?

2013-01-09 Thread chaouche yacine
Indeed, the console shows a traceback where data is misinterpreted, maybe due 
to my triple protective quotes around $GEDIT_SELECTED_TEXT. Try without them, 
like so (it worked for me) : 

$<
def addline(line):
    return "%s\n" % line

def addcolumn(item,nb_columns):
    if nb_columns != 3:
    return "%s" % (3 - nb_columns + 1, item)
    return "%s" % item

output = "\n"
selected_text = $GEDIT_SELECTED_TEXT
for line in selected_text.split("\n"):
    items = line.strip().split("\t")
    columns = ""
    for item in items :
    columns += addcolumn(item,len(items))
    output  += addline(columns)

output += ""
return output>




 From: Kurt Hansen 
To: python-list@python.org 
Sent: Wednesday, January 9, 2013 12:04 PM
Subject: Re: How to modify this script?
 
Den 09/01/13 11.23, chaouche yacine skrev:
> I figrued it out. Copy/paste exactly these lines in the snippets tool.
> You can bind it to a key as you may know, I bound it to Ctrl-E. So paste
> it in a new snippet (keep the original in a safe place), bind to a key,
> select the text you want to html-tableize and hit the key binding. In my
> case it worked.
> 
> $<
[cut]
> def addline(line):

Spooky behavior. Yes, the green-apple-example also works for me with your new 
script, BUT ...!

Try to copy the table content on this page:
http://www.danacord.dk/frmsets/records/732-r.html
which is a realistic scenario. That's whar I am doing these days.

Pasting it into Gedit and running the snippet blanks the edit area (on MY Mac 
at least).

And yes: I have pasted your code excatly and I've double-checked for linewraps. 
Everything is okay.

For your cenvenience I have put borders on the table online (see link above). 
You may ommit the rows after track 14. Not that it makes any differerence, but 
that block is surposed to be formatted differerent. I do that manually 
afterwards ... if not ... ;-)
-- Regards
Kurt Hansen
-- http://mail.python.org/mailman/listinfo/python-list-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PyDTLS

2013-01-09 Thread rbit
Neal,

A network protocol that is unreliable (i.e., lacks retransmission of
dropped packets) and lacks congestion control will certainly never be a
common, general purpose protocol, due to the amount of work it imposes on
its user. Implementing an AIMD congestion control algorithm is burdensome
to an application, and only some use cases (like DNS) won't need congestion
control. Use of the Datagram Congestion Control Protocol is a potential way
out for applications, but DCCP (RFC 4340) isn't available on some common
platforms, like Windows.

That being said, if you find yourself in the kind of unique situation that
requires a network protocol with characteristics different from TCP (namely
prioritizing availability of data over its reliability), and you need
network security as well, then RFC 6347 is really the only reasonable game
in town over rolling your own solution.

The following are some of the main use cases that force applications into
datagram protocols:

* Minimizing protocol overhead. TCP has relatively high overhead,
  for example, its 3-way handshake for connection establishment.
  One can see why DNS uses UDP.
* Real-time data streaming. With this use case, it makes no sense
  to hold arrived data from the application, because prior packets are
  being recovered through retransmission. Such packets should just
  be forgotten about, especially if they fall within the margin of the
error
  concealment strategy of the application. Any sort of audio and/or
video
  transmission falls in this category. RTP is usually done over UDP (and
  is an illustrative use case for RFC 6347).
* Anything that operates below the transport layer (layer 4 of the OSI
  model). Say you're writing a VPN at a virtual Ethernet level,
transmitting
  Ethernet frames among machines. In that case, protocols that either
  implement reliability (say, HTTP over TCP) or consciously try to avoid
  it (say, RTP over UDP) sit above you, and you would neither want to
  duplicate their reliability functions, nor introduce this unwanted
  behavior, respectively. But you may want security for your VPN.

I hope this helps.

Ray


On Wed, Jan 9, 2013 at 7:08 AM, Neal Becker  wrote:

> A bit OT, but the widespread use of rfc 6347 could have a big impact on my
> work.
> I wonder if it's likely to see widespread use?  What are likely/possible
> use
> cases?
>
> Thank.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Class confusion

2013-01-09 Thread Rodrick Brown
How can I make a class that has methods with attributes and other
functions?

I see a lot of code


I'm reading the documentation to Redhat's Satellite software which has a
XMLRPC interface and wrote the following code to test the api.

I would like to extend this code to support methods with methods? I see
this done a lot in python code but I'm not sure how to accomplish something
like this?

i.e.

sc = SatelliteConnect()
sc.get_systemlist().get_systemid() ?
or
sc.get_systemlist().get_running_kernel()

How does one chain methods and attributes like this with classes?

import xmlrpclib
import os
import sys

class SatelliteConnect(object):

SATELLITE_URL = "http://nebula.nydc.fxcorp.prv/rpc/api";
SATELLITE_LOGIN = os.environ['USER']
SATELLITE_PASS = os.environ.get('SATELLITE_PASS',None)

def __init__(self):
self.client = xmlrpclib.Server(self.SATELLITE_URL, verbose=0)
self._check_env('SATELLITE_PASS')
self.key = self.client.auth.login(self.SATELLITE_LOGIN,
self.SATELLITE_PASS)

def _check_env(self, env_var):
if not os.environ.get('SATELLITE_PASS'):
print("{} error please set environment varible {} and
re-run script".format(sys.argv[0], env_var))

sys.exit(-1)

def get_runningkernel(self, sysid):
self.get_systemid('somehost')
kernel = self.client.system.getRunningKernel(self.key, sysid)
if kernel:

return kernel
else:
return None


def get_systemlist(self):
systemlist = self.client.system.listSystems(self.key)
return([ system.get('name') for system in systemlist ])

self.client.auth.logout(self.key)

def get_systemid(self, host):
systemlist = self.client.system.getId(self.key, host)
for system in systemlist:
return system.get('id')
-- 
http://mail.python.org/mailman/listinfo/python-list


paralell ftp uploads and pool size

2013-01-09 Thread ben
Hello,

I have a python script that uploads multiple files from the local machine to a 
remote server in parallel via ftp  using p process pool:

p = Pool(processes=x)

Now as I increase the value of x, the overall upload time for all files drops 
as expected. If I set x too high however, then an exception is thrown. The 
exact value at which this happens varies, but is ~20

Traceback (most recent call last):
  File "uploadFTP.py", line 59, in 
FTP_Upload().multiupload()
  File "uploadFTP.py", line 56, in multiupload
p.map(upload_function,files)
  File "/usr/lib64/python2.6/multiprocessing/pool.py", line 148, in map
return self.map_async(func, iterable, chunksize).get()
  File "/usr/lib64/python2.6/multiprocessing/pool.py", line 422, in get
raise self._value
EOFError

Now this is not a problem - 20 is more than enough - but I'm trying to 
understand the mechanisms involved, and why the exact number of processes at 
which this exception occurs seems to vary.

I guess it comes down to the current resources of the server itself...but any 
insight would be much appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: new to python and programming at large.

2013-01-09 Thread kwakukwatiah



-Original Message- 
From: Dave Angel

Sent: Wednesday, January 09, 2013 12:00 PM
To: python-list@python.org
Subject: Re: new to python and programming at large.

On 01/09/2013 05:28 PM, kwakukwat...@gmail.com wrote:
thanks for ur help I wz able to do it.but I wish to expand it by asking a 
user to input a number for the sqrt to be calculated it I dd it this way 
but its not working.



from math import sqrt
number = raw_input('enter a number:')
def number(y):
return number(Y)






Please don't keep posting new messages on the same topic.  When adding
to a thread, use Reply (and make sure python-list is in the to: or cc:
field).

This program has a pile of problems with it.

You've used the name 'number' for three different purposes.  Let me
explain what those lines do.

number = raw_input(...
   Capture a string from the user.  Type is str.

def number(y):
toss out the string the user entered, and bind that name instead to
a function definition that takes a parameter y.

return number(Y)
   Attempt to call your own function recursively, but first crash since
Y is undefined.  Y is not the same as y.

Fortunately, you never actually call the function, by any name.

You never used the string you got from the user, but if you had fixed
everything else, you'd have discovered that sqrt() expects either an int
or a float.

Suggestions:
   put your imports first
   then put your function definitions and classes
   only then put your initialization and calls to those functions and
classes.
   Make sure you don't use the same name for two different purposes.
It can frequently be okay, but it's certainly confusing for a beginner.
   Watch the case of any names you use.  It matters.

You don't have a spec, but perhaps this is close to what you want
(untested):


from math import sqrt

def squareroot(y):
   return sqrt(y)


number = float(raw_input('enter a number:'))
print squareroot(number)


--

DaveA

thanks so much it worked.I have tried and tried.look at what I was doing.
me = raw_input("Enter a value:")
from math import sqrt
def squareroot(y):

   me = squareroot(y)
   return squareroot(y)

thanks I am very greatful.


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


Re: Class confusion

2013-01-09 Thread MRAB

On 2013-01-09 20:13, Rodrick Brown wrote:

How can I make a class that has methods with attributes and other
functions?
I see a lot of code


I'm reading the documentation to Redhat's Satellite software which has a
XMLRPC interface and wrote the following code to test the api.

I would like to extend this code to support methods with methods? I see
this done a lot in python code but I'm not sure how to accomplish
something like this?

i.e.

sc = SatelliteConnect()
sc.get_systemlist().get_systemid() ?
or
sc.get_systemlist().get_running_kernel()

How does one chain methods and attributes like this with classes?


[snip]
This:

sc.get_systemlist().get_systemid()

simply means that the method "get_systemlist" returns an instance of
some class (let's call it "SystemList") which has a method
"get_systemid".

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


Re: Class confusion

2013-01-09 Thread Matt Jones
# Something like...

class SystemList(object):
   def get_systemid(self):
  return "System Id: bleh"

   def get_running_kernel(self):
  return "Kernel: bleh"


class SatelliteConnect(object):
   def get_systemlist(self):
  return SystemList()


# Now the code you wrote would work, only return those literals thought,
you'd want to do something meaningful inside of SystemList's methods.

*Matt Jones*


On Wed, Jan 9, 2013 at 3:28 PM, MRAB  wrote:

> On 2013-01-09 20:13, Rodrick Brown wrote:
>
>> How can I make a class that has methods with attributes and other
>> functions?
>> I see a lot of code
>>
>>
>> I'm reading the documentation to Redhat's Satellite software which has a
>> XMLRPC interface and wrote the following code to test the api.
>>
>> I would like to extend this code to support methods with methods? I see
>> this done a lot in python code but I'm not sure how to accomplish
>> something like this?
>>
>> i.e.
>>
>> sc = SatelliteConnect()
>> sc.get_systemlist().get_**systemid() ?
>> or
>> sc.get_systemlist().get_**running_kernel()
>>
>> How does one chain methods and attributes like this with classes?
>>
>>  [snip]
> This:
>
> sc.get_systemlist().get_**systemid()
>
> simply means that the method "get_systemlist" returns an instance of
> some class (let's call it "SystemList") which has a method
> "get_systemid".
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: PyDTLS

2013-01-09 Thread Chris Angelico
On Thu, Jan 10, 2013 at 7:04 AM, rbit  wrote:
> The following are some of the main use cases that force applications into
> datagram protocols:
>
> * Minimizing protocol overhead. TCP has relatively high overhead,
>   for example, its 3-way handshake for connection establishment.
>   One can see why DNS uses UDP.

Yep. Related to that: One of our systems at work uses UDP rather than
TCP in order to simplify the detection of node loss. Rather than
working with TCP retry etc and handling the variety of different ways
in which "the other node is down" could be reported, the nodes simply
send UDP packets to each other, and keep track of the timestamp when
one was last received. There's only one failure state: silence. Not
sure if high-level protocol simplicity counts as the same thing or
not; it's a different form of overhead.

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


Re: Class confusion

2013-01-09 Thread Rodrick Brown
On Wed, Jan 9, 2013 at 4:34 PM, Matt Jones wrote:

> # Something like...
>
> class SystemList(object):
>def get_systemid(self):
>   return "System Id: bleh"
>
>def get_running_kernel(self):
>   return "Kernel: bleh"
>
>
> class SatelliteConnect(object):
>def get_systemlist(self):
>   return SystemList()
>
>
> # Now the code you wrote would work, only return those literals thought,
> you'd want to do something meaningful inside of SystemList's methods.
>
>
Thanks for the tip Matt, I had no idea it was so simple. :-)


> *Matt Jones*
>
>
> On Wed, Jan 9, 2013 at 3:28 PM, MRAB  wrote:
>
>> On 2013-01-09 20:13, Rodrick Brown wrote:
>>
>>> How can I make a class that has methods with attributes and other
>>> functions?
>>> I see a lot of code
>>>
>>>
>>> I'm reading the documentation to Redhat's Satellite software which has a
>>> XMLRPC interface and wrote the following code to test the api.
>>>
>>> I would like to extend this code to support methods with methods? I see
>>> this done a lot in python code but I'm not sure how to accomplish
>>> something like this?
>>>
>>> i.e.
>>>
>>> sc = SatelliteConnect()
>>> sc.get_systemlist().get_**systemid() ?
>>> or
>>> sc.get_systemlist().get_**running_kernel()
>>>
>>> How does one chain methods and attributes like this with classes?
>>>
>>>  [snip]
>> This:
>>
>> sc.get_systemlist().get_**systemid()
>>
>> simply means that the method "get_systemlist" returns an instance of
>> some class (let's call it "SystemList") which has a method
>> "get_systemid".
>>
>> --
>> http://mail.python.org/**mailman/listinfo/python-list
>>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Why BOM in logging message?

2013-01-09 Thread Roy Smith
We've got 10 (supposedly) identical servers, all running Ubuntu 12.04,
Python 2.7, Django 1.3.  We log to syslog using the logging module and
a custom fomatter.

'formatters': {
'verbose': {
'format': '%(asctime)s [%(process)d]: %(program)s 
%(session_id)s %(request_id)s %(request_id_digest)s %(remote_addr)s %(name)s 
%(level\
name)s %(funcName)s() %(message)s',
'()': 'songza.logging.ContextFormatter',
},
},

There's nothing particularly exciting in the formatter code:

class ContextFormatter(logging.Formatter):
def format(self, record):
record.program = context.get_program()
record.request_id = context.get_request_id()
record.request_id_digest = context.get_request_id_digest()
record.session_id = context.get_session_id() or '-'
record.remote_addr = context.get_remote_addr() or '-'
return logging.Formatter.format(self, record)

What's weird is that two of the servers, and only those two, stick a
BOM (Byte Order Mark) in front of the message they log.  It shows up
in syslog as:

2013-01-09T00:00:00+00:00 web5.songza.com 2013-01-0900:00:00,754 
[18979]: [etc...]

The other machines, never put the BOM in.  Given that all 10 machines
are ostensibly clones of each other, we're scratching our heads what
might be different about those two which cause the BOMs to appear.
Any ideas?

I suppose it's possible it's a syslog config problem and not a Python
problem, but I figured I'd start at the beginning of the chain.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interpolating/crossfading a stack of matrices

2013-01-09 Thread Oscar Benjamin
On 9 January 2013 16:02,   wrote:
> Hi,
>
> I want to interpolate (with quadratic splines) a stack of 2D-arrays/matrices 
> y1, y2, y3, ... in a third dimension (which I call x) e.g. for crossfading 
> images. I already have a working code which unfortunately still contains two 
> explicit loops over the rows and colums of the matrices. Inside these loops I 
> simply use 'interp1d' from scipy suitable for 1D-interpolations. Is anybody 
> here aware of a better, more efficient solution of my problem? Maybe 
> somewhere out there a compiled routine for my problem already exists in a 
> python library... :-)

It's possible. I wouldn't be surprised if there wasn't any existing
code ready for you to use.

>
> My code:
>
> --
> from scipy.interpolate import interp1d
> from numpy import array, empty_like, dstack
>
> x = [0.0, 0.25, 0.5, 0.75, 1.0]
>
> y1 = array([[1, 10, 100, 1000], [1,  10,   100,  1000]], float)
> y2 = array([[2, 20, 200, 2000], [2,  20,   200,  2000]], float)
> y3 = array([[3, 30, 300, 3000], [4,  40,   400,  4000]], float)
> y4 = array([[4, 40, 400, 4000], [8,  80,   800,  8000]], float)
> y5 = array([[5, 50, 500, 5000], [16, 160, 1600, 16000]], float)
>
> y = dstack((y1, y2, y3, y4, y5))
>
> y_interpol = empty_like(y[:, :, 0])
> i_range, j_range = y.shape[:2]
>
> for i in xrange(i_range):
> for j in xrange(j_range):
> # interpolated value for x = 0.2
> y_interpol[i,j] = interp1d(x, y[i, j,:], kind='quadratic')(0.2)
>
> print y_interpol
> --

Since numpy arrays make it so easy to form linear combinations of
arrays without loops I would probably eliminate the loops and just
form the appropriate combinations of the image arrays. For example, to
use linear interpolation you could do:

def interp_frames_linear(times, frames, t):
'''times is a vector of floats
frames is a 3D array whose nth page is the image for time t[n]
t is the time to interpolate for
'''
# Find the two frames to interpolate between
# Probably a better way of doing this
for n in range(len(t)-1):
if times[n] <= t < times[n+1]:
break
else:
raise OutOfBoundsError

# Interpolate between the two images
alpha = (t - times[n]) / (times[n+1] - times[n])
return (1 - alpha) * frames[:, :, n] + alpha * frames[:, :, n+1]

I'm not really sure how quadratic interpolation is supposed to work
(I've only ever used linear and cubic) but you should be able to do
the same sort of thing.


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


Re: Why BOM in logging message?

2013-01-09 Thread Chris Angelico
On Thu, Jan 10, 2013 at 9:54 AM, Roy Smith  wrote:
> What's weird is that two of the servers, and only those two, stick a
> BOM (Byte Order Mark) in front of the message they log.

Could it be this issue you're looking at?

http://bugs.python.org/issue14452

What are the exact Python versions in use? Are the two different
servers running an older revision of Py 2.7?

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


Re: Why BOM in logging message?

2013-01-09 Thread John Gordon
In  r...@panix.com (Roy Smith) writes:

> What's weird is that two of the servers, and only those two, stick a
> BOM (Byte Order Mark) in front of the message they log.  It shows up
> in syslog as:

> 2013-01-09T00:00:00+00:00 web5.songza.com 2013-01-0900:00:00,754 
> [18979]: [etc...]

I worked on an application that would insert a BOM in syslog messages if
the logged message contained unicode, but not if it was plain ascii.

Not sure if this relates to your issue, but it's similar enough that it
seemed worth mentioning.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Best way to do this? List loop (matrix?) iteration

2013-01-09 Thread andydtaylor
Thanks for your help - this is what I did - though it's probably obvious to 
most people reading this.

   for rowcount in range (0, stn_count):
  row_durations.append(stn_list_short[rowcount])
  for colcount in range (0, stn_count): 
 # 3. Determine Station pairs for API query
 query_origin_stop = stn_list_long[rowcount]
 query_destination_stop = stn_list_long[colcount]
 # 4. Paths for determining duration. "station x = station x" has 
journey time 0
 # 4a. Stations are SAME


etc. and this part works! I am now stuck on something else though, but I'll 
start a new topic for that.

Thanks

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


Re: socket.makefile raises ValueError when mode = 'rt'

2013-01-09 Thread Terry Reedy

On 1/9/2013 9:14 AM, Antoon Pardon wrote:

Op 01/09/13 14:54, Dave Angel schreef:

On 01/09/2013 08:22 AM, Antoon Pardon wrote:

This is using python 3.2.

...

But the documentation states:
socket.makefile(mode='r', buffering=None, *, encoding=None, errors=None,
newline=None)
 Return a file object associated with the socket. The exact returned
type depends on the arguments given to makefile(). These arguments are
interpreted the same way as by the built-in open() function.

And since 't' is allowed in the mode of the built-in open() function I
would consider this a bug.
Unless I am missing something?

I believe that 't' was a new addition to mode, for Python 3.x So
perhaps the socket library hasn't kept consistent with it.

I don't really know the socket library.  Does it even support text
mode?  Does that make sense?  Remember that text mode means a different
thing in 3.x than it did in 2.x

As far as I understand the code, it does support text. This is part of
the makefile method.

def makefile(self, mode="r", buffering=None, *,
  encoding=None, errors=None, newline=None):

 for c in mode:
 if c not in {"r", "w", "b"}:
 raise ValueError("invalid mode %r (only r, w, b allowed)")
 writing = "w" in mode
 reading = "r" in mode or not writing
 assert reading or writing
 binary = "b" in mode
 ...
 if binary:
 return buffer
 text = io.TextIOWrapper(buffer, encoding, errors, newline)
 text.mode = mode
 return text

So it seems that if the mode is not binary an io.TextIOWrapper is
returned. That indicates to me that
text mode is supported.


The doc does not specify any limit on mode, though the exclusions 'a', 
'+', 'x', and 'U' seem proper to me. That contradicts the mode check. 
The exclusion of of 't' (which is the default, in that 'b' must be 
explicitly given to have effect) contradicts the later code. I think you 
should open an issue on the tracker suggesting that 't' be added to the 
mode check and that the doc mention the remaining mode limitation.


In the meanwhile, your ftpfile.__init__ could remove t from the mode 
before passing it on.



--
Terry Jan Reedy

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


pylint or similar to test version-specific language constructs?

2013-01-09 Thread jkn
Hi all
I have to write python code which must run on an old version of
python (v2.4) as well as a newer (v2.7). I am using pylint and would
like to check if is possible to check with pylint the use of operators
etc. which are not present in 2.4; the ternary operator springs to
mind.

I haven't found anything in pylint which indicates it can do this sort
of check; am I missing anything? Other suggestions for this kind of
checking welcome.

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


Re: Best way to do this? List loop (matrix?) iteration

2013-01-09 Thread Dave Angel
On 01/09/2013 06:24 PM, andydtay...@gmail.com wrote:
> Thanks for your help - this is what I did - though it's probably obvious to 
> most people reading this.
>
>for rowcount in range (0, stn_count):
>   row_durations.append(stn_list_short[rowcount])
>   for colcount in range (0, stn_count): 
># 3. Determine Station pairs for API query
>  query_origin_stop = stn_list_long[rowcount]
>  query_destination_stop = stn_list_long[colcount]
>  # 4. Paths for determining duration. "station x = station x" has 
> journey time 0
>  # 4a. Stations are SAME
>
Please reread Chris Angelico's message.  Iterating over the lists
themselves, instead of making a range, is shorter, easier to read, and
usually quicker.

> etc. and this part works! I am now stuck on something else though, but 
> I'll start a new topic for that.
>
> Thanks
>
> Andy
Untested:

for rowshort, query_origin_stop in zip(stn_list_short, stn_list_long):
row_durations.append(rowshort)
for query_destination_stop in stn_list_long:
#4 . Determine ...   

-- 

DaveA

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


Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread andydtaylor
Hi,

I'm a bit stuck on this "INSERT INTO" syntax error. I have no idea why it's not 
working actually... I've tried changing column types to char but that didn't 
work. I've gone a bit blind looking at it, but hopefully you can set me right. 
With the '#'d out lines instead the file does work.

What am I missing?

Thanks


Andy


#!/usr/bin/python
import psycopg2
import sys

def main():
   db = psycopg2.connect(
  host = 'localhost',
  database = 'gisdb',
  user = 'postgres',
  password = '##'
   )
   cursor = db.cursor()
   cursor.execute("DROP TABLE IF EXISTS tubecross")
   cursor_to.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, 
station_code char, SAJ interval, SPB interval, SOQ interval);")
   #cursor.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, num integer, 
data varchar);") 
   #cursor.execute("INSERT INTO tubecross (num, data) VALUES (%s, %s)",(900, 
"9abc'def"))
   cursor_to.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) 
VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27))
   db.commit()

if __name__ == "__main__":
main()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to implement mouse gesture by python or pyqt ?

2013-01-09 Thread Michael Torrie
On 01/08/2013 07:57 PM, iMath wrote:
> 在 2013年1月8日星期二UTC+8上午8时44分20秒,iMath写道:
>> It would be better to give me some examples .thanks in advance !
>> 
>> 
>> 
>> P.S. which module or lib are needed ?
> 
> what I wanna perhaps like this: when a right mouse button is pressed
> and we go down and right with a cursor. As in letter 'L'. Our mouse
> gesture will close the window. I googled such gesture examples on
> PyQt4 ,but hard to find one ,so your help will be greatly appreciated
> ! thanks inadvance !

My guess is that if you google for it you'll find a gesture recognition
module for python.  moosegesture.py is one such implementation.  However
it is up to you to tie it into your chosen GUI toolkit.  It merely
processes tuples of points in the gesture.  Each GUI toolkit has mailing
lists and forums that would help you know that information, which is not
really python-specific.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pylint or similar to test version-specific language constructs?

2013-01-09 Thread Gisle Vanem

"jkn"  wrote:


   I have to write python code which must run on an old version of
python (v2.4) as well as a newer (v2.7). I am using pylint and would
like to check if is possible to check with pylint the use of operators
etc. which are not present in 2.4; the ternary operator springs to
mind.


No idea about PyLint. Why not install Python 2.4 and test
with that? Sounds safer IMHO.

-gv

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


Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread John Gordon
In  
andydtay...@gmail.com writes:

> I'm a bit stuck on this "INSERT INTO" syntax error. I have no idea why it's

What syntax error?  It's always helpful if you can post the actual error
message.

> not working actually... I've tried changing column types to char but that
> didn't work. I've gone a bit blind looking at it, but hopefully you can set
> me right. With the '#'d out lines instead the file does work.

> #!/usr/bin/python
> import psycopg2
> import sys

> def main():
>db = psycopg2.connect(
>   host = 'localhost',
>   database = 'gisdb',
>   user = 'postgres',
>   password = '##'
>)
>cursor = db.cursor()
>cursor.execute("DROP TABLE IF EXISTS tubecross")
>cursor_to.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, 
> station_code char, SAJ interval, SPB interval, SOQ interval);")
>#cursor.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, num 
> integer, data varchar);")
>#cursor.execute("INSERT INTO tubecross (num, data) VALUES (%s, %s)",(900, 
> "9abc'def"))
>cursor_to.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) 
> VALUES (%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27))
>db.commit()

> if __name__ == "__main__":
>   main()

You appear to have two very different versions of the tubecross table.
One version has three fields (id, num, data) and the other version has at
least four (station_code, SAJ, SPB, SOQ).  Which one is correct?

Also, what is the 'cursor_to' variable?  It doesn't appear to be defined
anywhere.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread andydtaylor
Hi John,

He're the code I would like to see work. The cursor_to is an oversight. I 
extracted this element from some other code in an attempt to isolate/resolve 
the problem myself, hence having a simplified table version. Which works 
actually, but unfortunately that's not educating me suffieciently. Actual error 
message I see follows.

- - - - - - - - - - - - - - - - - - - - - - - - - 
Code:

#!/usr/bin/python
import psycopg2
import sys

def main():
   db = psycopg2.connect(
  host = 'localhost',
  database = 'gisdb',
  user = 'postgres',
  password = '##' 
   )
   cursor = db.cursor()
   cursor.execute("DROP TABLE IF EXISTS tubecross")
   cursor.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, station_code 
char, SAJ interval, SPB interval, SOQ interval);")
   cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES 
(%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27))
   db.commit()

if __name__ == "__main__":
main()

- - - - - - - - - - - - - - - - - - - - - - - - - 
Error Message:

andyt@andyt-ThinkPad-X61:~/projects/django-stringer/Other/TFLJPAPI$ python 
creat_db_exp.py
  File "creat_db_exp.py", line 15
cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES 
(%s, %s, %s, %s)",(SAJ, 00:00, 00:22, 00:27))

 ^
SyntaxError: invalid syntax


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


Getting audio input and processing it?

2013-01-09 Thread Michael Curry
I've been working on a Morse Code translator, I've made it work so that you can 
input English and it will translate it to Morse and play the Audio. I now want 
to add a feature to the program that takes audio input, processes it and then 
outputs the English.

Are there any specific APIs that I can use to take input from a microphone, is 
there any way to detect frequencies or amplitudes, as well as find out for how 
long the wave lasts? If not, are there any implementations of this? Would there 
be a way to do it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class confusion

2013-01-09 Thread Rodrick Brown
Can anyone care to advise on the following? Based on the responses does
this look sufficient?

#!/opt/local/bin/python

class SystemList(object):
sysmap = { '1039' : 'nebula',
   '1040' : 'mercury'}

def __init__(self, sysid):
self.sysid = sysid

def get_sysname(self):
return self.sysmap[self.sysid]

class System(object):
def __init__(self):
pass

def get_hostname(self,sysid):
return  SystemList(sysid)

if __name__ == '__main__':
sc = System()

for sysid in ('1039','1040'):
print(sc.get_hostname(sysid).get_sysname())



On Wed, Jan 9, 2013 at 5:18 PM, Rodrick Brown wrote:

> On Wed, Jan 9, 2013 at 4:34 PM, Matt Jones wrote:
>
>> # Something like...
>>
>> class SystemList(object):
>>def get_systemid(self):
>>   return "System Id: bleh"
>>
>>def get_running_kernel(self):
>>   return "Kernel: bleh"
>>
>>
>> class SatelliteConnect(object):
>>def get_systemlist(self):
>>   return SystemList()
>>
>>
>> # Now the code you wrote would work, only return those literals thought,
>> you'd want to do something meaningful inside of SystemList's methods.
>>
>>
> Thanks for the tip Matt, I had no idea it was so simple. :-)
>
>
>>  *Matt Jones*
>>
>>
>> On Wed, Jan 9, 2013 at 3:28 PM, MRAB  wrote:
>>
>>> On 2013-01-09 20:13, Rodrick Brown wrote:
>>>
 How can I make a class that has methods with attributes and other
 functions?
 I see a lot of code


 I'm reading the documentation to Redhat's Satellite software which has a
 XMLRPC interface and wrote the following code to test the api.

 I would like to extend this code to support methods with methods? I see
 this done a lot in python code but I'm not sure how to accomplish
 something like this?

 i.e.

 sc = SatelliteConnect()
 sc.get_systemlist().get_**systemid() ?
 or
 sc.get_systemlist().get_**running_kernel()

 How does one chain methods and attributes like this with classes?

  [snip]
>>> This:
>>>
>>> sc.get_systemlist().get_**systemid()
>>>
>>> simply means that the method "get_systemlist" returns an instance of
>>> some class (let's call it "SystemList") which has a method
>>> "get_systemid".
>>>
>>> --
>>> http://mail.python.org/**mailman/listinfo/python-list
>>>
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread Mitya Sirenef

On Wed 09 Jan 2013 07:19:10 PM EST, andydtay...@gmail.com wrote:

Hi John,

He're the code I would like to see work. The cursor_to is an oversight. I 
extracted this element from some other code in an attempt to isolate/resolve 
the problem myself, hence having a simplified table version. Which works 
actually, but unfortunately that's not educating me suffieciently. Actual error 
message I see follows.

- - - - - - - - - - - - - - - - - - - - - - - - -
Code:

#!/usr/bin/python
import psycopg2
import sys

def main():
db = psycopg2.connect(
   host = 'localhost',
   database = 'gisdb',
   user = 'postgres',
   password = '##'
)
cursor = db.cursor()
cursor.execute("DROP TABLE IF EXISTS tubecross")
cursor.execute("CREATE TABLE tubecross (id serial PRIMARY KEY, station_code 
char, SAJ interval, SPB interval, SOQ interval);")
cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, 
%s, %s, %s)",(SAJ, 00:00, 00:22, 00:27))
db.commit()

if __name__ == "__main__":
main()

- - - - - - - - - - - - - - - - - - - - - - - - -
Error Message:

andyt@andyt-ThinkPad-X61:~/projects/django-stringer/Other/TFLJPAPI$ python 
creat_db_exp.py
   File "creat_db_exp.py", line 15
 cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, 
%s, %s, %s)",(SAJ, 00:00, 00:22, 00:27))

  ^
SyntaxError: invalid syntax


Thanks for your help



00:00 etc are not quoted?

- mitya



--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread MRAB

On 2013-01-10 00:19, andydtay...@gmail.com wrote:

Hi John,

He're the code I would like to see work. The cursor_to is an oversight. I 
extracted this element from some other code in an attempt to isolate/resolve 
the problem myself, hence having a simplified table version. Which works 
actually, but unfortunately that's not educating me suffieciently. Actual error 
message I see follows.


[snip]


- - - - - - - - - - - - - - - - - - - - - - - - -
Error Message:

andyt@andyt-ThinkPad-X61:~/projects/django-stringer/Other/TFLJPAPI$ python 
creat_db_exp.py
   File "creat_db_exp.py", line 15
 cursor.execute("INSERT INTO tubecross (station_code, SAJ, SPB, SOQ) VALUES (%s, 
%s, %s, %s)",(SAJ, 00:00, 00:22, 00:27))

  ^
SyntaxError: invalid syntax


"00:00", etc, aren't valid Python, they're two ints with a colon
between them.

You need to determine what Python class to use to represent those.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why BOM in logging message?

2013-01-09 Thread Roy Smith
In article ,
 John Gordon  wrote:

> In  r...@panix.com (Roy Smith) writes:
> 
> > What's weird is that two of the servers, and only those two, stick a
> > BOM (Byte Order Mark) in front of the message they log.  It shows up
> > in syslog as:
> 
> > 2013-01-09T00:00:00+00:00 web5.songza.com 2013-01-0900:00:00,754 
> > [18979]: [etc...]
> 
> I worked on an application that would insert a BOM in syslog messages if
> the logged message contained unicode, but not if it was plain ascii.
> 
> Not sure if this relates to your issue, but it's similar enough that it
> seemed worth mentioning.

That doesn't seem to be it.  All messages from web{2,5} have BOMs, no 
message from web{1,3,4,6,7,8,9,10} ever does.

I even tried looking at the output of socket.gethostname() on the 
various machines to see if maybe the hostname had some unicode character 
in it.  No joy.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why BOM in logging message?

2013-01-09 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Thu, Jan 10, 2013 at 9:54 AM, Roy Smith  wrote:
> > What's weird is that two of the servers, and only those two, stick a
> > BOM (Byte Order Mark) in front of the message they log.
> 
> Could it be this issue you're looking at?
> 
> http://bugs.python.org/issue14452
> 
> What are the exact Python versions in use? Are the two different
> servers running an older revision of Py 2.7?
> 
> ChrisA

It sounds like it might be it, but we're running 2.7.3 on all machines.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the selected text of the webpage in chrome through python ?

2013-01-09 Thread iMath
在 2013年1月9日星期三UTC+8下午5时35分15秒,Alister写道:
> On Mon, 07 Jan 2013 20:20:28 -0800, iMath wrote:
> 
> 
> 
> > How to get the selected text of the webpage in chrome through python ?
> 
> 
> 
> i think you need to explain your  requirement further
> 
> also what do you want to do to the text once you have it?
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Genius is one percent inspiration and ninety-nine percent perspiration.
> 
>   -- Thomas Alva Edison

I want to google it with a mouse gesture
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to download internet files by python ?

2013-01-09 Thread iMath
在 2013年1月8日星期二UTC+8下午1时04分54秒,Roy Smith写道:
> In article ,
> 
>  Cameron Simpson  wrote:
> 
> 
> 
> > On 07Jan2013 20:19, iMath  wrote:
> 
> > | for example ,if I want to download this file ,how to implement the 
> > download 
> 
> > | functionality by python ?
> 
> > | 
> 
> > | http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3
> 
> > | 
> 
> > | as for  download speed ,of course ,the fast ,the better ,so how to 
> 
> > | implement it ?
> 
> > | It would be better to show me an example :) thanks !!!
> 
> > 
> 
> > Look at urllib2.
> 
> 
> 
> Even better, look at requests 
> 
> (http://docs.python-requests.org/en/latest/).  There's nothing you can 
> 
> do with requests that you can't do with urllib2, but the interface is a 
> 
> whole lot easier to work with.

There is also a httplib2 module 
https://code.google.com/p/httplib2/

which one is more pythonic and powerful ?
-- 
http://mail.python.org/mailman/listinfo/python-list


How to call wget by python ?

2013-01-09 Thread iMath
can you  give me an example code ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread andydtaylor
Thanks for your help guys. 

I was actually doing a few things wrong, but I have got this script to work by 
declaring fields as varchar and all values as strings. But I would like to log 
journey time values in hours/minutes, so I will have to look into the following:

1. Retrieving this data from postgres as text, converting it and using it. I 
will need to add/subtract on this time value; or
2. Recognising it as a time class in the first instance by using the string 
parsing function.

Regards,

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


Re: How to call wget by python ?

2013-01-09 Thread Chris Angelico
On Thu, Jan 10, 2013 at 1:11 PM, iMath  wrote:
> can you  give me an example code ?
> --
> http://mail.python.org/mailman/listinfo/python-list

You've asked several very vague questions. I would strongly recommend
that you read this:

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

Invoking wget can be done, but you may want to consider alternatives
such as doing the network request (HTTP, FTP, or whatever) directly in
Python. A one-line request that we do heaps of work for you is not the
best way to get results.

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


Re: How to implement mouse gesture by python or pyqt ?

2013-01-09 Thread iMath
在 2013年1月10日星期四UTC+8上午8时06分13秒,Michael Torrie写道:
> On 01/08/2013 07:57 PM, iMath wrote:
> 
> > 在 2013年1月8日星期二UTC+8上午8时44分20秒,iMath写道:
> 
> >> It would be better to give me some examples .thanks in advance !
> 
> >> 
> 
> >> 
> 
> >> 
> 
> >> P.S. which module or lib are needed ?
> 
> > 
> 
> > what I wanna perhaps like this: when a right mouse button is pressed
> 
> > and we go down and right with a cursor. As in letter 'L'. Our mouse
> 
> > gesture will close the window. I googled such gesture examples on
> 
> > PyQt4 ,but hard to find one ,so your help will be greatly appreciated
> 
> > ! thanks inadvance !
> 
> 
> 
> My guess is that if you google for it you'll find a gesture recognition
> 
> module for python.  moosegesture.py is one such implementation.  However
> 
> it is up to you to tie it into your chosen GUI toolkit.  It merely
> 
> processes tuples of points in the gesture.  Each GUI toolkit has mailing
> 
> lists and forums that would help you know that information, which is not
> 
> really python-specific.

oh yes ,I find it  moosegesture.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Psycopg2 SyntaxError: invalid syntax on "INSERT INTO" database

2013-01-09 Thread Mitya Sirenef

On Wed 09 Jan 2013 09:20:10 PM EST, andydtay...@gmail.com wrote:

Thanks for your help guys.

I was actually doing a few things wrong, but I have got this script to work by 
declaring fields as varchar and all values as strings. But I would like to log 
journey time values in hours/minutes, so I will have to look into the following:

1. Retrieving this data from postgres as text, converting it and using it. I 
will need to add/subtract on this time value; or
2. Recognising it as a time class in the first instance by using the string 
parsing function.

Regards,

Andy



Why not store as an int, in minutes, and then parse into h:m
when displaying?

- m



--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
--
http://mail.python.org/mailman/listinfo/python-list


Re: new to python and programming at large.

2013-01-09 Thread Michael Torrie
On 01/09/2013 07:45 PM, kwakukwat...@gmail.com wrote:
> thanks so much it worked.I have tried and tried.look at what I was doing.
> me = raw_input("Enter a value:")
> from math import sqrt
> def squareroot(y):
> 
> me = squareroot(y)
> return squareroot(y)

Congratulations!  You've just created a recursive function!  If you call
your function, squareroot() with any value at all, the program will go
into an infinite loop and never output or return anything.

While recursive functions are useful, in your case I don't think that's
what you were aiming for.  What you need to do is drop the "me =" line,
which does nothing here except put it in a loop, and modify the "return"
line to return something useful (such as a calculation, perhaps created
by calling the appropriate function in the python math library) instead
of trying to return the result of calling your own function, which will
put it into a loop.

Step through the code in your head.  Consider what happens when someone
calls your squareroot function, with, say 5 as the input.  The first
line of the function runs, and then tries to run your function again
with 5 as the input, which then tries to run your function again with 5
as the input which then tries to run your function again with 5 as the
input, etc.  Recursion is very abstract at first, but i hope you
understand why this is happening.

For more information on how to define functions in general, see
http://docs.python.org/release/2.7/tutorial/controlflow.html#defining-functions

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


Re: How to call wget by python ?

2013-01-09 Thread Michael Torrie
On 01/09/2013 07:11 PM, iMath wrote:
> can you  give me an example code ?

No but I can suggest some alternative ideas, such as using httplib
(built into python), or libcurl.  Or if you have to use wget, you run it
the same way you run any external command from python.  If it were my
I'd plunk a few search terms in google, such as "python run external
process."

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


Re: Class confusion

2013-01-09 Thread Matt Jones
Does this look sufficient for what?  You haven't actually told us what it
is you're trying to accomplish.  I gave you the "how", you must supply the
"why".

*Matt Jones*


On Wed, Jan 9, 2013 at 6:43 PM, Rodrick Brown wrote:

> Can anyone care to advise on the following? Based on the responses does
> this look sufficient?
>
> #!/opt/local/bin/python
>
> class SystemList(object):
> sysmap = { '1039' : 'nebula',
>'1040' : 'mercury'}
>
> def __init__(self, sysid):
> self.sysid = sysid
>
> def get_sysname(self):
> return self.sysmap[self.sysid]
>
> class System(object):
> def __init__(self):
> pass
>
> def get_hostname(self,sysid):
> return  SystemList(sysid)
>
> if __name__ == '__main__':
> sc = System()
>
> for sysid in ('1039','1040'):
> print(sc.get_hostname(sysid).get_sysname())
>
>
>
> On Wed, Jan 9, 2013 at 5:18 PM, Rodrick Brown wrote:
>
>> On Wed, Jan 9, 2013 at 4:34 PM, Matt Jones 
>> wrote:
>>
>>> # Something like...
>>>
>>> class SystemList(object):
>>>def get_systemid(self):
>>>   return "System Id: bleh"
>>>
>>>def get_running_kernel(self):
>>>   return "Kernel: bleh"
>>>
>>>
>>> class SatelliteConnect(object):
>>>def get_systemlist(self):
>>>   return SystemList()
>>>
>>>
>>> # Now the code you wrote would work, only return those literals thought,
>>> you'd want to do something meaningful inside of SystemList's methods.
>>>
>>>
>> Thanks for the tip Matt, I had no idea it was so simple. :-)
>>
>>
>>>  *Matt Jones*
>>>
>>>
>>> On Wed, Jan 9, 2013 at 3:28 PM, MRAB  wrote:
>>>
 On 2013-01-09 20:13, Rodrick Brown wrote:

> How can I make a class that has methods with attributes and other
> functions?
> I see a lot of code
>
>
> I'm reading the documentation to Redhat's Satellite software which has
> a
> XMLRPC interface and wrote the following code to test the api.
>
> I would like to extend this code to support methods with methods? I see
> this done a lot in python code but I'm not sure how to accomplish
> something like this?
>
> i.e.
>
> sc = SatelliteConnect()
> sc.get_systemlist().get_**systemid() ?
> or
> sc.get_systemlist().get_**running_kernel()
>
> How does one chain methods and attributes like this with classes?
>
>  [snip]
 This:

 sc.get_systemlist().get_**systemid()

 simply means that the method "get_systemlist" returns an instance of
 some class (let's call it "SystemList") which has a method
 "get_systemid".

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

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


Re: How to call wget by python ?

2013-01-09 Thread 88888 Dihedral
Michael Torrie於 2013年1月10日星期四UTC+8上午11時04分31秒寫道:
> On 01/09/2013 07:11 PM, iMath wrote:
> 
> > can you  give me an example code ?
> 
> 
> 
> No but I can suggest some alternative ideas, such as using httplib
> 
> (built into python), or libcurl.  Or if you have to use wget, you run it
> 
> the same way you run any external command from python.  If it were my
> 
> I'd plunk a few search terms in google, such as "python run external
> 
> process."

Inherantly the python interpreter has a GC builtin 
to use pacakages like DLL by reference counting.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to call wget by python ?

2013-01-09 Thread Chris Angelico
On Thu, Jan 10, 2013 at 2:21 PM, 8 Dihedral
 wrote:
> Inherantly the python interpreter has a GC builtin
> to use pacakages like DLL by reference counting.

That almost makes sense. And it's almost profound, too.

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


Re: How to call wget by python ?

2013-01-09 Thread Steven D'Aprano
On Wed, 09 Jan 2013 18:11:34 -0800, iMath wrote:

> can you  give me an example code ?

Is the web broken where you are? If you google for "python wget", you 
will find example of how to call wget as an external process, as well as 
examples of downloading files from the web like wget would do but using 
only Python.

https://duckduckgo.com/?q=python%20wget


Or you could search for "python call external command" and then use wget 
as that external command.

https://duckduckgo.com/?q=python%20call%20external%20command



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


Re: how to download internet files by python ?

2013-01-09 Thread Tim Roberts
iMath  wrote:
>
>There is also a httplib2 module 
>https://code.google.com/p/httplib2/
>
>which one is more pythonic and powerful ?

Both are Pythonic, and power is irrelevant for this.  Your code is going to
spend 90% of its time waiting for the network.  Just solve the problem.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to call wget by python ?

2013-01-09 Thread rurpy
On Wednesday, January 9, 2013 7:11:34 PM UTC-7, iMath wrote:
> can you  give me an example code ?

For running any system command from Python, you can use the 
subprocess module:
  http://docs.python.org/3/library/subprocess.html#module-subprocess

To run "wget -p -k http://python.org"; from Python you could
do something like this:

  import subprocess
  subprocess.call (['wget', '-p', '-k', 'http://python.org'])


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


subprocess.Popen and multiprocessing fails to execute external program

2013-01-09 Thread Niklas Berliner
I have a pipline that involves processing some data, handing the data to an
external program (t_coffee used for sequence alignments in bioinformatics),
and postprocessing the result. Since I have a lot of data, I need to run my
pipeline in parallel which I implemented using the multiprocessing module
following Doug Hellmanns blog (
http://blog.doughellmann.com/2009/04/pymotw-multiprocessing-part-1.html).

My pipeline works perfectly fine when I run it with the multiprocessing
implementation and one consumer, i.e. on one core. If I increase the number
of consumers, i.e. that multiple instances of my pipeline run in parallel
the external program fails with a core dump.

To call the external programm I let python write a bash wrapper script that
is called by
subprocess.Popen(system_command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
result, error = childProcess.communicate()
rc = childProcess.returncode
(I also tried shell=False and calling the program directly specifying the
env for the call)

To avoid conflict between the external program each program call gets a
flushed environment and the important environment variables are set to
unique, existing paths. An example looks like this:
#!/bin/bash
env -i
export HOME_4_TCOFFEE="/home/niklas/tcoffee/parallel/99-1-Consumer-2/"
export CACHE_4_TCOFFEE="$HOME_4_TCOFFEE/cache/"
export TMP_4_TCOFFEE="$HOME_4_TCOFFEE/tmp/"
export LOCKDIR_4_TCOFFEE="$HOME_4_TCOFFEE/lock/"
mkdir -p $CACHE_4_TCOFFEE
mkdir -p $TMP_4_TCOFFEE
mkdir -p $LOCKDIR_4_TCOFFEE

t_coffee -mode expresso -seq
/home/niklas/tcoffee/parallel/Consumer-2Q9FHL4_ARATH -blast_server=LOCAL
-pdb_db=pdbaa -outorder=input -output fasta_aln -quiet -no_warning
-outfile=/tmp/tmpm3mViZ
If I replace the t_coffee command by some simple 'touch I--was-here'  the files are created as expected and no error is produced.
The developers of the external program assured me that running their
program in parallel should not be a problem if the environment variables
are set correctly. If a take the exact same bash scripts that are generated
by python and that failed when trying to run them in parallel through
python and execute batches of them manually using a for loop in multiple
terminals (i.e. in parallel) they don't produce an error.


I am really puzzled and stuck. Python seems to work correctly on its own
and the external program seems to work correctly on its own. But somehow,
when combined, they won't work.
Any help and hints would be really appreciated! I need that to work.

I am using Ubuntu 12.04 with python 2.7.3

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


Re: Getting audio input and processing it?

2013-01-09 Thread Dave Angel
On 01/09/2013 07:20 PM, Michael Curry wrote:
> I've been working on a Morse Code translator, I've made it work so that you 
> can input English and it will translate it to Morse and play the Audio. I now 
> want to add a feature to the program that takes audio input, processes it and 
> then outputs the English.
>
> Are there any specific APIs that I can use to take input from a microphone, 
> is there any way to detect frequencies or amplitudes, as well as find out for 
> how long the wave lasts? If not, are there any implementations of this? Would 
> there be a way to do it?

If you find an approach that gets audio information from your hardware,
and on your operating system, then you presumably end up with a stream
of bytes (or of some other data type, if the sample size is bigger than
8 bits).  If this were my project, I'd ignore the detecting of frequency
(though it can be done, by various filtering techniques), and just
measure energy.  Presumably the signal is quiet for space, and noisy for
mark.  So you set a threshold, and measure how long the signal is below
the threshold, and then how long it's above.  The time above the
threshold is how long the "wave lasts."   Presumably you can then set a
few length thresholds, and short values are dit and longer ones are dah.

So, how do you measure energy on a byte string?  The way I've seen audio
encoded in 8 bits has 128 as the DC zero reference point.  Values above
and below that represent a nonzero signal voltage.  So you'd do
something like:
abs( value-128)

to get an instantaneous energy.  Do a sanity check to make sure the
"quiet" signal gives you a very small energy (some noise expected, of
course).

There are lots of refinements possible.  But I suspect someone else is
going to pop in and say that libary xyz on pypi will do it all for you
automatically.  There's probably someone who's done the whole project
before.  But what's the fun in that?


-- 

DaveA

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


Re: subprocess.Popen and multiprocessing fails to execute external program

2013-01-09 Thread Dave Angel
On 01/09/2013 11:08 PM, Niklas Berliner wrote:
> I have a pipline that involves processing some data, handing the data to an
> external program (t_coffee used for sequence alignments in bioinformatics),
> and postprocessing the result. Since I have a lot of data, I need to run my
> pipeline in parallel which I implemented using the multiprocessing module
> following Doug Hellmanns blog (
> http://blog.doughellmann.com/2009/04/pymotw-multiprocessing-part-1.html).
>
> My pipeline works perfectly fine when I run it with the multiprocessing
> implementation and one consumer, i.e. on one core. If I increase the number
> of consumers, i.e. that multiple instances of my pipeline run in parallel
> the external program fails with a core dump.
>

Could it be that the external program is not designed to have multiple
simultaneous instances?  There are many such programs, some of which
check for an existing process before allowing another one to get far.

When using the multiprocessing module, always make sure your externals
are well-behaved before looking for problems in your multi-code.

To put it more strongly, a well-written program cannot easily be crashed
by the parent that launched it.


-- 

DaveA

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


How to run multiline shell command within python

2013-01-09 Thread Karim



Hello all,

I want to run multiline shell command within python without using a 
command file but directly execute several lines of shell.
I already use *subprocess.checkoutput("csh -f my_file.csh".split())* but 
I want to know if it is posssible to avoid making file and execute

shell lines of code directly.

Example:

cat< myfile
echo "foo"
echo "bar"
...
EOF

Regards

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


RIse and fall of languages in 2012

2013-01-09 Thread Steven D'Aprano
"In general-purpose scripting languages, Python continues to grow slowly, 
JavaScript and Ruby are treading water, and Perl continues its long 
decline. According to Google trends, the number of searches for Perl is 
19% of what it was in 2004. Its declining role in open-source communities 
further cements the perception that it's in an irretrievable tailspin. 
One should always be careful pronouncing a language dead or dying, 
because rare resurrections have occurred: JavaScript and Objective-C 
being two stand-out cases. However, Perl is unlikely to see such a new 
lease on life because of direct competition from Python, which is 
considerably more popular (whereas Objective-C and JavaScript had no 
direct equivalents when they came back)."

http://www.drdobbs.com/jvm/the-rise-and-fall-of-languages-in-2012/240145800


And from the TIOBE Index, Python is steady at number 8:

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html



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