Re: modifying a standard module?

2016-02-12 Thread Paul Rubin
Ulli Horlacher writes: >> tarfile.TarFile.extractall = new_extractall > > This is more easy than I could imagined :-) It is in my Python notes, > now. This is called "duck punching" or "monkey patching" and sometimes it's necessary, but it's something of an antipattern since the module could chan

Re: modifying a standard module?

2016-02-12 Thread Ulli Horlacher
Matt Wheeler wrote: > > How can I substitute the standard module function tarfile.extractall() with > > my own function? > > import tarfile > def new_extractall(self, *args, **kwargs): > print("I am a function. Woohoo!") > > tarfile.TarFile.extractall = new_extractall This is more easy tha

Re: modifying a standard module? (was: Re: tarfile : read from a socket?)

2016-02-12 Thread Matt Wheeler
On 11 February 2016 at 17:10, Ulli Horlacher wrote: > > Ulli Horlacher wrote: > As a hack, I modified the standard library module tarfile.py: > > root@diaspora:/usr/lib/python2.7# vv -d > --- ./.versions/tarfile.py~1~ 2015-06-22 21:59:27.0 +0200 > +++ tarfile.py 2016-02-11 18:01:50.185

modifying a standard module? (was: Re: tarfile : read from a socket?)

2016-02-11 Thread Ulli Horlacher
Ulli Horlacher wrote: > This code works so far: > > sfo = sock.makefile('r') > taro = tarfile.open(fileobj=sfo,mode='r|') > taro.extractall(path=edir) > > But it does not writes anything to the terminal to inform the user. > > When I use: > > for member in taro.getmembers(): >