SnakeCharmR icon indicating copy to clipboard operation
SnakeCharmR copied to clipboard

Python print() function does not work properly (under RStudio)

Open Madpentiste opened this issue 6 years ago • 2 comments

Python 3 print() function does not print at all (on stdout) when called by py.exec(). It works only if print is directed to a file (not the stdout) with the file=<python_file_object> option Whatever was printed on stdout during the python session, however, is printed on the R stdout when unloading the SnakeCharmR package.

To reproduce :

library("SnakeCharmR") # this loads python 3.4 on my installation output: SnakeCharmR 1.0.7.1 - R and Python Integration Contribute and submit issues at https://github.com/asieira/SnakeCharmR

Python version 3.4.3 (default, Nov 12 2018, 22:32:28) [GCC 4.8.4]

py.exec("print('Hello world')") output: none

unloadNamespace("SnakeCharmR") output: Hello world

Madpentiste avatar Oct 03 '19 11:10 Madpentiste

I tried with Python 2.7 and RStudio on Mac OS X and it seems to work:

> library(SnakeCharmR)
SnakeCharmR 1.0.7.1 - R and Python Integration
Contribute and submit issues at https://github.com/asieira/SnakeCharmR

Python version 2.7.16 (default, Oct 16 2019, 00:34:56) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)]
> py.exec("print('blah')")
blah

Will test with Python 3 and get back to you.

asieira avatar Nov 01 '19 16:11 asieira

Yes, was able to reproduce it with Python 3.7:

> library(SnakeCharmR)
SnakeCharmR 1.0.8 - R and Python Integration
Contribute and submit issues at https://github.com/asieira/SnakeCharmR

Python version 3.7.5 (default, Nov  1 2019, 02:16:32) 
[Clang 11.0.0 (clang-1100.0.33.8)]
> py.exec("print('Hello world')")
> py.exec("import sys")
> py.exec("sys.stdout.write('hello')")

I have to say I am as baffled as you are about this. I'll try to investigate what is going on.

asieira avatar Nov 01 '19 19:11 asieira