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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:03:08+00:00 2026-05-18T04:03:08+00:00

My problem is that I want to execute a python file with an argument

  • 0

My problem is that I want to execute a python file with an argument from inside another python file to get the returned values….

I don’t know if I’ve explained it well…

example:

from the shell I execute this:

          getCameras.py "path_to_the_scene"

and this return me a list of cameras….

so how can I call this script (including the argument) from another script ???

I’ve been trying to figure it out by myself by reading some other questions here , but I didn’t get it well, should I use the execfile() function?? how exactly??

Thanks in advance for helping a newbie like me!!

Ok, after take a look at your answers, I have to edit my question to make it more concise and because I don’t understand some answers(sorry, like I said I’m a newbie!!!):

I have two scripts, getMayaCameras.py and doRender.py, and one more, renderUI.py, that implements the first two scripts in a GUI.

getMayaCameras.py and doRender.py are both scripts that you can execute directly from the system shell by adding an argument (or flags, in the doRender.py case) and, if it is possible, I want to still having this possibility so I can choose between execute the UI or execute the script directly from the shell.

I’ve made already some modifications for them to work by importing them from renderUI.py but now they don’t work by themselves.

Is possible to have these scripts working by themselves and still having the possibility of calling them from another script? How exactly? This "separating the logic from the command line argument handling" that you told me before sounds good to me but I don’t know how to implement it on my script (I tried but without success).

That’s why I’m posting here the original code for you to see how I made it, feel free both to make critics and/or correct the code to explain me how I should make it for the script to work properly.

#!/usr/bin/env python

import re,sys

if len(sys.argv) != 2:
    print 'usage : getMayaCameras.py <path_to_originFile> \nYou must specify the path to the origin file as the first arg'
    sys.exit(1)


def getMayaCameras(filename = sys.argv[1]): 
    try:
        openedFile = open(filename, 'r')
    except Exception:
        print "This file doesn't exist or can't be read from"
        import sys
        sys.exit(1)
        
    cameras = []    
    for line in openedFile: 
        cameraPattern = re.compile("createNode camera")     
        cameraTest = cameraPattern.search(line) 
        if cameraTest:      
            cameraNamePattern = re.compile("-p[\s]+\"(.+)\"")           
            cameraNameTest = cameraNamePattern.search(line)         
            name = cameraNameTest.group(1)          
            cameras.append(name)            
    openedFile.close()
    
    return cameras      

getMayaCameras()
  • 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-18T04:03:09+00:00Added an answer on May 18, 2026 at 4:03 am

    The best answer is don’t. Write your getCameras.py as

    import stuff1
    import stuff2 
    import sys
    
    def main(arg1, arg2):
        # do whatever and return 0 for success and an 
        # integer x, 1 <= x <= 256 for failure
    
    if __name__=='__main__':
        sys.exit(main(sys.argv[1], sys.argv[2]))
    

    From your other script, you can then do

    import getCamera
    
    getCamera.main(arg1, arg2)
    

    or call any other functions in getCamera.py

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

Sidebar

Related Questions

My problem is that I want a grid that is populated with a set
Never used a cache like this before. The problem is that I want to
I am using VIM in Windows. The problem is that I want to use
The problem I'm having with writing a web application architecture is that I want
I have a class that i want to push_back into a deque. The problem
I'm working with CoreData in Cocoa (not document-based). My problem is, that I want
I'm troubleshooting a problem with creating Vista shortcuts. I want to make sure that
One problem that I come across regularly and yet don't have a solution to
A problem that we need to solve regularly at my workplace is how to
The problem that I am having has to do with the need to keep

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.