Python Parsing arguments to a python file

  • Thread starter Thread starter magistros
  • Start date Start date
  • Tags Tags
    File Python
AI Thread Summary
To parse arguments in a Python script for CMS_SW, the user attempted to run a command like "cmsRun script.py file.root" but faced issues with file input handling. The suggested method involved using `sys.argv` to retrieve the filename, but an error related to the input source configuration occurred. Another user recommended the `argparse` module for better argument parsing, but it was reported as missing. Due to these complications, the original poster decided to switch to C++ for their implementation. The discussion highlights challenges in integrating Python scripts with CMS_SW and the potential need for alternative programming solutions.
magistros
Messages
4
Reaction score
0
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!
 
Technology news on Phys.org
Try it like this:

Code:
import sys
cmd=sys.argv
filename=cmd[1]
infile = open(filename, 'r') # Now do what you want with the file
 
Depending on the complexity of your needs, you may want to look at the argparse module.
 
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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top