Skip to content

Commit fd0d804

Browse files
committed
Fix error when executing python code under python 3
1 parent 0ead08b commit fd0d804

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

python/console/console_editor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ def runScriptCode(self):
594594
tmpFile = self.createTempFile()
595595
filename = tmpFile
596596

597-
self.parent.pc.shell.runCommand(u"execfile(u'{0}'.encode('{1}'))"
597+
self.parent.pc.shell.runCommand(u"exec(open(u'{0}'.encode('{1}')).read())"
598598
.format(filename.replace("\\", "/"), sys.getfilesystemencoding()))
599599

600600
def runSelectedCode(self):

src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5145,7 +5145,7 @@ void QgisApp::runScript( const QString &filePath )
51455145

51465146
mPythonUtils->runString(
51475147
QString( "import sys\n"
5148-
"execfile(\"%1\".replace(\"\\\\\", \"/\").encode(sys.getfilesystemencoding()))\n" ).arg( filePath )
5148+
"exec(open(\"%1\".replace(\"\\\\\", \"/\").encode(sys.getfilesystemencoding())).read())\n" ).arg( filePath )
51495149
, tr( "Failed to run Python script:" ), false );
51505150
}
51515151

0 commit comments

Comments
 (0)