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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:24:43+00:00 2026-05-28T18:24:43+00:00

In file foo.py I want to import class A from file main.py with the

  • 0

In file foo.py I want to import class A from file main.py with the following folderStructur:

main.py
__init__.py
|-folder1
  __init__.py
  |-folder 2
    __init__.py
    foo.py
  |-folder 3
  ...

How does the import-line has to look like?
I tried things like

from ..main import A

but i just got

ValueError: Attempted relative import in non-package
  • 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-28T18:24:44+00:00Added an answer on May 28, 2026 at 6:24 pm

    That error comes from how you’re running the file – if you want to do that relative import, you need to run your foo program like this:

    >>> import topfolder.folder1.folder2.foo
    >>> foo.run()
    

    (In other words, you need to be treating the package structure from which you are importing as an actual package.)

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

Sidebar

Related Questions

Consider the following (broken) code: import functools class Foo(object): def __init__(self): def f(a,self,b): print
I want to read line n1->n2 from file foo.c into the current buffer. I
I want to execute a random .py file, say foo.py on the myproject/myapp folder
If you have the following class: class Foo(object): def __init__(name): self.name = name And
Let's say I have a really large file foo.txt and I want to iterate
I have a file like this: foo, bar, foo1 bar, foo foo I want
Let's say the source file name is Foo.txt . I want the name of
My project has a file foo that I've been using and checking in with
This is one line of the input file: FOO BAR 0.40 0.20 0.40 0.50
<py:match path=foo> <?python import os href = select('@href').render() SOMEWHERE = ... # what file

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.