Re: HTML templating tools

2016-10-21 Thread lists

+1 for Jinja2. I love that shit

On 2016-10-20 23:16, Adrian Petrescu wrote:

On Thu, 20 Oct 2016 11:34:36 +0200, Tony van der Hoff wrote:


Can anyone recommend a suitable replacement (preferably
compatible with htmltmpl)?


I don't think anything is going to be compatible with htmltmpl, but 
Jinja2
is a very widely-used, well-supported and easy-to-learn templating 
engine

for Python: http://jinja.pocoo.org/docs/dev/

There's nothing specific to HTML about it, but that is its most common
use case.

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


numpy problem

2016-05-23 Thread lists
Hi,

I've got a nympy problem I can't get my head around. (numpy is new to me).

I've got a 2D array with values:

values = np.array(
[[ 20, 38,  4,  45, 65],
 [ 81, 44, 38,  57, 92],
 [ 92, 41, 16,  77, 44],
 [ 53, 62,  9,  75, 12],
 [ 58,  2, 60, 100, 29],
 [ 63, 15, 48,  43, 71],
 [ 80, 97, 87,  64, 60],
 [ 16, 16, 70,  88, 80],
 [ 19,  1, 73,  39, 97],
 [ 48,  3, 27,  81, 14]])

And an array of indexes that for shows which row to keep for each column of 
values:

keep = np.array([2, 3, 1, 9, 2])

So, the result should be an array like array([ values[2,0], values[3,1], 
values[1,2], values[9,3], values[2,4] ]) == np.array([92, 62, 38, 81, 44])

Can this be accomplished in a vectorized manner?


Thx,

Peter


signature.asc
Description: Message signed with OpenPGP using GPGMail
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: numpy problem

2016-05-23 Thread lists
> 
> On 23 mei 2016, at 14:19, Peter Otten <__pete...@web.de> wrote:
> 
> li...@onemanifest.net wrote:
> 
>> I've got a 2D array with values:
>> 
>> values = np.array(
>> [[ 20, 38,  4,  45, 65],
>> [ 81, 44, 38,  57, 92],
>> [ 92, 41, 16,  77, 44],
>> [ 53, 62,  9,  75, 12],
>> [ 58,  2, 60, 100, 29],
>> [ 63, 15, 48,  43, 71],
>> [ 80, 97, 87,  64, 60],
>> [ 16, 16, 70,  88, 80],
>> [ 19,  1, 73,  39, 97],
>> [ 48,  3, 27,  81, 14]])
>> 
>> And an array of indexes that for shows which row to keep for each column
>> of values:
>> 
>> keep = np.array([2, 3, 1, 9, 2])
>> 
>> So, the result should be an array like array([ values[2,0], values[3,1],
>> values[1,2], values[9,3], values[2,4] ]) == np.array([92, 62, 38, 81, 44])
>> 
>> Can this be accomplished in a vectorized manner?
> 
> How about
> 
> values[keep].diagonal()

That seems to do the trick!

Thx.


signature.asc
Description: Message signed with OpenPGP using GPGMail
-- 
https://mail.python.org/mailman/listinfo/python-list


seeking deeper (language theory) reason behind Python design choice

2018-05-07 Thread all-lists
Hi,

I was wondering (and have asked on StackOverflow [1] in a more
elaborate way) whether there is a deeper reason to not allow
assignments in lambda expressions.

I'm not criticising, I'm asking in order to know ;-)

The surface-reason is the distinction between assignments and
statements, but why it was designed this way (with respect to lambda,
not in general)?

So far, no satisfying answer has come up, except for maybe to avoid a
programmer accidentally typing `=` instead of `==`, which I find a bit
unsatisfying as the only reason.

There's a bounty on the StackOverflow question.

Thanks for reading!
Stefan


[1] 
https://stackoverflow.com/questions/50090868/why-are-assignments-not-allowed-in-pythons-lambda-expressions


--
http://stefan-klinger.de  o/X
Send plain text messages only, not exceeding 32kB./\/
\
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Writing my own typing monitor program for RSI sufferers...

2006-02-20 Thread Sam&#x27;s Lists
Skip...

So, so close  The problem with this implementation is that it
doesn't monitor usb keyboards under linux at all as far as I can
tellsince no keyboard entry will show up in /proc/interrupts with a
usb keyboard.  I absolutely need the keyboard monitoring as well.

Otherwise, your project would be the perfect starting point for me!

Anyone else have an idea as to what I can use with Python to know when the keyboard is being used even when I don't have focus?

Thanks
SamOn 2/21/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> I want to write a program that will let me know after thirty minutes>> of typing that I need to take a five minute typing break.  But when I>> stop typing it's smart enough to pause the 30 minute timer
>> automatically.  This is under the X-Window System (Linux).Take a look athttp://sourceforge.net/projects/watch/If you'd like to be added as a developer, let me know...
Skip
-- 
http://mail.python.org/mailman/listinfo/python-list

Detecting an active exception

2007-06-01 Thread NeBlackCat (lists)
Hello everybody - my first post! And it may be the most monumentally 
stupid question ever asked, but I just can't see an answer after several 
hours experimenting, searching and reading.

It's simply this - how can a function determine whether or not it's 
being called in handling of an exception (ie. there is an "active" 
exception, and somewhere upstream on the stack there is an except: block 
statement)?

Depending on what you read, sys.exc_info() is supposed to return 
(None,None,None) when there is no active exception, but it seems that it 
returns info about the last exception when there isn't one currently 
active.

For example:

try:
a = a + 1
except:
pass

print sys.exc_info()

produces:
, , 

Where the traceback object identifies the offending a=a+1 line (of course).

Is there another way of doing this? Note that I can't rely on using 
sys.exc_clear() in any solution, unfortunately.

cheers

- John

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


Why this script can work?

2007-01-18 Thread Jm lists
Please help with this script:

class ShortInputException(Exception):
'''A user-defined exception class.'''
def __init__(self,length,atleast):
Exception.__init__(self)
self.length=length
self.atleast=atleast

try:
s=raw_input('Enter something --> ')
if len(s)<3:
raise ShortInputException(len(s),3)
# Other work can continue as usual here
except EOFError:
print '\nWhy did you do an EOF on me?'
except ShortInputException,x:
print 'ShortInputException: The input was of length %d, was
expecting at least %d' %(x.length,x.atleast)
else:
print 'No exception was raised.'


My questions are:

1) ShortInputException,x:   what's the 'x'? where is it coming?

2) The 'if' and 'else' are not in the same indent scope,why this can work?

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


Re: Why this script can work?

2007-01-19 Thread Jm lists
Thanks for all the helps.
I'm not habitual for this usage of 'else',other languages seem don't
support this syntax.
i.g,writting the codes below by Perl would get an error:

# perl -le 'for $i  (1..10){print $i}  else{print "finished"}'
syntax error at -e line 1, near "}else"
Execution of -e aborted due to compilation errors.

2007/1/19, Diez B. Roggisch <[EMAIL PROTECTED]>:
> Jm lists wrote:
>
> > Please help with this script:
> >
> > class ShortInputException(Exception):
> > '''A user-defined exception class.'''
> > def __init__(self,length,atleast):
> > Exception.__init__(self)
> > self.length=length
> > self.atleast=atleast
> >
> > try:
> > s=raw_input('Enter something --> ')
> > if len(s)<3:
> > raise ShortInputException(len(s),3)
> > # Other work can continue as usual here
> > except EOFError:
> > print '\nWhy did you do an EOF on me?'
> > except ShortInputException,x:
> > print 'ShortInputException: The input was of length %d, was
> > expecting at least %d' %(x.length,x.atleast)
> > else:
> > print 'No exception was raised.'
> >
> >
> > My questions are:
> >
> > 1) ShortInputException,x:   what's the 'x'? where is it coming?
>
> except , :
>
> will catch an exception of the kind specified in  (it might
> actually be more than one), and store the exception object in the variable
> named 
>
> > 2) The 'if' and 'else' are not in the same indent scope,why this can work?
>
>
> Because additionally to if, also for and try have else-clauses. The latter
> two are only being called if the body of the control structure hasn't been
> left due to "unnatural" circumstances. See this:
>
>
>
>
> for i in xrange(10):
> pass
> else:
> print "test 1"
>
> for i in xrange(10):
> break
> else:
> print "test 2"
>
> try:
> pass
> except:
> pass
> else:
> print "test 3"
>
> try:
> raise "I know I shouldn't rais strings..."
> except:
> pass
> else:
> print "test 4"
>
>
>
> It will only print
>
> test 1
> test 3
>
>
> Diez
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


**argv can't work

2007-01-19 Thread Jm lists
hello members,

See my script piece below:

def testB(shift,**argv):
print "first argument is %s" %shift
print "all other arguments are:",argv

testB('mails','Jen','[EMAIL PROTECTED]','Joe','[EMAIL PROTECTED]')

It can't work at all.please help tell me the reasons.thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: **argv can't work

2007-01-19 Thread Jm lists
Thanks for all the kind helps!

2007/1/20, Parthan SR <[EMAIL PROTECTED]>:
>
>
> On 1/20/07, Jm lists <[EMAIL PROTECTED]> wrote:
> > hello members,
> >
> > See my script piece below:
> >
> > def testB(shift,**argv):
> > print "first argument is %s" %shift
> > print "all other arguments are:",argv
> >
> > testB('mails','Jen',' [EMAIL PROTECTED]','Joe','[EMAIL PROTECTED]')
> >
> > It can't work at all.please help tell me the reasons.thanks.
> >
> >
>
> It works for me, check this one :
>
> >>> def argtst(x, **y):
> ... print "first arument is %s" % x
> ... print "other arguments are", y
> ...
> >>> argtst(x=10,a=1,b=2,c=3)
> first arument is 10
> other arguments are {'a': 1, 'c': 3, 'b': 2}
>
>
> (!) : Do not use the name 'argv' for the second argument.
>
> --
> With Regards,
>
> TechnoFreak
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Does eval has the same features as Perl's?

2007-01-20 Thread Jm lists
Hello members,

I want to know does the "eval" in python have the same features as in
Perl (capture errors)?

For example,in perl I can wrote:

$re = eval { 1 / 0 };

Though 1/0 is a fatal error but since it's in "eval" block so the perl
interpreter doesn't get exit.

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


Re: Does eval has the same features as Perl's?

2007-01-20 Thread Jm lists
Thank you.I'm just learning Python and want to make something clear to me.:)

2007/1/20, Steven D'Aprano <[EMAIL PROTECTED]>:
> On Sat, 20 Jan 2007 17:30:24 +0800, Jm lists wrote:
>
> > Hello members,
> >
> > I want to know does the "eval" in python have the same features as in
> > Perl (capture errors)?
> >
> > For example,in perl I can wrote:
> >
> > $re = eval { 1 / 0 };
> >
> > Though 1/0 is a fatal error but since it's in "eval" block so the perl
> > interpreter doesn't get exit.
>
> How hard would it be to actually try it?
>
> >>> eval("1/0")
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "", line 1, in 
> ZeroDivisionError: integer division or modulo by zero
>
> It took about three seconds to actually test it.
>
> eval has many security risks -- as a rule, you should never pass strings
> you've got from the user to eval, unless you want the user to p0wn your
> computer. It is harder than you might think to make eval safe -- you
> should seriously consider it an advanced tool, not a basic tool. As a
> newbie, you should work under the following rule:
>
> "If I think I need to use eval, I'm probably wrong."
>
> I've been using Python for seven or eight years, and I don't think I've
> ever used eval in serious code.
>
> Now, suppose you find yourself wanting to use eval. You've considered the
> above rule carefully, and decided that it doesn't apply in this case.
> You've been careful to use it only on safe strings, not arbitrary strings
> from users. How do you use eval so it captures errors?
>
> try:
> eval("1/0")
> except ZeroDivisionError: # capture only one error
> pass
>
>
> or something like this:
>
> try:
> eval("something or other goes here")
> except Exception: # capture any error
> pass
>
>
>
> --
> Steven.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


About getattr()

2007-02-11 Thread Jm lists
Hello,

Since I can write the statement like:

>>> print os.path.isdir.__doc__
Test whether a path is a directory

Why do I still need the getattr() func as below?

>>> print getattr(os.path,"isdir").__doc__
Test whether a path is a directory

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


MySQL posting confirmation for python-list@python.org

2005-07-04 Thread MySQL Lists Automoderator
This is an automatic reply to an email you sent to a MySQL mailing address
protected by our 'self-moderation' system. To reduce the amount of spam
received at these addresses, we require you to confirm that you're a real
person before your email will be allowed through.

Unfortunately, we got a bounce for one of the confirmation emails we
already sent, so you've been added to the list of addresses which will
get bounced immediately.

In order to have yourself added to the list of real email addresses, and
removed from the list of those who have bounced, you need to click on the
following link (or cut-and-paste it to a browser):

 
http://lists.mysql.com/c/a285fefe95ba36aded1612a93a5711cc/python-list@python.org

After we have received your confirmation, "python-list@python.org"
will be added to the list of pre-approved mail addresses for all of
the MySQL mail addresses and future emails from that address will be
delivered without delay automatically.

You will not receive an email confirmation of your confirmation -- future
messages will simply be sent along without delay.

Sorry for the hassle, but the volume of unsolicited commercial email
sent to these addresses has made this step necessary.

--- Your original email is below.

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


Exercises for dive into python

2006-07-24 Thread Ben Edwards (lists)
Have been working through Dive Into Python which is excellent.  My only
problem is that there are not exercises.  I find exercises are a great
way of helping stuff sink in and verifying my learning.  Has anyone done
such a thing?

Ben


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


Re: Exercises for dive into python

2006-07-24 Thread Ben Edwards (lists)
On Mon, 2006-07-24 at 16:39 +, Tal Einat wrote:
> Ben Edwards (lists  videonetwork.org> writes:
> 
> > 
> > Have been working through Dive Into Python which is excellent.  My only
> > problem is that there are not exercises.  I find exercises are a great
> > way of helping stuff sink in and verifying my learning.  Has anyone done
> > such a thing?
> > 
> > Ben
> > 
> 
> 
> I recently gave a Python crash-course in my company, and ran into the same
> problem. There are many good Python tutorials, manuals, references etc., most
> are accompannied by various code examples, but there are very few exercises. I
> had a hard time collecting and inventing a few good exercises, about 12 in 
> all.
> 
> There are probably some good exercises out there, but they seem to be 
> relatviely
> hard to find. Maybe they should be collected and organized at Python.org?

That sounds like an exelent idea.  Maybe the way to structure it is my
book/chapter. 

> 
> I think building a large collection of good Python exercises could help both
> those teaching Python and those learning it. Also, gathering a set of Python
> exercises for those learning general programming concepts (variables, 
> functions,
> object-oriented, etc.) could help spread the use of Python for teaching
> programming.

I think there is little doubt about this.  The reason I liked the
'Thinking in Java' book was it had 10 exercises at the end of each
chapter.  I would not more onto a chapter until I had completed them
all.

Ben

> 
> - Tal
> 


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


Re: Exercises for dive into python

2006-07-25 Thread Ben Edwards (lists)
On Mon, 2006-07-24 at 23:16 +0200, Tal Einat wrote:
> 
> 

snip...

> >
> >
> > I recently gave a Python crash-course in my company, and ran
> into the same 
> > problem. There are many good Python tutorials, manuals,
> references etc., most
> > are accompannied by various code examples, but there are
> very few exercises. I
> > had a hard time collecting and inventing a few good
> exercises, about 12 in all. 
> >
> > There are probably some good exercises out there, but they
> seem to be relatviely
> > hard to find. Maybe they should be collected and organized
> at Python.org?
> 
> That sounds like an exelent idea.  Maybe the way to structure
> it is my 
> book/chapter.
>  
> You probably meant "by book/chapter".
>  
> Well, that would be fine, but it's up to whoever wrote "dive into
> Python" to update it.
> I was actually suggesting a central repository for Python exercises,
> all in the public domain, so that they could be used by anyone
> learning or teaching Python (or programming in general).

I don't think this is necessarily the case.  I am fairly sure the
problem is not the people writing books do not have a way of publishing
the excesses, its just they have hot the time or inclination to do so.

what I was suggesting was a wiki type site where exercises could be
worked on collaboratively.  The authors should not have a problem with
this as it would add value to there work and make it more desirable.

Ben

> 
> >
> > I think building a large collection of good Python exercises
> could help both
> > those teaching Python and those learning it. Also, gathering
> a set of Python 
> > exercises for those learning general programming concepts
> (variables, functions,
> > object-oriented, etc.) could help spread the use of Python
> for teaching
> > programming.

snip...

> 


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


Possible error in 'dive into Python' book, help!

2006-07-28 Thread Ben Edwards (lists)
I have been going through Dive into Python which up to now has been
excellent.  I am now working through Chapter 9, XML Processing.  I am 9
pages in (p182) in the 'Parsing XML section.  The following code is
supposed to return the whole XML document (I have put ti at the end of
this email):

from xml.dom import minidom
 
xmldoc =
minidom.parse('/home/ben/diveintopython-5.4/py/kgp/binary.xml') 
grammerNode = xmldoc.firstChild
 
print grammerNode.toxml()

But it only returns:



The next line is then 

grammerNode.childNodes

And it returns an empty tuples;(

Kind of stuck here as I don't really want to continue.  Has anyone any
idea what is going on?

Ben

binary.xml





  0
  1


  






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


Unicode question

2006-07-28 Thread Ben Edwards (lists)
I am using python 2.4 on Ubuntu dapper, I am working through Dive into
Python.

There are a couple of inconsictencies.

Firstly sys.setdefaultencoding('iso−8859−1') does not work, I have to do
sys.setdefaultencoding = 'iso−8859−1'

secondly the following does not give a 'UnicodeError: ASCII encoding
error:', and I would expect ti to.  In fact it prints out the n with ~
above it fine:

sys.setdefaultencoding = 'ascii'
s = u'La Pe\xf1a'
print s

Any insight?
Ben


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

Another problem with 'Dive Into Python'

2006-07-31 Thread Ben Edwards (lists)
Am going through Chapter 9 - HTTP Web Services in dive into Python.  It
uses the following:

data = urllib.urlopen('http://diveintomark.org/xml/atom.xml').read()

The page no longer exists, can anyone recommend an alternative page to
use?

Ben



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


SOAP/WSDL Introspection

2006-08-01 Thread Ben Edwards (lists)
I have the below code to get info about SOAP services at a wsdl url.  It
gets the in parameters OK but does not seem to get out/return
parameters.  Any idea why?

Ben

from SOAPpy import WSDL
import sys

wsdlfile = "http://www.xmethods.net/sd/2001/TemperatureService.wsdl";

server = WSDL.Proxy(wsdlfile)

for methodName in  server.methods:
print "method = ", methodName
callInfo = server.methods[ methodName ]

for inParam in callInfo.inparams:
print "  inparam = ", inParam.name, inParam.type

for outParam in callInfo.outparams:
print "  outparam = ", outParam.name, outParam.type


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


python class instantiation

2006-10-23 Thread Éric Daigneault lists
Got a question for you all...

I noticed a behaviour in python class creation that is strange, to say 
the least.

When creating a class with data members but no __init__ method.  Python 
deals differently with data members that are muatable and immutables.

Ex:
class A(object):
stringData = "Whatever"
listData = []

instance = A()

Will have data members instantiated as expected (instance.stringData == 
"Whatever" and instance.listData == [])

instance.listData.append("SomeString")
instance.stringData = "Changed"

Now if I do

secondInstance = A()

it will come with the listData containing the SomeString appended to the 
instance...

this is clearly not normal

Especially that the stringData of Second instance contains the 
"Whatever" text.  If the behaviour was at least consistant...  but it is 
not...

Am I coing nuts or is this by desing, if so it is very misleading...  
The two instances are sharing the same list, but not the same string 
...  I did not declare the list to be static in any way  Why does it 
behave like this ?

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


Re: mean ans std dev of an array?

2006-10-23 Thread Éric Daigneault lists
Simplest I see is to do it manually.

If your array data is  numeric compatible

mean = sum(a)/len(a)

as for the standard Deviation it depends on the nature of your data...  
check out http://en.wikipedia.org/wiki/Standard_deviation  for info on 
that...  but in all a for loop with a few calculation within should be 
enough

I know no "standard" way to do this in python

Have not tested above code but it should work

Éric

SpreadTooThin wrote:
> import array
> a = array.array('f', [1,2,3])
>
> print a.mean()
> print a.std_dev()
>
> Is there a way to calculate the mean and standard deviation on array
> data?
>
> Do I need to import it into a Numeric Array to do this?
>
>   

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