Issues with `codecs.register` and `codecs.CodecInfo` objects

2012-07-06 Thread Karl Knechtel
Hello all, While attempting to make a wrapper for opening multiple types of UTF-encoded files (more on that later, in a separate post, I guess), I ran into some oddities with the `codecs` module, specifically to do with `.register` ing `CodecInfo` objects. I'd like to report a bug or something, bu

Re: append method

2012-05-23 Thread Karl Knechtel
On Wed, May 23, 2012 at 8:23 AM, 水静流深 <1248283...@qq.com> wrote: s=[1,2,3] s.append(5) s > [1, 2, 3, 5] s=s.append(5) s print s > None > > why can't  s=s.append(5)  ,what is the reason? For the same reason that you don't see `[1, 2, 3, 5]` immediately after doing `s.a

Re: print XML

2012-05-19 Thread Karl Knechtel
What do you want the contents of the file to look like? Why are you parsing the XML in the first place? (What do you want to happen if the data on `sys.stdin` isn't actually valid XML?) On Thu, May 17, 2012 at 9:52 AM, Nibin V M wrote: > Hello, > > I have the following code, which will assign  XM

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

2012-05-14 Thread Karl Knechtel
On Wed, May 9, 2012 at 7:02 AM, J. Mwebaze wrote: > > During object instantiaton, i would like to use  the specific class, that > corresponds to the version of the class that was used to create the object. I don't understand; "the version of the class that was used to create" **what** object? We'

Re: Good data structure for finding date intervals including a given date

2012-05-14 Thread Karl Knechtel
On Sat, May 12, 2012 at 10:18 AM, Jean-Daniel wrote: >> Since you say "intervals" in plural here, I assume that they can overlap? > > Yes, > > For instance, there are the following intervals : > [[1, 10], > [4, 7], > [6, 15], > [11, 17]] > > asking for the intervals including  5, the returned valu

Re: Dealing with the __str__ method in classes with lots of attributes

2012-05-14 Thread Karl Knechtel
On Sat, May 12, 2012 at 9:10 AM, Ethan Furman wrote: > > Firstly, __slots__ is a tuple. I object: conceptually, the "slots" of a class are set in stone, but the `__slots__` attribute of a class object is just an attribute, and any iterable (as long as it yields valid identifier names) can be used

Re: Dealing with the __str__ method in classes with lots of attributes

2012-05-12 Thread Karl Knechtel
On Thu, May 10, 2012 at 9:33 AM, Andreas Tawn wrote: > And there's also something like... > > return "\n".join((": ".join((str(k), str(self.__dict__[k]))) for k in > self.__dict__)) > > which is a nice length, but I lose control of the order of the attributes and > the formatting is fixed. It al

Re: Good data structure for finding date intervals including a given date

2012-05-12 Thread Karl Knechtel
On Sat, May 12, 2012 at 8:17 AM, Jean-Daniel wrote: > I am looking for a fast way to find the intervals > containing a given date, without having to check all intervals (less > than O(n)). Since you say "intervals" in plural here, I assume that they can overlap? -- ~Zahlman {:> -- http://mail.

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

2012-05-12 Thread Karl Knechtel
I really wish gmail picked up the mailing list as a default reply-to address... -- Forwarded message -- From: Karl Knechtel Date: Sat, May 12, 2012 at 8:25 AM Subject: Re: Newbie naive question ... int() throws ValueError To: Devin Jeanpierre On Sat, May 12, 2012 at 12:11 AM

Re: can I overload operators like "=>", "->" or something like that?

2012-04-19 Thread Karl Knechtel
On Fri, Apr 20, 2012 at 12:43 AM, Chris Angelico wrote: > On Fri, Apr 20, 2012 at 2:38 PM, alex23 wrote: >> On Apr 20, 5:54 am, Jacob MacDonald wrote: >> >>> On Thursday, April 19, 2012 12:28:50 PM UTC-7, dmitrey wrote: >>> > can I somehow overload operators like "=>", "->" or something like >>>

Re: can I overload operators like "=>", "->" or something like that?

2012-04-19 Thread Karl Knechtel
On Thu, Apr 19, 2012 at 3:28 PM, dmitrey wrote: > hi all, > can I somehow overload operators like "=>", "->" or something like > that? (I'm searching for appropriate overload for logical implication > "if a then b") > Thank you in advance, D. > -- > http://mail.python.org/mailman/listinfo/python-l

Fwd: Python one-liner?

2012-04-16 Thread Karl Knechtel
On Sat, Apr 14, 2012 at 7:26 AM, Tim Chase wrote: > > On 04/13/12 22:54, Chris Angelico wrote: >> >> Yes, that would be the right method to use. I'd not bother with the >> function and map() though, and simply iterate: >> >> d = {} >> for val in l: >>  d.setdefault(f(val), []).append(val) > > > Or

Re: File traversing

2012-04-16 Thread Karl Knechtel
On Sun, Apr 15, 2012 at 5:51 AM, Chris Angelico wrote: > > (You may also want to consider using the 'with' statement to guarantee > a timely closing of the file. Outside the scope of this mail though.) > > I think this list is just to collect unique entries, yes? If so, a set > may be more to you

Re: is this foolish?

2012-04-12 Thread Karl Knechtel
On Thu, Apr 12, 2012 at 7:15 AM, Tim Golden wrote: > On 12/04/2012 10:35, Cameron Simpson wrote: > > I've found myself using a Python gotcha as a feature. > > Have a look at Peter Inglesby's lightning talk from a > recent London Python Dojo: > > http://inglesp.github.com/2012/03/24/mutable-defau

[Windows] drag-and-drop onto .py file in modern versions?

2012-04-11 Thread Karl Knechtel
Hello all, Back when I had 2.6.x installed, I used to be able to drag a file onto a .py file in order to open it with that script (rather, pass the name of the file as `sys.argv[1]`). I did nothing special to make this work, as far as I can recall; it was something that the installer set up automa