correctly close files executed from QgsPythonRunner

This commit is contained in:
volaya 2019-03-18 08:27:22 +01:00 committed by Nyall Dawson
parent 1ab7925983
commit 7653e45321

View File

@ -1390,7 +1390,7 @@ int main( int argc, char *argv[] )
//replace backslashes with forward slashes
pythonfile.replace( '\\', '/' );
#endif
QgsPythonRunner::run( QStringLiteral( "exec(open('%1').read())" ).arg( pythonfile ) );
QgsPythonRunner::run( QStringLiteral( "with open('%1','r') as f: exec(f.read())" ).arg( pythonfile ) );
}
/////////////////////////////////`////////////////////////////////////