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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:08:39+00:00 2026-06-09T09:08:39+00:00

I have a class Person and a static method in that class called call_person

  • 0

I have a class Person and a static method in that class called call_person:

class Person:
    def call_person():
        print "hello person"

In the python console I import the class Person and call Person.call_person(). But it is giving me error that says 'module' object has no attribute 'call_person'. Can anyone please let me know why I am getting this error?

  • 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-09T09:08:40+00:00Added an answer on June 9, 2026 at 9:08 am

    You need to do something like:

    class Person:
        @staticmethod
        def call_person():
            print("hello person")
    
    # Calling static methods works on classes as well as instances of that class
    Person.call_person()  # calling on class
    p = Person()
    p.call_person()       # calling on instance of class
    

    Depending on what you want to do, a classmethod might be more appropriate:

    class Person:
        @classmethod
        def call_person(cls):
            print("hello person", cls)
    
    p = Person().call_person() # using classmethod on instance
    Person.call_person()       # using classmethod on class
    

    The difference here is that in the second example, the class itself is passed as the first argument to the method (as opposed to a regular method where the instance is the first argument, or a staticmethod which doesn’t receive any additional arguments).

    Now to answer your actual question. I’m betting that you aren’t finding your method because you have put the class Person into a module Person.py.

    Then:

    import Person  # Person class is available as Person.Person
    Person.Person.call_person() # this should work
    Person.Person().call_person() # this should work as well
    

    Alternatively, you might want to import the class Person from the module Person:

    from Person import Person
    Person.call_person()
    

    This all gets a little confusing as to what is a module and what is a class. Typically, I try to avoid giving classes the same name as the module that they live in. However, this is apparently not looked down on too much as the datetime module in the standard library contains a datetime class.

    Finally, it is worth pointing out that you don’t need a class for this simple example:

    # Person.py
    def call_person():
        print("Hello person")
    

    Now in another file, import it:

    import Person
    Person.call_person() # 'Hello person'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that can be called if the person has a specific
I have an simple class that I get from a webservice. public class person
Im having rather an annoying problem. I have a class called Person and a
Suppose I have this code (pseudocode) class SomeClass { class Person { public static
I have a class that looks like this: public class Person { public class
say I have a class: class x: def first_x_method(self): print 'doing first_x_method stuff...' def
I have a Security class that looks like this: package controllers; import play.Logger; public
I have this Person class that is part of various other transactions like a
I have class Person class person{ int ID ; sting FirstName ; string Last
I have a class Person and a class Name. Name contains two Strings firstName

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.