Now, i want t invoke this jython function (funtion1) from command line.
If, i modify my jython file to
I works fine and i can see the properties file values. (i invoke the py file directly from command prompt).
But when i put it in function, it does not work.
i have tried passing the function name with -c option but still it fails silently.
Could anybody tell me how to call a jython file from command prompt (for a specific function)?
In python there is no 'main()' type function or method. Any code that is not part of a function or class is executed when the file is loaded. So when you define a function in a file, the function is parsed but not executed. To execute it you would need to add a line:
Since you might also want to import this code into other modules, you might want to prevent the function from running automatically. In that case you look at the value of the __name__, if it is "__main__" the code is being executed directly by the interpreter and not being imported as a module (if it were imported as a module the __name__ would be the name of the file). So a typical thing to do when you want to run a function automatically from the command line would be: