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

Re: trouble creating tooltips using Wx in Tk canvas

2011-07-06 Thread Ian Kelly
On Wed, Jul 6, 2011 at 9:12 AM, Ravikanth wrote: > Hi all, > Hi all, > > I am having a trouble creating tooltips. I am trying to embed a > matplotlib graph inside  a TkInter canvas. After some search over the > net, I found out a way to create tooltips using the WXbackend. > But when I embed my ma

Re: Implicit initialization is EVIL!

2011-07-06 Thread Ian Kelly
On Wed, Jul 6, 2011 at 12:36 PM, Andrew Berg wrote: > On 2011.07.06 01:19 PM, rantingrick wrote: >> ## >>  The Roman Stawman Sketch >> ## > Nice try, but you have to use a Monty Python sketch (and you have to > spell correctly :-P ). Seriously. The

Re: Does hashlib support a file mode?

2011-07-06 Thread Ian Kelly
On Wed, Jul 6, 2011 at 1:07 PM, Phlip wrote: > If I call m = md5() twice, I expect two objects. > > I am now aware that Python bends the definition of "call" based on > where the line occurs. Principle of least surprise. There is no definition-bending. The code: """ def file_to_hash(path, m = h

Re: Large number multiplication

2011-07-06 Thread Ian Kelly
On Wed, Jul 6, 2011 at 1:30 PM, Billy Mays wrote: > I was looking through the python source and noticed that long multiplication > is done using the Karatsuba method (O(~n^1.5)) rather than using FFTs O(~n > log n).  I was wondering if there was a reason the Karatsuba method was > chosen over the

Re: Large number multiplication

2011-07-06 Thread Ian Kelly
On Wed, Jul 6, 2011 at 2:21 PM, Billy Mays wrote: > Side note: Are Numpy/Scipy the libraries you are referring to? I was thinking more of gmpy or mpmath, but I'm not personally well acquainted with any of them. -- http://mail.python.org/mailman/listinfo/python-list

Re: Large number multiplication

2011-07-07 Thread Ian Kelly
On Thu, Jul 7, 2011 at 2:30 AM, Ulrich Eckhardt wrote: > Even worse, most people would actually pay for its use, because they don't > use numbers large enough to merit the Schönhage–Strassen algorithm. As it stands, Karatsuba is only used for numbers greater than a specific threshold. Adding Sch

Re: Large number multiplication

2011-07-07 Thread Ian Kelly
On Thu, Jul 7, 2011 at 9:49 AM, Ian Kelly wrote: > On Thu, Jul 7, 2011 at 2:30 AM, Ulrich Eckhardt > wrote: >> Even worse, most people would actually pay for its use, because they don't >> use numbers large enough to merit the Schönhage–Strassen algorithm. > > As

Re: Implicit initialization is EXCELLENT

2011-07-07 Thread Ian Kelly
On Thu, Jul 7, 2011 at 1:12 AM, Ulrich Eckhardt wrote: >>> Just guessing, is it legacy, C-with-classes code rather than C++ code >>> perhaps? Haven't looked at wx for a while. Such code typically lacks >>> understanding of exceptions, which are the only way to signal failure >>> from e.g. construc

Re: The end to all language wars and the great unity API to come!

2011-07-08 Thread Ian Kelly
On Fri, Jul 8, 2011 at 1:05 PM, sal migondis wrote: >> I believe... > > Shifting from 'belief' to 'believe', the latter having a considerably > wider semantic scope. Wider how? Would you care to give an example of something that is believed but is not a belief? -- http://mail.python.org/mailman

Re: String concatenation vs. string formatting

2011-07-08 Thread Ian Kelly
On Fri, Jul 8, 2011 at 3:23 PM, Benjamin Kaplan wrote: > String formatting is the One Right Way here. It's fine to use string > concatenation for a few things, but the operation is O(n^2) because each > concat occurs one at a time: Python allocates space for a string the size of > the first 2 thin

Re: String concatenation vs. string formatting

2011-07-08 Thread Ian Kelly
On Fri, Jul 8, 2011 at 11:30 PM, Steven D'Aprano wrote: > Billy Mays wrote: > >> If it means anything, I think concatenation is faster. > > You are measuring the speed of an implementation-specific optimization. > You'll likely get *very* different results with Jython or IronPython, or > old versi

Re: String concatenation vs. string formatting

2011-07-08 Thread Ian Kelly
On Sat, Jul 9, 2011 at 12:16 AM, Chris Angelico wrote: > Has the same optimization been implemented for Unicode? The page > doesn't mention Python 3 at all, and I would guess that the realloc > optimization would work fine for both types of string. Seems to be implemented for strs in 3.2, but not

Re: python xauth

2011-07-11 Thread Ian Kelly
On Sun, Jul 10, 2011 at 11:23 PM, kracekumar ramaraju wrote: > I am looking to use xauth in python?It is for my command line process,I would > like to have few examples and resources. First, by "xauth" do you mean the X11 authorization scheme, or the "extended authentication" (xauth.org) scheme?

Re: An interesting beginner question: why we need colon at all in the python language?

2011-07-11 Thread Ian Kelly
On Mon, Jul 11, 2011 at 8:50 AM, Sébastien Volle wrote: > Could it have been made optional, like the trailing comma in list > declaration? Cobra makes the colons optional, so probably yes. -- http://mail.python.org/mailman/listinfo/python-list

Re: Property setter and lambda question

2011-07-11 Thread Ian Kelly
On Mon, Jul 11, 2011 at 9:54 AM, Anthony Kong wrote: > Hi, all, > This question is in the same context of my two earlier questions. This > question was raised by some python beginners, and I would like to check with > the list to ensure I provide a correct answer. > Here is a code snippet I used t

Re: Property setter and lambda question

2011-07-11 Thread Ian Kelly
On Mon, Jul 11, 2011 at 10:53 AM, Anthony Kong wrote: > Thanks again for your input, Thomas. > I normally prefer > not_here = property(lambda self: self.__get_not_here(), lambda self, v: > self.__set_not_here(v)) > than > not_here = property(__get_not_here, __set_not_here) > Because it allows me t

Re: Property setter and lambda question

2011-07-11 Thread Ian Kelly
On Mon, Jul 11, 2011 at 11:21 AM, Anthony Kong wrote: > Awesome, Thomas. The trick only works if there is only one leading > underscore in the method names. > The following example works as I expected for the derived class B. > class A(object): >     def __init__(self): >         self.__not_here =

Re: Set run vars with each call

2011-07-12 Thread Ian Kelly
On Tue, Jul 12, 2011 at 11:50 AM, Andrew Berg wrote: > On 2011.07.12 12:32 PM, Gnarlodious wrote: >> OK, that sets a value at init time. But is there a similar built-in >> to run whenever the class instance is called? > What do you mean by call an instance? Do you want to run certain code > whenev

Re: What is the difference between PyPy and Python? are there lot of differences?

2011-07-13 Thread Ian Kelly
On Wed, Jul 13, 2011 at 8:19 AM, Anthony Kong wrote: > One of the main difference is that pypy supports only R-Python, which stands > for 'Restricted Python". > It is a subset of C-python language. This is wrong. The PyPy *interpreter* is written in RPython. At the application level, PyPy suppo

Re: Functional style programming in python: what will you talk about if you have an hour on this topic?

2011-07-13 Thread Ian Kelly
On Wed, Jul 13, 2011 at 10:29 AM, Terry Reedy wrote: > The iteration protocol and the notion of iteraables as the common data > exchange format, with associated notions of iterators, generator functions, > and generators, are important features of Python. Not really functional > style, I guess. X

PyCon Australia 2011: Schedule Announced

2011-07-13 Thread Ryan Kelly
ehaviour Driven Development (Malcolm Tredinnick) Benchmarking stuff made ridiculously easy (Tennessee Leeuwenburg) Bytecode: What, Why, and How to Hack it (Ryan Kelly) Developing Scientific Software in Python (Duncan Gray) Fun with App Engine 1.5.0 (Greg Darke) Hosting Python W

Re: How can I make a program automatically run once per day?

2011-07-14 Thread Ian Kelly
On Thu, Jul 14, 2011 at 11:00 AM, monkeys paw wrote: > You could use the below code. time.sleep(# seconds in a day) > where i == 30 would run once a day for a month > > import time > i=0 > while (1): >        print 'hello' >        time.sleep(2)   # Change this to number of seconds in a day >    

Re: Possible File iteration bug

2011-07-14 Thread Ian Kelly
On Thu, Jul 14, 2011 at 1:46 PM, Billy Mays wrote: > def getLines(f): >    lines = [] >    for line in f: >        lines.append(line) >    return lines > > with open('/var/log/syslog', 'rb') as f: >    lines = getLines(f) >    # do some processing with lines >    # /var/log/syslog gets updated in

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Ian Kelly
On Sat, Jul 16, 2011 at 9:09 PM, Steven D'Aprano wrote: >> Personally, I like to use the tab _key_ as an input device, but to have >> my editor write real spaces to the file in consequence. With pure >> spaces, the text is laid out reliably for us both. And so I have my >> editor set to that behav

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Ian Kelly
On Sun, Jul 17, 2011 at 1:29 AM, Andrew Berg wrote: > You're right. TabError is only raised if the initial indentation is > inconsistent. > Not legal: > def spam(): > print('Wonderful spam!\n') > <4 spaces>print('Bloody Vikings!') > > Legal: > def eggs(): > print( > 'Blech!\n','Whaddya mean, "blec

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Ian Kelly
On Sun, Jul 17, 2011 at 9:15 AM, rantingrick wrote: >>  I can write my code to 80 >> columns using 4-space tabs, but if somebody later tries to edit the >> file using 8-space tabs, their lines will be too long. > > THEIR LINES is the key words. A tab control is a tab control is a (you > guessed it

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Ian Kelly
On Sun, Jul 17, 2011 at 10:29 AM, rantingrick wrote: > I hate  vertical white-space. I follow Python style guide suggestions, > and then some! I hate when people insert spaces into code blocks and > function/method bodies. If you feel a space must be inserted then that > is a good clue you should

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Ian Kelly
On Sun, Jul 17, 2011 at 1:54 PM, rantingrick wrote: > On Jul 17, 1:48 pm, Ian Kelly wrote: > >> Let me get this straight.  You want us to use tabs so that individuals >> can set their tab width to however many spaces they want, but then you >> want everybody to set thei

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Ian Kelly
On Sun, Jul 17, 2011 at 2:12 PM, rantingrick wrote: > On the face of it one might think vertical tabs are a good idea > however newlines work just fine. There is no reason for expanding > vertical whitespace to create readble code. If you can offer a good > reason i'm listening. Also be sure to po

Re: Crazy what-if idea for function/method calling syntax

2011-07-17 Thread Ian Kelly
2011/7/17 ΤΖΩΤΖΙΟΥ : > Jumping in: > > What if a construct > > xx(*args1, **kwargs1)yy(*args2, **kwargs2) > > was interpreted as > > xxyy(*(args1+args2), **(kwargs1+kwargs2)) > > (Note: with **(kwargs1+kwargs2) I mean "put keyword arguments in the > order given", since dicts can't be added) > >

Re: a little parsing challenge ☺

2011-07-18 Thread Ian Kelly
On Mon, Jul 18, 2011 at 11:12 AM, Billy Mays <81282ed9a88799d21e77957df2d84bd6514d9...@myhashismyemail.com> wrote: > I gave it a shot.  It doesn't do any of the Unicode delims, because let's > face it, Unicode is for goobers. Uh, okay... Your script also misses the requirement of outputting the i

Re: Partial Function Application -- Advantages over normal function?

2011-07-19 Thread Ian Kelly
On Tue, Jul 19, 2011 at 12:22 AM, Thomas Jollans wrote: >> Supplemental: The above can be simplified to >> >> def makeadder(y): return lambda x: x + y >> > > In turn: > > makeadder = lambda y: lambda x: x + y That's not an improvement. lambda is for making anonymous functions. If you're going to

Re: Partial Function Application -- Advantages over normal function?

2011-07-19 Thread Ian Kelly
On Tue, Jul 19, 2011 at 10:58 AM, Thomas Jollans wrote: > No, it's not an improvement. It's an illustration. I get that. The difference I pointed out between your "simplification" and the other Thomas's is the reason why yours would be unpythonic whilst his is fine. -- http://mail.python.org/ma

Re: a little parsing challenge ☺

2011-07-19 Thread Ian Kelly
On Tue, Jul 19, 2011 at 10:54 AM, Xah Lee wrote: > On Sunday, July 17, 2011 2:48:42 AM UTC-7, Raymond Hettinger wrote: >> On Jul 17, 12:47 am, Xah Lee wrote: >> > i hope you'll participate. Just post solution here. Thanks. >> >> http://pastebin.com/7hU20NNL > > just installed py3. > there seems t

Re: I am fed up with Python GUI toolkits...

2011-07-20 Thread Ian Kelly
On Tue, Jul 19, 2011 at 8:12 PM, sturlamolden wrote: > 3. Unpythonic memory management: Python references to deleted C++ > objects (PyQt). Manual dialog destruction (wxPython). Parent-child > ownership might be smart in C++, but in Python we have a garbage > collector. Perhaps you already know th

Re: a little parsing challenge ☺

2011-07-20 Thread Ian Kelly
On Wed, Jul 20, 2011 at 12:29 AM, jmfauth wrote: >> Then it is hard to code precisely. >> > > Not really. The trick is to count the different opener/closer > separately. > That is what I am doing to check balanced brackets in > chemical formulas. The rules are howerver not the same > as in math.

Re: total_ordering behaviour

2011-07-20 Thread Ian Kelly
On Wed, Jul 20, 2011 at 4:18 AM, risboo6909 wrote: > Hello all, > > I've noticed some strange behaviour of functools.total_ordering > decorator, at least it seems strange to me. Looks like this is already known and fixed as of March: http://bugs.python.org/issue10042 -- http://mail.python.org/m

Re: a little parsing challenge ☺

2011-07-21 Thread Ian Kelly
On Thu, Jul 21, 2011 at 6:58 AM, Xah Lee wrote: > Thanks a lot for the fix Raymond. That fix was from Thomas Jollans, not Raymond Hettinger. > Though, the code seems to have a minor problem. > It works, but the report is wrong. > e.g. output: > > 30068: c:/Users/h3/web/xahlee_org/p/time_machine\

Re: Inconsistencies between zipfile and tarfile APIs

2011-07-21 Thread Ryan Kelly
the PyFilesystem project: http://packages.python.org/fs/ If anyone cares enough to whip up a TarFS implementation it would be gratefully merged into trunk. (There may even be the start of one in the bugtracker somewhere, I don't recall...) Cheers, Ryan -- Ryan Kelly http://w

Re: Writing a MUD Console

2011-07-22 Thread Ian Kelly
On Fri, Jul 22, 2011 at 3:25 AM, Chris Angelico wrote: > In the early days of Android, my brother couldn't find a decent MUD > client, so I whipped one up for him in Python. The project never went > very far, but it's a start. It works on Linux, not Windows; but since > you're referring to /usr/bi

Re: PEP 8 and extraneous whitespace

2011-07-22 Thread Ian Kelly
On Fri, Jul 22, 2011 at 6:59 AM, Neil Cerutti wrote: > Under the assumption that leading white space is important for > code formatting, but that all alignment after that is > unimportant. ...unless you're trying to adhere to a line length limit. "80 characters" is a lot easier to do in a fixed-

Re: PEP 8 and extraneous whitespace

2011-07-22 Thread Ian Kelly
On Fri, Jul 22, 2011 at 11:43 AM, rusi wrote: > Also it is more optimized. For the same size -- and therefore > readability -- a proportional font packs in more text. More text == less readability. This is one of the reasons I limit my line lengths. -- http://mail.python.org/mailman/listinfo/py

Re: Decorator behavior

2011-07-22 Thread Ian Kelly
On Fri, Jul 22, 2011 at 2:38 PM, mhearne808[insert-at-sign-here]gmail[insert-dot-here]com wrote: > I am just trying to wrap my head around decorators in Python, and I'm > confused about some behavior I'm seeing.  Run the code below (slightly > adapted from a Bruce Eckel article), and I get the fol

PyCon Australia 2011: Registration Deadlines

2011-07-23 Thread Ryan Kelly
http://www.microsoft.com/> Thanks also to Linux Australia, who provide the overarching legal and organisational structure for PyCon Australia. Ryan Kelly PyCon Australia 2011 -- http://mail.python.org/mailman/listinfo/python-list

Re: XRC and AGW

2011-07-26 Thread Ian Kelly
On Tue, Jul 26, 2011 at 4:16 PM, azrael wrote: > Is there a support in the XRC for building advaced graphics widgets (AGW). Yes, create an "unknown" control in the XRC and then use the xrc.AttachUnknownControl method at runtime to swap in whatever widget you want. > also another thing. Is ther s

PyCon Australia 2011: Registration Back Online

2011-07-27 Thread Ryan Kelly
/www.wingware.com/> Silver: Arclight <http://www.arclight.com.au/> Silver: Bitbucket by Atlassian<http://bitbucket.org/> Silver: Microsoft <http://www.microsoft.com/> Thanks also to Linux Australia, who provide the overarching legal

Re: NoneType and new instances

2011-07-28 Thread Ian Kelly
On Thu, Jul 28, 2011 at 9:39 AM, Ethan Furman wrote: > Why is NoneType unable to produce a None instance?  I realise that None is a > singleton, but so are True and False, and bool is able to handle returning > them: The bool constructor works (actually just returns one of the existing singletons

Re: Is it bad practise to write __all__ like that

2011-07-28 Thread Ian Kelly
On Thu, Jul 28, 2011 at 7:22 AM, mark ferguson wrote: > I've not really got the hang of decorators yet, so I was wondering why one > might use your approach rather than just using Karim's original method? The advantage of Thomas's decorator here is that it lets you place the denotation of whether

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Ian Kelly
On Thu, Jul 28, 2011 at 2:18 PM, gry wrote: > [python 2.7] I have a (linux) pathname that I'd like to split > completely into a list of components, e.g.: >   '/home/gyoung/hacks/pathhack/foo.py'  -->  ['home', 'gyoung', > 'hacks', 'pathhack', 'foo.py'] > > os.path.split gives me a tuple of dirname

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Ian Kelly
On Thu, Jul 28, 2011 at 2:44 PM, Ian Kelly wrote: > path = '/home/gyoung/hacks/pathhack/foo.py' > parts = [part for path, part in iter(lambda: os.path.split(path), ('/', ''))] > parts.reverse() > print parts > > But that's horrendously

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Ian Kelly
On Thu, Jul 28, 2011 at 2:47 PM, Ian Kelly wrote: > On Thu, Jul 28, 2011 at 2:44 PM, Ian Kelly wrote: >> path = '/home/gyoung/hacks/pathhack/foo.py' >> parts = [part for path, part in iter(lambda: os.path.split(path), ('/', ''))] >> parts.rev

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Ian Kelly
On Thu, Jul 28, 2011 at 3:15 PM, Emile van Sebille wrote: > On 7/28/2011 1:18 PM gry said... >> >> [python 2.7] I have a (linux) pathname that I'd like to split >> completely into a list of components, e.g.: >>    '/home/gyoung/hacks/pathhack/foo.py'  -->   ['home', 'gyoung', >> 'hacks', 'pathhack

Re: Identical descriptor value, without leaking memory?

2011-07-29 Thread Ian Kelly
On Mon, Jul 25, 2011 at 11:46 AM, Jack Bates wrote: > How can you get a descriptor to return an identical value, each time > it's called with the same "instance" - without leaking memory? class MyDescriptor(object): def __get__(self, instance, owner): try: return instance.

Re: Identical descriptor value, without leaking memory?

2011-07-29 Thread Ian Kelly
On Fri, Jul 29, 2011 at 5:01 PM, Ian Kelly wrote: > On Mon, Jul 25, 2011 at 11:46 AM, Jack Bates wrote: >> How can you get a descriptor to return an identical value, each time >> it's called with the same "instance" - without leaking memory? Oops, that should

Re: How to avoid confusion with method names between layers of a package

2011-07-31 Thread Ian Kelly
> So far so good. The problem is that a CubeGrid instance is also a wx.Grid instance. However, different naming conventions apply there. All method names in wxPython are coming from C++. They use CamelCase method names. There is a naming conflict. What should I do? > > Solution #1: Mix CamelCase an

Code War at PyCon Au 2011

2011-08-01 Thread Ryan Kelly
A huge hit at PyCon-Au last year, Code War is back! Eight teams, onstage knockout rounds of short programming bouts, loud crowd...mildly impressive prizes. Any language allowed, no holds bared. Think of it like cage fighting for coders. Originally based on an idea from the book PeopleWare,

Re: import hooks (PEP 302) broken in Python >=2.5?

2011-08-07 Thread Ryan Kelly
ieve that comment is referring specifically to "ihooks" the stdlib module, not "import hooks" the general concept as defined in PEP302. The former pre-dates the later. I use custom PEP302 loaders all the time and they work fine in at least 2.6, 2.7 and 3.2. Ryan -- Ry

Re: WxPython and TK

2011-08-07 Thread Ian Kelly
On Sun, Aug 7, 2011 at 6:26 PM, azrael wrote: > Today I found a quote from Guido. > > wxPython is the best and most mature cross-platform GUI toolkit, given a > number of constraints. The only reason wxPython isn't the standard Python GUI > toolkit is that Tkinter was there first. > -- Guido van

Re: allow line break at operators

2011-08-10 Thread Ian Kelly
On Wed, Aug 10, 2011 at 8:37 AM, Steven D'Aprano wrote: >> Without the parentheses, this is legal but (probably) useless; it >> applies the unary + operator to the return value of those functions. >> Putting the + at the end of the previous line at least prevents that, >> since most unary operator

Re: how to dynamically generate __name__ for an object?

2011-08-10 Thread Ian Kelly
On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman wrote: > __name__ can be a descriptor, so you just need to write a descriptor > that can be fetched from classes as well as instances. > > Here's an example with a property (instance only): > class Foo(object): > ...   @property > ...   def __name__(s

PyCon Australia 2011: Registration Closing Soon!

2011-08-10 Thread Ryan Kelly
> Silver: Django Software Foundation <http://www.djangoproject.com> Silver: Ninefold <http://ninefold.com/> Internet: GitHub <http://github.com/> Thanks also to Linux Australia, who provide the overarching legal and organisational stru

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 a

Re: Hiding token information from users

2011-08-23 Thread Ian Kelly
How many of these codes do you need, and do they only need to be decrypted at a central server? You might be able to just create random strings of whatever form you want and associate them with the tokens in a database. Then they will be completely opaque. -- http://mail.python.org/mailman/listinf

Re: extended slicing and negative stop value problem

2011-08-23 Thread Ian Kelly
On Aug 21, 2011 1:34 PM, "Max" wrote: > > a[0:11][::-1] > > # Instead of a[10:-1:-1], which looks like it should work, but doesn't. > > It works nicely, but it is 1.3 times slower in my code (I am surprised > the interpreter doesn't optimize this). Have you tried reverse()? I haven't timed it, bu

Re: Design principles: no bool arguments

2011-08-25 Thread Ian Kelly
On Thu, Aug 25, 2011 at 3:29 AM, Thomas 'PointedEars' Lahn wrote: > Both variants work (even in Py3) if you only define > > class Data(object): >  def merge_with(self, bar, overwrite_duplicates): >    pass > > data1 = Data() > data2 = Data() > > You have to define > > class Data(object): >  def me

Re: Understanding .pth files

2011-08-28 Thread Ian Kelly
On Sat, Aug 27, 2011 at 10:42 AM, Josh English wrote: > According to the docs, I should be able to put a file in the site-packages > directory called xmldb.pth pointing anywhere else on my drive to include the > package. I'd like to use this to direct Python to include the version in the > dev

Re: about if __name == '__main__':

2011-08-28 Thread Ian Kelly
On Sun, Aug 28, 2011 at 9:34 AM, Amit Jaluf wrote: > hello group > > i have one question about this > > if __name == '__main__': First, it should be: if __name__ == '__main__': > is it same as other languages like[c,c++]  main function. because of i > google and read faqs > and also " > http:/

Re: about if __name == '__main__':

2011-08-28 Thread Ian Kelly
On Sun, Aug 28, 2011 at 12:56 PM, woooee wrote: > Two main routines, __main__ and main(), is not the usual or the common > way to do it.  It is confusing and anyone looking at the end of the > program for statements executed when the program is called will find > an isolated call to main(), and th

Re: Checking Signature of Function Parameter

2011-08-28 Thread Ian Kelly
On Sun, Aug 28, 2011 at 3:20 PM, Travis Parks wrote: > I am trying to write an algorithms library in Python. Most of the > functions will accept functions as parameters. For instance, there is > a function called any: > > def any(source, predicate): >    for item in source: >        if predicate(i

Re: Checking Signature of Function Parameter

2011-08-29 Thread Ian Kelly
On Mon, Aug 29, 2011 at 10:45 AM, Travis Parks wrote: > I wanted to allow for calls like this: > > extend(range(0, 1000)).map(lambda x: x * x).where(lambda x: x % 2 == > 0).first(lambda x: x % 7 == 0) > > It allows me to compose method calls similarly to LINQ in C#. I think > this looks better tha

Re: Returning a value from exec or a better solution

2011-08-31 Thread Ian Kelly
On Wed, Aug 31, 2011 at 12:35 AM, Arnaud Delobelle wrote: >> You don't know that, an implementation may for example set __bultins__ >> to None, prior to returning, its not an unreasonable thing to do and >> the docs don't say they can't. > > I haven't studied the docs but I'm certain that such an

Re: Handling 2.7 and 3.0 Versions of Dict

2011-08-31 Thread Ian Kelly
On Wed, Aug 31, 2011 at 3:55 AM, Martin v. Loewis wrote: > if sys.version_info < (3,): > def getDictValues(dict): > return dict.itervalues() > else: > def getDictValues(dict): > return dict.values() The extra level of function call indirection is unnecessary here. Better to write it a

Re: Subclassing str object

2011-08-31 Thread Ian Kelly
2011/8/31 Yaşar Arabacı : > I made a class like this (I shortened it just to show the point), what do > you think about it, do you think it is the python way of subclassing str (or > unicode in this case) You don't need the _sozcuk attribute at all here. It's just the same as the value of the uni

Re: Closures and Partial Function Application

2011-08-31 Thread Ian Kelly
On Wed, Aug 31, 2011 at 12:02 PM, Travis Parks wrote: > Am I doing something wrong, here? nonlocal isn't registering. Which > version did this get incorporated? 3.0 -- http://mail.python.org/mailman/listinfo/python-list

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Ian Kelly
On Wed, Aug 31, 2011 at 11:12 AM, Prasad, Ramit wrote: > It seems to me that if I add a function to the list of class attributes it > will automatically wrap with "self" but adding it to the object directly will > not wrap the function as a method. Can somebody explain why? I would have > thoug

Re: Subclassing str object

2011-08-31 Thread Ian Kelly
2011/8/31 Yaşar Arabacı : > @Ian: Thanks for you comments. I indeed didn't need the _sozcuk attribute at > all, so I deleted it. My class's addition and multiplication works without > overwriting __add__ and __mul__ because, this class uses unicode's __add__ > and __mul__ than creates a new kelime

Re: Constructors...BIIIIG PROBLEM!

2011-09-01 Thread Ian Kelly
On Thu, Sep 1, 2011 at 3:04 AM, Michiel Overtoom wrote: > > On Sep 1, 2011, at 10:24, Hegedüs Ervin wrote: > >> On Thu, Sep 01, 2011 at 10:00:27AM +0200, Michiel Overtoom wrote: >>> Derive your class from object, >> >> why's that better than just create a simple class, without >> derive? > > Among

Re: Why do class methods always need 'self' as the first parameter?

2011-09-01 Thread Ian Kelly
On Thu, Sep 1, 2011 at 6:45 AM, John Roth wrote: > I personally consider this to be a wart. Some time ago I did an > implementation analysis. The gist is that, if self and cls were made > special variables that returned the current instance and class > respectively, then the compiler could determi

Re: Listing HAL devices

2011-09-01 Thread Ian Kelly
On Thu, Sep 1, 2011 at 9:46 AM, mukesh tiwari wrote: > dbus.exceptions.DBusException: > org.freedesktop.DBus.Error.ServiceUnknown: The name > org.freedesktop.Hal was not provided by any .service files > > Kindly some one please tell me why i am getting this error . > Thank you It looks like you d

Re: Optparse buggy?

2011-09-01 Thread Ian Kelly
On Thu, Sep 1, 2011 at 3:12 PM, Fulvio wrote: > Hello, > > I'm on python3.2, trying some experiment with OptionParser but no success > from optparse import OptionParser as parser parser.add_option('-n','--new', dest='new') > Traceback (most recent call last): >  File "", line 1, in >  F

Re: Algorithms Library - Asking for Pointers

2011-09-02 Thread Ian Kelly
On Fri, Sep 2, 2011 at 10:59 AM, Travis Parks wrote: > Hello: > > I am working on an algorithms library. It provides LINQ like > functionality to Python iterators. Eventually, I plan on having > feaures that work against sequences and mappings. > > I have the code up at http://code.google.com/p/py

Re: Why do class methods always need 'self' as the first parameter?

2011-09-02 Thread Ian Kelly
On Fri, Sep 2, 2011 at 11:51 AM, John Roth wrote: >> I don't see how you could get rid of the wrappers.  Methods would >> still need to be bound, somehow, so that code like this will work: >> >> methods = {} >> for obj in objs: >>     if obj.is_flagged: >>         methods[obj.user_id] = obj.do_wor

Re: sqlite3 with context manager

2011-09-02 Thread Ian Kelly
On Fri, Sep 2, 2011 at 12:43 PM, Tim Arnold wrote: > Hi, > I'm using the 'with' context manager for a sqlite3 connection: > > with sqlite3.connect(my.database,timeout=10) as conn: >            conn.execute('update config_build set datetime=?,result=? > where id=?', >                              (

Re: Functions vs OOP

2011-09-03 Thread Ian Kelly
On Sat, Sep 3, 2011 at 10:15 AM, William Gill wrote: > During some recent research, and re-familiarization with Python, I came > across documentation that suggests that programming using functions, and > programming using objects were somehow opposing techniques. > > It seems to me that they are c

Re: import os or import os.path

2011-09-06 Thread Ian Kelly
On Tue, Sep 6, 2011 at 3:25 PM, Jabba Laci wrote: > Hi, > > If I want to use the 'os.path' module, it's enought to import 'os': > > import os > if os.path.isfile('/usr/bin/bash'): >    print 'got it' > > In other source codes I noticed that people write 'import os.path' in > this case. Which is be

Re: Is this a safe use of eval?

2011-02-24 Thread Ryan Kelly
.__mro__[-1].__subclasses__()[58]("/secret/file","w")') Traceback (most recent call last): File "", line 1, in File "", line 2, in testit File "", line 1, in IOError: [Errno 2] No such file or directory: '/sec

Re: Is this a safe use of eval?

2011-02-24 Thread Ryan Kelly
On Thu, 2011-02-24 at 20:13 +1100, Ryan Kelly wrote: > On Thu, 2011-02-24 at 10:48 +0200, Frank Millman wrote: > > Hi all > > > > I know that the use of 'eval' is discouraged because of the dangers of > > executing untrusted code. > > > > Here

Re: Preferred method of sorting/comparing custom objects

2011-02-24 Thread Ian Kelly
On Thu, Feb 24, 2011 at 9:41 AM, Jeremy wrote: > I recently found the wiki page on sorting > (http://wiki.python.org/moin/HowTo/Sorting/).  This page describes the new > key parameter to the sort and sorted functions. > > What about custom objects?  Can I just write __lt__, __gt__, etc. function

Re: I'm happy with Python 2.5

2011-03-03 Thread Ian Kelly
On Sun, Feb 27, 2011 at 7:15 AM, n00m wrote: > http://www.spoj.pl/problems/TMUL/ > > Python's "print a * b" gets Time Limit Exceeded. If speed is the only thing you care about, then you can forget about fretting over whether 2.5 or 3.1 is faster. You're using the wrong language to begin with. --

Re: how to read the last line of a huge file???

2011-03-04 Thread Ian Kelly
On Fri, Mar 4, 2011 at 5:26 PM, MRAB wrote: >> UnsupportedOperation: can't do non-zero end-relative seeks >> >> But offset is initialized to -10. Does anyone have any thoughts on >> what the error might be caused by? >> > I think it's because the file has been opened in text mode, so there's > the

Re: ImSim: Image Similarity

2011-03-08 Thread Ian Kelly
On Mon, Mar 7, 2011 at 6:30 AM, n00m wrote: > Remind me this piece of humor: > > One man entered a lift cabin at the 1st floor, > lift goes to the3rd floor, opens and ... it's empty! > Physicist, Chemist and Mathematician were asked: > what happened to the man? > > Physicist: he was squashed to th

Re: Don't Want Visitor To See Nuttin'

2011-03-10 Thread Ian Kelly
On Wed, Mar 9, 2011 at 2:01 PM, Victor Subervi wrote: > Maya 2012: Transform At the Source Yow. You're designing a Maya 2012 website to help some travel company bilk gullible people out of thousands of dollars? I would be ashamed to have anything to do with this. -- http://mail.python.org/mail

Re: Don't Want Visitor To See Nuttin'

2011-03-14 Thread Ian Kelly
On Fri, Mar 11, 2011 at 10:40 AM, Victor Subervi wrote: > Um...just for the record, these guys have ben featured on the FRONT PAGES > OF: > [SNIPPED] I don't care if the company was founded by the second coming of Jesus Christ; I just call it like I see it. > They're ligit :) Oh, I have no doub

Re: Guido rethinking removal of cmp from sort method

2011-03-14 Thread Ian Kelly
On Mon, Mar 14, 2011 at 1:39 PM, Paul Rubin wrote: > Finally I concocted an "infinite" example which we agreed is artificial: > you are given a list of generators denoting real numbers, for example > pi generates the infinite sequence 3,1,4,1,5,9... while e generates > 2,7,1,8,...  You can sort th

Re: Guido rethinking removal of cmp from sort method

2011-03-15 Thread Ian Kelly
On Tue, Mar 15, 2011 at 2:00 AM, Paul Rubin wrote: > Ian Kelly writes: >> I would think that you can sort them with key as long as none of the >> sequences are equal (which would result in an infinite loop using >> either method).  Why not this? > > Yes you can do so

Re: value of pi and 22/7

2011-03-17 Thread Ian Kelly
On Thu, Mar 17, 2011 at 10:46 AM, kracekumar ramaraju wrote: > I tried the following 22/7.0 > 3.1428571428571428 import math math.pi > 3.1415926535897931 > > > Why is the difference is so much ?is pi =22/7 or something ? Pi is not 22/7. That is just a commonly-used approximat

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