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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:20:40+00:00 2026-05-22T15:20:40+00:00

I am new to Python and I haven’t figured out a simple way of

  • 0

I am new to Python and I haven’t figured out a simple way of separating code in multiple code files and folders.

What I do today is: for each folder I create an __init__.py file. Sometimes it’s empty. I don’t know why I do it, but it seems necessary. That’s the first difference from working with C#.

The second difference is that for any file to reference any another I must use an import, like from model.table import Table. And if I have multiple references I need to use multiple imports:

from model import table1,table2

and then in the rest of the code I must use table1.Table1 per example. If I don’t want to, I should

from model.table1 import Table1
from model.table2 import Table2

and then I can use simply Table1

That differs too much from what I’m used to in C#, where if all files were in the same namespace, we didn’t have to import. Is there a simpler way for me?

  • 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-05-22T15:20:40+00:00Added an answer on May 22, 2026 at 3:20 pm

    You should read up on modules: http://docs.python.org/tutorial/modules.html

    Basically, I think you aren’t organizing your code right. With Python, directories and files have a meaning; it’s not just what you write into the files. With every new directory (with __init__.py) and every new file you create a new “namespace”…

    If you have the file /mydatabase/model.py
    and the Table1, Table2, etc defined in that model.py file you can simply:

    from mydatabase.model import *
    

    Do not create a new file for each Table class!

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

Sidebar

Related Questions

I am new to both python, and to threads. I have written python code
I am new to Python and currently have to write a python program/script to
I am very new to Python and I have been trying to detect missing
I'm pretty new to Python and, in writing an app, have ended up with
I am new to Python and plan to learn Python/Django. I am in the
I'm using Google App Engine (Python), and using OpenID for login. Specifically, I'm playing
i want to find the intersection of two lists in python. i have something
I have dates in a Python script that I need to work with that
I would like to hold running threads in my Django application. Since I cannot
I am trying to run the following HelloWorld Script at Command Line import tornado.httpserver

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.