Re: List comprehension for testing **params

2012-11-11 Thread Steven D'Aprano
On Sun, 11 Nov 2012 18:21:32 -0600, Tim Chase wrote: > On 11/11/12 17:18, Steven D'Aprano wrote: >> but that leaves you with the next two problems: >> >> 2) Fixing the assert still leaves you with the wrong exception. You >> wouldn't raise a ZeroDivisionError, or a UnicodeDecodeError, or an >> IO

Re: A gnarly little python loop

2012-11-11 Thread rusi
On Nov 11, 3:58 am, Roy Smith wrote: > I'm trying to pull down tweets with one of the many twitter APIs.  The > particular one I'm using (python-twitter), has a call: > > data = api.GetSearch(term="foo", page=page) > > The way it works, you start with page=1.  It returns a list of tweets. > If the

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steven D'Aprano
On Mon, 12 Nov 2012 00:31:53 +, Oscar Benjamin wrote: [...] >>> You were right the first time, Chris. A point that happens to coincide >>> with the arbitrarily chosen origin is no more truthy or falsey than >>> any other. A vector of length 0 on the other hand is a very different >>> beast. >>

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Oscar Benjamin
On 12 November 2012 01:29, Mark Lawrence wrote: > On 12/11/2012 01:18, Oscar Benjamin wrote: >> >> On 12 November 2012 01:10, Mark Lawrence wrote: >>> >>> On 12/11/2012 00:31, Oscar Benjamin wrote: Plain wrong. Vectors are not defined *from any origin*. >>> >>> So when the Captain says

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
On Nov 11, 4:44 pm, Cameron Simpson wrote: > On 11Nov2012 11:16, Steve Howell wrote: > | On Nov 11, 10:34 am, Peter Otten <__pete...@web.de> wrote: > | > Steve Howell wrote: > | > > On Nov 11, 1:09 am, Paul Rubin wrote: > | > >> Cameron Simpson writes: > | > >> > | I'd prefer the original code

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Roy Smith
In article , Oscar Benjamin wrote: > But then I'm assuming you meant that 245 degrees was a bearing > relative to North. Was it supposed to be relative to my current angle? > Truthfully I wouldn't know what to do without asking the captain a > couple more questions. Granted, this requires some

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Mark Lawrence
On 12/11/2012 01:15, Roy Smith wrote: In article , Mark Lawrence wrote: On 12/11/2012 00:31, Oscar Benjamin wrote: Plain wrong. Vectors are not defined *from any origin*. So when the Captain says "full speed ahead, steer 245 degrees", you haven't the faintest idea where you're going, be

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Mark Lawrence
On 12/11/2012 01:18, Oscar Benjamin wrote: On 12 November 2012 01:10, Mark Lawrence wrote: On 12/11/2012 00:31, Oscar Benjamin wrote: Plain wrong. Vectors are not defined *from any origin*. So when the Captain says "full speed ahead, steer 245 degrees", you haven't the faintest idea where

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Roy Smith
In article , Mark Lawrence wrote: > On 12/11/2012 00:31, Oscar Benjamin wrote: > > > > Plain wrong. Vectors are not defined *from any origin*. > > > > So when the Captain says "full speed ahead, steer 245 degrees", you > haven't the faintest idea where you're going, because you have no origin?

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Oscar Benjamin
On 12 November 2012 01:10, Mark Lawrence wrote: > On 12/11/2012 00:31, Oscar Benjamin wrote: >> >> >> Plain wrong. Vectors are not defined *from any origin*. >> > > So when the Captain says "full speed ahead, steer 245 degrees", you haven't > the faintest idea where you're going, because you have

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Mark Lawrence
On 12/11/2012 00:31, Oscar Benjamin wrote: Plain wrong. Vectors are not defined *from any origin*. So when the Captain says "full speed ahead, steer 245 degrees", you haven't the faintest idea where you're going, because you have no origin? -- Cheers. Mark Lawrence. -- http://mail.python

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steve Howell
On Nov 11, 4:31 pm, Oscar Benjamin wrote: > On 11 November 2012 22:31, Steven D'Aprano > > Nonsense. The length and direction of a vector is relative to the origin. > > If the origin is arbitrary, as you claim, then so is the length of the > > vector. > > Wrong on all counts. Neither the length n

Re: A gnarly little python loop

2012-11-11 Thread Cameron Simpson
On 11Nov2012 11:16, Steve Howell wrote: | On Nov 11, 10:34 am, Peter Otten <__pete...@web.de> wrote: | > Steve Howell wrote: | > > On Nov 11, 1:09 am, Paul Rubin wrote: | > >> Cameron Simpson writes: | > >> > | I'd prefer the original code ten times over this inaccessible beast. | > >> > Me too.

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steve Howell
On Nov 10, 11:33 am, Jennie wrote: > What is the best solution to solve the following problem in Python 3.3? > > import math >  >>> class Point: > ...     def __init__(self, x=0, y=0): > ...         self.x = x > ...         self.y = y > ...     def __sub__(self, other): > ...         return Point(

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Oscar Benjamin
On 11 November 2012 22:31, Steven D'Aprano wrote: > On Sun, 11 Nov 2012 14:21:19 +, Oscar Benjamin wrote: > >> On 11 November 2012 02:47, Chris Angelico wrote: >>> On Sun, Nov 11, 2012 at 1:43 PM, Ian Kelly >>> wrote: On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico wrote: > I

Re: writing a csv file

2012-11-11 Thread Mark Lawrence
On 12/11/2012 00:05, ejsa...@alaska.edu wrote: with open("/home/eyalak/Documents/weather/weather.csv", "wb") as f: writer = csv.writer(f) table = soup.findAll("table")[3] #print table for tr in table.findAll("tr", valign="top"): a={x.string for x in tr.findA

Re: List comprehension for testing **params

2012-11-11 Thread Tim Chase
On 11/11/12 17:18, Steven D'Aprano wrote: > but that leaves you with the next two problems: > > 2) Fixing the assert still leaves you with the wrong exception. You > wouldn't raise a ZeroDivisionError, or a UnicodeDecodeError, or an IOError > would you? No of course not. So why are you suggestin

writing a csv file

2012-11-11 Thread ejsaiet
Hello, I have the script below, which it extracts NOAA data from HTML and is planed writes it to a CSV file. Here is the script: import urllib2 from bs4 import BeautifulSoup from time import localtime, strftime import csv #This script is intended to retrive NOAA data and apend it to a csv file.

Re: List comprehension for testing **params

2012-11-11 Thread Cantabile
Thanks everyone for your answers. That's much clearer now. I see that I was somehow fighting python instead of using it. Lesson learned (for the time being at least) :) I'll probably get back with more questions... Cheers, Cantabile -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension for testing **params

2012-11-11 Thread Steven D'Aprano
On Sun, 11 Nov 2012 18:37:05 -0500, Terry Reedy wrote: > or if you want them to be identified by keyword only (since 7 positional > args is a bit much) > > def __init__(self, smtp, login, *, subject, from, to, msg): > > (I forget when this feature was added) It's a Python 3 feature. -- Stev

Re: List comprehension for testing **params

2012-11-11 Thread Terry Reedy
On 11/11/2012 5:56 PM, Ian Kelly wrote: On Sun, Nov 11, 2012 at 3:24 PM, Cantabile wrote: I'd like to do something like that instead of the 'for' loop in __init__: assert[key for key in required if key in params.keys()] A list evaluates as true if it is not empty. As long as at least one of

Re: List comprehension for testing **params

2012-11-11 Thread Steven D'Aprano
On Sun, 11 Nov 2012 23:24:14 +0100, Cantabile wrote: > Hi, > I'm writing a small mail library for my own use, and at the time I'm > testing parameters like this: > > class Mail(object): > def __init__(self, smtp, login, **params) > blah > blah > required = ['Subjec

Re: List comprehension for testing **params

2012-11-11 Thread Tim Chase
> assert[key for key in required if key in params.keys()] ... > Could you explain why it doesn't work and do you have any idea of how it > could work ? Well, here, if any of the items are found, you get a list that is non-False'ish, so the assert passes. It sounds like you want all() (available

Re: List comprehension for testing **params

2012-11-11 Thread Ian Kelly
On Sun, Nov 11, 2012 at 3:24 PM, Cantabile wrote: > I'd like to do something like that instead of the 'for' loop in __init__: > > assert[key for key in required if key in params.keys()] A list evaluates as true if it is not empty. As long as at least one of the required parameters is present, th

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steven D'Aprano
On Sun, 11 Nov 2012 14:21:19 +, Oscar Benjamin wrote: > On 11 November 2012 02:47, Chris Angelico wrote: >> On Sun, Nov 11, 2012 at 1:43 PM, Ian Kelly >> wrote: >>> On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico >>> wrote: I would not assume that. The origin is a point, just like any

List comprehension for testing **params

2012-11-11 Thread Cantabile
Hi, I'm writing a small mail library for my own use, and at the time I'm testing parameters like this: class Mail(object): def __init__(self, smtp, login, **params) blah blah required = ['Subject', 'From', 'To', 'msg'] for i in required: if not i

Re: problem with module PyVisa

2012-11-11 Thread Jean Dubois
On 9 nov, 22:14, w...@mac.com wrote: > On Nov 9, 2012, at 3:43 PM, Jean Dubois wrote: > > > > > > > > > > > > > The error may be obvious but finding this file and how to install it > > is not unfortunately. > > It seems I have to install it from the National Instruments site but > > Debian Linux d

Re: A gnarly little python loop

2012-11-11 Thread Roy Smith
In article , Peter Otten <__pete...@web.de> wrote: > deque( > imap( > process, > chain.from_iterable( > takewhile(bool, imap(partial(api.GetSearch, term), count(1), > maxlen=0) > > ;) If I wanted STL, I would still be writing C++ :-) -- http://mail.pyth

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
On Nov 11, 10:34 am, Peter Otten <__pete...@web.de> wrote: > Steve Howell wrote: > > On Nov 11, 1:09 am, Paul Rubin wrote: > >> Cameron Simpson writes: > >> > | I'd prefer the original code ten times over this inaccessible beast. > >> > Me too. > > >> Me, I like the itertools version better.  The

Re: A gnarly little python loop

2012-11-11 Thread Peter Otten
Steve Howell wrote: > On Nov 11, 1:09 am, Paul Rubin wrote: >> Cameron Simpson writes: >> > | I'd prefer the original code ten times over this inaccessible beast. >> > Me too. >> >> Me, I like the itertools version better. There's one chunk of data >> that goes through a succession of transform

Re: logging, can one get it to email messages over a certain level?

2012-11-11 Thread Steve Howell
On Nov 11, 9:48 am, tinn...@isbd.co.uk wrote: > I'm sure this must be possible but at the moment I can't see how to do it. > > I want to send an E-Mail when the logging module logs a message above > a certain level (probably for ERROR and CRITICAL messages only). > > I.e. I want some sort of hook t

logging, can one get it to email messages over a certain level?

2012-11-11 Thread tinnews
I'm sure this must be possible but at the moment I can't see how to do it. I want to send an E-Mail when the logging module logs a message above a certain level (probably for ERROR and CRITICAL messages only). I.e. I want some sort of hook that will be called when these messages are logged (I can

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-11 Thread Steve Howell
On Nov 9, 4:48 pm, bruceg113...@gmail.com wrote: > Is there a simpler way to modify all arguments in a function before using the > arguments? > > For example, can the below code, in the modify arguments section be made into > a few statements? > >     def someComputation (aa, bb, cc, dd, ee, ff,

Re: Question about email.message_from_string() and Message objects

2012-11-11 Thread tinnews
tinn...@isbd.co.uk wrote: > I'm a little confused about the relationship between the Python > email.parser convenience function email.message_from_string() and the > mailbox.Message objects. > > If I want an mailbox.mboxMessage given the message as a stream of text > is the right way to do it as f

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
On Nov 11, 1:09 am, Paul Rubin wrote: > Cameron Simpson writes: > > | I'd prefer the original code ten times over this inaccessible beast. > > Me too. > > Me, I like the itertools version better.  There's one chunk of data > that goes through a succession of transforms each of which > is very str

Re: A gnarly little python loop

2012-11-11 Thread Steve Howell
On Sunday, November 11, 2012 1:54:46 AM UTC-8, Peter Otten wrote: > Paul Rubin wrote: > > > > > Cameron Simpson writes: > > >> | I'd prefer the original code ten times over this inaccessible beast. > > >> Me too. > > > > > > Me, I like the itertools version better. There's one chunk of da

Re: Printing characters outside of the ASCII range

2012-11-11 Thread Lele Gaifax
danielk writes: > Ian's solution gives me what I need (thanks Ian!). But I notice a > difference between '__str__' and '__repr__'. > > class Pytest(str): > def __init__(self, data = None): > if data == None: data = "" > self.data = data > > def __repr__(self): > re

Question about email.message_from_string() and Message objects

2012-11-11 Thread tinnews
I'm a little confused about the relationship between the Python email.parser convenience function email.message_from_string() and the mailbox.Message objects. If I want an mailbox.mboxMessage given the message as a stream of text is the right way to do it as follows (or at least a reasonable way t

Re: Printing characters outside of the ASCII range

2012-11-11 Thread Thomas Rachel
Am 09.11.2012 18:17 schrieb danielk: I'm using this character as a delimiter in my application. Then you probably use the *byte* 254 as opposed to the *character* 254. So it might be better to either switch to byte strings, or output the representation of the string instead of itself. So d

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Oscar Benjamin
On 11 November 2012 02:47, Chris Angelico wrote: > On Sun, Nov 11, 2012 at 1:43 PM, Ian Kelly wrote: >> On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico wrote: >>> I would not assume that. The origin is a point, just like any other. >>> With a Line class, you could deem a zero-length line to be l

Re: Printing characters outside of the ASCII range

2012-11-11 Thread danielk
On Friday, November 9, 2012 5:11:12 PM UTC-5, Ian wrote: > On Fri, Nov 9, 2012 at 2:46 PM, danielk wrote: > > > D:\home\python>pytest.py > > > Traceback (most recent call last): > > > File "D:\home\python\pytest.py", line 1, in > > > print(chr(253).decode('latin1')) > > > AttributeErro

Re: A gnarly little python loop

2012-11-11 Thread Peter Otten
Paul Rubin wrote: > Cameron Simpson writes: >> | I'd prefer the original code ten times over this inaccessible beast. >> Me too. > > Me, I like the itertools version better. There's one chunk of data > that goes through a succession of transforms each of which > is very straightforward. [Steve

Re: Is there a simpler way to modify all arguments in a function before using the arguments?

2012-11-11 Thread Peter Otten
Aahz wrote: > In article , > Peter Otten <__pete...@web.de> wrote: >>Miki Tebeka wrote: >> Is there a simpler way to modify all arguments in a function before using the arguments? >>> >>> You can use a decorator: >>> >>> from functools import wraps >>> >>> def fix_args(fn): >>> @w

Re: A gnarly little python loop

2012-11-11 Thread Paul Rubin
Cameron Simpson writes: > | I'd prefer the original code ten times over this inaccessible beast. > Me too. Me, I like the itertools version better. There's one chunk of data that goes through a succession of transforms each of which is very straightforward. -- http://mail.python.org/mailman/lis

Re: A gnarly little python loop

2012-11-11 Thread Cameron Simpson
On 11Nov2012 08:56, Stefan Behnel wrote: | Steve Howell, 11.11.2012 04:03: | > On Nov 10, 2:58 pm, Roy Smith wrote: | >> page = 1 | >> while 1: | >> r = api.GetSearch(term="foo", page=page) | >> if not r: | >> break | >> for tweet in r: | >>

Re: KAJOL SEX VIDEOS'''''''''''''''''''

2012-11-11 Thread nagurbasha55
On Thursday, August 2, 2012 10:05:25 PM UTC+5:30, devi wrote: > KAJAL SEX VIDEOS > > http://maxworkerds.co.cc -- http://mail.python.org/mailman/listinfo/python-list

Re: A gnarly little python loop

2012-11-11 Thread Stefan Behnel
Steve Howell, 11.11.2012 04:03: > On Nov 10, 2:58 pm, Roy Smith wrote: >> I'm trying to pull down tweets with one of the many twitter APIs. The >> particular one I'm using (python-twitter), has a call: >> >> data = api.GetSearch(term="foo", page=page) >> >> The way it works, you start with page=1