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

  • SEARCH
  • Home
  • 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 8300955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:45:12+00:00 2026-06-08T16:45:12+00:00

I have a Bottle webserver module with the following line: from foobar.formtools import auto_process_form_insert

  • 0

I have a Bottle webserver module with the following line:

from foobar.formtools import auto_process_form_insert

And the foobar.formtools module contains this line:

from foobar.webserver import redirect, redirect_back

Of course, both result in the following errors (respectively):

ImportError: cannot import name auto_process_form_insert
ImportError: cannot import name redirect

Is it simply a fact that in Python two modules can’t import each other and all module imports must be hierarchical in nature, or am I doing something wrong? Alternatively, is there a workaround short of placing all these nice functions in new modules?

  • 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-08T16:45:14+00:00Added an answer on June 8, 2026 at 4:45 pm

    Modules can import each other cyclically, but there’s a catch. In the simple case, it should work by moving the import statements to the bottom of the file or not using the from syntax.

    Here’s why that works:

    When you import a module, Python first checks sys.modules. If it’s in there, it just imports from there. If it’s not there, it tries to import it in the normal way; basically, it finds the file and runs the stuff in it.

    Running a module populates the module’s contents. For example, say we have this module, creatively named example_opener:

    import webbrowser
    
    def open_example():
        webbrowser.open('http://www.example.com/')
    

    At the start, the module is empty. Then Python executes:

    import webbrowser
    

    After that, the module only contains webbrowser. Then Python executes this:

    def open_example():
        webbrowser.open('http://www.example.com/')
    

    Python creates open_example. Now the module contains webbrowser and open_example.

    Say webbrowser contained this code:

    from example_opener import open_example
    
    def open(url):
        print url
    

    Say example_opener is imported first. This code is executed:

    import webbrowser
    

    webbrowser has not yet been imported, so Python executes the contents of webbrowser:

    from example_opener import open_example
    

    example_opener has been imported, but not yet fully executed. Python doesn’t care. Python pulls the module out of sys.modules. At this point, example_opener is still empty. It hasn’t defined open_example yet, nor even completed importing webbrowser. Python can’t find open_example in example_opener, so it fails.

    What if we imported open_example from the end of webbrowser and webbrowser from the end of example_opener? Python would start by executing this code:

    def open_example():
        webbrowser.open('http://www.example.com/')
    

    webbrowser does not exist yet, but it doesn’t matter until open_example is called. Now example_opener contains only open_example. It then executes:

    import webbrowser
    

    It has not been imported yet, so Python executes webbrowser. It starts:

    def open(url):
        print url
    

    It defines open. Then it executes:

    from example_opener import open_example
    

    example_opener is in sys.modules, so it uses that. example_opener contains open_example, so it succeeds. Python finishes importing webbrowser. That concludes importing webbrowser from example_opener. That’s the last thing in example_opener, so the import of example_opener finishes, successful, as well.

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

Sidebar

Related Questions

I have a very simple CRUD API: from bottle import get, post, put, delete,
I'm having an issues with bottle python where I have the following code import
I have the following php code $bigImageSrc = 'images/'.$prodXML->bottles->bottle[$i]->bigImage; $text = $prodXML->bottles->bottle[$i]->title; $title =
I have a Web Service ( model-layer ) which communicates with Database. This module
So i supose that i have a server application written in python import bottle
I have a Python application in the bottle web-server that accesses a C shared-object
Does anyone have any examples on how to integrate a task scheduler in Bottle.
have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have two IQueryable<> lists. Say one is filled with objects of Class Bottle

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.