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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:52:51+00:00 2026-05-14T22:52:51+00:00

I have a Python script and I want to call it several functions down

  • 0

I have a Python script and I want to call it several functions down the script. Example code below:

class Name():

    def __init__(self):
        self.name = 'John'
        self.address = 'Place'
        self.age = '100'

    def printName(self):
        print self.name

    def printAddress(self):
        print self.address

    def printAge(self):
        print self.age

if __name__ == '__main__': 
    Person = Name()
    Person.printName()
    Person.printAddress()
    Person.printage()

I execute this code by entering ./name.py. How could I exectute this code from the function printAddress() down the the end of the script?

Thanks

  • 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-14T22:52:51+00:00Added an answer on May 14, 2026 at 10:52 pm

    If you are asking how can you launch your python script and have it start executing at different positions then you will have to launch the script with some information on what you want it to do. The most common way to do this would be to add support for command line arguments.

    import sys
    
    if __name__ == '__main__':   
    
        for arg in sys.argv: 
            print arg
    

    If you were to execute the above script from the command line by itself it would not do anything, but if you launch it with some extra parameters such as

    ./launch.py my_argument another_argument and_so_on
    

    You will see the script has access to the extra launch arguments through the sys.argv list. Using this, you can check for any passed args on launch and then start executing your script at your desired location.

    One example with your script could be as follows

    import sys
    
    class Name:
    
        def __init__(self):
            self.name = 'John'
            self.address = 'Place'
            self.age = '100'
    
        def printName(self):
            print self.name
    
        def printAddress(self):
            print self.address
    
        def printAge(self):
            print self.age
    
    
    if __name__ == '__main__': 
    
        Person = Name()
    
        launchOptions = sys.argv[1:]
    
        if not launchOptions or 'name' in launchOptions:
            Person.printName()
    
        if not launchOptions or 'address' in launchOptions:
            Person.printAddress()
    
        if not launchOptions or 'age' in launchOptions:
            Person.printAge()
    

    The range on the sys.argv[1:] is because the first entry in the sys.argv will be the path to the launched script.

    So you could launch this example and get the following results

    ./launch
    John
    Place
    100
    
    ./launch age
    100
    
    ./launch address
    Place
    
    ./launch name
    John
    

    Now this is just a very basic example. If you are decide to go further in this direction it may be useful for you to read up on pythons getopt module. It’s a parser for command line options.

    Hopefully I understood the question correctly.

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

Sidebar

Ask A Question

Stats

  • Questions 418k
  • Answers 418k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer With support from #latex @ freenode.net, I found this hack:… May 15, 2026 at 9:55 am
  • Editorial Team
    Editorial Team added an answer Can Moles be used without having to use Pex? Yes.… May 15, 2026 at 9:55 am
  • Editorial Team
    Editorial Team added an answer Some possibilities/things to check include: Is this database part of… May 15, 2026 at 9:55 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.