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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:01:37+00:00 2026-05-30T17:01:37+00:00

/projects/mymath$ ls __init__.py __init__.pyc mymath.py mymath.pyc tests and under the directory tests I have

  • 0
/projects/mymath$ ls
__init__.py  __init__.pyc  mymath.py  mymath.pyc  tests

and under the directory tests I have

/projects/mymath/tests/features$ ls
steps.py  steps.pyc  zero.feature

I tried to import my factorial function

sys.path.insert(0,"../../")
#import mymath
from mymath.MyMath import factorial

But it said No module named MyMath.

Here is my dummy MyMath class.

class MyMath(object):

        def factorial(self, number):
                if n <= 1:
                        return 1
                else:
                        return n * factorial(n-1)

So what’s wrong? Thanks. Is this even a good practice (editing the sys path?)

This will work import mymath

  • 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-30T17:01:39+00:00Added an answer on May 30, 2026 at 5:01 pm

    From what I can tell, it’s right. There is no module named mymath.MyMath. There’s a module named mymath.mymath though…

    To be explicit, when you create a folder and put an __init__.py file in it, you’ve crated a package. If your __init__.py file is empty, then you still have to explicitly import the modules in the package. So you have to do import mymath.mymath to import the mymath module into your namespace. Then you can access the things you want via mymath.mymath.MyMath, and so on. If you want to import the class directly in, you have to do this:

    from mymath.mymath import MyMath
    

    And as someone else has already explained, you can’t import a method from a class. You have to import the whole class.

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

Sidebar

Related Questions

Projects have many tasks and a task has a custom RESTful action called 'approve'.
Some projects have properties have miscellaneous settings such as: AllowPayments, ShowSideBar, SectionTitle. Really things
C++ projects have a linker option to embed manifest to require UAC elevation (/MANIFESTUAC:level)
I have multiple projects in a couple of different workspaces. However, it seems like
Most mature C++ projects seem to have an own reflection and attribute system ,
Projects habtm Tasks On tasks/show.html.erb I have link_to Add This Task To Project, new_project_path(:task
2 projects under TFS Source Control. DependancyProject.sln AppProject.sln With AppProject referencing DependancyProject. - The
I have the following simple page; <%@ Import namespace=System.IO %> <script runat=server> int pageSize
I have a Projects table, which lists the client info. Then I have four
I have several projects with a very large over-lapping code-base. We've just recently started

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.