Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 什么是「;sys.stdout.write();Ruby中的等价物?_Python_Ruby_Stdout - Fatal编程技术网

Python 什么是「;sys.stdout.write();Ruby中的等价物?

Python 什么是「;sys.stdout.write();Ruby中的等价物?,python,ruby,stdout,Python,Ruby,Stdout,正如在Python中看到的,Ruby中的sys.stdout.write()等价物是什么?(或者如果您不想自动添加换行符(\n) 或打印——因为它已缓冲 在Ruby中,您可以使用$stdout或stdout访问标准输出。因此,您可以使用如下方法: $stdout.write 'Hello, World!' 或相当于: STDOUT.write 'Hello, World!' $stdout实际上是一个全局变量,其默认值为stdout 您也可以使用put,但我认为这更类似于python的pri

正如在Python中看到的,Ruby中的
sys.stdout.write()
等价物是什么?

(或者如果您不想自动添加换行符(
\n


打印
——因为它已缓冲

在Ruby中,您可以使用
$stdout
stdout
访问标准输出。因此,您可以使用如下方法:

$stdout.write 'Hello, World!'
或相当于:

STDOUT.write 'Hello, World!'
$stdout
实际上是一个全局变量,其默认值为
stdout


您也可以使用
put
,但我认为这更类似于python的
print

,这里有一个用于向stdin和stdout写入和读取的一行程序

$ ruby -e '$stdout.write "hi\n" '
hi

$ echo "somestring" | ruby -e 'p  $stdin.read'
"somestring\n"

$ echo "somestring" | ruby -e 'puts   $stdin.read'
somestring

如果您能解释一下sys.stdout.write()在python@Salil:它将字符串写入标准输出。
$ ruby -e '$stdout.write "hi\n" '
hi

$ echo "somestring" | ruby -e 'p  $stdin.read'
"somestring\n"

$ echo "somestring" | ruby -e 'puts   $stdin.read'
somestring