Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91355

Re: Returning a custom file object (Python 3)

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'python3': 0.05; 'subject:file': 0.07; 'versions.': 0.07; '"r")': 0.09; 'typeerror:': 0.09; 'writable': 0.09; 'cc:addr:python-list': 0.10; 'python': 0.11; 'question.': 0.13; 'thu,': 0.15; 'after,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'heap': 0.16; 'new;': 0.16; 'obviously,': 0.16; 'subject:object': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'trying': 0.22; '"",': 0.22; '2015': 0.23; 'header:In-Reply-To:1': 0.24; '(most': 0.24; 'feature': 0.24; 'sort': 0.25; 'idea': 0.26; 'linux': 0.26; 'separate': 0.27; 'message-id:@mail.gmail.com': 0.28; "doesn't": 0.28; 'skip:( 20': 0.28; 'appear': 0.29; 'guess': 0.29; 'work.': 0.30; 'source': 0.31; "d'aprano": 0.33; 'steven': 0.33; 'traceback': 0.33; 'file': 0.34; 'received:google.com': 0.34; 'fresh': 0.35; 'weekend': 0.35; 'but': 0.36; 'except': 0.36; "didn't": 0.37; 'subject:: ': 0.37; 'beyond': 0.37; 'version': 0.38; 'thank': 0.39; 'pm,': 0.39; 'does': 0.39; 'build': 0.40; 'subject: (': 0.40; 'even': 0.61; 'you.': 0.64; 'chrisa': 0.84; 'soon...': 0.84; 'to:none': 0.90
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=heS+0Kq+PBZ53O5adsHz+QKxUbcpw/oxbmlRpBMNWUY=; b=z9MKjprUDlTprvcMaybIflbDxMBoMF7Pr5YO46PUKhuEq6bY4lzgzsM6ni0rO4MV5z AnxidkJ1RX3zqABIbzxxtePC48dFLKy336KVWNsqOJ4tj09T8HdS4MXM4nQgjAUPrbrh rO0j7g3fNVuy563wYVlgA8/QyyiFc0npBggUhZ14QkTPHXFaom19vwskl2Pf+XDYSUei Yg56ioDxqV9y28UHoxnSX7MJW63cNN9g9/4I7UVoowUUZSuD5Wrhpoy+GVsPREEWZkyL vbDp69p2WdW/GUu0vsW87kbs7tuzaOl+uQXvFkfhz6fzFdTh9MZvY8ZqYtTNkU/z0lov TItA==
MIME-Version 1.0
X-Received by 10.43.39.1 with SMTP id tk1mr8255242icb.26.1432803969094; Thu, 28 May 2015 02:06:09 -0700 (PDT)
In-Reply-To <5566bdf4$0$13013$c3e8da3$5496439d@news.astraweb.com>
References <55667a6d$0$13002$c3e8da3$5496439d@news.astraweb.com> <85iobdwhti.fsf@benfinney.id.au> <mailman.113.1432780860.5151.python-list@python.org> <87wpztclsu.fsf@elektro.pacujo.net> <mailman.119.1432792558.5151.python-list@python.org> <5566bdf4$0$13013$c3e8da3$5496439d@news.astraweb.com>
Date Thu, 28 May 2015 19:06:09 +1000
Subject Re: Returning a custom file object (Python 3)
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.121.1432804427.5151.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1432804427 news.xs4all.nl 2915 [2001:888:2000:d::a6]:55688
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91355

Show key headers only | View raw


On Thu, May 28, 2015 at 5:04 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
>> This does appear to work. Whether or not it's a good idea is a
>> separate question.
>
>
> And this is EXACTLY the sort of use-case that having __class__ be writable
> is intended to solve. So this is exactly the solution I was after, thank
> you. Er... except for one little problem... in Python 3.3:
>
> py> f = open("/tmp/a", "r")
> py> f.__class__ = MyFile
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: __class__ assignment: only for heap types
>
>
> So it doesn't work for me. What version of Python are you using?

Huh, didn't even think to check other versions.

$ python3
Python 3.5.0b1+ (default:7255af1a1c50+, May 26 2015, 00:39:06)
[GCC 4.9.2] on linux

It's a build fresh from source control around about this weekend (some
time after feature freeze, obviously, but beyond that all I know is
what you see there). I guess this is pretty new; trying the same thing
on 3.4.2 doesn't work. But hey! 3.5 will be out soon...

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Returning a custom file object (Python 3) Steven D'Aprano <steve@pearwood.info> - 2015-05-28 12:16 +1000
  Re: Returning a custom file object (Python 3) Ben Finney <ben+python@benfinney.id.au> - 2015-05-28 12:40 +1000
    Re: Returning a custom file object (Python 3) Marko Rauhamaa <marko@pacujo.net> - 2015-05-28 08:29 +0300
      Re: Returning a custom file object (Python 3) Chris Angelico <rosuav@gmail.com> - 2015-05-28 15:49 +1000
        Re: Returning a custom file object (Python 3) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-28 17:04 +1000
          Re: Returning a custom file object (Python 3) Chris Angelico <rosuav@gmail.com> - 2015-05-28 19:06 +1000
      Re: Returning a custom file object (Python 3) Gary Herron <gherron@digipen.edu> - 2015-05-27 22:56 -0700
        Re: Returning a custom file object (Python 3) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-28 16:52 +1000
  Re: Returning a custom file object (Python 3) Ben Finney <ben+python@benfinney.id.au> - 2015-05-28 12:34 +1000
  Re: Returning a custom file object (Python 3) Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-05-28 10:29 +0100

csiph-web