Thursday, February 18, 2010

comp.lang.python - 25 new messages in 13 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* unit testing a routine that sends mail - 6 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/33e5d23bbb8724a3?hl=en
* string to list when the contents is a list - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/d604be2eee402ced?hl=en
* Paypal payment Discount Wholesale/Retail LV,Paket,Rolex,Omega,RADO,Armani ,
Hermes,GUCCI ,Chanel,D&G,Burberry etc BRAND watches(www.globlepurchase.com) -
1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/61600bf40b1218f4?hl=en
* Python library for working with simple equations - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/08335ec2e2d655aa?hl=en
* Few questions on SOAP - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/3808b1054771aa1c?hl=en
* Static method - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/68f5cd03927c9d3f?hl=en
* Upgrading Py2exe App - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/425fea70d75ab788?hl=en
* Interesting talk on Python vs. Ruby and how he would like Python to have
just a bit more syntactic flexibility. - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/9a88c79d4043ba30?hl=en
* Constraints on __sub__, __eq__, etc. - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/98434610aa827c3c?hl=en
* Is automatic reload of a module available in Python? - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/71d2e8e4a38c3b1d?hl=en
* Why this doesn't work? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/698b29e4a1bebed4?hl=en
* NOW Watch Hot Sexy Star Aishwarya rai Bathing Videos In All Angles. - 1
messages, 1 author
http://groups.google.com/group/comp.lang.python/t/daa1fed2a9f2aa91?hl=en
* What happened to pyjamas? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/4480c0898703d657?hl=en

==============================================================================
TOPIC: unit testing a routine that sends mail
http://groups.google.com/group/comp.lang.python/t/33e5d23bbb8724a3?hl=en
==============================================================================

== 1 of 6 ==
Date: Thurs, Feb 18 2010 6:37 am
From: commander_coder


Hello,

I have a routine that sends an email (this is how a Django view
notifies me that an event has happened). I want to unit test that
routine. So I gave each mail a unique subject line and I want to use
python's mailbox package to look for that subject. But sometimes the
mail gets delivered and sometimes it does not (I use sendmail to send
it but I believe that it is always sent since I can see an entry in
the mail log).

I thought that the mail delivery system was occasionally hitting my
mailbox lock, and that I needed to first sleep for a while. So I
wrote a test that sleeps, then grabs the mailbox and looks through it,
and if the mail is not there then it sleeps again, etc., for up to ten
tries. It is below.

However, I find that if the mail is not delivered on the first try
then it is never delivered, no matter how long I wait. So I think I
am doing mailbox wrong but I don't see how.

The real puzzler for me is that the test reliably fails every third
time. For instance, if I try it six times then it succeeds the first,
second, fourth, and fifth times. I have to say that I cannot
understand this at all but it certainly makes the unit test useless.

I'm using Python 2.6 on an Ubuntu system. If anyone could give me a
pointer to why the mail is not delivered, I sure could use it.

Thanks,
Jim

...................................................................

class sendEmail_test(unittest.TestCase):
"""Test sendEmail()
"""
config = ConfigParser.ConfigParser()
config.read(CONFIG_FN)
mailbox_fn=config.get('testing','mailbox')

def look_in_mailbox(self,uniquifier='123456789'):
"""If the mailbox has a message whose subject line contains
the
given uniquifier then it returns that message and deletes it.
Otherwise, returns None.
"""
sleep_time=10.0 # wait for message to be delivered?
message_found=None
i=0
while i<10 and not(message_found):
time.sleep(sleep_time)
m=mailbox.mbox(self.mailbox_fn)
try:
m.lock()
except Exception, err:
print "trouble locking the mailbox: "+str(err)
try:
for key,message in m.items():
subject=message['Subject'] or ''
print "subject is ",subject
if subject.find(uniquifier)>-1:
print "+++found the message+++ i=",str(i)
message_found=message
m.remove(key)
break
m.flush()
except Exception, err:
print "trouble reading from the mailbox: "+str(err)
m.unlock()
try:
m.unlock()
except Exception, err:
print "trouble unlocking the mailbox: "+str(err)
try:
m.close()
except Exception, err:
print "trouble closing the mailbox: "+str(err)
del m
i+=1
return message_found

def test_mailbox(self):
random.seed()
uniquifier=str(int(random.getrandbits(20)))
print "uniquifier is ",uniquifier # looks different every
time to me
rc=az_view.sendEmail(uniquifier=uniquifier)
if rc:
self.fail('rc is not None: '+str(rc))
found=self.look_in_mailbox(uniquifier)
if not(found):
self.fail('message not found')
print "done"


== 2 of 6 ==
Date: Thurs, Feb 18 2010 6:55 am
From: Roy Smith


In article
<a9524166-5b0f-4740-8123-e2582faeeedd@g26g2000yqn.googlegroups.com>,
commander_coder <commander_coder@hotmail.com> wrote:

> The real puzzler for me is that the test reliably fails every third
> time. For instance, if I try it six times then it succeeds the first,
> second, fourth, and fifth times. I have to say that I cannot
> understand this at all but it certainly makes the unit test useless.

Just a wild guess here, but maybe there's some DNS server which
round-robins three address records for some hostname you're using, one of
which is bogus.

I've seen that before, and this smells like the right symptoms.


== 3 of 6 ==
Date: Thurs, Feb 18 2010 7:25 am
From: commander_coder


On Feb 18, 9:55 am, Roy Smith <r...@panix.com> wrote:
> Just a wild guess here, but maybe there's some DNS server which
> round-robins three address records for some hostname you're using, one of
> which is bogus.
>
> I've seen that before, and this smells like the right symptoms.

Everything happens on my laptop, localhost, where I'm developing.

I'm sorry; I wasn't sure how much information was too much (or too
little) but I should have said that.

Thank you.


== 4 of 6 ==
Date: Thurs, Feb 18 2010 7:27 am
From: Bruno Desthuilliers


commander_coder a écrit :
> Hello,
>
> I have a routine that sends an email (this is how a Django view
> notifies me that an event has happened). I want to unit test that
> routine.

http://docs.djangoproject.com/en/dev/topics/email/#e-mail-backends

Or if you're stuck with 1.x < 1.2a, you could just mock the send_mail
function to test that your app does send the appropriate mail - which is
what you really want to know.

My 2 cents...


== 5 of 6 ==
Date: Thurs, Feb 18 2010 7:59 am
From: commander_coder


On Feb 18, 10:27 am, Bruno Desthuilliers <bruno.
42.desthuilli...@websiteburo.invalid> wrote:

> you could just mock the send_mail
> function to test that your app does send the appropriate mail - which is
> what you really want to know.

That's essentially what I think I am doing.

I need to send a relatively complex email, multipart, with both a
plain text and html versions of a message, and some attachments. I am
worried that the email would fail to get out for some reason (say,
attaching the html message fails), so I want to test it. I started
out with a simple email, thinking to get unit tests working and then
as I add stuff to the email I'd run the tests to see if it broke
anything.

I could mock the send_mail function by having it print to the screen
"mail sent" or I could have a unit test that looked for the mail. I
did the first, and it worked fine. I thought to do the second,
starting with a unit test checking simply that the message got to the
mailbox. But I am unable to check that, as described in the original
message.

Jim


== 6 of 6 ==
Date: Thurs, Feb 18 2010 8:11 am
From: commander_coder


Bruno, I talked to someone who explained to me how what you said
gives a way around my difficulty. Please ignore the other reply.
I'll do what you said. Thank you; I appreciate your help.

Jim

==============================================================================
TOPIC: string to list when the contents is a list
http://groups.google.com/group/comp.lang.python/t/d604be2eee402ced?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Feb 18 2010 6:52 am
From: nn


Wes James wrote:
> I have been trying to create a list form a string. The string will be
> a list (this is the contents will look like a list). i.e. "[]" or
> "['a','b']"
>
> The "[]" is simple since I can just check if value == "[]" then return []
>
> But with "['a','b']" I have tried and get:
>
> a="['a','b']"
>
> b=a[1:-1].split(',')
>
> returns
>
> [ " 'a' "," 'b' " ]
>
> when I want it to return ['a','b'].
>
> How can I do this?
>
> thx,
>
> -wes


I am surprised nobody gave you the simple answer yet that may even
work for your situation:

b=a[2:-2].split("','")


== 2 of 2 ==
Date: Thurs, Feb 18 2010 7:18 am
From: Tim Chase


Wes James wrote:
> I have been trying to create a list form a string. The string will be
> a list (this is the contents will look like a list). i.e. "[]" or
> "['a','b']"
>
> The "[]" is simple since I can just check if value == "[]" then return []
>
> But with "['a','b']" I have tried and get:
>
> a="['a','b']"
>
> b=a[1:-1].split(',')
>
> returns
>
> [ " 'a' "," 'b' " ]
>
> when I want it to return ['a','b'].

Just to add to the list of solutions I've seen, letting the
built-in csv module do the heavy lifting:

>>> s = "['a','b']"
>>> import csv
>>> no_brackets = s[1:-1] # s.strip(' \t[]')
>>> c = csv.reader([no_brackets], quotechar="'")
>>> c.next()
['a', 'b']

This also gives you a bit of control regarding how escaping is
done, and other knobs & dials to twiddle if you need.
Additionally, if you have more than one string to process coming
from an iterable source (such as a file), you can just pass that
iterator to csv.reader() instead of concocting a one-element list.

-tkc

==============================================================================
TOPIC: Paypal payment Discount Wholesale/Retail LV,Paket,Rolex,Omega,RADO,
Armani ,Hermes,GUCCI ,Chanel,D&G,Burberry etc BRAND watches(www.globlepurchase.
com)
http://groups.google.com/group/comp.lang.python/t/61600bf40b1218f4?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 18 2010 6:52 am
From: brandtrade


Ebel Watch wholesale (paypal payment) (www.globlepurchase.com)
Bape Watch wholesale (paypal payment) (www.globlepurchase.com)
Bell&Ross Watch wholesale (paypal payment) (www.globlepurchase.com)
Breit Ling Watch wholesale (paypal payment) (www.globlepurchase.com)
Burberry Watch wholesale (paypal payment) (www.globlepurchase.com)
Cartier Watch wholesale (paypal payment) (www.globlepurchase.com)
Chopard Watch wholesale (paypal payment) (www.globlepurchase.com)
D&G Watch wholesale (paypal payment) (www.globlepurchase.com)
Givenchy Watch wholesale (paypal payment) (www.globlepurchase.com)
Jacob&Co Watch wholesale (paypal payment) (www.globlepurchase.com)
Kappa Watch wholesale (paypal payment) (www.globlepurchase.com)
Prada Watch wholesale (paypal payment) (www.globlepurchase.com)
Tissot Watch wholesale (paypal payment) (www.globlepurchase.com)
Titoni Watch wholesale (paypal payment) (www.globlepurchase.com)
U-BOAT Watch wholesale (paypal payment) (www.globlepurchase.com)
Zenith Watch wholesale (paypal payment) (www.globlepurchase.com)
A.Lange&Sohne Watch wholesale (paypal payment)
(www.globlepurchase.com)
Audemars Piguet Watch wholesale (paypal payment)
(www.globlepurchase.com)
Baume&Mercier Watch wholesale (paypal payment)
(www.globlepurchase.com)
Blancpain Watch wholesale (paypal payment) (www.globlepurchase.com)
Breguet Watch wholesale (paypal payment) (www.globlepurchase.com)
BRM Watch wholesale (paypal payment) (www.globlepurchase.com)
Bvlgari Watch wholesale (paypal payment) (www.globlepurchase.com)
Chanel Watch wholesale (paypal payment) (www.globlepurchase.com)
Concord Watch wholesale (paypal payment) (www.globlepurchase.com)
Corum Watch wholesale (paypal payment) (www.globlepurchase.com)
Dewitt Watch wholesale (paypal payment) (www.globlepurchase.com)
Ferrari Watch wholesale (paypal payment) (www.globlepurchase.com)
Franck Muller Watch wholesale (paypal payment)
(www.globlepurchase.com)
Girard Perregaux Watch (paypal payment) (www.globlepurchase.com)
Glashutte Watch (paypal payment) (www.globlepurchase.com)
Graham Watch wholesale (paypal payment) (www.globlepurchase.com)
GUCCI Watch wholesale (paypal payment) (www.globlepurchase.com)
GUESS Watch wholesale (paypal payment) (www.globlepurchase.com)
Hamilton Watch wholesale (paypal payment) (www.globlepurchase.com)
Hermes Watch wholesale (paypal payment) (www.globlepurchase.com)
Hublot Watch wholesale (paypal payment) www.globlepurchase.com)
IWC Watch wholesale (paypal payment) (www.globlepurchase.com)
Jaeger Le Coultre Watch wholesale (paypal payment)
(www.globlepurchase.com)
Longines Watch wholesale (paypal payment) (www.globlepurchase.com)
LV Watch wholesale (paypal payment) (www.globlepurchase.com)
Montblanc Watch wholesale (paypal payment) (www.globlepurchase.com)
Movado Watch wholesale (paypal payment) (www.globlepurchase.com)
Omega Watch wholesale (paypal payment) (www.globlepurchase.com)
Oris Watch wholesale (paypal payment) (www.globlepurchase.com)
Paket Philippe Watch wholesale (paypal payment)
(www.globlepurchase.com)
Panerai Watch wholesale (paypal payment) (www.globlepurchase.com)
Parmigiani Fleurier Watch wholesale (paypal payment)
(www.globlepurchase.com)
Piaget Watch wholesale (paypal payment) (www.globlepurchase.com)
Porsche Design Watch wholesale (paypal payment)
(www.globlepurchase.com)
Rolex Watch wholesale (paypal payment) (www.globlepurchase.com)
Romain Jerome Titanic-Dna Watch wholesale (paypal payment)
(www.globlepurchase.com)
Tag Heuer Watch wholesale (paypal payment) (www.globlepurchase.com)
Tudor Watch wholesale (paypal payment) (www.globlepurchase.com)
Vach.Constantine Watch wholesale (paypal payment)
(www.globlepurchase.com)
Armani Watch wholesale (paypal payment) (www.globlepurchase.com)
RADO Watch wholesale (paypal payment) (www.globlepurchase.com)


==============================================================================
TOPIC: Python library for working with simple equations
http://groups.google.com/group/comp.lang.python/t/08335ec2e2d655aa?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 18 2010 7:30 am
From: geremy condra


On Thu, Feb 18, 2010 at 4:09 AM, lallous <lallous@lgwm.org> wrote:
> Hello
>
> Is there is any Python library that allow such things:
>
> Given a string expression as: x + 5 + x * (y + 2), any library that
> can develop the equation for example.
> Or if we say factor with "x" then it renders the expression with x *
> ( rest of expression ).
> There could be a functionality where when x,y are given then the
> expression can be evaluated.
> If there are two expressions, they can be added and the symbols
> preserved.
>
> Does such a thing exist?
>
> Thanks,
> Elias
> --
> http://mail.python.org/mailman/listinfo/python-list
>

>From sage:

>>> x = var('x')
>>> g = x**2 + x
>>> g(x=5)
30
>>> g.factor
... (x + 1)*x

Geremy Condra

==============================================================================
TOPIC: Few questions on SOAP
http://groups.google.com/group/comp.lang.python/t/3808b1054771aa1c?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Feb 18 2010 7:36 am
From: joy99


Dear Group,

I was reading on SOA or Service Oriented Architecture for last few
days and got some questions. As this is a room for the expert computer
scientists, if you can help me solve my queries.

As per I read and felt SOA is an architecture, which relies on few
basic principles as,
the system must be modular, the modules must be distributive, module
interfaces must be clearly defined and documented, module that
implements a service can be swapped out for another module that offers
the same service and interface, service provider modules must be
shareable.
SOA is an architecture which is now a days governed like XML by W3C.
The latest version is SOAP 1.2.
SOA is implemented mainly in a client/server environment, where
applications have the use of service, thus we can say it is a service-
oriented architecture.
It is a step towards cloud computing with its sister WSDL and BPM.

If both client/server are following the SOA then they can communicate
and exchange information without worrying for platform.

SOAP is a software implementation of Python,.NET,J2EE based on this
principle.
SOAPPy is a Python implementation.

My questions are:
(i) Am I understanding correctly?
(ii) Does SOAP has any standard architecture like UML other than the
W3C one?
(iii) Can I write short programs to check the SOAP using my personal
computer as client as well as Server?
(iv) Is SOAPpy fine?
(v) What is the difference among SOAP, WSDL and BPM.
(vi) As SOAP is for communication with a server if I pick a URL and
start to communicate with Google/Yahoo would they allow?
(vii) Can I design a web based robot/crawler with SOAP?

Wishing you a Happy Day Ahead,
Best Regards,
Subhabrata.

== 2 of 3 ==
Date: Thurs, Feb 18 2010 8:12 am
From: Stefan Behnel


joy99, 18.02.2010 16:36:
> SOA is an architecture which is now a days governed like XML by W3C.
> The latest version is SOAP 1.2.

SOA has nothing to do with SOAP. SOAP is a (rather bloated) protocol for
remote procedure calls. SOA is a system architecture, be it distributed or not.

Stefan


== 3 of 3 ==
Date: Thurs, Feb 18 2010 10:14 am
From: Simon Brunning


On 18 February 2010 15:36, joy99 <subhakolkata1234@gmail.com> wrote:
> (iv)    Is SOAPpy fine?

AFAIK, SOAPpy is unsupported, and a bit on the stale side. Those poor
souls forced to make SOAP calls with Python seem to be using Suds
mostly these days,.

--
Cheers,
Simon B.

==============================================================================
TOPIC: Static method
http://groups.google.com/group/comp.lang.python/t/68f5cd03927c9d3f?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 18 2010 7:44 am
From: mk


Bruno Desthuilliers wrote:

> I think you broke something somewhere. Assuming you're using Python 2.x
> (>= 2.3 IIRC), my above code works.


ARGH! Forgot the "delayed staticmethod" line -- in effect I called
staticmethod twice:

@staticmethod
def print_internal_date(filename):
f = open(filename + 'c', "rb")
data = f.read(8)
mtime = struct.unpack("<i", data[4:])
return time.asctime(time.gmtime(mtime[0]))

tagdata = {'compiled_fname': lambda x: x + 'c',
'size': os.path.getsize,
'internal_date': lambda x:
PYFileInfo.print_internal_date.__get__(x)
}

# HERE I BROKE IT
print_internal_date = staticmethod(print_internal_date)

def __init__(self, fname=None):
FileInfo.__init__(self,fname)

def __setitem__(self, key, value):
FileInfo.__setitem__(self, key, value)
if key == 'name' and value:
self.__get_props(value)

def testit(self, fname):
self.print_internal_date(fname+'c')
PYFileInfo.print_internal_date.__get__(fname+'c')


You're right. It works.


==============================================================================
TOPIC: Upgrading Py2exe App
http://groups.google.com/group/comp.lang.python/t/425fea70d75ab788?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 18 2010 7:46 am
From: T


I have a Python app which I converted to an EXE (all files separate;
single EXE didn't work properly) via py2exe - I plan on distributing
this and would like the ability to remotely upgrade the program (for
example, via HTTP/HTTPS). Looks like it's not just the EXE that I
will need need to replace (DLLs, the library.zip, etc.). What would
be the best way to go about doing this?

==============================================================================
TOPIC: Interesting talk on Python vs. Ruby and how he would like Python to
have just a bit more syntactic flexibility.
http://groups.google.com/group/comp.lang.python/t/9a88c79d4043ba30?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Feb 18 2010 7:50 am
From: Duncan Booth


Steve Howell <showell30@yahoo.com> wrote:

> If this is an argument against using anonymous functions, then it is a
> quadruple strawman.
>
> Shipping buggy code is a bad idea, even with named functions.

I doubt very much whether I have ever shipped any bug-free code but
even if it was fit for purpose when shipped it is quite possible that the
software will interact badly with other software that did not exist at the
time of shipping.

>
> Obscuring line numbers is a bad idea, even with named functions.

In principle I agree, but where Javascript is concerned compressing the
downloaded files is generally a pretty good idea and practicality beats
purity.

>
> Having your customers stay on older versions of your software is a bad
> idea, even with named functions.

I think that's their decision, not mine.

>
> Not being able to know which version of software you're customer is
> running is a bad idea, even with named functions.
>
I agree, but getting a complete coherent description out of a customer is
not always an easy task. (I'm reading the word 'customer' here to include
the case where there is no monetary relationship between the software
author and the entity using it, but even when there is I think this still
true.)


--
Duncan Booth http://kupuguy.blogspot.com


== 2 of 2 ==
Date: Thurs, Feb 18 2010 8:15 am
From: Steve Howell


On Feb 18, 7:50 am, Duncan Booth <duncan.bo...@invalid.invalid> wrote:
> Steve Howell <showel...@yahoo.com> wrote:
> > If this is an argument against using anonymous functions, then it is a
> > quadruple strawman.
>
> > Shipping buggy code is a bad idea, even with named functions.
>
> I doubt very much whether I have ever shipped any bug-free code but
> even if it was fit for purpose when shipped it is quite possible that the
> software will interact badly with other software that did not exist at the
> time of shipping.
>
>
>
> > Obscuring line numbers is a bad idea, even with named functions.
>
> In principle I agree, but where Javascript is concerned compressing the
> downloaded files is generally a pretty good idea and practicality beats
> purity.
>
>
>
> > Having your customers stay on older versions of your software is a bad
> > idea, even with named functions.
>
> I think that's their decision, not mine.
>
>
>
> > Not being able to know which version of software you're customer is
> > running is a bad idea, even with named functions.
> mpr
> I agree, but getting a complete coherent description out of a customer is
> not always an easy task. (I'm reading the word 'customer' here to include
> the case where there is no monetary relationship between the software
> author and the entity using it, but even when there is I think this still
> true.)
>

Just to be clear, I'm not saying it's unforgivable to occasionally
ship software with bugs. It happens.

Compressing Javascript is sometimes necessary, but I believe that
often mangles named functions too.

To the the extent that your customer is running old software and
cannot always coherently describe tracebacks over a telephone, that
problem can be solved in the software itself, assuming an Internet
connection. The software can capture the traceback and report back to
a server with the version number.

So, much of the argument against anonymous functions presented so far
is really orthogonal to whether functions are named or not.

Circling back to the original topic, Ruby blocks, I think there is a
misconception about how blocks are often used in Ruby. Usually Ruby
blocks are inlined into a function and execute within that function.
Example:

def print_numbers()
[1, 2, 3, 4, 5, 6].map { |n|
[n * n, n * n * n]
}.reject { |square, cube|
square == 25 || cube == 64
}.map { |square, cube|
cube
}.each { |n|
puts n
raise 'problem here'
}
end

print_numbers()

The bug that I inserted into the "each" block gets reported in the
traceback:

foo.rb:10:in `print_numbers': problem here (RuntimeError)
from foo.rb:2:in `each'
from foo.rb:2:in `print_numbers'
from foo.rb:14

(I do prefer Python tracebacks BTW, but that is again orthogonal to
blocks vs. named functions.)

The blocks of code in the above Ruby code are somewhat analogous to
blocks of code in Python that happen within certain control
structures, such as "if," "while," "with," etc. The extra
expressiveness of Ruby comes from the fact that you can act on those
blocks with your own method. Of course, there is always a tradeoff
between expressiveness and simplicity. I know the person who gave the
talk about Ruby vs. Python, and trust me, nine times out of ten, he
prefers Python's simplicity to Ruby's expressiveness. But he likes
blocks.

I'm in the same boat. I use Python a lot, Ruby less so, but when I'm
in Ruby-land, I actually enjoy the expressiveness of blocks. They're
not particularly dangerous, and they allow you to express certain
sequential operations tersely and sequentially. The contrived code
below maps numbers to squares and cubes, then rejects a couple tuples,
then maps back to cubes, then prints each of the cubes.

def print_numbers()
[1, 2, 3, 4, 5, 6].map { |n|
[n * n, n * n * n]
}.reject { |square, cube|
square == 25 || cube == 64
}.map { |square, cube|
cube
}.each { |n|
puts n
}
end

IMHO there is no reason that I should have to name the content of each
of those four blocks of code, nor should I have to introduce the
"lambda" keyword.

I don't have a less contrived example handy, but the techniques above
apply often when you are filtering and massaging data.


==============================================================================
TOPIC: Constraints on __sub__, __eq__, etc.
http://groups.google.com/group/comp.lang.python/t/98434610aa827c3c?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Feb 18 2010 8:37 am
From: Benjamin Kaplan


On Thu, Feb 18, 2010 at 11:19 AM, Andrey Fedorov <anfedorov@gmail.com> wrote:
> It seems intuitive to me that the magic methods for overriding the +, -, <,
> ==, >, etc. operators should have no sideffects on their operands. Also,
> that == should be commutative and transitive, that > and < should be
> transitive, and anti-commutative.
> Is this intuition written up in a PEP, or assumed to follow from the
> mathematical meanings?
> - Andrey

There are no assumptions about anything. You can do whatever you want
when you implement the functions yourself. For the numeric types, they
follow the intuitive meanings but that's not necessary for user
defined types. Of course, your users will get very confused if a == b
but b != a. Or if a == b and a != b at the same time.


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


== 2 of 3 ==
Date: Thurs, Feb 18 2010 8:39 am
From: Robert Kern


On 2010-02-18 10:19 AM, Andrey Fedorov wrote:
> It seems intuitive to me that the magic methods for overriding the +, -,
> <, ==, >, etc. operators should have no sideffects on their operands.
> Also, that == should be commutative and transitive, that > and < should
> be transitive, and anti-commutative.
>
> Is this intuition written up in a PEP, or assumed to follow from the
> mathematical meanings?

Some of it is covered in the reference manual. E.g.

http://docs.python.org/reference/datamodel.html#object.__lt__

--
Robert Kern

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

== 3 of 3 ==
Date: Thurs, Feb 18 2010 8:58 am
From: Jean-Michel Pichavant


Andrey Fedorov wrote:
>
> It may be intuitive to you, but its not true, written down
> anywhere, nor assumed by the language, and the mathematical
> meaning of the operators doesn't matter to Python. Python
> purposefully does not enforce anything for these methods.
>
>
> Right, so neither is anything in PEP-8, but it's still considered
> "good practice". I'm running across examples like you gave (__sub__
> having a side-effect on the left-hand operand) in some code, and am
> trying to find concrete justification for avoiding it.
>
> - Andrey

This is all about communication. Python allows you to call a cat a dog.
You'll confuse everyone if you do so, but you can do it.
If your '-' operator is doing something else than returning the sub
result, it's your call, but do not expect people to get it easily. You'd
better be good at writting the documentation :-)

JM


==============================================================================
TOPIC: Is automatic reload of a module available in Python?
http://groups.google.com/group/comp.lang.python/t/71d2e8e4a38c3b1d?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Feb 18 2010 8:38 am
From: "R (Chandra) Chandrasekhar"


Arnaud Delobelle wrote:
> Here is a very simple way to improve what you do, which won't require
> you to change the way you work or to learn a new paradigm:
>
> Instead of testing your functions interactively, put your testing code
> in a file, e.g. 'program_tests.py'. Your can then type
>
> python program_tests.py
>
> at the shell interactive prompt. To perform the tests again, just
> re-execute that file. If your tests are divided into
> different units, you can put these in functions:
>
> def test_frobz():
> #testing code for frobzation of klops
>
> def test_frizz():
> #testing code for frizzment of frobzied klops
>
> # etc..
>
> So if you want to keep doing interactive tests, you can import
> program_tests and call whichever testing functions you want. You may
> even have arguments to those functions to test them with different
> parameters.
>
> I know some people will point at more 'pro' ways of testing but this has
> the merit of being very straightforward. Then when you move on to more
> sophisticated techniques, I think you will understand better the
> motivations behind them.

It took me some time to cotton on to exactly what you were saying, but
once I grasped it and tried it out, I found it very effective and
time-saving.

Thank you very much Arnaud.

--
Chandra


== 2 of 2 ==
Date: Thurs, Feb 18 2010 8:55 am
From: Simon Brunning


2010/2/17 Arnaud Delobelle <arnodel@googlemail.com>:
> I know some people will point at more 'pro' ways of testing but this has
> the merit of being very straightforward.  Then when you move on to more
> sophisticated techniques, I think you will understand better the
> motivations behind them.

Oh, I don't know. I like to think I'm fairly "pro" when it comes to
TDD, and this is exactly what I do - a unit test module run from the
shell.

--
Cheers,
Simon B.

==============================================================================
TOPIC: Why this doesn't work?
http://groups.google.com/group/comp.lang.python/t/698b29e4a1bebed4?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 18 2010 9:28 am
From: mk

Sorry to bother everyone again, but I have this problem bugging me:

#!/usr/bin/python -i

class Foo(object):

def nostat(self,val):
print val

nostat.__orig_get__ = nostat.__get__

@staticmethod
def nostatget(*args, **kwargs):
print 'args:', args, 'kwargs:', kwargs
nostat.__orig_get__(*args, **kwargs)

nostat.__get__ = nostatget
setattr(nostat,'__get__',nostatget)


f = Foo()

f.nostat('a')

print f.nostat.__get__ is f.nostat.__orig_get__


This produces:

a
False

I expected to see 'nostatget' output: nostat.__get__ = nostatget
obviously failed to replace this function's __get__ method.

The question is why? Isn't __get__ a normal attribute of a function nostat?

This is made so much weirder that nostat.__get__ is no longer original
__get__, so it looks like it should have been replaced, but if so, why
nostatget doesn't get called?

Regards,
mk


==============================================================================
TOPIC: NOW Watch Hot Sexy Star Aishwarya rai Bathing Videos In All Angles.
http://groups.google.com/group/comp.lang.python/t/daa1fed2a9f2aa91?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 18 2010 10:12 am
From: KD NUMBER 1


NOW Watch Hot Sexy Star Aishwarya rai Bathing Videos In All Angles at

http://blogcreationandhosting.blogspot.com/2009/11/earn-money-online.html

< Due to high sex content,I have hidden these videos inside an Image.
In that website,click on big vertical shining image on the right side
of website & watch the videos >

==============================================================================
TOPIC: What happened to pyjamas?
http://groups.google.com/group/comp.lang.python/t/4480c0898703d657?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Feb 18 2010 10:16 am
From: Daniel Fetchinson


Does anyone know what happened to pyjs.org ?

Cheers,
Daniel


--
Psss, psss, put it down! - http://www.cafepress.com/putitdown


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate