Movatterモバイル変換


[0]ホーム

URL:


other python ideas

Jeff Petkaujpet at eskimo.com
Mon Apr 9 00:32:34 EDT 2001


Douglas Alan <nessus at mit.edu> wrote in messagenews:lcvgoeiva4.fsf at gaffa.mit.edu...>>    mymodule::foo(a, b, c)>> This syntax would invoke mymodule.foo(), and would load module> "mymodule" it if it wasn't already loaded.  You'd probably also want> some sort of module aliasing notation so you could use>>   alias m my_really_long_named_module>   m::foo(a, b, c)>> in place of>>   my_really_long_named_module::foo(a, b, c)How is this any better than:    import my_really_long_named_module as m    m.foo(a, b, c)?For avoiding import statements, you could write somethinglike this:    class ModuleGetter:        def __getattr__(self,name):            if name.startswith('__'):                raise AttributeError                    return __import__(name)    module = ModuleGetter()And now you can do without the imports:    module.mymodule.foo(a, b, c)    module.os.chmod(blah, blah)    x = module.re.compile('[a-z]')--Jeff Petkau


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp