Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-09 Thread Ian Kelly
On Wed, May 9, 2012 at 4:30 PM, Adrian Hunt wrote: > > Hi ya, > > Not to be confrontative but just because a project is open-source, it > doesn't mean IP is open too!! The original idea is still property of the > originator... It just has the global community adding their own IP and > fixes.  This

Re: Newbie naive question ... int() throws ValueError

2012-05-11 Thread Ian Kelly
On Fri, May 11, 2012 at 10:23 AM, Chris Angelico wrote: > Hmm. What happens if the interpreter can't construct a MemoryError exception? I believe that a MemoryError instance is pre-allocated for just this scenario. You can see it in the result of gc.get_objects(). >>> [x for x in gc.get_objects

Re: dynamically selecting a class to instantiate based on the object attributes.

2012-05-14 Thread Ian Kelly
On Wed, May 9, 2012 at 5:02 AM, J. Mwebaze wrote: > > I have a  bunch of objects of the same type. Each object has a version > attribute and this refers to source code that was used to make the object. > SouceCode is maintained in separate files. eg. > myclass_01.py, myclass_02.py, myclass_03.py, 

Re: tiny script has memory leak

2012-05-14 Thread Ian Kelly
On Fri, May 11, 2012 at 3:29 PM, gry wrote: > sys.version --> '2.6 (r26:66714, Feb 21 2009, 02:16:04) \n[GCC 4.3.2 > [gcc-4_3-branch revision 141291]] > I thought this script would be very lean and fast, but with a large > value for n (like 15), it uses 26G of virtural memory, and things > sta

Re: Hashability questions

2012-05-14 Thread Ian Kelly
On Mon, May 14, 2012 at 7:50 PM, Christian Heimes wrote: > Am 13.05.2012 21:11, schrieb Bob Grommes: >> Noob alert: writing my first Python class library. >> >> I have a straightforward class called Utility that lives in Utility.py. >> >> I'm trying to get a handle on best practices for fleshing o

Re: specify end of line character for readline

2012-05-14 Thread Ian Kelly
On Fri, May 11, 2012 at 1:32 PM, Jason wrote: > Is there any way to specify the end of line character to use in > file.readline() ? > > I would like to use '\r\n' as the end of line and allow either \r or \n by > itself within the line. In Python 3 you can pass the argument newline='\r\n' to th

Re: Hashability questions

2012-05-15 Thread Ian Kelly
On Tue, May 15, 2012 at 3:25 AM, Christian Heimes wrote: > Code explains more than words. I've created two examples that some issues. > > Mutable values break dicts as you won't be able to retrieve the same > object again: Sure, you'll get no argument from me on that. I was more interested in th

Re: what does newP = func(code,p) do?

2012-05-16 Thread Ian Kelly
On Wed, May 16, 2012 at 8:08 AM, e-mail mgbg25171 wrote: > def execute (code) : >     p = 0 >     while p < len(code) : >     func = code[p] >     p += 1 >     newP = func(code,p) >     if newP != None : >     p = newP > > I'm trying to work out what this does > > code

Re: Difference between str.isdigit() and str.isdecimal() in Python 3

2012-05-16 Thread Ian Kelly
On Wed, May 16, 2012 at 9:48 AM, Marco wrote: > Hi all, because > > "There should be one-- and preferably only one --obvious way to do it", > > there should be a difference between the two methods in the subject, but I > can't find it: > '123'.isdecimal(), '123'.isdigit() > (True, True)

Re: Difference between str.isdigit() and str.isdecimal() in Python 3

2012-05-16 Thread Ian Kelly
On Wed, May 16, 2012 at 10:24 AM, Ulrich Eckhardt wrote: > Marco wrote: >>  >>> '123'.isdecimal(), '123'.isdigit() >> (True, True) >>  >>> print('\u0660123') >> ٠123 >>  >>> '\u0660123'.isdigit(), '\u0660123'.isdecimal() >> (True, True) >>  >>> print('\u216B') >> Ⅻ >>  >>> '\u216B'.isdecimal(), '\

Re: How to embed python2 into python3?

2012-05-16 Thread Ian Kelly
On Wed, May 16, 2012 at 8:59 AM, ytj wrote: > Hello, all: > > I have two programs, one is written in py3k, the other is written in > python 2. I am wondering how to make them work together except port > the python 2 code to py3k? Is that possible to expose python2's > function to py3k? In other wo

Re: Difference between str.isdigit() and str.isdecimal() in Python 3

2012-05-16 Thread Ian Kelly
On Wed, May 16, 2012 at 3:07 PM, Thomas 'PointedEars' Lahn wrote: > RTFM. > > $ python3 -c 'print("42".isdecimal.__doc__ + "\n"); > print("42".isdigit.__doc__)' > S.isdecimal() -> bool > > Return True if there are only decimal characters in S, > False otherwise. > > S.isdigit() -> bool > > Return

Re: cPython, IronPython, Jython, and PyPy (Oh my!)

2012-05-16 Thread Ian Kelly
On Wed, May 16, 2012 at 3:33 PM, Ethan Furman wrote: > Just hit a snag: > > In cPython the deterministic garbage collection allows me a particular > optimization when retrieving records from a dbf file -- namely, by using > weakrefs I can tell if the record is still in memory and active, and if so

Re: non-pickle persistance for dicts?

2012-05-16 Thread Ian Kelly
On Wed, May 16, 2012 at 3:52 PM, Charles Hixson wrote: > I want to persist simple dicts, but due to the security problems with > (un)pickle, I'd prefer to not use shelve, and the only way I could see to > persist them onto sqlite also invoked pickle. > > As (un)pickle allows arbitrary system comma

Re: non-pickle persistance for dicts?

2012-05-16 Thread Ian Kelly
On Wed, May 16, 2012 at 4:53 PM, Charles Hixson wrote: > On 05/16/2012 03:11 PM, Ian Kelly wrote: >> >> On Wed, May 16, 2012 at 3:52 PM, Charles Hixson >>  wrote: >> >>> >>> I want to persist simple dicts, but due to the security problems with >

Re: what do these mean

2012-05-20 Thread Ian Kelly
On Sun, May 20, 2012 at 10:52 AM, e-mail mgbg25171 wrote: > There's a little forth program written in python here > #http://openbookproject.net/py4fun/forth/forth.py > I'm struggling to understand what these lines mean. > > def rJnz (cod,p) : return (cod[p],p+1)[ds.pop()] > def rJz  (cod,p) : retu

Re: Help doing it the "python way"

2012-05-25 Thread Ian Kelly
On Thu, May 24, 2012 at 5:12 PM, Emile van Sebille wrote: > On 5/24/2012 2:30 PM Paul Rubin said... > >> Paul Rubin  writes: >>> >>>     new_list = chain( ((x,y-1), (x,y+1)) for x,y in coord_list ) >> >> >> Sorry: >> >>    new_list = list(chain( ((x,y-1), (x,y+1)) for x,y in coord_list)) > > > >>>

Re: Email Id Verification

2012-05-25 Thread Ian Kelly
On Fri, May 25, 2012 at 10:33 AM, Chris Angelico wrote: > On Sat, May 26, 2012 at 2:25 AM, Peter Pearson > wrote: >> Amusingly, every time I log into Discovercard's web site, I >> get a red-letter warning that my registered email address is >> invalid.  Inquiring, I was told that the presence of

Re: PEP 405 vs 370

2012-05-25 Thread Ian Kelly
On Fri, May 25, 2012 at 1:45 PM, Damjan Georgievski wrote: > http://www.python.org/dev/peps/pep-0405/ > > I don't get what PEP 405 (Python Virtual Environments) brings vs what we > already had in PEP 370 since Python 2.6. > > Obviously 405 has a tool to create virtual environments, but that's triv

Re: Finding all regex matches by index?

2012-05-29 Thread Ian Kelly
On Tue, May 29, 2012 at 7:33 PM, Roy Smith wrote: > I have a long string (possibly 100s of Mbytes) that I want to search for > regex matches.  re.finditer() is *almost* what I want, but the problem > is that it returns matching strings.  What I need is a list of offsets > in the string where the r

Re: Finding all regex matches by index?

2012-05-29 Thread Ian Kelly
On Tue, May 29, 2012 at 7:45 PM, MRAB wrote: > On 30/05/2012 02:33, Roy Smith wrote: >> >> I have a long string (possibly 100s of Mbytes) that I want to search for >> regex matches.  re.finditer() is *almost* what I want, but the problem >> is that it returns matching strings.  What I need is a li

Re: pygame: transparency question

2012-05-30 Thread Ian Kelly
On Tue, May 29, 2012 at 9:33 AM, Scott Siegler wrote: > Hello, > > I have a surface that I load an image onto.  During a collision I would like > to clear out the images of both surfaces that collided and show the score.   > Is there a function call to clear a surface with an image? > > One way I

Re: Where is the latest step by step guide to use Jython to compilePython into Java?

2012-06-04 Thread Ian Kelly
On Mon, Jun 4, 2012 at 10:17 AM, Benjamin Kaplan wrote: > On Mon, Jun 4, 2012 at 11:47 AM, David Shi wrote: >> Hello, Mohan, >> >> Did you test it?  I am using Windows.  Where are the exact steps for >> compiling in DOS? >> >> Once .class or jar files created, how to use these files? >> >> Could

Re: How do I get the constructor signature for built-in types?

2012-06-05 Thread Ian Kelly
On Mon, Jun 4, 2012 at 11:19 PM, Steven D'Aprano wrote: > How do I programmatically get the argument spec of built-in types' > __init__ or __new__ methods? I don't think that you can. Methods implemented in C don't really even have established argument specs. They just take tuples and dicts and

Re: Metaclass of a metaclass

2012-06-05 Thread Ian Kelly
On Tue, Jun 5, 2012 at 2:48 AM, Steven D'Aprano wrote: > I was playing around with metaclasses and I wondered what would happen if > the metaclass itself had a metaclass. Sort of a metametaclass. > > Apparently it gives an error. Can anyone explain why this does not work? In your example, Meta is

Re: Why does this leak memory?

2012-06-07 Thread Ian Kelly
On Thu, Jun 7, 2012 at 12:48 PM, Steve wrote: > The leaks can be removed by uncommenting both lines shown. That's just a matter of timing. You call the function before you call set_debug, so when you uncomment the lines, the garbage collector is explicitly run before the debug flags are set. Wh

Re: Why does this leak memory?

2012-06-07 Thread Ian Kelly
For comparison, here is what a leaking program would look like: class Foo(object): def __init__(self, other=None): if other is None: other = Foo(self) self.other = other def __del__(self): pass import gc gc.set_debug(gc.DEBUG_STATS | gc.DEBUG_LEAK) f

Re: Why does this leak memory?

2012-06-08 Thread Ian Kelly
On Fri, Jun 8, 2012 at 10:02 AM, Steve wrote: > Well, I guess I was confused by the terminology. I thought there were leaked > objects _after_ a garbage collection had been run (as it said "collecting > generation 2"). That means that it's going to check all objects. The garbage collector divide

Re: About a list comprehension to transform an input list

2012-06-08 Thread Ian Kelly
On Fri, Jun 8, 2012 at 10:43 AM, Emile van Sebille wrote: > Or alternately by leveraging true/false as 1/0: > [ 100*(not(ii%2))+ii for ii in range(10)] The same thing, leaving bools out of it altogether: >>> [100*(1-ii%2)+ii for ii in range(10)] -- http://mail.python.org/mailman/listinfo/p

Re: Import semantics?

2012-06-08 Thread Ian Kelly
On Fri, Jun 8, 2012 at 4:24 PM, Dan Stromberg wrote: > Am I misinterpreting this?  It seems like according to the PEP, I should > have still been able to import treap.py despite having a treap/.  But I > couldn't; I had to rename treap/ to treap-dir/ first. That's how I understand it. The existe

Re: Passing ints to a function

2012-06-08 Thread Ian Kelly
On Fri, Jun 8, 2012 at 5:41 PM, stayvoid wrote: > Hello, > > I want to pass several values to a function which is located on a > server (so I can't change its behavior). > That function only accepts five values which must be ints. > > There are several lists: > a = [1, 2, 3, 4, 5] > b = [5, 4, 3,

Re: Decorator Pattern with Iterator

2012-06-11 Thread Ian Kelly
On Mon, Jun 11, 2012 at 1:51 AM, Tom Harris wrote: > Greetings, > > I have a class that implements the iterator protocol, and tokenises a string > into a series of tokens. As well as the token, it keeps track of some > information such as line number, source file, etc. So each processor needs to

Re: string to list

2012-06-13 Thread Ian Kelly
On Wed, Jun 13, 2012 at 10:06 PM, Jose H. Martinez wrote: > string.split(',') will give you an array. > > Example: > > 'AAA,",,",EEE,FFF,GGG '.split(',') > > ['AAA', '"', '', '"', 'EEE', 'FFF', 'GGG'] But it incorrectly splits the quoted part. A proper CSV parser (like th

Re: Komodo, Python

2012-06-16 Thread Ian Kelly
On Sat, Jun 16, 2012 at 3:20 AM, Dieter Maurer wrote: > In addition it shows that the "kdb.py" code is very old. "whrandom" > is been replaced by "random" a long time ago. Komodo 2.5 was released in 2003. At the time, Python was on release 2.3. Komodo is currently on version 7. The OP should co

Re: Passing array from java to python

2011-06-02 Thread Ian Kelly
On Thu, Jun 2, 2011 at 4:47 AM, loial wrote: > Unfortunately using jpython or json are not options at the moment How about JPype? Or do the Java and Python need to be in separate processes? -- http://mail.python.org/mailman/listinfo/python-list

Re: Something is rotten in Denmark...

2011-06-02 Thread Ian Kelly
On Thu, Jun 2, 2011 at 11:22 AM, Steven D'Aprano wrote: > It seems to me that early binding is less flexible than late, because > with late binding you have a chance to simulate early binding by saving a > reference of the variable elsewhere, such as in a default value, or an > instance attribute.

Re: Best way to compute length of arbitrary dimension vector?

2011-06-02 Thread Ian Kelly
On Thu, Jun 2, 2011 at 3:26 PM, Algis Kabaila wrote: > import math > > length = math.hypot(z, math.hypot(x, y)) > > One line and fast. The dimension is arbitrary, though, so: length = reduce(math.hypot, self._coords, 0) Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is this so much faster?

2011-06-02 Thread Ian Kelly
On Thu, Jun 2, 2011 at 4:38 PM, Tim Delaney wrote: > First of all, do you have the parameters to the lambda the wrong way around > in the map() version? zip(histogram, range(255)) will return (histogram > value, index), but enumerate(histogram) will return (index, histogram > value). But the param

Re: Why is this so much faster?

2011-06-03 Thread Ian Kelly
On Thu, Jun 2, 2011 at 7:28 PM, Keir Rice wrote: > Ian, I was basing my code off Fredrik Lundh post on comparing images. > http://effbot.org/zone/pil-comparing-images.htm Ah, now I get what it's doing. Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: Something is rotten in Denmark...

2011-06-03 Thread Ian Kelly
On Fri, Jun 3, 2011 at 2:30 AM, Thomas Rachel wrote: > So there should be a way to replace the closure of a function with a > snapshot of it at a certain time. If there was an internal function with > access to the readonly attribute func_closure and with the capability of > changing or creating a

Re: Best way to compute length of arbitrary dimension vector?

2011-06-03 Thread Ian Kelly
On Fri, Jun 3, 2011 at 3:53 PM, Gabriel wrote: > But still, is this solution really faster or better than the one using > list comprehension and the expression 'x*x'? No, not really. >c:\python32\python -m timeit -s "coords = list(range(100))" -s "from math >import hypot" -s "from functools imp

Re: Lambda question

2011-06-04 Thread Ian Kelly
On Sat, Jun 4, 2011 at 12:09 PM, Chris Angelico wrote: > Python doesn't seem to have an inbuilt function to divide strings in > this way. At least, I can't find it (except the special case where n > is 1, which is simply 'list(string)'). Pike allows you to use the > division operator: "Hello, worl

Re: Determine attributes of calling method

2011-06-04 Thread Ian Kelly
On Fri, Jun 3, 2011 at 2:35 PM, Joe wrote: >    foo.__dict__['color']='blue' >    fu.__dict__['color']='red' You don't need to use __dict__ to set function attributes. Just do: foo.color = 'blue' -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 9:29 AM, Steven D'Aprano wrote: > [...] >> I would expect >> any regex processor to compile the regex into an FSM. > > Flying Spaghetti Monster? > > I have been Touched by His Noodly Appendage!!! Finite State Machine. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to avoid leading white spaces

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 10:08 AM, Neil Cerutti wrote: > import re > > print("re solution") > with open("data.txt") as f: >    for line in f: >        fixed = re.sub(r"(TABLE='\S+)\s+'", r"\1'", line) >        print(fixed, end='') > > print("non-re solution") > with open("data.txt") as f: >    for l

Re: how to avoid leading white spaces

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 11:17 AM, Neil Cerutti wrote: > I wrestled with using addition like that, and decided against it. > The 7 is a magic number and repeats/hides information. I wanted > something like: > >   prefix = "TABLE='" >   start = line.index(prefix) + len(prefix) > > But decided I searc

Re: how to avoid leading white spaces

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 11:48 AM, Ethan Furman wrote: > I like the readability of this version, but isn't generating an exception on > every other line going to kill performance? I timed it on the example data before I posted and found that it was still 10 times as fast as the regex version. I di

Re: python + php encrypt/decrypt

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 4:19 PM, miamia wrote: > php I am trying to use is here: > http://code.google.com/p/antares4pymes/source/browse/trunk/library/System/Crypt/AES.php?r=20 That library does not appear to be doing CBC as far as I can tell. Maybe they will agree if you use EBC instead? > BLOCK_

Re: new string formatting with local variables

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney wrote: >> You must use prefix-** in the call to unpack the mapping as keyword >> arguments. Note that using locals() like this isn't best-practice. > > Who says so, and do you find their argument convincing? Do you have a > reference for that so we can se

Re: new string formatting with local variables

2011-06-06 Thread Ian Kelly
On Mon, Jun 6, 2011 at 6:11 PM, Ben Finney wrote: > Chris Rebert writes: > >> print "{solo} was captured by {jabba}".format(**locals()) # RIGHT > > I tend to use ‘u"foo {bar} baz".format(**vars())’, since ‘vars’ can also > take the namespace of an object. I only need to remember one “give me > th

Re: Function call arguments in stack trace?

2011-06-07 Thread Ian Kelly
On Tue, Jun 7, 2011 at 1:31 PM, Dun Peal wrote: > On Jun 7, 1:23 pm, Neil Cerutti wrote: >> Use pdb. > > Neil, thanks for the tip; `pdb` is indeed a great debugging tool. > > Still, it doesn't obviate the need for arguments in the stack trace. Your program could use sys.excepthook to generate a

Re: GIL in alternative implementations

2011-06-07 Thread Ian Kelly
On Tue, Jun 7, 2011 at 11:51 AM, Ethan Furman wrote: >> I'm not sure where he gets the idea that this has any impact on >> concurrency, though. > > What if f has two calls to self.h() [or some other function], and self.h > changes in between? > > Surely that would be a major headache. I could ima

Re: GIL in alternative implementations

2011-06-07 Thread Ian Kelly
On Tue, Jun 7, 2011 at 2:22 PM, Ian Kelly wrote: > from functools import partial > > def g(value): >    print(value) >    return partial(g, value+1) > > f = partial(0) > for i in range(1): >    f = f() The "partial(0)" should read "partial(g,

Re: How good is security via hashing

2011-06-07 Thread Ian Kelly
On Tue, Jun 7, 2011 at 2:42 PM, Paul Rubin wrote: > geremy condra writes: >> # adds random junk to the filename- should make it hard to guess >> rrr = os.urandom(16) >> fname += base64.b64encode(rrr) > > Don't use b64 output in a filename -- it can have slashes in it!  :-( > > Simplest is to use

Re: the stupid encoding problem to stdout

2011-06-10 Thread Ian Kelly
2011/6/10 Sérgio Monteiro Basto : > ok after thinking about this, this problem exist because Python want be > smart with ttys, which is in my point of view is wrong, should not encode to > utf-8, because tty is in utf-8. Python should always encode to the same > thing. If the default is ascii, shou

Re: how to inherit docstrings?

2011-06-10 Thread Ian Kelly
On Fri, Jun 10, 2011 at 10:55 AM, Eric Snow wrote: > The only problem, as seen in the last line, is that the __doc__ on > instances is not inherited on instances of the class.  Object > attribute lookup only looks to the type's __dict__ for inheritance, > and not the types's type.  However, that s

ContextDecorator via contextmanager: broken?

2011-06-10 Thread Ian Kelly
Python 3.2 has this lovely new contextlib.ContextDecorator mixin [1] for context manager classes that allows you to apply the context manager as a decorator. The docs for this feature include the note: ContextDecorator is used by contextmanager(), so you get this functionality automatically.

Re: ContextDecorator via contextmanager: broken?

2011-06-10 Thread Ian Kelly
On Fri, Jun 10, 2011 at 4:57 PM, Ian Kelly wrote: > So as far as I can tell, generator-based context managers simply can't > be used as ContextDecorators.  Furthermore, the documentation's claim > that they can is actually harmful, since they *appear* to work at > first.  

Re: How to avoid "()" when writing a decorator accepting optional arguments?

2011-06-11 Thread Ian Kelly
On Sat, Jun 11, 2011 at 1:27 PM, Giampaolo Rodolà wrote: >    @deprecated() >    def foo(): >        return 0 This is equivalent to: foo = deprecated()(foo) >    @deprecated(some_function) >    def foo(): >        return 0 foo = deprecated(some_function)(foo) >    @deprecated >    def foo():

Re: __dict__ is neato torpedo!

2011-06-11 Thread Ian Kelly
On Sat, Jun 11, 2011 at 8:21 PM, Andrew Berg wrote: > On 2011.06.11 09:12 PM, Terry Reedy wrote: >> On 6/11/2011 9:32 PM, Andrew Berg wrote: >> > I'm pretty happy that I can copy variables and their value from one >> >> You are copying names and their associations, but not the objects or >> thier

Re: __dict__ is neato torpedo!

2011-06-11 Thread Ian Kelly
On Sat, Jun 11, 2011 at 10:32 PM, Andrew Berg wrote: > On 2011.06.11 10:40 PM, Ben Finney wrote: >> It's exactly the same as with an ordinary assignment (‘a = b’) in >> Python. > Fair enough. >> > How would I make actual copies? >> At what level? > Level? I just want to be able to create an object

Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?

2011-06-15 Thread Ian Kelly
On Tue, Jun 14, 2011 at 12:11 AM, Xah Lee wrote: > numerical keypad is useful to many. Most people can't touch type. Even > for touch typist, many doesn't do the number keys. So, when they need > to type credit, phone number, etc, they go for the number pad. It's not about being *able* to touch t

Re: HTTPConncetion - HEAD request

2011-06-16 Thread Ian Kelly
On Thu, Jun 16, 2011 at 4:43 PM, gervaz wrote: > Hi all, can someone tell me why the read() function in the following > py3 code returns b''? > h = http.client.HTTPConnection("www.twitter.com") h.connect() h.request("HEAD", "/", "HTTP 1.0") r = h.getresponse() r.read() > b

Re: break in a module

2011-06-16 Thread Ian Kelly
On Tue, Jun 14, 2011 at 4:57 PM, MRAB wrote: > To me, the obvious choice would be "return", not "break". No, "return" returns a value. Modules do not return values. Therefore "return" would be inappropriate. If this feature were deemed desirable, "break" would make more sense to me. -- http://

Re: break in a module

2011-06-16 Thread Ian Kelly
On Thu, Jun 16, 2011 at 7:21 PM, Erik Max Francis wrote: >> This would, if I understand imports correctly, have ham() operate in >> one namespace and spam() in another. Depending on what's being done, >> that could be quite harmless, or it could be annoying (no sharing >> module-level constants, e

Re: break in a module

2011-06-16 Thread Ian Kelly
On Thu, Jun 16, 2011 at 10:24 PM, Erik Max Francis wrote: > True.  So let's use `in` to represent breaking out of the top-level code of > a module.  Why not, it's not the first time a keyword has been reused, > right? > > The point is, if it's not obvious already from that facetious proposal, it's

Re: break in a module

2011-06-16 Thread Ian Kelly
On Thu, Jun 16, 2011 at 10:21 PM, Erik Max Francis wrote: > Ethan Furman wrote: >> >> The Context: >> >> "It's quite consistent on which control structures you can break out of" >> >> Hmmm Nope, nothing there to suggest you were talking about the 'break' >> keyword. > > That's what I wrote, al

Re: How to avoid "()" when writing a decorator accepting optional arguments?

2011-06-17 Thread Ian Kelly
On Fri, Jun 17, 2011 at 4:27 AM, bruno.desthuilli...@gmail.com wrote: > On Jun 11, 10:28 pm, Ian Kelly wrote: >> >> Since there is no way to distinguish the two cases by the arguments, > > def deprecated(func=None, replacement=None): >    if replacement: >    

Re: Python and Lisp : car and cdr

2011-06-17 Thread Ian Kelly
On Fri, Jun 17, 2011 at 8:45 AM, Franck Ditter wrote: > Hi, I'm just wondering about the complexity of some Python operations > to mimic Lisp car and cdr in Python... > > def length(L) : >  if not L : return 0 >  return 1 + length(L[1:]) > > Should I think of the slice L[1:] as (cdr L) ? I mean, i

Re: Fun and games with lambda

2011-06-17 Thread Ian Kelly
On Fri, Jun 17, 2011 at 10:56 AM, Wolfgang Rohdewald wrote: > On Freitag 17 Juni 2011, Steven D'Aprano wrote: >> run this one- >> liner and wonder no more... > > looks like something dangerous to me. What does > it do? rm -rf ? The thread at the link discusses what it does in great detail. -- ht

Re: Best way to insert sorted in a list

2011-06-17 Thread Ian Kelly
On Fri, Jun 17, 2011 at 3:02 PM, Shashank Singh wrote: > Correct me if I am wrong here but isn't the second one is O(log N)? > Binary search? > That is when you have an already sorted list from somewhere and you > are inserting just one new value. Finding the position to insert is O(log n), but t

Re: Best way to insert sorted in a list

2011-06-17 Thread Ian Kelly
On Fri, Jun 17, 2011 at 3:48 PM, Chris Torek wrote: > If len(large_list) is m, this is O(m).  Inserting each item in > the "right place" would be O(m log (n + m)).  But we still > have to sort: > >    a.sort() > > This is O(log (n + m)), hence likely better than repeatedly inserting > in the corre

Re: What's the best way to write this base class?

2011-06-18 Thread Ian Kelly
On Sat, Jun 18, 2011 at 7:37 AM, bruno.desthuilli...@gmail.com wrote: > If you go that way, then using polymorphic dispatch might (or not, > depending on the game's rules ) be a good idea: > > > class Character(object): >    BASE_HEALTH = 50 >    ... >    def __init__(self, name): >        ... >  

Re: What's the best way to write this base class?

2011-06-20 Thread Ian Kelly
On Mon, Jun 20, 2011 at 5:57 AM, Mel wrote: > Battle for Wesnoth is set up this way.  I don't know what the code does, but > you can go wild creating new classes of character by mixing up new > combinations of attribute settings in new configuration files, and injecting > them into the standard ga

Re: Parsing a dictionary from a format string

2011-06-20 Thread Ian Kelly
On Mon, Jun 20, 2011 at 12:14 PM, Tim Johnson wrote: > Currently using python 2.6, but am serving some systems that have > older versions of python (no earlier than. > Question 1: >  With what version of python was str.format() first implemented? 2.6 > Question 2: >  Given the following string:

Re: Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-20 Thread Ian Kelly
On Mon, Jun 20, 2011 at 1:43 PM, deathweaselx86 wrote: > Howdy guys, I am new. > > I've been converting lists to sets, then back to lists again to get > unique lists. > e.g > > Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) > [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 > Type "help", "copyrigh

Re: Better way to iterate over indices?

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 12:05 PM, Billy Mays wrote: > I know I could use enumerate: > > for i, v in enumerate(myList): >    doStuff(i, myList[i]) > > ...but that stiff seems clunky. Why not: for i, v in enumerate(myList): doStuff(i, v) -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get return values of a forked process

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 12:26 PM, Ian wrote: > myForkedScript has code like this: > if fail: >os._exit(1) > else: >os._exit(os.EX_OK) > > Is using os._exit() the correct way to get a return value back to the > main process? sys.exit() is the preferred way. > I thought the value 'n', pass

Re: How to get return values of a forked process

2011-06-21 Thread Ian Kelly
> Where did you find the Unix docs you pasted in?  I didn't find it in > the man pages.  Thank you.  Based on what you say, I will change my > os._exit() to sys.exit(). http://docs.python.org/library/os.html#os.wait http://docs.python.org/library/os.html#os.waitpid I don't know what man pages you

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 1:48 PM, John Salerno wrote: > Here is what I have so far. Initially the get_factors function just > iterated over the entire range(2, n + 1), but since a number can't > have a factor greater than half of itself, I tried to shorten the > range by doing range(2, n //2), but

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 3:09 PM, John Salerno wrote: > Don't worry, I was still unclear about what to do after reading all > the responses, even yours! But one thing that made me feel better was > that I wasn't having a Python problem as much as a *math* problem. I > changed my get_factors functio

Re: Using django ORM from web browser and from command line apps

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 5:39 PM, News123 wrote: > Hi, > > I'm having a django browser application. > > There's certain administrative tasks, that I'd like to perform from the > command line (cronjob or manually). > As these scripts might be huge and might consume quite some memory I'd > prefer, th

Re: using only the django ORM (DB access model) and nothing else.

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 6:42 PM, News123 wrote: > ### > If running myapp.py I get following output: > > yes this line is executed > Traceback (most recent call last): >  File "./myapp.py", line 11, in >    class Mini(models.Model): >  File > "/opt/my_py

Re: Using django ORM from web browser and from command line apps

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 6:21 PM, News123 wrote: > Out of curiousity: Do you know whether the imports would be executed for > each potential command as soon as I call manage.py or only > 'on demand'? Off the top of my head, I don't know. -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-22 Thread Ian Kelly
On Tue, Jun 21, 2011 at 11:58 PM, Chris Torek wrote: > I was curious about implementing prime factorization as a generator, > using a prime-number generator to come up with the factors, and > doing memoization of the generated primes to produce a program that > does what "factor" does, e.g.: This

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-22 Thread Ian Kelly
On Wed, Jun 22, 2011 at 6:01 AM, Anny Mous wrote: > def sieve(): >    """Yield prime integers efficiently. > >    This uses the Sieve of Eratosthenes, modified to generate the primes >    lazily rather than the traditional version which operates on a fixed >    size array of integers. >    """ >  

Re: writable iterators?

2011-06-23 Thread Ian Kelly
On Wed, Jun 22, 2011 at 3:54 PM, Steven D'Aprano wrote: > Fortunately, that's not how it works, and far from being a "limitation", > it would be *disastrous* if iterables worked that way. I can't imagine > how many bugs would occur from people reassigning to the loop variable, > forgetting that it

Re: How do you print a string after it's been searched for an RE?

2011-06-23 Thread Ian Kelly
On Thu, Jun 23, 2011 at 1:58 PM, John Salerno wrote: > After I've run the re.search function on a string and no match was > found, how can I access that string? When I try to print it directly, > it's an empty string, I assume because it has been "consumed." How do > I prevent this? This has noth

Re: Using decorators with argument in Python

2011-06-28 Thread Ian Kelly
On Tue, Jun 28, 2011 at 10:52 AM, Jigar Tanna wrote: > coming across to certain views from people, it is not a good practice > to use > decorators with arguments (i.e. @memoize() ) and instead it is good to > just > use @memoize. Can any of you guys explain me advantages and > disadvantages of > u

Re: How to create n number of threads

2011-06-28 Thread Ian Kelly
On Tue, Jun 28, 2011 at 1:33 PM, hisan wrote: > How to create n number thread in python. i want iterate over the for loop and > create a thread for each iteration . > sample code >  for i in range(o,50): >  i want to create 50 thread here which call the same function. how start and > stop each t

Re: what is the airspeed velocity of an unladen swallow

2011-06-28 Thread Ian Kelly
On Tue, Jun 28, 2011 at 1:33 PM, Xah Lee wrote: > this will be of interest to those bleeding-edge pythoners. > > “what… is the airspeed velocity of an unladen swallow?” > > xahlee.org/funny/unladen_swallow.html More interesting to me is not the ad but that Wolfram Alpha will actually answer the q

Re: Using decorators with argument in Python

2011-06-29 Thread Ian Kelly
On Wed, Jun 29, 2011 at 1:30 PM, Ethan Furman wrote: > How about just having one bit of code that works either way? How would you adapt that code if you wanted to be able to decorate a function that takes arguments? This also won't work if the argument to the decorator is itself a callable, such

Re: Using decorators with argument in Python

2011-06-29 Thread Ian Kelly
On Wed, Jun 29, 2011 at 3:29 PM, Ethan Furman wrote: > 8< > class enclose(object): >    func = None >    def __init__(self, char='#'): >        self.char = char >        if callable(char):  # was a function passed in directly? >      

Re: how to call a function for evry 10 secs

2011-06-30 Thread Ian Kelly
On Thu, Jun 30, 2011 at 11:18 AM, MRAB wrote: >>        And that was a direct cut&paste from a command window; showing it >> had slept for some 90 seconds before I killed it. >> > Looks like it hasn't changed even in WinXP, Python 3.2. It gets cast to an unsigned long, so I expect sleep(-1) on Wi

Re: Why won't this decorator work?

2011-07-02 Thread Ian Kelly
On Sat, Jul 2, 2011 at 12:08 PM, John Salerno wrote: > But why does the documentation say "The return value of the decorator > need not be callable"? Because the language does not enforce the restriction that the return value should be a callable. If it's not a callable, then the result will jus

Re: Testing if a global is defined in a module

2011-07-04 Thread Ian Kelly
On Mon, Jul 4, 2011 at 6:01 PM, Tim Johnson wrote: >> Yes, but what are you actually *trying to do*? "Detecting data members" is >> not an end in itself. Why do you think you need to detect data members? > >  Steven, I'm building a documentation system. I have my own MVC framework >  and the goal

Re: emacs lisp text processing example (html5 figure/figcaption)

2011-07-05 Thread Ian Kelly
On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee wrote: > So, a solution by regex is out. Actually, none of the complications you listed appear to exclude regexes. Here's a possible (untested) solution: ((?:\s*)+) \s*((?:[^<]|<(?!/p>))+) \s* and corresponding replacement string: \1 \2 I don't kno

Re: emacs lisp text processing example (html5 figure/figcaption)

2011-07-05 Thread Ian Kelly
On Tue, Jul 5, 2011 at 2:37 PM, Xah Lee wrote: > but in anycase, i can't see how this part would work > ((?:[^<]|<(?!/p>))+) It's not that different from the pattern 「alt="[^"]+"」 earlier in the regex. The capture group accepts one or more characters that either aren't '<', or that are '<' but a

Re: Implicit initialization is EXCELLENT

2011-07-06 Thread Ian Kelly
On Wed, Jul 6, 2011 at 12:49 AM, Ulrich Eckhardt wrote: > Mel wrote: >> In wx, many of the window classes have Create methods, for filling in >> various attributes in "two-step construction".  I'm not sure why, because >> it works so well to just supply all the details when the class is called >>

Re: interactive plots

2011-07-06 Thread Ian Kelly
On Wed, Jul 6, 2011 at 9:04 AM, Mihai Badoiu wrote: > How do I do interactive plots in python?  Say I have to plot f(x) and g(x) > and I want in the plot to be able to click on f and make it disappear.  Any > python library that does this? Matplotlib can be integrated with either wxPython or PyQt

<    3   4   5   6   7   8   9   10   11   12   >