-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New command line parameter --py-args #50092
Conversation
src/app/main.cpp
Outdated
pythonfileArgs.prepend( pythonfile ); | ||
QgsPythonRunner::run( QStringLiteral( "sys.argv = ['%1']\n" | ||
"with open('%2','r') as f: exec(f.read())\n" | ||
"sys.argv = []" ).arg( pythonfileArgs.join( "','" ), pythonfile ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not the best way to pass an array from c++ to python. Do someone know a better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this a raw string r'...'
and escape any '
in the string?
@domi4484 A documentation ticket will be opened at https://github.com/qgis/QGIS-Documentation when this PR is merged. Please update the description (not the comments) with helpful description and screenshot to help the work from documentors. Thank you! |
@domi4484 |
This PR will allow to pass arguments to the script provided via
--code
parameter and more generally to each python execution. All arguments after--py-args
till--
are passed over to the python interpreter and ignored by QGIS.Note: After
--code-args
is not possible to pass any other parameter than--
to QGISFor example:
test.py
will have this content insys.argv
:['/home/domi/test.py', '--specialScriptArguments', 'a text arg', 'and another arg']
layer1
andlayer2
will be normally handled by QGIS as layers to load