Setting a module package to use new-style classes

  • Thread starter Panos Laganakos
  • Start date
P

Panos Laganakos

Is there a way to have a whole module package use the new-style
classes, without having to specify it per module-file or even worse,
per class definition?

Maybe by declaring the __metaclass__ in the module's __init__.py?
 
B

Ben Finney

Panos Laganakos said:
Is there a way to have a whole module package use the new-style
classes, without having to specify it per module-file or even worse,
per class definition?

TTBOMK, you do that with a single statement per module, before any
class definitions:

__metaclass__ = object

In general, code in one module doesn't magically affect other modules.
Maybe by declaring the __metaclass__ in the module's __init__.py?

Presumably you mean "the package's __init__.py", which is itself a
separate module; so no.
 
A

Alex Martelli

Ben Finney said:
TTBOMK, you do that with a single statement per module, before any
class definitions:

__metaclass__ = object

Almost: the assignment you need is

__metaclass__ = type

but yes, it has to be per-module.


Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top