Re: PyWart: Python modules are not so modular after all!

2013-11-11 Thread Rick Johnson
On Monday, November 11, 2013 1:34:54 AM UTC-6, Steven D'Aprano wrote:
 import sys
 sys.modules[mymodule] = any_object_you_like()

Thanks for this great advice!

I'm not particularly fond of injecting names and objects in
this manner due to the surprise factor, especially when
the names are going to be global, but i'm going to do it
anyway since python gives me no other choice!

*evil-grin*

However, there is no reason why good cannot prevail over
evil. By utilizing an intelligent design, logical
hierarchy, and most importantly: quality documentation and
commenting to shine a light on such dark and mystical
practices, i can elevate a kludge into the realms of
elegance.

Stay tuned for a future thread discussion on the topic...
-- 
https://mail.python.org/mailman/listinfo/python-list


PyWart: Python modules are not so modular after all!

2013-11-10 Thread Rick Johnson


 The Pros of Python Modules:


  Python modules require no special syntax to create, nor do
  they induce extra indentation in your source code to
  maintain readability. Simply write some Python code in an
  editor, save it with a py|pyw extension, throw in a
  directory that python can find, and WHAMO, you've got
  yourself an importable module namespace!

  Of all the package implementations i've seen, Python's use
  of the source file as a module is absolutely my favorite

  But don't pucker up your benevolent anus just yet!


 The Cons of Python Modules:


  1. Modules cannot be extended or manipulated by the
  programmer. Basically the PyGods have handed us modules,
  but they failed to give us any tools to manipulate them --
  heck, they might as well have blessed us an unlimited
  supply of high carbon steel but cursed us with an
  atmosphere that does not support combustion.

  What good is ANY namespace when you cannot override it's
  fundamental interface? And interfaces are the key to OOP!

  Is __setattr__/__getattr__ ringing a bell people?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyWart: Python modules are not so modular after all!

2013-11-10 Thread Steven D'Aprano
On Sun, 10 Nov 2013 20:13:45 -0800, Rick Johnson wrote:

   What good is ANY namespace when you cannot override it's fundamental
   interface? And interfaces are the key to OOP!
 
   Is __setattr__/__getattr__ ringing a bell people?


import sys
sys.modules[mymodule] = any_object_you_like()


Want a module with __setattr__ and __getattr__? Make a class, instantiate 
it, and shove it in sys.modules.


This has worked since Python 2.1:

http://code.activestate.com/recipes/65207-constants-in-python/



-- 
Steven
-- 
https://mail.python.org/mailman/listinfo/python-list