[Python-ideas] Idea: Named code blocks / inline module declarations
M.-A. Lemburg
mal at egenix.com
Wed Sep 17 10:08:31 CEST 2014
On 17.09.2014 07:19, Tennessee Leeuwenburg wrote:
> I would like to be able to use named sections to organise my code, much an
> inline submodules, bit without using classes or functions to organise them.
> I would use this if I had a group of related functions which were not
> written in an object-oriented-style, possibly due to not needing any shared
> state. Rather than break these out into a new file, I would like to just be
> able to use internal structure to declare the relationship. I've used the
> keyword 'block' to indicate the start of a named block.
>
> For example,
>
> block signin:
> def handle_new_user():
> do_it()
>
> def handle_existing_user():
> do_it()
>
>
> while True:
> try:
> signin.handle_existing_user():
> except:
> signin.handle_new_user()
>
> do_other_stuff()
>
> At the moment, I would have to either break out into more files, or
> somewhat clumsily co-opt things like functions or staticmethods. I think
> that supporting named blocks or inline module declarations would really
> help me organise some of my code much better. It could also provide a more
> seamless way to decide to break out into a new file. Once a named block got
> big enough, I could easily create a new file and import those functions
> into the same namespace.
>
> I hope this makes sense and that I'm not overlooking anything obvious.
Change "block" to "class" and you're done :-)
You can make your code even better (i.e. more OO-style and future
proof), by implementing those functions as true methods and
instantiating your Signin class as signin singleton.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Sep 17 2014)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
2014-09-19: PyCon UK 2014, Coventry, UK ... 2 days to go
2014-09-27: PyDDF Sprint 2014 ... 10 days to go
2014-09-30: Python Meeting Duesseldorf ... 13 days to go
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-ideas
mailing list