Re: Top-posting &c. (was Re: [ANNC] pybotwar-0.8)

2012-08-21 Thread Bob Martin
in 679182 20120821 181439 Dennis Lee Bieber wrote: >On Tue, 21 Aug 2012 08:07:33 +0200, Alex Strickland >declaimed the following in gmane.comp.python.general: > >> On 2012/08/17 12:42 AM, Madison May wrote: >> >> > As a lurker, I agree completely with Chris'

help me debug my "word capitalizer" script

2012-08-21 Thread Santosh Kumar
Here is the script I am using: from os import linesep from string import punctuation from sys import argv script, givenfile = argv with open(givenfile) as file: # List to store the capitalised lines. lines = [] for line in file: # Split words by spaces. words = line.s

Re: asking

2012-08-21 Thread alex23
On 22/08/12 03:57, mingqiang hu wrote: > can I use just one statement to figure out if substring “a” ,"b" "c" > are in string "adfbdfc" ? not use the statement like > ("a" in "adfbdfc") or ( "b" in "adfbdfc") or ("c" in "adfbdfc" ) > ,because if I have lots of substring, this could sucks subs = ['

Re: something about split()???

2012-08-21 Thread Terry Reedy
On 8/21/2012 11:43 PM, mingqiang hu wrote: why filter is bad when use lambda ? Inefficient, not 'bad'. Because the equivalent comprehension or generator expression does not require a function call. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list

Re: asking

2012-08-21 Thread Terry Reedy
On 8/21/2012 10:57 PM, mingqiang hu wrote: can I use just one statement to figure out if substring “a” ,"b" "c" are in string "adfbdfc" ? not use the statement like ("a" in "adfbdfc") or ( "b" in "adfbdfc") or ("c" in "adfbdfc" ) ,because if I have lots of substring, this could sucks >>>

Re: asking

2012-08-21 Thread Dave Angel
On 08/22/2012 12:17 AM, Ian Foote wrote: > Oops, hopefully this with indent correctly: > > def all_in(string, substrings): > for substring in substrings: > if substring not in string: > return False > return True The POP's question was ambiguous (did he want to match an

Re: asking

2012-08-21 Thread Ian Foote
Oops, hopefully this with indent correctly: def all_in(string, substrings): for substring in substrings: if substring not in string: return False return True -- http://mail.python.org/mailman/listinfo/python-list

Re: asking

2012-08-21 Thread Ian Foote
On 22/08/12 03:57, mingqiang hu wrote: can I use just one statement to figure out if substring “a” ,"b" "c" are in string "adfbdfc" ? not use the statement like ("a" in "adfbdfc") or ( "b" in "adfbdfc") or ("c" in "adfbdfc" ) ,because if I have lots of substring, this could sucks This might

Re: something about split()???

2012-08-21 Thread mingqiang hu
why filter is bad when use lambda ?actually I think I can use lambda like this: filter(lambda x:x==None,"|",split("|")) On Wed, Aug 15, 2012 at 1:33 PM, Ramchandra Apte wrote: > filter is bad when you use lambda with it > there are (good) cases for filter > > > On 14 August 2012 22:39, Jean-Miche

Re: Books?

2012-08-21 Thread Anonymous Group
On Aug 21, 7:04 pm, Chris Angelico wrote: > On Wed, Aug 22, 2012 at 11:39 AM, Roy Smith wrote: > > In article > > <5203ee16-5a80-4cd9-9434-ee2efb645...@kg10g2000pbc.googlegroups.com>, > >  Anonymous Group wrote: > > >> What books do you recomend for learning python? Preferably free and/or > >> o

Re: Books?

2012-08-21 Thread Chris Angelico
On Wed, Aug 22, 2012 at 11:39 AM, Roy Smith wrote: > In article > <5203ee16-5a80-4cd9-9434-ee2efb645...@kg10g2000pbc.googlegroups.com>, > Anonymous Group wrote: > >> What books do you recomend for learning python? Preferably free and/or >> online. > > I would start with http://docs.python.org/tu

Re: Books?

2012-08-21 Thread Roy Smith
In article <5203ee16-5a80-4cd9-9434-ee2efb645...@kg10g2000pbc.googlegroups.com>, Anonymous Group wrote: > What books do you recomend for learning python? Preferably free and/or > online. I would start with http://docs.python.org/tutorial/ -- http://mail.python.org/mailman/listinfo/python-list

Re: protobuf + pypy

2012-08-21 Thread Mark Lawrence
On 21/08/2012 22:55, Pedro Larroy wrote: Hi Anyone knows if it's possible to use protobuffers with pypy? Seems there isn't much info on the web about this. Pedro. Did you mean this, in which case there loads on the web http://code.google.com/p/protobuf/ ? -- Cheers. Mark Lawrence. --

Reimporting modules, and sandboxing?

2012-08-21 Thread Dan Stromberg
I know I've seen this discussed before, and I came away from observing the discussion thinking "Python doesn't do that very well...", but we have some people here who really would like to do this, and I need to better understand the pros and cons now. Is there a good way of reimporting an _indepen

Re: Why doesn't Python remember the initial directory?

2012-08-21 Thread John Roth
On Sunday, August 19, 2012 7:57:46 PM UTC-6, kj wrote: > This means that no library code can ever count on, for example, > > being able to reliably find the path to the file that contains the > > definition of __main__. If you want to find that, look up __main__ in sys.modules and then look at

Re: unittest - sort cases to be run

2012-08-21 Thread Peter Otten
Kevin Zhang wrote: > I want to sort the order of the unittest cases to be run, but found such > statement in Python doc, > "Note that the order in which the various test cases will be run is > determined by sorting the test function names with respect to the built-in > ordering for strings." > >

Re: Why does dynamic doc string do not work?

2012-08-21 Thread Miki Tebeka
Thanks! > On 08/21/2012 12:44 PM, Miki Tebeka wrote: > > > > > >>> class B: > > > ... '''a {} string'''.format('doc') > > > ... > > B.__doc__ > > > > > I wonder why the first B docstring is empty. Thanks, -- Miki > > > > According to some early documentation: > >

Re: Why does dynamic doc string do not work?

2012-08-21 Thread Dave Angel
On 08/21/2012 12:44 PM, Miki Tebeka wrote: > >>> class B: > ... '''a {} string'''.format('doc') > ... B.__doc__ > I wonder why the first B docstring is empty. Thanks, -- Miki According to some early documentation: "convenient initialization of the |__doc__| attribute of modu

Re: Why does dynamic doc string do not work?

2012-08-21 Thread Steven D'Aprano
On Tue, 21 Aug 2012 09:44:10 -0700, Miki Tebeka wrote: > Greetings, > class A: > ... '''a doc string''' > ... A.__doc__ > 'a doc string' class B: > ... '''a {} string'''.format('doc') ... B.__doc__ > Is there's a reason for this? Yes. Python only generates

Re: unittest - sort cases to be run

2012-08-21 Thread goon12
On Tuesday, August 21, 2012 5:34:33 AM UTC-4, Terry Reedy wrote: > On 8/21/2012 5:09 AM, Kevin Zhang wrote: > > > Hi all, > > > > > > I want to sort the order of the unittest cases to be run, but found such > > > statement in Python doc, > > > "Note that the order in which the various test cas

Re: Why does dynamic doc string do not work?

2012-08-21 Thread Ian Kelly
On Tue, Aug 21, 2012 at 11:09 AM, Ian Kelly wrote: > On Tue, Aug 21, 2012 at 10:44 AM, Miki Tebeka wrote: >> Greetings, >> > class A: >> ... '''a doc string''' >> ... > A.__doc__ >> 'a doc string' > class B: >> ... '''a {} string'''.format('doc') >> ... > B.__doc__ > >

Re: Why does dynamic doc string do not work?

2012-08-21 Thread MRAB
On 21/08/2012 17:44, Miki Tebeka wrote: Greetings, class A: ... '''a doc string''' ... A.__doc__ 'a doc string' class B: ... '''a {} string'''.format('doc') ... B.__doc__ Is there's a reason for this? I know I can do: class B: ...__doc__ = '''a {} string'''.format('doc')

Re: Abuse of subject, was Re: Abuse of Big Oh notation

2012-08-21 Thread wxjmfauth
Le mardi 21 août 2012 09:52:09 UTC+2, Peter Otten a écrit : > wxjmfa...@gmail.com wrote: > > > > > By chance and luckily, first attempt. > > > > > c:\python32\python -m timeit "('€'*100+'€'*100).replace('€' > > > , 'œ')" > > > 100 loops, best of 3: 1.48 usec per loop > > > c:\python33

Re: Why does dynamic doc string do not work?

2012-08-21 Thread Ian Kelly
On Tue, Aug 21, 2012 at 10:44 AM, Miki Tebeka wrote: > Greetings, > class A: > ... '''a doc string''' > ... A.__doc__ > 'a doc string' class B: > ... '''a {} string'''.format('doc') > ... B.__doc__ > > Is there's a reason for this? > > I know I can do: class B

Re: color coding for numbers

2012-08-21 Thread DJC
On 21/08/12 12:55, Ulrich Eckhardt wrote: Am 21.08.2012 10:38, schrieb namenobodywa...@gmail.com: what is the best way Define "best" before asking such questions. ;) matplotlib.colors A module for co

Re: How to set the socket type and the protocol of a socket using create_connection?

2012-08-21 Thread Guillaume Comte
Unfortunatly, my_socket.bind((src_addr, 1)) doesn't work. I get the error message: "socket.error: [Errno 49] Can't assign requested address"... I've tried to change the protocol to IPPROTO_RAW. Here is a simple example of the code: import socket import os import struct import time import sele

Why does dynamic doc string do not work?

2012-08-21 Thread Miki Tebeka
Greetings, >>> class A: ... '''a doc string''' ... >>> A.__doc__ 'a doc string' >>> class B: ... '''a {} string'''.format('doc') ... >>> B.__doc__ >>> Is there's a reason for this? I know I can do: >>> class B: ...__doc__ = '''a {} string'''.format('doc') And it'll work, but I wo

Re: How to convert base 10 to base 2?

2012-08-21 Thread Miki Tebeka
> You get the binary by doing bin(x), where x is an integer. Note that Python also support binary number literals (prefixed with 0b): In [1]: 0b101 Out[1]: 5 -- http://mail.python.org/mailman/listinfo/python-list

Re: [ANNC] pybotwar-0.8

2012-08-21 Thread Ramchandra Apte
On Tuesday, 21 August 2012 12:41:39 UTC+5:30, Jamie Paul Griffin wrote: > [ Ramchandra Apte wrote on Sat 18.Aug'12 at 19:21:03 +0530 ] > > > > > I'll be using Google Groups (hopefully it won't top-post by default) to > > > post stuff. > > > > You are encouraged to get used to it i'm afraid

Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On 21 August 2012 16:19, Oscar Benjamin wrote: > > On Aug 21, 2012 3:42 PM, "Massimo DiPierro" > wrote: > > > > Thanks again Oscar. I cannot do that. I have tight constraints. I am not > at liberty to modify the code that uses the class. The exposed API cannot > change including a.x, dict(a), is

Re: Class.__class__ magic trick help

2012-08-21 Thread Massimo DiPierro
Thanks again Oscar. I cannot do that. I have tight constraints. I am not at liberty to modify the code that uses the class. The exposed API cannot change including a.x, dict(a), is isinstance(a,dict). My goal it so change the definition of this class to make it faster. Where is in the Python so

Re: Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On 21 August 2012 14:50, Massimo Di Pierro wrote: > Hello Oscar, > > thanks for your help but your proposal of adding: > > def __setitem__(self,key,value): >self.__dict__[key] = value >dict.__setitem__(self, key, value) > > does not help me. > > What I have today is a class that works like

Re: Class.__class__ magic trick help

2012-08-21 Thread Massimo Di Pierro
Hello Oscar, thanks for your help but your proposal of adding: def __setitem__(self,key,value): self.__dict__[key] = value dict.__setitem__(self, key, value) does not help me. What I have today is a class that works like SlowStorage. I want to replace it with NewStorage because it is 10x

Re: remote read eval print loop

2012-08-21 Thread Eric Frederich
This isn't really for users. It is for developers like me. Yes it is a security hole but again, it is a debugger. The people who will be using it can all ssh into the server machine with the same ID that the server process is running on. In fact, this is quite normal. As it is right now, we log

Re: Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On 21 August 2012 13:52, Massimo Di Pierro wrote: > On Aug 21, 2:40 am, Oscar Benjamin wrote: > > On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro > > > > > > > > > > > > > > > > > > > > wrote: > > > Consider this code: > > > class SlowStorage(dict): > > > def __getattr__(self,key

Re: Class.__class__ magic trick help

2012-08-21 Thread Massimo Di Pierro
On Aug 21, 2:40 am, Oscar Benjamin wrote: > On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro > > > > > > > > > > wrote: > > Consider this code: > > class SlowStorage(dict): > >     def __getattr__(self,key): > >           return self[key] > >     def __setattr__(self,key): > >        

Re: python 6 compilation failure on RHEL

2012-08-21 Thread Jerry Hill
On Tue, Aug 21, 2012 at 12:34 AM, John Nagle wrote: > After a thread of clueless replies, it's clear that nobody > responding actually read the build log. Here's the problem: The very first reply, Emile's, pointed out that these were optional modules, and that python did, in fact build succe

Re: Does Polymorphism mean python can create object?

2012-08-21 Thread Roy Smith
In article , Chris Angelico wrote: > On Tue, Aug 21, 2012 at 10:20 AM, alex23 wrote: > > On Tue, Aug 21, 2012 at 12:01 AM, Levi Nie wrote: > >> Does Polymorphism mean python can create object? > > > > No. This isn't D&D. Polymorphism has a distinct meaning in computer > > science, one which yo

Re: New internal string format in 3.3

2012-08-21 Thread Roy Smith
In article , Michael Torrie wrote: > > And if you want the "fudge it somehow" behavior (which is often very > > useful!), there's always http://pypi.python.org/pypi/Unidecode/ > > Sweet tip, thanks! I often want to process text that has smart quotes, > emdashes, etc, and convert them to plain

Re: color coding for numbers

2012-08-21 Thread Ulrich Eckhardt
Am 21.08.2012 10:38, schrieb namenobodywa...@gmail.com: what is the best way Define "best" before asking such questions. ;) using color/shading on a tkinter canvas as a visualization for a two-dimensional grid of numbers? so far my best idea is to use the same value for R,G and B (fill = '#x

Re: Abuse of Big Oh notation

2012-08-21 Thread Steven D'Aprano
On Mon, 20 Aug 2012 11:12:22 -0600, Ian Kelly wrote: > On Mon, Aug 20, 2012 at 10:09 AM, Chris Angelico > wrote: >> On Tue, Aug 21, 2012 at 2:01 AM, Paul Rubin >> wrote: >>> Analogy: how big a box is required to hold a pair of shoes? In a >>> purely theoretical sense we might say O(S) where S i

Re: unittest - sort cases to be run

2012-08-21 Thread Terry Reedy
On 8/21/2012 5:09 AM, Kevin Zhang wrote: Hi all, I want to sort the order of the unittest cases to be run, but found such statement in Python doc, "Note that the order in which the various test cases will be run is determined by sorting the test function names with respect to the built-in orderi

python-list@python.org

2012-08-21 Thread Ulrich Eckhardt
Am 21.08.2012 00:49, schrieb Prasad, Ramit: I also tend to blame M$ (Outlook and variants) for this tendency to quote everything and top-post -- Outlook makes it almost impossible to do a trim&interleave response style. I [think] that Outlook & Co are guilty. That and the fact that few people e

unittest - sort cases to be run

2012-08-21 Thread Kevin Zhang
Hi all, I want to sort the order of the unittest cases to be run, but found such statement in Python doc, "Note that the order in which the various test cases will be run is determined by sorting the test function names with respect to the built-in ordering for strings." s.addTest(BTest())

Re: Does Polymorphism mean python can create object?

2012-08-21 Thread Chris Angelico
On Tue, Aug 21, 2012 at 10:20 AM, alex23 wrote: > On Tue, Aug 21, 2012 at 12:01 AM, Levi Nie wrote: >> Does Polymorphism mean python can create object? > > No. This isn't D&D. Polymorphism has a distinct meaning in computer science, > one which you would've found in less time searching Wikipedia

Re: Top-posting &c. (was Re: [ANNC] pybotwar-0.8)

2012-08-21 Thread Steven D'Aprano
On Tue, 21 Aug 2012 08:07:33 +0200, Alex Strickland wrote: > On 2012/08/17 12:42 AM, Madison May wrote: > >> As a lurker, I agree completely with Chris's sentiments. > > I too, but I'd prefer something top-posted than have to skip through 38 > pages of quoted e-mail to get to a (generally) 1 lin

Abuse of subject, was Re: Abuse of Big Oh notation

2012-08-21 Thread Peter Otten
wxjmfa...@gmail.com wrote: > By chance and luckily, first attempt. > c:\python32\python -m timeit "('€'*100+'€'*100).replace('€' > , 'œ')" > 100 loops, best of 3: 1.48 usec per loop > c:\python33\python -m timeit "('€'*100+'€'*100).replace('€' > , 'œ')" > 10 loops, best of 3: 7.62 usec p

Re: Class.__class__ magic trick help

2012-08-21 Thread Oscar Benjamin
On Mon, 20 Aug 2012 21:17:15 -0700 (PDT), Massimo Di Pierro wrote: Consider this code: class SlowStorage(dict): def __getattr__(self,key): return self[key] def __setattr__(self,key): self[key]=value class FastStorage(dict): def __init__(self, __d__=None, *

Re: [ANNC] pybotwar-0.8

2012-08-21 Thread Jamie Paul Griffin
[ Ramchandra Apte wrote on Sat 18.Aug'12 at 19:21:03 +0530 ] > I'll be using Google Groups (hopefully it won't top-post by default) to > post stuff. You are encouraged to get used to it i'm afraid as any mailing list you use, its users will prefer you to use the correct formatting of responses.

Re: How do I display unicode value stored in a string variable using ord()

2012-08-21 Thread Neil Hodgson
Steven D'Aprano: Using variable-sized strings like UTF-8 and UTF-16 for in-memory representations is a terrible idea because you can't assume that people will only every want to index the first or last character. On average, you need to scan half the string, one character at a time. In Big-Oh, w