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


Groups > comp.lang.python > #105934

Re: List of Functions

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: List of Functions
Date 2016-03-29 10:40 +1100
Message-ID <mailman.120.1459208421.28225.python-list@python.org> (permalink)
References (3 earlier) <87mvpjx9kh.fsf@elektro.pacujo.net> <ndb8ln$u0f$1@dont-email.me> <87twjqn2jn.fsf@elektro.pacujo.net> <mailman.116.1459201207.28225.python-list@python.org> <56f9b5c2$0$1606$c3e8da3$5496439d@news.astraweb.com>

Show all headers | View raw


On Tue, Mar 29, 2016 at 9:52 AM, Steven D'Aprano <steve@pearwood.info> wrote:
> That would be called "type" :-)
>
> type(name, bases, namespace) returns a new class:
>
>
> py> C = type("MyClass", (object,), {'foo': 1})
> py> C
> <class '__main__.MyClass'>
> py> C.foo
> 1

Yeah, but to do that in a single expression, you need to have all the
functions in the dictionary, so it's no improvement over
SimpleNamespace. The functions get attached to the class, not the
instance, which means they need 'self' - but without assignment, you
wouldn't be able to make much use of self anyway. Hence the call for
an example.

ChrisA

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


Thread

List of Functions Richard Riehle <rriehle@itu.edu> - 2016-03-27 12:38 -0700
  Re: List of Functions Erik <python@lucidity.plus.com> - 2016-03-28 00:10 +0100
  Re: List of Functions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-28 01:19 +0100
    Re: List of Functions Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-28 10:51 +0300
      Re: List of Functions Marko Rauhamaa <marko@pacujo.net> - 2016-03-28 11:58 +0300
        Re: List of Functions Dan Sommers <dan@tombstonezero.net> - 2016-03-28 12:39 +0000
          Re: List of Functions Marko Rauhamaa <marko@pacujo.net> - 2016-03-28 16:40 +0300
            Re: List of Functions Chris Angelico <rosuav@gmail.com> - 2016-03-29 08:40 +1100
              Re: List of Functions Steven D'Aprano <steve@pearwood.info> - 2016-03-29 09:52 +1100
                Re: List of Functions Chris Angelico <rosuav@gmail.com> - 2016-03-29 10:40 +1100
                Re: List of Functions Marko Rauhamaa <marko@pacujo.net> - 2016-03-29 07:49 +0300
              Re: List of Functions Marko Rauhamaa <marko@pacujo.net> - 2016-03-29 07:45 +0300
                Re: List of Functions Chris Angelico <rosuav@gmail.com> - 2016-03-29 16:00 +1100
      Re: List of Functions Steven D'Aprano <steve@pearwood.info> - 2016-03-29 10:40 +1100
        Re: List of Functions Random832 <random832@fastmail.com> - 2016-03-28 19:50 -0400
        Re: List of Functions Chris Angelico <rosuav@gmail.com> - 2016-03-29 10:54 +1100
        Re: List of Functions Rustom Mody <rustompmody@gmail.com> - 2016-03-28 19:23 -0700
        Re: List of Functions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-03-29 03:45 +0100
          Re: List of Functions Chris Angelico <rosuav@gmail.com> - 2016-03-29 14:33 +1100
          Re: List of Functions Rustom Mody <rustompmody@gmail.com> - 2016-03-28 23:21 -0700
            Re: List of Functions Marko Rauhamaa <marko@pacujo.net> - 2016-03-29 09:50 +0300
            Re: List of Functions Christian Gollwitzer <auriocus@gmx.de> - 2016-03-29 08:52 +0200

csiph-web