Parsing arguments to a python file

  • Python
  • Thread starter magistros
  • Start date
  • #1
4
0

Main Question or Discussion Point

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!
 

Answers and Replies

  • #2
phyzguy
Science Advisor
4,572
1,507
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
 
  • #3
jhae2.718
Gold Member
1,161
20
Depending on the complexity of your needs, you may want to look at the argparse module.
 
  • #4
4
0
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!!
 

Related Threads on Parsing arguments to a python file

  • Last Post
Replies
4
Views
1K
Replies
9
Views
16K
  • Last Post
Replies
1
Views
21K
Replies
4
Views
1K
Replies
2
Views
20K
Replies
2
Views
3K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
1
Views
1K
Replies
4
Views
865
  • Last Post
Replies
5
Views
2K
Top