Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Parsing arguments to a python file

  1. Mar 12, 2012 #1
    Dear forum,
    I would like you to help me on .py scripts.
    I am using CMS_SW and I want to do something like this:

    cmsRun script.py file.root

    where "file.root" is the file that the .py script needs to run... But I cannot find, how I declare it to the .py code...
    these .py files, are configuration files...

    thank you in advance!
  2. jcsd
  3. Mar 12, 2012 #2


    User Avatar
    Science Advisor

    Try it like this:

    Code (Text):

    import sys
    infile = open(filename, 'r') # Now do what you want with the file
  4. Mar 12, 2012 #3


    User Avatar
    Gold Member

    Depending on the complexity of your needs, you may want to look at the argparse module.
  5. Mar 12, 2012 #4
    Dear phyzguy,
    I tried it but I get this error
    cms::Exception caught in cmsRun
    ---- Configuration BEGIN
    FailedInputSource Configuration of primary input source has failed
    ---- Configuration END

    Maybe the CMS_SW does not run python but something like this....

    Dear jhae2.718,
    I tried the argparse and it says that the argparse is missing....

    Anyway, I will make it in C++..

    Thank you for your time guys!!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook