【发布时间】:2021-11-06 17:50:39
【问题描述】:
我正在尝试生锈,我想为我的计时器创建一行打印。
我想用 rust 编写的 Python 代码:
from time import sleep
for i in range(61):
print(i, end="\r")
sleep(1)
此代码在一行中打印秒数,从而更新行中的秒数
我试过用 rust 来做这个:
use std::thread::sleep;
use std::time::Duration;
fn main() {
for i in 0..61 {
print!("{}\r", i);
sleep(Duration::from_millis(1000));
}
}
Rust 脚本不会打印任何内容,但 python 脚本会打印第二个并更新它: 当你运行它时
$ python script.py
0
当它运行 1 秒时
$ python script.py
1
当它运行 2 秒时
$ python script.py
0
我尝试从 rust 代码中的行中删除“\r”,现在它等待 60 秒,然后在一行中打印从 0 到 61 的数字:0123456789...%
我看不出 python 和 rust 代码之间的区别
【问题讨论】:
-
这能回答你的问题吗? Why does this read input before printing?
标签: rust