Re: Windows service in production?

2011-08-18 Thread Adam Jorgensen
Yeah, we run our Python App as a service under Windows.

You can look at the open-souce part of our product using
http://trac.sjsoft.com/browser
If you look into the code you should be able to find some stuff to do with
services.

Specficially, look in trunk/j5/src/j5/OS/WinService.py

On 19 August 2011 07:00, Stephen Hansen  wrote:

> On 8/15/11 9:32 PM, snorble wrote:
> > Anyone know of a Python application running as a Windows service in
> > production? I'm planning a network monitoring application that runs as
> > a service and reports back to the central server. Sort of a heartbeat
> > type agent to assist with "this server is down, go check on it" type
> > situations.
> >
> > If using Visual Studio and C# is the more reliable way, then I'll go
> > that route. I love Python, but everything I read about Python services
> > seems to have workarounds ahoy for various situations (or maybe that's
> > just Windows services in general?). And there seem to be multiple
> > layers of workarounds, since it takes py2exe (or similar) and there
> > are numerous workarounds required there, depending on which libraries
> > and functionality are being used. Overall, reading about Windows
> > services in Python is not exactly a confidence inspiring experience.
> > If I knew of a reference example of something reliably running in
> > production, I'd feel better than copying and pasting some code from a
> > guy's blog.
>
> Belatedly: I run a few quite major windows services which are installed
> at various customer sites in production, and we have no issues with it
> being a windows service.
>
> I basically only ever ran into two problems:
>
>  1. The lack of a console. Your service flat out /does not have/ a
> console, which is a slightly weird state to be in: writing to sys.stdout
> will fail. A print statement left in can crash things up -- even if in
> third-party code.
>
>Now, once you realize this is there, its easy to "fix". I end up
> doing something like this very early on in processing:
>
>class FakeFile:
>def __init__(self, fp):
>self._fp = fp
>def write(self, data):
>try:
>self._fp.write(data)
>except:
>pass
>
># repeat with flush()
>
>sys.stdout = FakeFile(sys.stdout)
>sys.stderr = FakeFile(sys.stderr)
>
>That way it'll run from a regular terminal fine and write out fine,
> but if any stray attempts to print are left in, things will pass through
> fine when its running as a service.
>
>  2. Importing modules with the same names as dlls in system32 can go
> awry. I don't know if this is still there, I last touched this part of
> our code a long, long, long time ago: but my service does some manual
> PATH / PYTHONHOME / PYTHONPATH fiddling to take care of it. Its easy
> to do.
>
> It worked fine, and was stable and once going, everything worked fine.
>
> Ultimately, I have since abandoned running things as a real service
> directly, and wrote a "Metaservice" application we use in our company
> instead. It runs as a service, and executes any random series of
> programs beneath it, creating JOB's for each so any subprocesses of they
> launch all get killed together cleanly, and handling dependencies via
> between them through various means, and stuff like that. I just got
> tired of dealing with windows stuff, so. :)
>
> --
>
>   Stephen Hansen
>   ... Also: Ixokai
>   ... Mail: me+list/python (AT) ixokai (DOT) io
>   ... Blog: http://meh.ixokai.io/
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2011-08-18 Thread Stephen Hansen
On 8/15/11 9:32 PM, snorble wrote:
> Anyone know of a Python application running as a Windows service in
> production? I'm planning a network monitoring application that runs as
> a service and reports back to the central server. Sort of a heartbeat
> type agent to assist with "this server is down, go check on it" type
> situations.
> 
> If using Visual Studio and C# is the more reliable way, then I'll go
> that route. I love Python, but everything I read about Python services
> seems to have workarounds ahoy for various situations (or maybe that's
> just Windows services in general?). And there seem to be multiple
> layers of workarounds, since it takes py2exe (or similar) and there
> are numerous workarounds required there, depending on which libraries
> and functionality are being used. Overall, reading about Windows
> services in Python is not exactly a confidence inspiring experience.
> If I knew of a reference example of something reliably running in
> production, I'd feel better than copying and pasting some code from a
> guy's blog.

Belatedly: I run a few quite major windows services which are installed
at various customer sites in production, and we have no issues with it
being a windows service.

I basically only ever ran into two problems:

 1. The lack of a console. Your service flat out /does not have/ a
console, which is a slightly weird state to be in: writing to sys.stdout
will fail. A print statement left in can crash things up -- even if in
third-party code.

Now, once you realize this is there, its easy to "fix". I end up
doing something like this very early on in processing:

class FakeFile:
def __init__(self, fp):
self._fp = fp
def write(self, data):
try:
self._fp.write(data)
except:
pass

# repeat with flush()

sys.stdout = FakeFile(sys.stdout)
sys.stderr = FakeFile(sys.stderr)

That way it'll run from a regular terminal fine and write out fine,
but if any stray attempts to print are left in, things will pass through
fine when its running as a service.

  2. Importing modules with the same names as dlls in system32 can go
awry. I don't know if this is still there, I last touched this part of
our code a long, long, long time ago: but my service does some manual
PATH / PYTHONHOME / PYTHONPATH fiddling to take care of it. Its easy
to do.

It worked fine, and was stable and once going, everything worked fine.

Ultimately, I have since abandoned running things as a real service
directly, and wrote a "Metaservice" application we use in our company
instead. It runs as a service, and executes any random series of
programs beneath it, creating JOB's for each so any subprocesses of they
launch all get killed together cleanly, and handling dependencies via
between them through various means, and stuff like that. I just got
tired of dealing with windows stuff, so. :)

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



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


Re: List spam

2011-08-18 Thread Terry Reedy

On 8/18/2011 10:10 PM, Steven D'Aprano wrote:


Now, an ISP might not have the bandwidth to supply all the needs of their
customers, that's a separate issue. But complaining that the problem is
specifically because they use bittorrent, as if it would disappear if they
changed to HTTP, is bogus.


Or changed to getting their movies via NetFlix, for instance, as Comcast 
*is* complaining about. I believe their real complaint is that they are 
only paid to move bits, and not for originating them, even though they 
already get several times as much per month as NetFlix.


--
Terry Jan Reedy

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


Re: [Python] Re: Windows service in production?

2011-08-18 Thread Chris Gonnerman
Chiming in late here, but I've been running a very simple Python service 
for some time now on a number of computers.  It's my Raw Print Server, 
available at 
http://newcenturycomputers.net/projects/rawprintserver.html, and I have 
instructions on the page for installing the Windows service version. 
It's really quite simple to do in plain Python; the only reason to use 
py2exe is if you don't want to install a full Python interpreter on the 
computer.  But since I generally do anyway, it doesn't matter to me.


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


Re: Help with regular expression in python

2011-08-18 Thread Josh Benner
On Thu, Aug 18, 2011 at 4:03 PM, Matt Funk  wrote:

> Hi guys,
>
> thanks for the suggestions. I had tried the white space before as well (to
> no
> avail). So here is the expression i am using (based on suggestions), but
> still
> no success:
>
> instance_linetype_pattern_str =\
>r'(([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+))?\s+){32}(.+)'
> instance_linetype_pattern = re.compile(instance_linetype_pattern_str)
> results = instance_linetype_pattern.findall(line)
> print "results: "; print results
>
>
> The match i get is:
> results:
> [('2.199000e+01 ', '2.199000', '.199000', 'e+01', ': (instance: 0)\t:\tsome
> description')]
>
>
> btw: The line to be matched (given below) is ONE line. There are no line
> breaks (even though my email client adds them).
>
>
> matt
>
>
>
If a group matches multiple times, only the last match is accessible.  The
matches returned represent the inner groupings of the last match found.

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


Check email header for RFC 822 standard and match emails between imap servers.

2011-08-18 Thread Vincent Davis
The sort story, I have been attempting to use the Google Migration assistant
to migrate emails from one google account to another, about 80,000 emails.
I have two problems.
1. Many emails that fail to transfer because of errors like "Invalid RFC 822
Message: Date header "Mon Feb 05 22:07:16 2007" is invalid." See
full error below.
 emails that.
2. I need to delete the emails from the old account that have been
transferred.

And the Two question are:
1:
I am able to connect and get an email. But I am not clear how I would check
that the header is valid or identify the problem.
grl = imaplib.IMAP4_SSL('imap.gmail.com', 993)
grl.login('n...@domain.com', 'password')
grl.fetch(17006, 'uid')
# So now I have an email how do I check the header, I know how to view it
but not check it for RFC 822.

2:
Since I don't know which emails have been transferred I want to delete all
the email that have. To be more correct I don't know which ones on the old
account, when they are moved to the new account they get the label as
transferred. How should I compare emails? The uid is different on each
server so I think using the TO: FROM: and DATE: TIME: would work.
How do I compare emails in this way?
How to I get the TO: FROM: DATE: TIME: from one email to reach for the same
email in the other account.


Sample error from google migration app.

2011-08-16T16:47:47.141-06:00  808 E:Network
ExchangeMigration!WinHttp::ExecuteHttpRequestIStreamResponse @ 696 (
gmetan...@domain.com )> Response:

Invalid RFC 822 Message: Date header "Mon Feb 05 22:07:16 2007" is
invalid.

2011-08-16T16:47:47.141-06:00  808 E:Migration
ExchangeMigration!EmailUploader::HandleStatus @ 462
(gmetan...@domain.com)>
Permanent Message Failure, skipping the message!.

2011-08-16T16:47:47.328-06:00  808 E:Migration
ExchangeMigration!IMAPMessageWrapper::GetMessageSentTime @ 154 (
gmetan...@domain.com )> Failed with 0x80004005, last
successful line = 151.

2011-08-16T16:47:47.328-06:00  808 E:Migration
ExchangeMigration!IMAPMessageWrapper::GetMessageReceivedTime @ 170 (
gmetan...@domain.com )> Failed with 0x80004001, last
successful line = 168.

2011-08-16T16:47:47.328-06:00  808 E:Migration
ExchangeMigration!GetMessageDescription @ 198
(gmetan...@domain.com)>
Sent: 2011-08-16T22:47:47.000Z. Received: 2011-08-16T22:47:47.000Z. Size:
196114. Subject RE: ppt templates.


-- 
Thanks
Vincent Davis
720-301-3003
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows service in production?

2011-08-18 Thread Grummble

On 08/16/2011 12:32 AM, snorble wrote:

Anyone know of a Python application running as a Windows service in
production? I'm planning a network monitoring application that runs as
a service and reports back to the central server. Sort of a heartbeat
type agent to assist with "this server is down, go check on it" type
situations.



I modified something similar to:
http://code.activestate.com/recipes/551780-win-services-helper/
and it was in production for several years without any issues.

Specifically it processed orders generated by a customer's MRP system, 
delivered to us via LPR, then processed into a format our in house 
windows hosted picking/shipping system could digest. Availability was a 
*major* requirement, and it worked flawlessly.




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


Re: List spam

2011-08-18 Thread Steven D'Aprano
Alain Ketterlin wrote:

> "Jason Staudenmayer"  writes:
> 
>> I really like this list as part of my learning tools but the amount of
>> spam that I've been getting from it is CRAZY. Doesn't anything get
>> scanned before it sent to the list?
> 
> I'm using nntp to read this newsgroup (through an academic server).
> No spam at all.


I'm also using nntp (Usenet) and see very little spam. There was a flurry of
about ten *extremely* obnoxious pr0n spams in a row, and the occasional odd
one here or there, but generally I see hardly any.

It is ironic that some people say that the solution to the spam problem is
to move to Google Groups, because most of the spam comes *from* Google
Groups. 


-- 
Steven

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


Re: Measure the amount of memory used?

2011-08-18 Thread MrJean1
Take a look it this recipe (for Linux only):



/Jean

On Aug 18, 8:08 am, Jack Bates  wrote:
> I wrote a content filter for Postfix with 
> Python,https://github.com/jablko/cookie
>
> It should get started once, and hopefully run for a long time - so I'm
> interested in how it uses memory:
>
>  1) How does the amount of memory used change as it runs?
>
>  2) How does the amount of memory used change as I continue to hack on
> it, and change the code?
>
> My naive thought was that I'd periodically append to a file, the virtual
> memory size from /proc/[pid]/stat and a timestamp. From this a could
> make a graph of the amount of memory used as my content filter runs, and
> I could compare two graphs to get a clue whether this amount changed as
> I continue to hack
>
>  - but some Googling quickly revealed that measuring memory is actually
> quite complicated? Neither the virtual memory size nor the "resident set
> size" accurately measure the amount of memory used by a process
>
> Has anyone else measured the memory used by a Python program? How did
> you do it?

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


Re: List spam

2011-08-18 Thread Steven D'Aprano
gene heskett wrote:


>> But I'd like to return the question. What's wrong with nntp?
> 
> The sheer volume of traffic eats 99% of an ISP's bandwidth.

I doubt that very much, particularly if the ISP drops the binary newsgroups.

My ISP, Internode, has provided nntp for many years. For a while a few years
back they dropped binary newsgroups, but thay have brought them back. They
wouldn't do that if there wasn't a clear demand for it, and if they didn't
believe that on the balance, providing free Usenet access to customers
didn't pay for itself.

These days, many big ISPs complain about bittorrent using up their
bandwidth. I call shenanigans. That's like my local bottle shop complaining
that 99% of their sales comes from wine, and that stocking all that wine
takes away valuable shelf space that could be used for imported Romanian
beers and Chinese whiskey (no offense to anyone who likes Romanian beer or
Chinese whiskey). It's a nonsense claim -- if your customers want to use
the bandwidth they're paying for on bittorrent, or any other protocol, what
difference does it make to you? It's not like you have to install a second
Interweb tube just for bittorrent, or that bittorrent packets cost more
than HTTP packets. Fer fecks sake, the ISP doesn't even have to run a
bittorrent server! It's practically free money to the ISP, packets go in,
packets go out, they don't have to do a bloody thing with them.

Now, an ISP might not have the bandwidth to supply all the needs of their
customers, that's a separate issue. But complaining that the problem is
specifically because they use bittorrent, as if it would disappear if they
changed to HTTP, is bogus.



-- 
Steven

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


Re: 'super' object has no attribute '__setitem__'

2011-08-18 Thread Eric Snow
On Thu, Aug 18, 2011 at 7:44 PM, luvspython  wrote:
> I'm using Python 2.7 and the code below fails at the 'super' statement
> in the __setitem__ function in the HistoryKeeper class.  The error is:
>   'super' object has no attribute '_setitem__'
>
> Can anyone please tell me why and how to fix it?   (I've googled
> endlessly and I don't see the problem.)
>
> [The code will seem silly as it is, because it's pared down to show
> the example.  The goal is that multiple classes, like the Vehicle
> class below, will inherit HistoryKeeper.  History keeper overloads
> __setitem__ and will eventually keep a running history every time an
> attribute of any of the inheriting classes is changed.]
>
> Thanks in advance 
>
>
> class HistoryKeeper(object):
>    def __init__(self, args):
>        for arg, value in args.items():
>            if arg != 'self':
>                self.__setitem__(arg, value)
>
>    def __setitem__(self, item, value):
>        super(HistoryKeeper, self).__setitem__(item, value)
>
>
> class Vehicle(HistoryKeeper):
>    def __init__(self, tag, make, model):
>        args = locals()
>        super(Vehicle, self).__init__(args)
>
>
> if __name__ == "__main__":
>    car = Vehicle('TAG123', 'FORD', 'Model A')
>    print car.make

Did you mean to use __setattr__ instead?  object, the base class of
HistoryKeeper, does not have a __setitem__ method, hence the
AttributeError.  super() is a proxy for the next class in the MRO,
typically the base class of your class.

Keep in mind that  is equivalent to
.  However, 
is equivalent to .

see:

http://docs.python.org/reference/datamodel.html#object.__setattr__
http://docs.python.org/reference/datamodel.html#object.__setitem__
http://docs.python.org/library/functions.html#super

-eric

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


Re: 'super' object has no attribute '__setitem__'

2011-08-18 Thread Benjamin Peterson
luvspython  gmail.com> writes:
> def __setitem__(self, item, value):
> super(HistoryKeeper, self).__setitem__(item, value)

object has no __setitem__. Are you looking for __setattr__?

> 
> class Vehicle(HistoryKeeper):
> def __init__(self, tag, make, model):
> args = locals()

This is hideous by the way.




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


'super' object has no attribute '__setitem__'

2011-08-18 Thread luvspython
I'm using Python 2.7 and the code below fails at the 'super' statement
in the __setitem__ function in the HistoryKeeper class.  The error is:
   'super' object has no attribute '_setitem__'

Can anyone please tell me why and how to fix it?   (I've googled
endlessly and I don't see the problem.)

[The code will seem silly as it is, because it's pared down to show
the example.  The goal is that multiple classes, like the Vehicle
class below, will inherit HistoryKeeper.  History keeper overloads
__setitem__ and will eventually keep a running history every time an
attribute of any of the inheriting classes is changed.]

Thanks in advance 


class HistoryKeeper(object):
def __init__(self, args):
for arg, value in args.items():
if arg != 'self':
self.__setitem__(arg, value)

def __setitem__(self, item, value):
super(HistoryKeeper, self).__setitem__(item, value)


class Vehicle(HistoryKeeper):
def __init__(self, tag, make, model):
args = locals()
super(Vehicle, self).__init__(args)


if __name__ == "__main__":
car = Vehicle('TAG123', 'FORD', 'Model A')
print car.make
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert a list of strings into a list of variables

2011-08-18 Thread Steven D'Aprano
Chris Angelico wrote:

> On Thu, Aug 18, 2011 at 5:09 PM, John Gordon  wrote:
>> for x in list_of_strings:
>> list_of_variables.append(eval(x))
>>
> 
> If this really is what you need, you can simplify it by using the
> globals() dictionary - it's a regular dictionary whose contents are
> all the global variables in your current module. Inside a function,
> use locals() instead.

You can use locals outside of a function too, because it just returns
globals().

Lookup of names in locals/globals is much safer than eval, particularly if
there is any risk that the list of names comes from an untrusted or 
potentially hostile source.

list_of_strings = ['red', 'blue', 
'__import__("os").system("echo I just p0wned your system")',
'green', 'yellow']

(The simplest way out of a billion to cause grief.)

Code injection attacks are the first and second most common form of security
vulnerability, ahead of even buffer overflows. Please don't add to the
list.

http://cwe.mitre.org/top25/?2011

(Oh, and if you think that protecting against code injection attacks while
still using eval or exec is simple, please step away from the keyboard.)



-- 
Steven

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


nose + processes + xunit

2011-08-18 Thread Noon Silk
Has anyone had any trouble with this setup?

I am in a situation where, the tests run fine when I don't include
"--processes=N", however, when I *do* do that, they exit early?

The reason I think they exit, is that I'm actually running a different
executable, and I load it like so:

retcode = subprocess.call(["start /wait myprog.exe"], shell=True)

Now, note that this is on Windows 7; the "start /wait" does basically
exactly what you think. *And indeed it operates correctly in a single
process*, but when nose tries to run multi-process, it fails to block,
and the test executes far sooner than it should.

Indeed, Nose claims that it ran 0 tests, when it actually at least ran
1! So, I think the myprog.exe is sending some signal to kill it.

It so happens that start has a "/B"  parameter that may also help
here, but actually it doesn't. The result is that I don't get any
further output from the test (that is, the xunit xml isn't generated,
and even the console doesn't report anything as having happened).

Interested in thoughts ...

-- 
Noon Silk

Fancy a quantum lunch? http://groups.google.com/group/quantum-lunch?hl=en

"Every morning when I wake up, I experience an exquisite joy — the joy
of being this signature."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Chris Angelico
On Fri, Aug 19, 2011 at 12:03 AM, Seebs  wrote:
> I don't.  If I want to get started in a language, I might well want to
> read about it a bit, and maybe ask questions like "what is a good book
> for me to start with?"
>
> If I have to know the language to do that, well...
>

When I start with a language, I want two things: a
compiler/interpreter, and online documentation. (A book would be
equivalent to the latter, but I tend to prefer to read things online.)
Asking questions comes later; first, I want to get a comprehension for
the language's features. By the time I join a list like this, I want
to be able to understand the answers I get.

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


Re: Word Perfect integration

2011-08-18 Thread Seebs
On 2011-08-18, Ethan Furman  wrote:
> Yes, we still use Word Perfect, and will as long as it is available. 
> The ability to see the codes in use (bold, margins, columns, etc) has so 
> far been unequaled in anything else I have looked at.

I have used other software that had this functionality, but not so much
lately.  (Although it appears that PageStream still does this, which is
totally of relevance to someone, I'm sure.)

But yeah, that was an AMAZING feature, and not having it is one of the
reasons I'm so often unable to get things done in MS Word.

Sadly, Corel dropped Mac and Linux support, and I don't do real work on
Windows, so WP has been off my list for a long time now.  :(

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Seebs
On 2011-08-18, Prasad, Ramit  wrote:
>>> Or 'Enter a Python keyword (search the tutorial if you do not know any)
>>> '
>>
>>Sounds good, but now you've trained the spammer who is without a doubt 
>>watching this list.
> 
> Teach them Python before they can post, I like it!

I don't.  If I want to get started in a language, I might well want to
read about it a bit, and maybe ask questions like "what is a good book
for me to start with?"

If I have to know the language to do that, well...

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Word Perfect integration

2011-08-18 Thread Rhodri James
On Thu, 18 Aug 2011 20:24:17 +0100, Ethan Furman   
wrote:



Alec Taylor wrote:

wow, people still use WordPerfect?


Them's fightin' words right there!  :)

Yes, we still use Word Perfect, and will as long as it is available. The  
ability to see the codes in use (bold, margins, columns, etc) has so far  
been unequaled in anything else I have looked at.


I take it you haven't looked at TeX, then? :-)

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


Re: List spam

2011-08-18 Thread Rhodri James
On Thu, 18 Aug 2011 16:00:40 +0100, Jason Staudenmayer  
 wrote:



I'm a strong opponent of dropping any email with a
stupid footer spam.


By contrast, an excessively large sig (particularly an excessively large  
sig without a proper separator) is something that's guaranteed to get on  
my wick, and usually indicates someone I don't want to bother listening  
to.  Thank you for trimming it.


I'm reading this as the comp.lang.python newsgroup, straight off an NNTP  
server, and to be honest I'm not getting the level of spam you are talking  
about.  There's some, sure -- usually for Bollywood actress pictures --  
but not enough to make me worry about Opera's relatively poor newsgroup  
filtering facilities.  If you're getting as much as you say, it's being  
injected on the mail side of the gateway somehow.


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


Re: Help with regular expression in python

2011-08-18 Thread Matt Funk
Hi guys,

thanks for the suggestions. I had tried the white space before as well (to no 
avail). So here is the expression i am using (based on suggestions), but still 
no success:

instance_linetype_pattern_str =\
r'(([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+))?\s+){32}(.+)'
instance_linetype_pattern = re.compile(instance_linetype_pattern_str)
results = instance_linetype_pattern.findall(line)
print "results: "; print results


The match i get is:
results: 
[('2.199000e+01 ', '2.199000', '.199000', 'e+01', ': (instance: 0)\t:\tsome 
description')]


btw: The line to be matched (given below) is ONE line. There are no line 
breaks (even though my email client adds them).


matt


On Thursday, August 18, 2011, Vlastimil Brom wrote:
> 2011/8/18 Matt Funk :
> > Hi,
> > i am sorry if this doesn't quite match the subject of the list. If
> > someone takes offense please point me to where this question should go.
> > Anyway, i have a problem using regular expressions. I would like to
> > match the line:
> > 
> > 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01
> > 1.914000e+01 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01
> > 2.209000e+01 2.376000e+01 2.158000e+01 2.177000e+01 2.152000e+01
> > 2.267000e+01 1.084000e+01 1.671000e+01 1.888000e+01 1.854000e+01
> > 2.064000e+01 2.00e+01 2.20e+01 2.139000e+01 2.137000e+01
> > 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.15e+01
> > 2.15e+01 2.199000e+01 : (instance: 0)   :   some description
> > 
> > The number of floats can vary (in this example there are 32). So what i
> > thought i'd do is the following:
> > instance_linetype_pattern_str =
> > '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?) {32}'
> > instance_linetype_pattern = re.compile(instance_linetype_pattern_str)
> > Basically the expression in the first major set of paranthesis matches a
> > scientific number format. The '{32}' is supposed to match the previous 32
> > times. However, it doesn't. I  can't figure out why this does not work.
> > I'd really like to understand it if someone can shed light on it.
> > 
> > thanks
> > matt
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> 
> Hi,
> the already suggested handling of whitespace with \s+ etc. at the end
> of the parenthesised patern should help;
> furhtermore, if you are using this pattern in the python source, you
> should either double all backslashes or use a raw string for the
> pattern - with r prepended before the opening quotation mark:
> pattern_str = r"..."
> in order to handle backslashes literally and not as escape character.
> hth,
> vbr

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


Re: List spam

2011-08-18 Thread Ben Finney
gene heskett  writes:

> Short answer is to disconnect the the NNTP link and make this list
> into a REAL mailing list. Subscribers only, or get past a GOOD
> captcha.

Many of the more valuable contributors post via NNTP, which does not
require mailing list subscription nor CAPTCHA.

One of the compelling features of this forum is that newcomers to Python
can post here without the hurdles you're describing.

-- 
 \   “We spend the first twelve months of our children's lives |
  `\  teaching them to walk and talk and the next twelve years |
_o__)   telling them to sit down and shut up.” —Phyllis Diller |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: List spam

2011-08-18 Thread Prasad, Ramit
>> Or 'Enter a Python keyword (search the tutorial if you do not know any)
>> '
>
>Sounds good, but now you've trained the spammer who is without a doubt 
>watching this list.

Teach them Python before they can post, I like it!

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert a list of strings into a list of variables

2011-08-18 Thread AB
Hi,

If the «variables» are named attributes you can use getattr.


#
class colors:
red=1
green=2
blue=3

c=colors()

a=['red','green','blue']

for v in a:
print v,getattr(c,v)
#---

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


Re: pairwise combination of two lists

2011-08-18 Thread SigmundV
On Aug 17, 9:22 pm, Yingjie Lin  wrote:
> I found zip() but it only gives [('a', '1'), ('b', '2')],  not exactly what I 
> am looking for.

Yet, if you feed the zip into a list comprehension you get what you
want:

li3 = [''.join(l) for l in zip(li1,li2)]


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


Re: Help with regular expression in python

2011-08-18 Thread Vlastimil Brom
2011/8/18 Matt Funk :
> Hi,
> i am sorry if this doesn't quite match the subject of the list. If someone
> takes offense please point me to where this question should go. Anyway, i have
> a problem using regular expressions. I would like to match the line:
>
> 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01
> 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01
> 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01
> 1.888000e+01 1.854000e+01 2.064000e+01 2.00e+01 2.20e+01 2.139000e+01
> 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.15e+01
> 2.15e+01 2.199000e+01 : (instance: 0)       :       some description
>
> The number of floats can vary (in this example there are 32). So what i 
> thought
> i'd do is the following:
> instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)
> {32}'
> instance_linetype_pattern = re.compile(instance_linetype_pattern_str)
> Basically the expression in the first major set of paranthesis matches a
> scientific number format. The '{32}' is supposed to match the previous 32
> times. However, it doesn't. I  can't figure out why this does not work. I'd
> really like to understand it if someone can shed light on it.
>
> thanks
> matt
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Hi,
the already suggested handling of whitespace with \s+ etc. at the end
of the parenthesised patern should help;
furhtermore, if you are using this pattern in the python source, you
should either double all backslashes or use a raw string for the
pattern - with r prepended before the opening quotation mark:
pattern_str = r"..."
in order to handle backslashes literally and not as escape character.
hth,
vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread gene heskett
On Thursday, August 18, 2011 05:18:42 PM Terry Reedy did opine:

> On 8/18/2011 12:14 PM, gene heskett wrote:
> > into a REAL mailing list.  Subscribers only, or get past a GOOD
> > captcha.
> 
> I just had an idea. Ask 'What is python? __" or "What
> can you do with a python?' with a free-form fill in the blank answer.
> Look for 'computer', 'program' or 'language' in the response. 'snake'
> fails the test.
> 
> Or 'Enter a Python keyword (search the tutorial if you do not know any)
> '

Sounds good, but now you've trained the spammer who is without a doubt 
watching this list.
  
Cheers, gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
QOTD:
"I may not be able to walk, but I drive from the sitting position."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to build python using visual studio 2005?

2011-08-18 Thread Brian Curtin
On Wed, Aug 17, 2011 at 13:16, smith jack  wrote:

> anybody here have build it correctly?
> how to make a msi file just as the official site did?
> is there any detailed tutorial online?


We're currently shipping CPython built on VS 2008, but I do know of people
building with 2005. How they do it, I'm not entirely sure, but all of the
related files are available -- see the PC folder for previous versions of
project and solution files.

As for making the MSI, from a source checkout, the Tools/msi/msi.py script
is how its generated, but there isn't currently any documentation or
tutorial. What I'd do is start by running that script, then piece together
what you're missing in order to get it working. You'll need a built Python
including the third-party things like tkinter in order for it to work. I
know it needs pywin32, but I can't remember anything else I needed off the
top of my head, but I have gotten it to work before.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to print non-printable chars??

2011-08-18 Thread coldpizza
On Aug 13, 7:59 am, Julio Cesar Rodriguez Cruz
 wrote:
> Hi all,
> If I open an .exe file in any text editor I get lot of odd chars,
> what I want is to know how to output those chars if I have the hexadecimal
> code. I found out how to do the reverse process with the quopri module,
>
> i.e.:>>> import quopri
> >>> quopri.encodestring('ñè ')
> '=F1=E8=18'
> >>> quopri.decodestring('=F1=E8=18')
>
> '\xf1\xe8\x18'
>
> but how to do the reverse? ...gived '\xf1\xe8\x18', print 'ñè '
>
> any tips?
> thanks
> Julio Cesar

In a web/html environment or in broken ascii-only consoles like the
one on windows, I use the following hack:

print your_unicode_string.encode('us-ascii','xmlcharrefreplace')

This will print unicode chars using pure ASCII symbols which will
display correctly in a web browser and are more readable in a console
than unicode escapes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Word Perfect integration

2011-08-18 Thread Terry Reedy

On 8/18/2011 3:24 PM, Ethan Furman wrote:

Alec Taylor wrote:

wow, people still use WordPerfect?


Them's fightin' words right there! :)

Yes, we still use Word Perfect, and will as long as it is available. The
ability to see the codes in use (bold, margins, columns, etc) has so far
been unequaled in anything else I have looked at.


Definitely. I did a book with WP and periodically went through with 
codes revealed to delete any junk and got the camera-ready copy I 
wanted. I have recently used OpenO modeled after MSO and occasionally 
get frustrated when I cannot see what it actually inserts, to explain 
why it does not behave as expected.


That aside, if you are on Windows, check the list archives for 'office 
automation' or somesuch. If WP has the standard API, I believe the 
answer is to use the PythonWin extensions, included with the ActiveState 
Python distribution and available on SourceForge.
There is a windows module includes in the stdlib, but I do not know if 
it has enough.


--
Terry Jan Reedy

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


Re: List spam

2011-08-18 Thread Terry Reedy

On 8/18/2011 12:14 PM, gene heskett wrote:


into a REAL mailing list.  Subscribers only, or get past a GOOD captcha.


I just had an idea. Ask 'What is python? __" or "What 
can you do with a python?' with a free-form fill in the blank answer. 
Look for 'computer', 'program' or 'language' in the response. 'snake' 
fails the test.


Or 'Enter a Python keyword (search the tutorial if you do not know any) 
'



--
Terry Jan Reedy

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


Re: Help with regular expression in python

2011-08-18 Thread John Gordon
In  Matt Funk 
 writes:

> 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 

> instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)
> {32}'
> instance_linetype_pattern = re.compile(instance_linetype_pattern_str)

Does your regexp account for the space in between each float?  I can't tell
due to your post having a linebreak at a really inconvenient spot.  

-- 
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: Help with regular expression in python

2011-08-18 Thread Martin Komoň
You don't seem to account for the whitespace between the floats. Try
> '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?\s+){32}'
(just added \s+).

Martin

On 8/18/2011 9:49 PM, Matt Funk wrote:
> Hi,
> i am sorry if this doesn't quite match the subject of the list. If someone 
> takes offense please point me to where this question should go. Anyway, i 
> have 
> a problem using regular expressions. I would like to match the line:
> 
> 1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 
> 2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 
> 2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 
> 1.888000e+01 1.854000e+01 2.064000e+01 2.00e+01 2.20e+01 2.139000e+01 
> 2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.15e+01 
> 2.15e+01 2.199000e+01 : (instance: 0) :   some description
> 
> The number of floats can vary (in this example there are 32). So what i 
> thought 
> i'd do is the following:
> instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)
> {32}'
> instance_linetype_pattern = re.compile(instance_linetype_pattern_str)
> Basically the expression in the first major set of paranthesis matches a 
> scientific number format. The '{32}' is supposed to match the previous 32 
> times. However, it doesn't. I  can't figure out why this does not work. I'd 
> really like to understand it if someone can shed light on it.
> 
> thanks
> matt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Terry Reedy



I did check, though.  I found a free, open news server with
comp.lang.python after 6 that didn't work.  Unfortunately, the one I
found is read-only.  I'll have to do some more looking if I want to
participate in the newsgroup.  I set it up in Thunderbird.


I read and post to this and other Python lists via news.gmane.org (free) 
with Thunderbird. It mirrors 1000s of technical mail lists, including 
200+ with 'python'. I believe it therefore has less spam than c.l.p (ie, 
minus whatever gets filtered out by the pipermail at python.org). First 
post to any list requires a response to an email. Uptime is pretty good.


--
Terry Jan Reedy

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


Help with regular expression in python

2011-08-18 Thread Matt Funk
Hi,
i am sorry if this doesn't quite match the subject of the list. If someone 
takes offense please point me to where this question should go. Anyway, i have 
a problem using regular expressions. I would like to match the line:

1.002000e+01 2.037000e+01 2.128000e+01 1.908000e+01 1.871000e+01 1.914000e+01 
2.007000e+01 1.664000e+01 2.204000e+01 2.109000e+01 2.209000e+01 2.376000e+01 
2.158000e+01 2.177000e+01 2.152000e+01 2.267000e+01 1.084000e+01 1.671000e+01 
1.888000e+01 1.854000e+01 2.064000e+01 2.00e+01 2.20e+01 2.139000e+01 
2.137000e+01 2.178000e+01 2.179000e+01 2.123000e+01 2.201000e+01 2.15e+01 
2.15e+01 2.199000e+01 : (instance: 0)   :   some description

The number of floats can vary (in this example there are 32). So what i thought 
i'd do is the following:
instance_linetype_pattern_str = '([-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)
{32}'
instance_linetype_pattern = re.compile(instance_linetype_pattern_str)
Basically the expression in the first major set of paranthesis matches a 
scientific number format. The '{32}' is supposed to match the previous 32 
times. However, it doesn't. I  can't figure out why this does not work. I'd 
really like to understand it if someone can shed light on it.

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


Re: Word Perfect integration

2011-08-18 Thread Ethan Furman

John Gordon wrote:

I suspect that learning how to integrate python with wordperfect will
end up being much more work than learning wordperfect macros.


Possibly... but I enjoy coding in Python.  :)

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


Re: Word Perfect integration

2011-08-18 Thread Ethan Furman

Alec Taylor wrote:

wow, people still use WordPerfect?


Them's fightin' words right there!  :)

Yes, we still use Word Perfect, and will as long as it is available. 
The ability to see the codes in use (bold, margins, columns, etc) has so 
far been unequaled in anything else I have looked at.


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


Re: How to convert a list of strings into a list of variables

2011-08-18 Thread Nobody
On Thu, 18 Aug 2011 16:09:43 +, John Gordon wrote:

>> How would you convert a list of strings into a list of variables using
>> the same name of the strings?
> 
>> So, ["red", "one", "maple"] into [red, one, maple]
> 
> If the strings and the object names are exactly the same, you could use
> eval().

Eval is overkill for variables; use globals() and/or locals().

But data which is supposed to be indexed by a variable key (i.e. a name
which is determined at run-time) should normally be put into a dictionary.
If access with fixed keys is far more common than variable keys, using an
object (with getattr/setattr for variable keys) may be preferable.


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


Re: List spam

2011-08-18 Thread Nobody
On Thu, 18 Aug 2011 14:30:37 +0100, Tim Golden wrote:

>> I really like this list as part of my learning tools but the amount of
>> spam that I've been getting from it is CRAZY. Doesn't anything get
>> scanned before it sent to the list?
> 
> I haven't seen any significant quantity of spam on the list for ages. (The
> occasional one does get through although I can't remember the last).
> 
> I always access it as a mailing list, and I seem to recall that the
> newsgroup feed isn't filtered the same way as the mailing list is.

That depends upon your news server. I see a small amount of spam for this
group, but not enough that it concerns me.

If the mailing list is getting spam from the newsgroup, the solution is to
either find a cleaner feed or add a spam filter to the gateway.

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


Re: List spam

2011-08-18 Thread Dan Stromberg
On Thu, Aug 18, 2011 at 6:39 AM, Jason Staudenmayer <
jas...@adventureaquarium.com> wrote:

>
> > On 18/08/2011 13:58, Jason Staudenmayer wrote:
> > > I really like this list as part of my learning tools but the amount
> > > of spam that I've been getting from it is CRAZY. Doesn't
> > anything get
> > > scanned before it sent to the list?
> I can deal with normal spam but this stuff I've gotten is all about
> rape.
>

Agreed, a few of the recent messages would've been far too many at a count
of 1.

What I do is forward the list to gmail.  gmail has pretty decent spam
filtering - normally.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread gene heskett
On Thursday, August 18, 2011 02:26:24 PM Peter Pearson did opine:

> On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett 
> wrote: [snip]
> 
> > What is wrong with the mailing list only approach?
> 
> In the mailing-list approach, how do I search for prior discussions
> on a subject?  (I'm not particularly opposed to the mailing list,
> I'm just an NNTP follower worried about the uncertainties of change.)

If the message still exists in your local email corpus, kmail for one has 
no problems searching it.  However, since my corpus is close to 10gigs 
because my inbox and one list are not expired, the rest of them are expired 
on a selectable schedule that only saves the last 2000 or so msgs.

Cheers, gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Hoare's Law of Large Problems:
Inside every large problem is a small problem struggling to get 
out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread gene heskett
On Thursday, August 18, 2011 02:12:58 PM Alain Ketterlin did opine:

> gene heskett  writes:
> >> Or save work and find a public nntp server (or setup one, or ask your
> >> provider), and use a news reader to follow the list (even thunderbird
> >> can do this). No spam, no need to store messages on your machine,
> >> auto-purge after a configurable delay, etc.
> > 
> > That is asking the user to take considerable effort and resources to
> > do that.  What is wrong with the mailing list only approach?
> 
> Nothing really.
> 
> Regarding effort and resources, once you've found a NNTP server there's
> very little effort (probably less than subscribing to a mailing list). I
> have 4 lines in my .emacs. And this lets me browse dozens of groups (or
> thousands if I had time for this). It might not be easy to find a server
> which will let you post, but that's because a few years back many
> internet providers decided that nntp was too much traffic. I guess it
> would now be considered ridiculous compared to the average web-site.
> 
> But I'd like to return the question. What's wrong with nntp?

The sheer volume of traffic eats 99% of an ISP's bandwidth.  The last time 
I checked with one of the local ISP's that I quit using years ago because 
it was 30 miles away and was then long distance, giving me $300 phone 
bills, they said their server died (again, and that then traffic was such 
that a 300GB hard drive was being subject to a posting lifetime of 3 hours 
because it was filling the drive that quickly.  At the time, they had 5 T1 
circuits, and NNTP was eating 4 of them.  To an ISP, that stuff is found on 
the ground behind the male of the bovine specie.  No ISP I have access to a 
mail account on, except google, has the resources to maintain a full 
listing nnpt server.

> It looks
> like everybody agrees that nntp brings spam. I just wanted to say that's
> not true, I use nntp extensively and haven't seen spam for months (I'm
> talking about 15-20 groups, not comp.lang.python only).
> 
> The real problem here seems to be google groups, which in some way
> forwards spam to the mailing-list. How this happens is beyond my
> understanding. But let's try to fix the real problem.
 
I could just nuke them, but I suppose I'd then have to resubscribe to about 
10 of my mailing lists through the server this msg comes from.  That is 
gradually happening anyway because posting through a gmail account, you 
cannot turn off the dup deletions, so one never knows if ones post to a 
list got there until someone replies, you don't get an echo.  I have even 
tried CCing this address as some have suggested, but that doesn't work 
either.

gmail is NOT the huge thing it was touted to be, not by a hell of a long 
row of apple trees.
 
> -- Alain.


Cheers, gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
"It's not just a computer -- it's your ass."
-- Cal Keegan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Anssi Saari
Ghodmode  writes:

> Newsgroups aren't inherently spam-free.  They're filtered.  At least
> that's the case with Gmane (http://gmane.org/spam.php).
>
> My own ISP doesn't provide a news server and, although there are many
> links for free open news servers, most of them don't seem to work.

You know, Gmane allows access also via NNTP, including this list.
Server news.gmane.org, group name gmane.comp.python.general.

Haven't used it since I get this list via "normal" NNTP as
comp.lang.python. My NNTP access is via a computer club for 8 euros
per year.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wait for a keypress before continuing?

2011-08-18 Thread Nobody
On Thu, 18 Aug 2011 01:24:30 -0700, peter wrote:

> This is very similar to my solution, which was to use stty turn off
> keyboard echo, then repeatedly read sys.stdin.read(1) until a unique
> keystroke had been defined. For example, the 'Insert' key seems to
> return a sequence of four codes, namely 27, 91, 50, 126.  It works but
> has two disadvantages which I have managed to live with:-
> 
> 1. As character 27 is used to signal the start of a 'special' key
> sequence, it cannot detect a single press of the Esc key. The
> workaround is to detect a double press instead.
> 
> 2. Some keys seem to return different sets of codes depending on the
> circumstances.  For example, F1 returns 27,91,91,65 from the command
> line, and 27,79,80 from a GUI window. I suspect there may be
> variations between flavours of Linux too. The solution is to detect
> all possibilities - so far I haven't found any overlaps.

Escape sequences vary between terminals. A given key may have different
escape sequences on the Linux console, xterm, a vt220, etc. The
termcap and terminfo databases exist for this purpose (terminfo is newer).

Some escape sequences vary by "mode". E.g. the cursor keys typically
produce different sequences depending upon whether the terminal is in
"keypad" mode.

The normal solution for distinguishing the escape key from an escape
sequence is a timeout. Unfortunately, it needs to be quite long in order
to reliably support network (ssh, telnet, etc) connections.

> Not pretty, but as I said it works. I know now not to spend time
> looking further. Whilst there may be a historical reason for the
> current situation, it would be a great convenience for amateur coders
> like mayself if the gurus could devise a platform independent version
> of mscvrt.

The platform-independent high-level terminal interface is called "curses".

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


Re: Word Perfect integration

2011-08-18 Thread Alec Taylor
wow, people still use WordPerfect?

On Fri, Aug 19, 2011 at 2:51 AM, John Gordon  wrote:
> In  Ethan Furman 
>  writes:
>
>> I have WordPerfect v13 which we are currently using for letter merges.
>> I would like to automate this with Python instead of learning the WP
>> Macro language.
>
> I suspect that learning how to integrate python with wordperfect will
> end up being much more work than learning wordperfect macros.
>
> Just my two cents.
>
> --
> 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
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Alec Taylor
5963 unread emails.

Thanks python-list + other mailing-lists!

My recommendation to you is to setup a different account for your
mailing-lists. Alternatively setup some mail rules.

On Fri, Aug 19, 2011 at 3:46 AM, Chris Angelico  wrote:
> On Thu, Aug 18, 2011 at 3:37 PM, Ghodmode  wrote:
>> Make an effort to curb the spam even if it means killing the newsgroup
>> availability.  Choose mailman or Google Groups, or another single
>> solution.  Make it members only, but allow anyone to register with an
>> automated confirmation email and a CAPTCHA.  Appoint a list admin who
>> has a few minutes each day to scan subjects of emails for spammers and
>> remove them from the members list.
>>
>
> Unfortunately spammers can create email addresses very quickly, and
> CAPTCHAs are inherently weak (even the best of them are easily cracked
> by the Chinese human "botnets"). However, I wouldn't be against a
> system of spam filtering with three levels: Not Spam, gets straight
> onto the list; Definite Spam, gets deleted; and Dubious, which gets
> dropped into a mod's basket.
>
> ChrisA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert a list of strings into a list of variables

2011-08-18 Thread Chris Angelico
On Thu, Aug 18, 2011 at 5:09 PM, John Gordon  wrote:
> for x in list_of_strings:
>    list_of_variables.append(eval(x))
>

If this really is what you need, you can simplify it by using the
globals() dictionary - it's a regular dictionary whose contents are
all the global variables in your current module. Inside a function,
use locals() instead.

http://docs.python.org/library/functions.html#globals

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


Re: Measure the amount of memory used?

2011-08-18 Thread Dan Stromberg
"A person with one watch knows what time it is.  A person with two is never
sure."

You're probably best off just picking one or more measures that work for
your purposes, and going with them.  Don't concern yourself overmuch with
finding "the" amount.

Memory can actually contract on some modern systems, due to garbage
collection and the relatively new ability of some malloc's to mmap away
no-longer-needed pages.

Going directly to /proc is fine, though it might be a little more common
(and portable) to run ps and let it sift through /proc.  But of course,
running ps over and over is less efficient.

On Thu, Aug 18, 2011 at 8:08 AM, Jack Bates  wrote:

> I wrote a content filter for Postfix with Python,
> https://github.com/jablko/cookie
>
> It should get started once, and hopefully run for a long time - so I'm
> interested in how it uses memory:
>
>  1) How does the amount of memory used change as it runs?
>
>  2) How does the amount of memory used change as I continue to hack on
> it, and change the code?
>
> My naive thought was that I'd periodically append to a file, the virtual
> memory size from /proc/[pid]/stat and a timestamp. From this a could
> make a graph of the amount of memory used as my content filter runs, and
> I could compare two graphs to get a clue whether this amount changed as
> I continue to hack
>
>  - but some Googling quickly revealed that measuring memory is actually
> quite complicated? Neither the virtual memory size nor the "resident set
> size" accurately measure the amount of memory used by a process
>
> Has anyone else measured the memory used by a Python program? How did
> you do it?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Chris Angelico
On Thu, Aug 18, 2011 at 3:37 PM, Ghodmode  wrote:
> Make an effort to curb the spam even if it means killing the newsgroup
> availability.  Choose mailman or Google Groups, or another single
> solution.  Make it members only, but allow anyone to register with an
> automated confirmation email and a CAPTCHA.  Appoint a list admin who
> has a few minutes each day to scan subjects of emails for spammers and
> remove them from the members list.
>

Unfortunately spammers can create email addresses very quickly, and
CAPTCHAs are inherently weak (even the best of them are easily cracked
by the Chinese human "botnets"). However, I wouldn't be against a
system of spam filtering with three levels: Not Spam, gets straight
onto the list; Definite Spam, gets deleted; and Dubious, which gets
dropped into a mod's basket.

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


Re: List spam

2011-08-18 Thread Ghodmode
On Fri, Aug 19, 2011 at 12:37 AM, Ned Deily  wrote:
> 4. gmane (various formats)
>   http://dir.gmane.org/gmane.comp.python.general
>   a.  gmane.comp.python.general (non-Usenet group via NNTP)

> All of the above allow both reading and posting.  gmane does spam
> filtering so, if you read and post through it, you will avoid most of
> the spam (a little bit gets through).  The gmane nntp server (which is
> for gmane groups only, not regular Usenet groups) is free to use.

Unfortunately, Gmane's version of this newsgroup
(gmane.comp.python.general) has all of the offensive spam.  I'm kinda
surprised considering the detailed information that they put on their
site about spam filtering.

These are the ones I got to work:
  - textnews.news.cambrium.nl
  - mail.tsu.ru

... They're light on the spam, but they're read-only.

Ironically, the Google Groups version
(https://groups.google.com/forum/#!forum/comp.lang.python) has almost
none of the spam, although I did see one message that said "This topic
has been hidden because it was flagged for abuse".  I can't join that
Google Group, though.  I guess that's because it's just a viewer for
the newsgroup.


> --
>  Ned Deily,
>  n...@acm.org

--
Ghodmode
http://www.ghodmode.com/blog
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Philip Semanchuk

On Aug 18, 2011, at 1:10 PM, Peter Pearson wrote:

> On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett  wrote:
> [snip]
>> What is wrong with the mailing list only approach?
> 
> In the mailing-list approach, how do I search for prior discussions
> on a subject?  (I'm not particularly opposed to the mailing list,
> I'm just an NNTP follower worried about the uncertainties of change.)

I use a Google search like this:
site:mail.python.org/pipermail/python-list/  banana

Although that has its own issues, as not all messages seem to make it to that 
list (or they have the X-No-Archive bit set?)


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


Re: List spam

2011-08-18 Thread Peter Pearson
On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett  wrote:
[snip]
> What is wrong with the mailing list only approach?

In the mailing-list approach, how do I search for prior discussions
on a subject?  (I'm not particularly opposed to the mailing list,
I'm just an NNTP follower worried about the uncertainties of change.)

-- 
To email me, substitute nowhere->spamcop, invalid->net.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Peter Pearson
On Thu, 18 Aug 2011 16:58:04 +0200, Alain Ketterlin wrote:
> Ghodmode  writes:
>
> [...]
>> Make an effort to curb the spam even if it means killing the newsgroup
>> availability.  Choose mailman or Google Groups, or another single
>> solution.  Make it members only, but allow anyone to register with an
>> automated confirmation email and a CAPTCHA.  Appoint a list admin who
>> has a few minutes each day to scan subjects of emails for spammers and
>> remove them from the members list.
>
> Or save work and find a public nntp server (or setup one, or ask your
> provider), and use a news reader to follow the list (even thunderbird
> can do this). No spam, no need to store messages on your machine,
> auto-purge after a configurable delay, etc.

Or pay for filtered NNTP service.  I'm happy with
news.individual.net: 10 euros per year, appears to be
competently run, very little spam gets through (maybe like 1
message per heavily posted group per day), and they probably
carry all the newsgroups you follow.  I have no affiliation
with them, except for being a customer who hopes they stay
in business.

-- 
To email me, substitute nowhere->spamcop, invalid->net.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Alain Ketterlin
gene heskett  writes:

>> Or save work and find a public nntp server (or setup one, or ask your
>> provider), and use a news reader to follow the list (even thunderbird
>> can do this). No spam, no need to store messages on your machine,
>> auto-purge after a configurable delay, etc.

> That is asking the user to take considerable effort and resources to do 
> that.  What is wrong with the mailing list only approach?

Nothing really.

Regarding effort and resources, once you've found a NNTP server there's
very little effort (probably less than subscribing to a mailing list). I
have 4 lines in my .emacs. And this lets me browse dozens of groups (or
thousands if I had time for this). It might not be easy to find a server
which will let you post, but that's because a few years back many
internet providers decided that nntp was too much traffic. I guess it
would now be considered ridiculous compared to the average web-site.

But I'd like to return the question. What's wrong with nntp? It looks
like everybody agrees that nntp brings spam. I just wanted to say that's
not true, I use nntp extensively and haven't seen spam for months (I'm
talking about 15-20 groups, not comp.lang.python only).

The real problem here seems to be google groups, which in some way
forwards spam to the mailing-list. How this happens is beyond my
understanding. But let's try to fix the real problem.

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


Re: Word Perfect integration

2011-08-18 Thread John Gordon
In  Ethan Furman 
 writes:

> I have WordPerfect v13 which we are currently using for letter merges. 
> I would like to automate this with Python instead of learning the WP 
> Macro language.

I suspect that learning how to integrate python with wordperfect will
end up being much more work than learning wordperfect macros.

Just my two cents.

-- 
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: lists and for loops

2011-08-18 Thread Peter Pearson
On Wed, 17 Aug 2011 20:08:23 -0700 (PDT), Emily Anne Moravec wrote:
> I want to add 5 to each element of a list by using a for loop.
>
> Why doesn't this work?
>
> numbers = [1, 2, 3, 4, 5]
> for n in numbers:
>  n = n + 5
> print numbers

Because integers are immutable.  You cannot turn 1 into 6.
Contrast this behavior with lists, which *are* mutable:

>>> numbers = [[1],[2],[3],[4],[5]]
>>> for n in numbers:
...   n[0]= n[0] + 5
... 
>>> numbers
[[6], [7], [8], [9], [10]]

For practical purposes, I'm sure you'll find other responders'
excellent posts to be of more immediate use, but keeping
mutability in mind helps.

-- 
To email me, substitute nowhere->spamcop, invalid->net.
-- 
http://mail.python.org/mailman/listinfo/python-list


Word Perfect integration

2011-08-18 Thread Ethan Furman
I have WordPerfect v13 which we are currently using for letter merges. 
I would like to automate this with Python instead of learning the WP 
Macro language.


Does anyone have any pointers?

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


Re: List spam

2011-08-18 Thread Ned Deily
In article 
,
 Ghodmode  wrote:
> Newsgroups aren't inherently spam-free.  They're filtered.  At least
> that's the case with Gmane (http://gmane.org/spam.php).
> 
> My own ISP doesn't provide a news server and, although there are many
> links for free open news servers, most of them don't seem to work.
> 
> I did check, though.  I found a free, open news server with
> comp.lang.python after 6 that didn't work.  Unfortunately, the one I
> found is read-only.  I'll have to do some more looking if I want to
> participate in the newsgroup.  I set it up in Thunderbird.  I waited
> for a few minutes while it loaded the available newsgroups, then
> filtered the list for comp.lang.python and subscribed.  I noticed
> that, when clicking on a message, there is another delay while I wait
> for the content of the message to load.
> 
> I was happy to see significantly less spam in the newsgroup than in
> the mailing list, but there was still more than I see in other mailing
> lists.
> 
> For me, this is much more difficult, although I'm sure that this is a
> matter of perspective.  Also, I have something that's tied to this
> computer.  I can't read it on my laptop, my mobile device, or at a
> cyber-cafe.  I have to sit in front of this computer if I want to read
> the newsgroup and, until I find another news server that isn't
> read-only, I can't even post messages.

Confusingly, this "forum" is available via a number of channels.  Here 
is a subset of them (there are more):

1. python-list mailing list
   http://mail.python.org/mailman/listinfo/python-list
2. comp.lang.python
   news:comp.lang.python  (Usenet group via NNTP)
3. google groups
4. gmane (various formats)
   http://dir.gmane.org/gmane.comp.python.general
   a.  gmane.comp.python.general (non-Usenet group via NNTP)
   b.  web interfaces

All of the above allow both reading and posting.  gmane does spam 
filtering so, if you read and post through it, you will avoid most of 
the spam (a little bit gets through).  The gmane nntp server (which is 
for gmane groups only, not regular Usenet groups) is free to use. 

http://gmane.org/about.php

-- 
 Ned Deily,
 n...@acm.org

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


Re: List spam

2011-08-18 Thread gene heskett
On Thursday, August 18, 2011 12:14:39 PM Alain Ketterlin did opine:

> Ghodmode  writes:
> 
> [...]
> 
> > Make an effort to curb the spam even if it means killing the newsgroup
> > availability.  Choose mailman or Google Groups, or another single
> > solution.  Make it members only, but allow anyone to register with an
> > automated confirmation email and a CAPTCHA.  Appoint a list admin who
> > has a few minutes each day to scan subjects of emails for spammers and
> > remove them from the members list.
> 
> Or save work and find a public nntp server (or setup one, or ask your
> provider), and use a news reader to follow the list (even thunderbird
> can do this). No spam, no need to store messages on your machine,
> auto-purge after a configurable delay, etc.
> 
> Problem solved.
> 
> -- Alain.

That is asking the user to take considerable effort and resources to do 
that.  What is wrong with the mailing list only approach?

Cheers, gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
The plot was designed in a light vein that somehow became varicose.
-- David Lardner
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread gene heskett
On Thursday, August 18, 2011 12:08:38 PM Alain Ketterlin did opine:

> "Jason Staudenmayer"  writes:
> > I really like this list as part of my learning tools but the amount of
> > spam that I've been getting from it is CRAZY. Doesn't anything get
> > scanned before it sent to the list?
> 
> I'm using nntp to read this newsgroup (through an academic server).
> No spam at all.
> 
> -- Alain.

Which I think re-enforces the conclusion I have reached, and that is that 
the most obnoxious spammer here is injecting his spam directly to a machine 
handling google's groups that is downstream of any filtering they claim to 
do.  Short answer is to disconnect the the NNTP link and make this list 
into a REAL mailing list.  Subscribers only, or get past a GOOD captcha.
Spammers have stuff that can do the average captcha in a second or less, so 
choose the images wisely and randomize both the background and the text.

Cheers, gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
The state of innocence contains the germs of all future sin.
-- Alexandre Arnoux, "Etudes et caprices"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Ghodmode
On Thu, Aug 18, 2011 at 10:58 PM, Alain Ketterlin
 wrote:
> Ghodmode  writes:
>
> [...]
>> Make an effort to curb the spam even if it means killing the newsgroup
>> availability.  Choose mailman or Google Groups, or another single
>> solution.  Make it members only, but allow anyone to register with an
>> automated confirmation email and a CAPTCHA.  Appoint a list admin who
>> has a few minutes each day to scan subjects of emails for spammers and
>> remove them from the members list.
>
> Or save work and find a public nntp server (or setup one, or ask your
> provider), and use a news reader to follow the list (even thunderbird
> can do this). No spam, no need to store messages on your machine,
> auto-purge after a configurable delay, etc.
>
> Problem solved.

Is that easier than just checking your email?  I guess it's a matter
of perspective...

Newsgroups aren't inherently spam-free.  They're filtered.  At least
that's the case with Gmane (http://gmane.org/spam.php).

My own ISP doesn't provide a news server and, although there are many
links for free open news servers, most of them don't seem to work.

I did check, though.  I found a free, open news server with
comp.lang.python after 6 that didn't work.  Unfortunately, the one I
found is read-only.  I'll have to do some more looking if I want to
participate in the newsgroup.  I set it up in Thunderbird.  I waited
for a few minutes while it loaded the available newsgroups, then
filtered the list for comp.lang.python and subscribed.  I noticed
that, when clicking on a message, there is another delay while I wait
for the content of the message to load.

I was happy to see significantly less spam in the newsgroup than in
the mailing list, but there was still more than I see in other mailing
lists.

For me, this is much more difficult, although I'm sure that this is a
matter of perspective.  Also, I have something that's tied to this
computer.  I can't read it on my laptop, my mobile device, or at a
cyber-cafe.  I have to sit in front of this computer if I want to read
the newsgroup and, until I find another news server that isn't
read-only, I can't even post messages.

For me, I'll stick with email.


> -- Alain.

--
Ghodmode
http://www.ghodmode.com/blog
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert a list of strings into a list of variables

2011-08-18 Thread John Gordon
In <2ab25f69-6017-42a6-a7ef-c71bc2ee8...@l2g2000vbn.googlegroups.com> noydb 
 writes:

> How would you convert a list of strings into a list of variables using
> the same name of the strings?

> So, ["red", "one", "maple"] into [red, one, maple]

> Thanks for any help!

If the strings and the object names are exactly the same, you could use
eval().  (Of course this assumes the objects already exist.)

  red = "this is the red object"
  one = 1
  maple = "this is the maple object"

  list_of_strings = ["red", "one", "maple"]
  list_of_variables = []

  for x in list_of_strings:
list_of_variables.append(eval(x))

  for y in list_of_variables:
print y

-- 
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: List spam

2011-08-18 Thread gene heskett
On Thursday, August 18, 2011 12:08:00 PM Ghodmode did opine:

> On Thu, Aug 18, 2011 at 9:39 PM, Philip Semanchuk  
wrote:
> > On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote:
> >> I really like this list as part of my learning tools but the amount
> >> of spam that I've been getting from it is CRAZY. Doesn't anything
> >> get scanned before it sent to the list?
> > 
> > This has been discussed on the list a number of times before, so I'll
> > refer you to the archives for details.
> > 
> > Basically, the mailing list receives postings from Google Groups and
> > vice versa. Most of the spam comes from Google Groups. If you add a
> > mail filter that deletes anything with the "Organization" header set
> > to "http://groups.google.com";, you won't see much spam anymore. In my
> > experience, you'll also miss a number of legitimate postings.
> 
> You are absolutely right, it has been brought up before.  But I'm glad
> it's been brought up again.  It's such a problem that it degrades the
> usefulness of the list and the community.
> 
> Most of the mailing lists I'm on are managed using Google Groups and
> many of them are on mailman, like this list.  I don't see spam on
> them, so I don't know what's going on here.
> 
> It's not really filtering at all.  Most lists only allow members to
> post and the admins are quick to boot offenders.
> 
> For the most part, I'm just a lurker, so my suggestion shouldn't carry
> as much weight, but here it is anyway...
> 
> Make an effort to curb the spam even if it means killing the newsgroup
> availability.  Choose mailman or Google Groups, or another single
> solution.  Make it members only, but allow anyone to register with an
> automated confirmation email and a CAPTCHA.  Appoint a list admin who
> has a few minutes each day to scan subjects of emails for spammers and
> remove them from the members list.
> 
> ... problem solved.
> 
> Yes.  I'm saying we should abandon those who only follow the list via
> newsgroups.
> Yes.  I'm willing to do the work, but I'm not the right choice.

+100 (or whatever it takes) 
> > HTH
> > Philip
> 
> --
> Ghodmode
> http://www.ghodmode.com/blog


Cheers, gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
The state of innocence contains the germs of all future sin.
-- Alexandre Arnoux, "Etudes et caprices"
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: List spam

2011-08-18 Thread Jason Staudenmayer
> On Aug 18, 8:39 am, "Jason Staudenmayer"
>  wrote:
> >
> > [snip irony]
> >
> > Adventure Aquarium is America's Most Touchable Aquarium!
> > Featuring the ALL NEW Stingray Beach Club
> > Where you can touch and hand feed the gentle stingrays
> >
> > To buy and print your tickets at home visit  
www.AdventureAquarium.com
>       ..·><º>..·`·.><º>..·`·.><º>..·`·.><º>
>                                     ..·`·.><º>..·`·.><º>..·`·.><º>
> ..·><º>..·`·.><º>
>
> A Herschend Family Entertainment Company

>Don't you find it a bit ironic that you are complaining about spam but
>yet you are spamming this group with your link to buy tickets to a
>stingray petting zoo (which is in fact an oxymoron?) under the guise
>of spam bashing?  Tip of the day: Create a website!

>PS: I do however find the recent "rape" spam atrocious!

I do know it is ironic that I forgot to stop the footer for the one reply.
It's not my choice to add it but I was able to find a way around that work 
policy for list emails. I'm a strong opponent of dropping any email with a 
stupid footer spam.

Jason
 
 
 
..·><º>


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


Sqlalchemy + Cherrypy

2011-08-18 Thread Navkirat Singh
Hi Guys,

I am not sure if this is the right place to put this question. I am trying
to figure out what the proper/clean way is to integrate cherrypy and
sqlalchemy? I am currently trying to do this cherrypy 3 and sqlalchemy .7 in
python 3.2

a) Cherrypy tools
b) Integrate it directly into the app

Any help will be really appreciated.


Regards,
Nav
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread D'Arcy J.M. Cain
On Thu, 18 Aug 2011 22:37:37 +0800
Ghodmode  wrote:
> Make an effort to curb the spam even if it means killing the newsgroup
> availability.  Choose mailman or Google Groups, or another single
> solution.  Make it members only, but allow anyone to register with an
> automated confirmation email and a CAPTCHA.  Appoint a list admin who
> has a few minutes each day to scan subjects of emails for spammers and
> remove them from the members list.

I'm not sure it would scale but I have a few lists that I protect by
doing a few simple things.  First, I make the list so that only members
can post.  I then set the list so that everyone is moderated by
default.  When someone posts a legitimate message I simply pass it and
then unmoderate that user.

It's not as onerous as it sounds.  Very few people actually post and
you only have to deal with those that do once.  Mailman makes it pretty
simple to manage too.

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


Re: How to convert a list of strings into a list of variables

2011-08-18 Thread noydb
On Aug 18, 11:29 am, Jerry Hill  wrote:
> On Thu, Aug 18, 2011 at 11:19 AM, noydb  wrote:
> > I am being passed the list of strings.  I have variables set up
> > already pointing to files.  I need to loop through each variable in
> > the list and do things to the files.  The list of strings will change
> > each time, include up to 22 of the same strings each time.
>
> If you have a mapping of strings to values, you should just go ahead
> and store them in a dictionary.  Then the lookup becomes simple:
>
> def foo(list_of_strings):
>         mapping = {
>                 "bar0": "/var/log/bar0.log",
>                 "bar1": "/usr/local/bar/bar1.txt",
>                 "bar2": "/home/joe/logs/bar2.log",
>         }
>         for item in list_of_strings:
>                 filename = mapping[item]
>                 do_something(filename)
>
> (Untested)
>
> --
> Jerry

Thanks, implemented something along those lines, and it worked!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Measure the amount of memory used?

2011-08-18 Thread John Gordon
In  Jack Bates 
 writes:

>  1) How does the amount of memory used change as it runs?

I've observed that the amount of memory consumed by a program will
stay constant or increase; it never decreases.

Or were you wanting to measure the rate of increase over time?

> Has anyone else measured the memory used by a Python program? How did
> you do it?

I generally use 'top' to do this for any program.

-- 
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: How to convert a list of strings into a list of variables

2011-08-18 Thread Jerry Hill
On Thu, Aug 18, 2011 at 11:19 AM, noydb  wrote:
> I am being passed the list of strings.  I have variables set up
> already pointing to files.  I need to loop through each variable in
> the list and do things to the files.  The list of strings will change
> each time, include up to 22 of the same strings each time.

If you have a mapping of strings to values, you should just go ahead
and store them in a dictionary.  Then the lookup becomes simple:

def foo(list_of_strings):
mapping = {
"bar0": "/var/log/bar0.log",
"bar1": "/usr/local/bar/bar1.txt",
"bar2": "/home/joe/logs/bar2.log",
}
for item in list_of_strings:
filename = mapping[item]
do_something(filename)


(Untested)

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


Re: How to convert a list of strings into a list of variables

2011-08-18 Thread noydb
On Aug 18, 11:12 am, David Robinow  wrote:
> On Thu, Aug 18, 2011 at 10:57 AM, noydb  wrote:
> > How would you convert a list of strings into a list of variables using
> > the same name of the strings?
>
> > So, ["red", "one", "maple"] into [red, one, maple]
>
>   Why would you want to?

I am being passed the list of strings.  I have variables set up
already pointing to files.  I need to loop through each variable in
the list and do things to the files.  The list of strings will change
each time, include up to 22 of the same strings each time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: extend class: include factories functions inside constructor

2011-08-18 Thread aspineux
On Aug 18, 4:45 pm, Peter Otten <__pete...@web.de> wrote:
> aspineux wrote:
> > Hi
> > I have a closed class and 2 factories function
>
> > class Data:
> >   def __init__(self):
> >     self.payload=None
>
> > def data_from_string(payload):
> >   data=Data()
> >   data.payload=payload
> >   return data
>
> > def data_from_file(f):
> >   data=Data()
> >   data.payload=f.read()
> >   return data
>
> > And I want to extend the class, by first including the factories
> > function inside the constructor,
> > second add some method to the class.
>
> > class MyData(Data):
>
> >   def __init__(self, arg):
> >     # I know this coke is not working, this is to show you
> >     # what I expect
> >     if isinstance(arg, file):
> >         self=data_from_file(arg)
> >     else:
> >         self=data_from_string(arg)
> >     return self
>
> >   def len(self):
> >     return len(self.payload)
>
> > And how I want to use it
>
>  m=MyData('hello')
>  print m.len()
> > 5
>
> > any idea ?
>
> Assuming that Data is an oldstyle class you can either copy the Data
> instance's state
>
> class MyData(Data):
>     def __init__(self, arg):
>         if hasattr(arg, "read"):
>             factory = data_from_file
>         else:
>             factory = data_from_string
>         obj = factory(arg)
>         self.__dict__.update(obj.__dict__)
>
>     def __len__(self):
>         return len(self.payload)
>
> or use another factory function and manually set the __class__:
>
> class MyData(Data):
>     def __len__(self):
>         return len(self.payload)
>
> def make_mydata(arg):
>     if hasattr(arg, "read"):
>         factory = data_from_file
>     else:
>         factory = data_from_string
>     obj = factory(arg)
>     obj.__class__ = MyData
>     return obj
>
> If Data were a newstyle class you could move the hand-made polymorphism into
> the __new__() method:
>
> class MyData(Data):
>     def __new__(class_, arg):
>         if hasattr(arg, "read"):
>             factory = data_from_file
>         else:
>             factory = data_from_string
>         obj = factory(arg)
>         obj.__class__ = class_
>         return obj
>     def __init__(self, arg):
>         pass
>     def __len__(self):
>         return len(self.payload)
>
> if __name__ == "__main__":
>     m = MyData("hello")
>     print len(m)
>
> Nothing of the above strikes me as pretty. Perhaps we could come up with a
> neater solution if you tell us more about your use-case...

Ops, I clicked send before to finish my post.

Thanks for your quick and very valuable answer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Measure the amount of memory used?

2011-08-18 Thread Jack Bates
I wrote a content filter for Postfix with Python,
https://github.com/jablko/cookie

It should get started once, and hopefully run for a long time - so I'm
interested in how it uses memory:

 1) How does the amount of memory used change as it runs?

 2) How does the amount of memory used change as I continue to hack on
it, and change the code?

My naive thought was that I'd periodically append to a file, the virtual
memory size from /proc/[pid]/stat and a timestamp. From this a could
make a graph of the amount of memory used as my content filter runs, and
I could compare two graphs to get a clue whether this amount changed as
I continue to hack

 - but some Googling quickly revealed that measuring memory is actually
quite complicated? Neither the virtual memory size nor the "resident set
size" accurately measure the amount of memory used by a process

Has anyone else measured the memory used by a Python program? How did
you do it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to convert a list of strings into a list of variables

2011-08-18 Thread David Robinow
On Thu, Aug 18, 2011 at 10:57 AM, noydb  wrote:
> How would you convert a list of strings into a list of variables using
> the same name of the strings?
>
> So, ["red", "one", "maple"] into [red, one, maple]
  Why would you want to?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pairwise combination of two lists

2011-08-18 Thread Ian Kelly
On Wed, Aug 17, 2011 at 4:22 PM, Yingjie Lin  wrote:
> Hi Python users,
>
> I have two lists:
>
> li1 = ['a', 'b']
> li2 = ['1', '2']
>
> and I wish to obtain a list like this
>
> li3 = ['a1', 'a2', 'b1', 'b2']
>
> Is there a handy and efficient function to do this, especially when li1 and 
> li2 are long lists.
> I found zip() but it only gives [('a', '1'), ('b', '2')],  not exactly what I 
> am looking for.

Use the "roundrobin" recipe from the itertools documentation.

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


Re: List spam

2011-08-18 Thread Alain Ketterlin
Ghodmode  writes:

[...]
> Make an effort to curb the spam even if it means killing the newsgroup
> availability.  Choose mailman or Google Groups, or another single
> solution.  Make it members only, but allow anyone to register with an
> automated confirmation email and a CAPTCHA.  Appoint a list admin who
> has a few minutes each day to scan subjects of emails for spammers and
> remove them from the members list.

Or save work and find a public nntp server (or setup one, or ask your
provider), and use a news reader to follow the list (even thunderbird
can do this). No spam, no need to store messages on your machine,
auto-purge after a configurable delay, etc.

Problem solved.

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


Re: extend class: include factories functions inside constructor

2011-08-18 Thread aspineux
On Aug 18, 4:45 pm, Peter Otten <__pete...@web.de> wrote:
> aspineux wrote:
> > Hi
> > I have a closed class and 2 factories function
>
> > class Data:
> >   def __init__(self):
> >     self.payload=None
>
> > def data_from_string(payload):
> >   data=Data()
> >   data.payload=payload
> >   return data
>
> > def data_from_file(f):
> >   data=Data()
> >   data.payload=f.read()
> >   return data
>
> > And I want to extend the class, by first including the factories
> > function inside the constructor,
> > second add some method to the class.
>
> > class MyData(Data):
>
> >   def __init__(self, arg):
> >     # I know this coke is not working, this is to show you
> >     # what I expect
> >     if isinstance(arg, file):
> >         self=data_from_file(arg)
> >     else:
> >         self=data_from_string(arg)
> >     return self
>
> >   def len(self):
> >     return len(self.payload)
>
> > And how I want to use it
>
>  m=MyData('hello')
>  print m.len()
> > 5
>
> > any idea ?
>
> Assuming that Data is an oldstyle class you can either copy the Data
> instance's state
>
> class MyData(Data):
>     def __init__(self, arg):
>         if hasattr(arg, "read"):
>             factory = data_from_file
>         else:
>             factory = data_from_string
>         obj = factory(arg)
>         self.__dict__.update(obj.__dict__)
>
>     def __len__(self):
>         return len(self.payload)
>
> or use another factory function and manually set the __class__:

Exactly what I was looking for

The magic is in  self.__dict__.update(obj.__dict__) :-)


>
> class MyData(Data):
>     def __len__(self):
>         return len(self.payload)
>
> def make_mydata(arg):
>     if hasattr(arg, "read"):
>         factory = data_from_file
>     else:
>         factory = data_from_string
>     obj = factory(arg)
>     obj.__class__ = MyData
>     return obj
>

I don't want to replace 2 factories by one !

> If Data were a newstyle class you could move the hand-made polymorphism into
> the __new__() method:
>
> class MyData(Data):
>     def __new__(class_, arg):
>         if hasattr(arg, "read"):
>             factory = data_from_file
>         else:
>             factory = data_from_string
>         obj = factory(arg)
>         obj.__class__ = class_
>         return obj
>     def __init__(self, arg):
>         pass
>     def __len__(self):
>         return len(self.payload)

Very nice, I wahad no solution for newer style class. Thanks
>
> if __name__ == "__main__":
>     m = MyData("hello")
>     print len(m)
>



> Nothing of the above strikes me as pretty. Perhaps we could come up with a
> neater solution if you tell us more about your use-case...

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


How to convert a list of strings into a list of variables

2011-08-18 Thread noydb
How would you convert a list of strings into a list of variables using
the same name of the strings?

So, ["red", "one", "maple"] into [red, one, maple]

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


Re: List spam

2011-08-18 Thread Alain Ketterlin
"Jason Staudenmayer"  writes:

> I really like this list as part of my learning tools but the amount of
> spam that I've been getting from it is CRAZY. Doesn't anything get
> scanned before it sent to the list?

I'm using nntp to read this newsgroup (through an academic server).
No spam at all.

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


Re: extend class: include factories functions inside constructor

2011-08-18 Thread Peter Otten
aspineux wrote:

> Hi
> I have a closed class and 2 factories function
> 
> class Data:
>   def __init__(self):
> self.payload=None
> 
> def data_from_string(payload):
>   data=Data()
>   data.payload=payload
>   return data
> 
> def data_from_file(f):
>   data=Data()
>   data.payload=f.read()
>   return data
> 
> And I want to extend the class, by first including the factories
> function inside the constructor,
> second add some method to the class.
> 
> class MyData(Data):
> 
>   def __init__(self, arg):
> # I know this coke is not working, this is to show you
> # what I expect
> if isinstance(arg, file):
> self=data_from_file(arg)
> else:
> self=data_from_string(arg)
> return self
> 
>   def len(self):
> return len(self.payload)
> 
> And how I want to use it
> 
 m=MyData('hello')
 print m.len()
> 5
> 
> any idea ?

Assuming that Data is an oldstyle class you can either copy the Data 
instance's state

class MyData(Data):
def __init__(self, arg):
if hasattr(arg, "read"):
factory = data_from_file
else:
factory = data_from_string
obj = factory(arg)
self.__dict__.update(obj.__dict__)

def __len__(self):
return len(self.payload)

or use another factory function and manually set the __class__:

class MyData(Data):
def __len__(self):
return len(self.payload)

def make_mydata(arg):
if hasattr(arg, "read"):
factory = data_from_file
else:
factory = data_from_string
obj = factory(arg)
obj.__class__ = MyData
return obj

If Data were a newstyle class you could move the hand-made polymorphism into 
the __new__() method:

class MyData(Data):
def __new__(class_, arg):
if hasattr(arg, "read"):
factory = data_from_file
else:
factory = data_from_string
obj = factory(arg)
obj.__class__ = class_
return obj
def __init__(self, arg):
pass
def __len__(self):
return len(self.payload)

if __name__ == "__main__":
m = MyData("hello")
print len(m)


Nothing of the above strikes me as pretty. Perhaps we could come up with a 
neater solution if you tell us more about your use-case...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread rantingrick
On Aug 18, 8:39 am, "Jason Staudenmayer"
 wrote:
>
> [snip irony]
>
> Adventure Aquarium is America's Most Touchable Aquarium!
> Featuring the ALL NEW Stingray Beach Club
> Where you can touch and hand feed the gentle stingrays
>
> To buy and print your tickets at home visit  www.AdventureAquarium.com
>       ..·><º>..·`·.><º>..·`·.><º>..·`·.><º>
>                                     ..·`·.><º>..·`·.><º>..·`·.><º>
> ..·><º>..·`·.><º>
>
> A Herschend Family Entertainment Company

Don't you find it a bit ironic that you are complaining about spam but
yet you are spamming this group with your link to buy tickets to a
stingray petting zoo (which is in fact an oxymoron?) under the guise
of spam bashing?  Tip of the day: Create a website!

PS: I do however find the recent "rape" spam atrocious!


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


Re: List spam

2011-08-18 Thread Ghodmode
On Thu, Aug 18, 2011 at 9:39 PM, Philip Semanchuk  wrote:
>
> On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote:
>
>> I really like this list as part of my learning tools but the amount of spam 
>> that I've been getting from it is CRAZY. Doesn't anything get scanned before 
>> it sent to the list?
>
> This has been discussed on the list a number of times before, so I'll refer 
> you to the archives for details.
>
> Basically, the mailing list receives postings from Google Groups and vice 
> versa. Most of the spam comes from Google Groups. If you add a mail filter 
> that deletes anything with the "Organization" header set to 
> "http://groups.google.com";, you won't see much spam anymore. In my 
> experience, you'll also miss a number of legitimate postings.

You are absolutely right, it has been brought up before.  But I'm glad
it's been brought up again.  It's such a problem that it degrades the
usefulness of the list and the community.

Most of the mailing lists I'm on are managed using Google Groups and
many of them are on mailman, like this list.  I don't see spam on
them, so I don't know what's going on here.

It's not really filtering at all.  Most lists only allow members to
post and the admins are quick to boot offenders.

For the most part, I'm just a lurker, so my suggestion shouldn't carry
as much weight, but here it is anyway...

Make an effort to curb the spam even if it means killing the newsgroup
availability.  Choose mailman or Google Groups, or another single
solution.  Make it members only, but allow anyone to register with an
automated confirmation email and a CAPTCHA.  Appoint a list admin who
has a few minutes each day to scan subjects of emails for spammers and
remove them from the members list.

... problem solved.

Yes.  I'm saying we should abandon those who only follow the list via
newsgroups.
Yes.  I'm willing to do the work, but I'm not the right choice.


> HTH
> Philip

--
Ghodmode
http://www.ghodmode.com/blog
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python] Re: Windows service in production?

2011-08-18 Thread Chris Gonnerman
Chiming in late here, but I've been running a very simple Python service 
for some time now on a number of computers.  It's my Raw Print Server, 
available at 
http://newcenturycomputers.net/projects/rawprintserver.html, and I have 
instructions on the page for installing the Windows service version.  
It's really quite simple to do in plain Python; the only reason to use 
py2exe is if you don't want to install a full Python interpreter on the 
computer.  But since I generally do anyway, it doesn't matter to me.


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


Re: List spam

2011-08-18 Thread Ghodmode
On Thu, Aug 18, 2011 at 9:30 PM, Tim Golden  wrote:
> On 18/08/2011 13:58, Jason Staudenmayer wrote:
>>
>> I really like this list as part of my learning tools but the amount
>> of spam that I've been getting from it is CRAZY. Doesn't anything get
>> scanned before it sent to the list?
>
> I haven't seen any significant quantity of spam on the list for ages. (The
> occasional one does get through although I can't remember the last).

Maybe your email client is filtering it out for you.  This list gets A
LOT of spam.  I'm lurking on over 25 different mailing lists and most
of them don't seem to get any spam.  On the others, it's only
occasional and the list admins are quick to pounce on it.  Here, it's
like the floodgates are wide open.


> I always access it as a mailing list, and I seem to recall that
> the newsgroup feed isn't filtered the same way as the mailing list is.

The last time I brought up the topic, I offered to do the work of
filtering and banning spammers.  The consensus seemed to be that it
wasn't possible because the newsgroup IS filtered the same way as the
mailing list.


> TJG

--
Ghodmode
http://www.ghodmode.com/blog
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread gene heskett
On Thursday, August 18, 2011 09:51:04 AM Philip Semanchuk did opine:

> On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote:
> > I really like this list as part of my learning tools but the amount of
> > spam that I've been getting from it is CRAZY. Doesn't anything get
> > scanned before it sent to the list?
> 
> This has been discussed on the list a number of times before, so I'll
> refer you to the archives for details.
> 
> Basically, the mailing list receives postings from Google Groups and
> vice versa. Most of the spam comes from Google Groups. If you add a
> mail filter that deletes anything with the "Organization" header set to
> "http://groups.google.com";, you won't see much spam anymore. In my
> experience, you'll also miss a number of legitimate postings.
> 
> HTH
> Philip

I am about to do just that, block groups.google.com.

AFAIAC, if someone wants to contribute to this mailing list, they can 
damned well join THIS list if they want their posts to be read by the 
subscribers to this list.  Google is not too big to block as I just told 
them while fwding that last bit of boilerplate to them at groups-abuse AT 
google dot com.

Cheers, gene
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Such a fine first dream!
But they laughed at me; they said
I had made it up.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: List spam

2011-08-18 Thread Jason Staudenmayer

> On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote:
>
> > I really like this list as part of my learning tools but
> the amount of spam that I've been getting from it is CRAZY.
> Doesn't anything get scanned before it sent to the list?
>
> This has been discussed on the list a number of times before,
> so I'll refer you to the archives for details.
>
> Basically, the mailing list receives postings from Google
> Groups and vice versa. Most of the spam comes from Google
> Groups. If you add a mail filter that deletes anything with
> the "Organization" header set to "http://groups.google.com";,
> you won't see much spam anymore. In my experience, you'll
> also miss a number of legitimate postings.
>

Ahhh, that would explain all the google stuff in the headers. Thanks for
the heads-up
I'll look at changing my spamassassin scoring for those.

Jason


Adventure Aquarium is America's Most Touchable Aquarium!
Featuring the ALL NEW Stingray Beach Club
Where you can touch and hand feed the gentle stingrays


To buy and print your tickets at home visit  www.AdventureAquarium.com
  ..·><º>..·`·.><º>..·`·.><º>..·`·.><º>
..·`·.><º>..·`·.><º>..·`·.><º>
..·><º>..·`·.><º>

A Herschend Family Entertainment Company
-- 
http://mail.python.org/mailman/listinfo/python-list


extend class: include factories functions inside constructor

2011-08-18 Thread aspineux
Hi
I have a closed class and 2 factories function

class Data:
  def __init__(self):
self.payload=None

def data_from_string(payload):
  data=Data()
  data.payload=payload
  return data

def data_from_file(f):
  data=Data()
  data.payload=f.read()
  return data

And I want to extend the class, by first including the factories
function inside the constructor,
second add some method to the class.

class MyData(Data):

  def __init__(self, arg):
# I know this coke is not working, this is to show you
# what I expect
if isinstance(arg, file):
self=data_from_file(arg)
else:
self=data_from_string(arg)
return self

  def len(self):
return len(self.payload)

And how I want to use it

>>> m=MyData('hello')
>>> print m.len()
5

any idea ?

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


RE: List spam

2011-08-18 Thread Jason Staudenmayer

> On 18/08/2011 13:58, Jason Staudenmayer wrote:
> > I really like this list as part of my learning tools but the amount
> > of spam that I've been getting from it is CRAZY. Doesn't
> anything get
> > scanned before it sent to the list?
>
> I haven't seen any significant quantity of spam on the list for ages.
> (The occasional one does get through although I can't
> remember the last).
>
> I always access it as a mailing list, and I seem to recall that
> the newsgroup feed isn't filtered the same way as the mailing list is.

I've been getting more and more. Upon checking the header info the last
hop
is from the list server. Here's part of the header:

Received: from  (HELO mail.python.org) (82.94.164.166)
  by mail2.adventureaquarium.com with SMTP; 17 Aug 2011 23:53:17 -
Received: from albatross.python.org (localhost [127.0.0.1])
by mail.python.org (Postfix) with ESMTP id 3RfS705P3czN9Y
for ; Thu, 18 Aug 2011 01:53:16
+0200 (CEST)


I can deal with normal spam but this stuff I've gotten is all about
rape.

Jason


Adventure Aquarium is America's Most Touchable Aquarium!
Featuring the ALL NEW Stingray Beach Club
Where you can touch and hand feed the gentle stingrays


To buy and print your tickets at home visit  www.AdventureAquarium.com
  ..·><º>..·`·.><º>..·`·.><º>..·`·.><º>
..·`·.><º>..·`·.><º>..·`·.><º>
..·><º>..·`·.><º>

A Herschend Family Entertainment Company
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List spam

2011-08-18 Thread Philip Semanchuk

On Aug 18, 2011, at 8:58 AM, Jason Staudenmayer wrote:

> I really like this list as part of my learning tools but the amount of spam 
> that I've been getting from it is CRAZY. Doesn't anything get scanned before 
> it sent to the list?

This has been discussed on the list a number of times before, so I'll refer you 
to the archives for details.

Basically, the mailing list receives postings from Google Groups and vice 
versa. Most of the spam comes from Google Groups. If you add a mail filter that 
deletes anything with the "Organization" header set to 
"http://groups.google.com";, you won't see much spam anymore. In my experience, 
you'll also miss a number of legitimate postings. 

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


Re: List spam

2011-08-18 Thread Tim Golden

On 18/08/2011 13:58, Jason Staudenmayer wrote:

I really like this list as part of my learning tools but the amount
of spam that I've been getting from it is CRAZY. Doesn't anything get
scanned before it sent to the list?


I haven't seen any significant quantity of spam on the list for ages. 
(The occasional one does get through although I can't remember the last).


I always access it as a mailing list, and I seem to recall that
the newsgroup feed isn't filtered the same way as the mailing list is.

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


Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-18 Thread Roy Smith
In article 
<16ea4848-db0c-489a-968c-ca40700f5...@m5g2000prh.googlegroups.com>,
 gc  wrote:

> I frequently need to initialize several variables to the same
> value, as I'm sure many do. Sometimes the value is a constant, often
> zero; sometimes it's more particular, such as defaultdict(list). I use
> dict() below.

Keep in mind that when you do:

a = dict()
b = dict()

you are NOT initializing a and b to the same value.  You are 
initializing each of them to a different empty dictionary, which is very 
different from

a = b = dict()

I suspect you knew that, but it's worth mentioning.

> # Option 1 (separate lines)
> # Verbose and annoying, particularly when the varnames are long and of
> irregular length
> 
> a = dict()
> b = dict()
> c = dict()
> d = dict()
> e = dict()

This seems the best to me.  Simple, straight-forward, easy to 
understand.  What could be bad?  It may not be elegant, but if I could 
have a nickel for every hour I've wasted trying to understand elegant 
code, I'd be a rich man.  I can understand the above code in an instant, 
even at 2 AM juiced up on sugar and caffeine.
-- 
http://mail.python.org/mailman/listinfo/python-list


List spam

2011-08-18 Thread Jason Staudenmayer
I really like this list as part of my learning tools but the amount of spam 
that I've been getting from it is CRAZY. Doesn't anything get scanned before it 
sent to the list?

Jason
 
 
 
..·><º>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lists and for loops

2011-08-18 Thread Tim Chase

On 08/18/2011 07:22 AM, Mark Niemczyk wrote:

Or, using list comprehension.


numbers = [1, 2, 3, 4, 5]
numbers = [n + 5 for n in numbers]
numbers

[6, 7, 8, 9, 10]


Or, if you want it in-place:

  numbers[:] = [n+5 for n in numbers]

which makes a difference if you have another reference to numbers:

>>> numbers = [1,2,3,4,5]
>>> digits = numbers
>>> numbers = [n+5 for n in numbers]
>>> numbers, digits
([6, 7, 8, 9, 10], [1, 2, 3, 4, 5])
>>> numbers = [1,2,3,4,5]
>>> digits = numbers
>>> numbers[:] = [n+5 for n in numbers]
>>> numbers, digits
([6, 7, 8, 9, 10], [6, 7, 8, 9, 10])

-tkc



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


Re: lists and for loops

2011-08-18 Thread Mark Niemczyk
Or, using list comprehension.

>>> numbers = [1, 2, 3, 4, 5]
>>> numbers = [n + 5 for n in numbers]
>>> numbers
[6, 7, 8, 9, 10]
-- 
http://mail.python.org/mailman/listinfo/python-list


decorator issue with modules dbus & gobject

2011-08-18 Thread Makiavelik
Hi,
Here is a sample code that reproduces the issue :
[code]
import logging
import unittest
import signal
import gobject
import dbus
from functools import wraps
from dbus.mainloop.glib import DBusGMainLoop

class TimeoutException(Exception):
   pass

def timeout(timeout_time=1800):
   """
   decorator function catching the argument
   """
   def timeout_function(func):
   """
   decorator function
   """
   @wraps(func)
   def _timeout_function(self):
   """
   create a signal handler
   set the timeout with the argument given while calling the
decorator @timeout
   call the function
   catch a timeout exception if necessary
   """
   def timeout_handler(signum, frame):
   print 'Timeout (%s sec) reached' % str(timeout_time)
   raise TimeoutException()

   old_handler = signal.signal(signal.SIGALRM,
timeout_handler)
   signal.alarm(timeout_time) # triger alarm in timeout_time
seconds
   try:
   retval = func(self)
   finally:
   signal.signal(signal.SIGALRM, old_handler)
   signal.alarm(0)
   return retval
   return _timeout_function
   return timeout_function

class Test_loopRun_And_Timeout(unittest.TestCase):
   def __init__(self,*args,**kwargs):
   super(Test_loopRun_And_Timeout, self).__init__(*args,**kwargs)
   dbus_loop = DBusGMainLoop(set_as_default=True)
   self.bus = dbus.SessionBus(private=True,mainloop=dbus_loop)
   self.loop = gobject.MainLoop()

   logging.basicConfig()
   self.__logger = logging.getLogger("Tests.%s" %
self.__class__.__name__)
   self.__logger.setLevel(logging.DEBUG)

   def setUp(self):
   '''
   in this part, mediarouter can not be created
   Setup are all launch in //
   So if 50 tests are run in this class, 50 mediarouters are
created
   '''
   pass


   def tearDown(self):
   '''
   '''

   @timeout(5)
   def test_001(self):
   '''
   '''
   self.__logger.info('[CHECKPOINT] test_001')
   try:
   self.__logger.info('entering a waiting loop')
   self.loop.run()
   self.__logger.info('dummy log, should not appear')
   self.fail()

   except KeyboardInterrupt:
   self.__logger.exception('Catching a Ctrl+c event (user or
timeout)')
   except :
   self.__logger.exception('Unexpected error')
   self.fail()


   @timeout(5)
   def test_002(self):
   '''
   '''
   def loop_quit(loop):
   loop.quit()
   return False


   self.__logger.info('[CHECKPOINT] test_002')
   try:
   self.__logger.info('entering a waiting loop')
   gobject.timeout_add(1000, loop_quit, self.loop)
   self.loop.run()
   self.__logger.info('exiting the loop')

   except KeyboardInterrupt:
   self.__logger.exception('Catching a Ctrl+c event (user or
timeout)')
   self.fail()
   except :
   self.__logger.exception('Unexpected error')
   self.fail()
[/code]

If I start a unittest campaign like this :
[code]
if __name__ == "__main__":
   #Add the test you want to run
   suite = unittest.TestSuite()

   #To choose a list of tests, comment those you don't want to run
   suite.addTest(Test_loopRun_And_Timeout('test_002'))
   suite.addTest(Test_loopRun_And_Timeout('test_001'))
   unittest.TextTestRunner(verbosity=0).run(suite)
   print 'done'
[/code]
the result give me 2 tests OK

Now If I launch this
[code]
if __name__ == "__main__":
   #Add the test you want to run
   suite = unittest.TestSuite()

   #To choose a list of tests, comment those you don't want to run
   suite.addTest(Test_loopRun_And_Timeout('test_001'))
   suite.addTest(Test_loopRun_And_Timeout('test_002'))
   unittest.TextTestRunner(verbosity=0).run(suite)
   print 'done'
[/code]
1 OK (test_001)
1 Fail (test_002 goes on timeout)

And if I am using more than 3 Testcases, the code is going to run in
infinite loop (Ctrl+C or timeout decorator does not work, only a kill
works)


Is there an issue using the 'timeout' decorator with the loop.run() ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-18 Thread John Pinner
On Aug 3, 2:45 am, gc  wrote:
> Hi everyone! Longtime lurker, hardly an expert, but I've been using
> Python for various projects since 2007 and love it.
>
> I'm looking for either (A) suggestions on how to do a very common
> operation elegantly and Pythonically, or (B) input on whether my
> proposal is PEP-able, assuming there's no answer to A. (The proposal
> is sort of like the inverse of PEP 3132; I don't think it has been
> proposed before, sorry if I missed it.)
>
> Anyway, I frequently need to initialize several variables to the same
> value, as I'm sure many do. Sometimes the value is a constant, often
> zero; sometimes it's more particular, such as defaultdict(list). I use
> dict() below.
>
> Target lists using comma separation are great, but they don't work
> very well for this task. What I want is something like
>
> a,b,c,d,e = *dict()
>
> where * in this context means something like "assign separately to
> all." I'm not sure that * would the best sugar for this, but the
> normal meaning of * doesn't seem as if it would ever be valid in this
> case, and it somehow feels right (to me, anyway).
>
> Statements fitting the form above would get expanded during parsing to
> a sequence of separate assignments (a = dict(); b = dict(); c = dict()
> and so forth.) That's all there is to it. Compared to the patterns
> below, it's svelte, less copy-paste-y (so it removes an opportunity
> for inconsistency, where I remember to change a-d to defaultdict(list)
> but forget with e), and it doesn't require me to keep count of the
> number of variables I'm initializing.
>
> This would update section 6.2 of the language reference and require a
> small grammar expansion.
>
> But: Is there already a good way to do this that I just don't know?
> Below, I compare four obvious patterns, three of which are correct but
> annoying and one of which is incorrect in a way which used to surprise
> me when I was starting out.
>
> # Option 1 (separate lines)
> # Verbose and annoying, particularly when the varnames are long and of
> irregular length
>
> a = dict()
> b = dict()
> c = dict()
> d = dict()
> e = dict()
>
> # Option 2 (one line)
> # More concise but still pretty annoying, and hard to read (alternates
> variables and assignments)
>
> a = dict(); b = dict(); c = dict(); d = dict(); e = dict()
>
> # Option 3 (multiple target list: this seems the most Pythonic, and is
> normally what I use)
> # Concise, separates variables from assignments, but somewhat
> annoying; have to change individually and track numbers on both sides.
>
> a,b,c,d,e = dict(),dict(),dict(),dict(),dict()
>
> # Option 4 (iterable multiplication)
> # Looks better, and if the dict() should be something else, you only
> have to change it once, but the extra brackets are ugly and you still
> have to keep count of the targets...
>
> a,b,c,d,e = [dict()] * 5
>
> # and it will bite you...
>
> >>> a[1] = 1
> >>> b
> {1: 1}
> >>> id(a) == id(b)
>
> True
>
> # Gotcha!
>
> # Other forms of 4 also have this behavior:
>
> a,b,c,d,e = ({},) * 5>>> a[1] = 1
> >>> b
>
> {1: 1}
>
> Alternatively, is there a version of iterable multiplication that
> creates new objects rather than just copying the reference? That would
> solve part of the problem, though it would still look clunky and you'd
> still have to keep count.
>
> Any thoughts? Thanks!

I hesitate to put this forward, as it smells and is probably
considered bad practice, but heh!

for char in 'abcdefg' :
globals()[ char ] = dict()

does what you wanted.

Best wishes,

John
--


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


Re: Wait for a keypress before continuing?

2011-08-18 Thread peter
On Aug 17, 3:16 pm, Hans Mulder  wrote:
> On 17/08/11 10:03:00, peter wrote:
>
> > Is there an equivalent to msvcrt for Linux users?  I haven't found
> > one, and have resorted to some very clumsy code which turns off
> > keyboard excho then reads stdin. Seems such an obvious thing to want
> > to do I am surprised there is not a standard library module for it. Or
> > have I missed someting (wouldn't be the first time!)
>
> The quick and dirty way is to invoke stty(1) using os.system:
>
> import os
>
> def getpassword(prompt="Password: "):
>      try:
>          os.system("stty -echo")
>          passwd = raw_input(prompt)
>      finally:
>          os.system("stty echo")
>      return passwd
>
> Strictly speaking, os.system is deprecated and you should use
> the equivalent invocation of subprocess.call:
>
> import subprocess
>
> def getpassword(prompt="Password: "):
>      try:
>          subprocess.call(["stty", "-echo"])
>          passwd = raw_input(prompt)
>      finally:
>          subprocess.call(["stty", "echo"])
>      return passwd
>
> If you don't want to use an external process, use termios:
>
> import termios, sys
>
> def getpassword(prompt="Password: "):
>      fd = sys.stdin.fileno()
>      old = termios.tcgetattr(fd)
>      new = termios.tcgetattr(fd)
>      new[3] = new[3] & ~termios.ECHO          # lflags
>      try:
>          termios.tcsetattr(fd, termios.TCSADRAIN, new)
>          passwd = raw_input(prompt)
>      finally:
>          termios.tcsetattr(fd, termios.TCSADRAIN, old)
>      return passwd
>
> These functions work on any Posix system (including Mac OSX),
> but not on Windows.
>
> Hope this helps,
>
> -- HansM

This is very similar to my solution, which was to use stty turn off
keyboard echo, then repeatedly read sys.stdin.read(1) until a unique
keystroke had been defined. For example, the 'Insert' key seems to
return a sequence of four codes, namely 27, 91, 50, 126.  It works but
has two disadvantages which I have managed to live with:-

1. As character 27 is used to signal the start of a 'special' key
sequence, it cannot detect a single press of the Esc key. The
workaround is to detect a double press instead.

2. Some keys seem to return different sets of codes depending on the
circumstances.  For example, F1 returns 27,91,91,65 from the command
line, and 27,79,80 from a GUI window. I suspect there may be
variations between flavours of Linux too. The solution is to detect
all possibilities - so far I haven't found any overlaps.

Not pretty, but as I said it works. I know now not to spend time
looking further. Whilst there may be a historical reason for the
current situation, it would be a great convenience for amateur coders
like mayself if the gurus could devise a platform independent version
of mscvrt.

If anyone is interested in the code I can post it, but it's quite long
as it comprises multiple if statements to cover each combination.

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


Re: pairwise combination of two lists

2011-08-18 Thread Alain Ketterlin
Yingjie Lin  writes:

> I have two lists: 
>
> li1 = ['a', 'b']
> li2 = ['1', '2']
>
> and I wish to obtain a list like this
>
> li3 = ['a1', 'a2', 'b1', 'b2']
>
> Is there a handy and efficient function to do this, especially when
> li1 and li2 are long lists.

It's not difficult to write your own:

def product(l1,l2):
for x1 in l1:
for x2 in l2:
yield x1+x2

use it like: for p in product(l1,l2) ... The call to product() produces
a generator, the cross product is never built in full, it should work on
long lists.

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


Re: pairwise combination of two lists

2011-08-18 Thread Paul Rubin
Yingjie Lin  writes:
> li1 = ['a', 'b']
> li2 = ['1', '2']
>
> and I wish to obtain a list like this
> li3 = ['a1', 'a2', 'b1', 'b2']

from itertools import *

li3 = list(chain.from_iterable(izip(li1,li2)))
-- 
http://mail.python.org/mailman/listinfo/python-list