Import rPython and __future__

My python script starts with

from __future__ import division

In R I do

library(rPython)
python.load("myscript.py")

I get

File "", line 2 SyntaxError: from future imports should appear at the beginning of the file

+4
source share
1 answer

I just ran into the same problem - obviously, python.load () is simply loading the script from the location, as if it were a group of commands.

I'm not sure if it is somehow packaged or preceded by some kind of code template, but it seems like that. And if you have to catch errors using rPython, then this will probably be done in the try block ... (given the current code on GitHub , at least).

, execfile(), :

python.exec("execfile('myscript.py')")

, ,

python.exec("import myscript")

, , , , , , .

(, - , .)

0

Source: https://habr.com/ru/post/1682866/


All Articles