Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8961079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:48:16+00:00 2026-06-15T15:48:16+00:00

I am reading great python twisted tutorial http://krondo.com/?page_id=1327 little bit confusion, in many examples

  • 0

I am reading great python twisted tutorial http://krondo.com/?page_id=1327 little bit confusion, in many examples there is importing twisted reactor or other module multiple time in a python file instead of at the beginning. Because in python way we use import modules at the file beginning. Any one can elaborate it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:48:17+00:00Added an answer on June 15, 2026 at 3:48 pm

    In general you’re correct–in Python as in most languages the relevant import statements in a module should be at the beginning of the module where they’re easily found. In most cases that’s desirable so that’s how it’s taught.

    But like most rules there are exceptions. Python allows import statements within function and class definitions as well as at the module level. One good reason to put an import inside a function is that some imports can actually be fairly expensive, time-consuming operations.

    In the case of Twisted’s from twisted.internet import reactor there’s a lot of extra work and magic going on behind the scenes. So it makes more sense to defer that import until it’s actually needed–preferably within a function that will only be called once (or on rare occasions). Another reason specific to Twisted (the aforementioned “magic”) is that the very act of importing reactor creates a singleton instance of that object, and other code can affect how the reactor instance is created. So we defer importing the reactor until any other setup code has had a chance to execute.

    One final reason that it’s sometimes necessary to use these kinds of in-line imports is the problem of circular imports. I won’t go into detail about that here unless you ask, but I think you can find some other discussions of that problem on this site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've finished reading a great article on http://addyosmani.com/largescalejavascript/ This article explains how to combine
I was just reading this article: http://www.tutorialized.com/view/tutorial/Spring-MVC-Application-Architecture/11986 which I find great. It explains the
I've been reading up on SqlTransactions and have found a great load of examples
After reading the great answer for Absolute Beginner's Guide to Bit Shifting? I tested
I am reading a great Rails tutorial and came across a passage that I
I am just reading a great tutorial about threads and have a problem with
I've been reading this: http://www.thebuzzmedia.com/designing-a-secure-rest-api-without-oauth-authentication/ It's been a really great article. One problem I'm
i was just reading a great presentation about Quality Assurance for PHP Projects by
I had learnt by reading your great answers here, that it is not good
I want to implement a great text reading experience in my app, similar to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.