Pycharm Python console not printing the output(Pycharm Python控制台不打印输出)
本文介绍了Pycharm Python控制台不打印输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从 Pycharm python 控制台调用的函数,但没有显示输出.
I have a function that I call from Pycharm python console, but no output is shown.
In[2]: def problem1_6():
...: for i in range(1, 101, 2):
...: print(i, end = ' ')
...:
In[3]: problem1_6()
In[4]:
另一方面,像这样,它打印但顺序错误
On the other hand, like this, it prints but in the wrong order
In[7]: def problem1_6():
...: print('hello')
...:
...: for i in range(1, 101, 2):
...: print(i, end = ' ')
...:
In[8]: problem1_6()
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 hello
作为第三种选择,作为@DavidS 的建议,
As a third option, as a suggestion of @DavidS,
In[18]: import sys
...:
...: def problem1_6():
...: for i in range(1, 101, 2):
...: sys.stdout.write(str(i) + ' ')
...:
In[19]: problem1_6()
In[20]:
它仍然不打印.
推荐答案
这将起作用:
def problem1_6():
for i in range(1, 101, 2):
sys.stdout.write(str(i) + ' ')
sys.stdout.flush()
或:
def problem1_6():
for i in range(1, 101, 2):
print(i, end=' ', flush=True)
这篇关于Pycharm Python控制台不打印输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:Pycharm Python控制台不打印输出
基础教程推荐
猜你喜欢
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
