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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:28:47+00:00 2026-05-26T00:28:47+00:00

I have my python file called convertImage.py and inside the file I have a

  • 0

I have my python file called convertImage.py and inside the file I have a script that converts an image to my liking, the entire converting script is set inside a function called convertFile(fileName)

Now my problem is I need to execute this python script from the linux command line while passing the convertFile(fileName) function along with it.

example:

 linux user$: python convertImage.py convertFile(fileName)

This should execute the python script passing the appropriate function.

example:

def convertFile(fileName):

    import os, sys
    import Image
    import string

    splitName = string.split(fileName, "_")
    endName = splitName[2]
    splitTwo = string.split(endName, ".")
    userFolder = splitTwo[0]

    imageFile = "/var/www/uploads/tmp/"+fileName

    ...rest of the script...

    return

What is the right way to execute this python script and properly pass the file name to the function from the liunx command line?

Thank in advanced

  • 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-26T00:28:48+00:00Added an answer on May 26, 2026 at 12:28 am

    This

    if __name__ == "__main__":
        command= " ".join( sys.argv[1:] )
        eval( command )
    

    This will work. But it’s insanely dangerous.

    You really need to think about what your command-line syntax is. And you need to think about why you’re breaking the long-established Linux standards for specifying arguments to a program.

    For example, you should consider removing the useless ()‘s in your example. Make it this, instead.

    python convertImage.py convertFile fileName
    

    Then, you can — with little work — use argparse to get the command (“convertFile”) and the arguments (“fileName”) and work within the standard Linux command line syntax.

    function_map = { 
        'convertFile': convertFile,
        'conv': convertFile,
    }
    parser = argparse.ArgumentParser()
    parser.add_argument( 'command', nargs=1 )
    parser.add_argument( 'fileName', nargs='+' )
    args= parser.parse_args()
    function = function_map[args.command]
    function( args.fileName )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Python file to generate a Mandelbrot set image. The original
I have a python application that relies on a file that is downloaded by
I have a file that I want to include in Python but the included
I have a binary file that I have to parse and I'm using Python.
I've got a file whose format I'm altering via a python script. I have
I have a very simple Python file, called python1.py, whose contents are: f =
We have a c file called dbookpy.c, which will provide a Python binding some
I have a python script called mythicalPythonBindings.py. It outputs something like Establishing database connection
I have a need for a high-performance string hashing function in python that produces
I have a series of Python classes in a file. Some classes reference others.

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.