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


Groups > comp.lang.python > #52693 > unrolled thread

opposite of __init__.py

Started byTamer Higazi <th982a@googlemail.com>
First post2013-08-19 18:48 +0200
Last post2013-08-19 17:13 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  opposite of __init__.py Tamer Higazi <th982a@googlemail.com> - 2013-08-19 18:48 +0200
    Re: opposite of __init__.py Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-19 17:13 +0000

#52693 — opposite of __init__.py

FromTamer Higazi <th982a@googlemail.com>
Date2013-08-19 18:48 +0200
Subjectopposite of __init__.py
Message-ID<mailman.32.1376930910.19984.python-list@python.org>
Hi people!

I have asked myself a question, if there is a opposite of "__init__.py"
like "__del__.py" ?!

I want, that when the application ends, certain functions are executed.
I know I could make a constructor and a destructor, but I simply want to
know if there is a opposite....


Thanks



Tamer

[toc] | [next] | [standalone]


#52697

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-08-19 17:13 +0000
Message-ID<52125242$0$29986$c3e8da3$5496439d@news.astraweb.com>
In reply to#52693
On Mon, 19 Aug 2013 18:48:19 +0200, Tamer Higazi wrote:

> Hi people!
> 
> I have asked myself a question, if there is a opposite of "__init__.py"
> like "__del__.py" ?!

No. If you want to run code when your application is shutting down, run 
it just before your code finishes:

def main():
   do_this()
   do_that()


if __name__ == '__main__':
    main()
    shutdown()


If you care about code running even if an exception takes place:


if __name__ == '__main__':
    try:
        main()
    finally:
        shutdown()


-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web