inicio mail me! sindicaci;ón

Updates from Python SVN, part 5

The list of picklable objects has a new citizen: slices.

[code lang="python"]

s = slice(1, 10, 2) import cPickle pickled = cPickle.dumps(s, -1) print pickled ?c__builtin__ slice qKK K?Rq. print cPickle.loads(pickled) slice(1, 10, 2) range(1, 10)[s] [2, 4, 6, 8] range(1, 10)[cPickle.loads(pickled)] [2, 4, 6, 8] [/code]

There’s also a new method, chgat() in the curses module to change the font style of certain characters.

You can use the string’s translate() method to delete a series of char in one shot without translating, just pass None to the table argument:

[code lang="python"]

‘mary had a little lamb’.translate(None, ‘a’) ‘mry hd little lmb’ [/code]

Last but not least there’s a change in how __ slots __ works. I think it’s better to cite directly the documentation and the code instead of inferring in this case:

When __slots__ are set to a unicode string, make it work the same as setting a plain string, ie don’t expand to single letter identifiers.

That was not really clear to me at the first glance so I think it’s safer to report some code from the tests also to explain it better:

[code lang="python"]

class C(object): … slots = ‘abc’ … c = C() c.abc = 5 assert c.abc == 5 class C(object): … slots = u’abc’ … c = C() c.abc = 5 assert c.abc == 5 [/code]

Related posts

  • Updates from Python SVN, Part 12
  • Updates from Python SVN, Part 6
  • Updates from Python SVN, Part 10
  • Updates from Python SVN, Part 11
  • Updates from Python SVN, Part 16
  • Leave a Comment