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 7904109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:54:57+00:00 2026-06-03T09:54:57+00:00

I was recently told that I should keep my code in separate files; like

  • 0

I was recently told that I should keep my code in separate files; like main.py, engine.py, settings.py and so on. Although this surely does have benefits, like easier management, scalability and others, to me it seems like it has too many drawbacks…

For example, if I have a script called settings.py, where some things like sizes of onscreen objects, speed of the simulation and color of various objects are defined, what do I do if those variables are needed both in my engine.py script and my main.py script? Do I import it two times, in both scripts? It seems rather messy. What if some of my classes, that are in the engine.py script, require code from main.py?

Let me show you the exact situation…

My main.py script imports Pygame in itself, initializes it, and so on. It used to have a class which represented an onscreen object, and that class had a method draw, which just called a Pygame draw function. Now, when I put the class inside my engine.py script, things no longer work, because Pygame doesn’t exist there! I ended up importing both settings.py and Pygame in the engine.py, and then importing the engine into main.py, but then it’s more like an initializer than an engine… Is there a way to deal with things like these, like general guide lines?

  • 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-03T09:54:59+00:00Added an answer on June 3, 2026 at 9:54 am

    Here are the official PEP guidelines for imports: http://www.python.org/dev/peps/pep-0008/#imports

    Also please see this StackOverflow question: What are good rules of thumb for Python imports?

    You can import a variable from more than one class without a problem but you should try and structure your code so that things aren’t circularly imported. Circular import dependency in Python

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

Sidebar

Related Questions

I recently found an article online that told me about this: RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2
I was recently told that I should use transactions in my application as they
Someone recently told me that this is bad: var el = $(#myID); $(el).addClass(a); $(el).addClass(b);
This is a (hopefully) really simple question - I have been told recently that
Recently someone on Stack Overflow told me that the code below does not leak,
I've been told recently a good practice in object oriented programming that you should
I was recently told that I'm abusing exceptions to control the flow in my
Someone recently told me that Scala's traits aren't true traits, and that they were
Recently I have been told that static class/methods are evil. Take for example my
I was told recently by a Flash developer that I respect that using include

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.