Python - 无输出

问题描述 投票:0回答:1

`在 Spyder 5.5.4 / conda 3.11.7 中使用以下代码/示例时,我不会得到任何输出 从 -> *print("No Output") 开始,请参见粗体。 通过使用控制台,例如print("no Output") 我得到输出。 有什么建议吗?

%matplotlib qt
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import networkx as nx
import pymarket as pm
import pprint
r = np.random.RandomState(1234)
mar = pm.Market()
mar.accept_bid(1, 6.7, 0, True, 0)
mar.accept_bid(1, 6.6, 1, True, 0)
mar.accept_bid(1, 6.5, 2, True, 0)
mar.accept_bid(1, 6.4, 3, True, 0)
mar.accept_bid(1, 6.3, 4, True, 0)
mar.accept_bid(1, 6, 5, True, 0)

mar.accept_bid(1, 1, 6, False, 0)
mar.accept_bid(1, 2, 7, False, 0)
mar.accept_bid(2, 3, 8, False, 0)
mar.accept_bid(2, 4, 9, False, 0)
mar.accept_bid(1, 6.1, 10, False, 0)

bids = mar.bm.get_df()
transactions, extras = mar.run('p2p', r=r)
stats = mar.statistics()
***print("No Output")***

bids # bids dataframe
transactions.get_df() # transactions dataframe

extras # additional information characteristic of P2P trading,

mar.plot()
ax = mar.plot_method('p2p')


print('Percentage of the maximum possible traded quantity')
stats['percentage_traded']`

尝试重新启动内核, 尝试在控制台中输出 -> 正在工作

python spyder
1个回答
0
投票

我对您正在使用的库了解不多,但您可以尝试将数据“手动”打印到

stdout
,如下所示:

import sys
_ = sys.stdout.write('Percentage of the maximum possible traded quantity\n')

注意

print()
sys.stdout.write()
之间的区别:使用第二个意味着您手动添加换行符,并且由于函数返回内容,大多数时候您需要管理输出,这里设置输出到
_
,因为这个变量名经常被用作“垃圾”。

如果这段代码有效,那么这是

print()
函数的问题:可能是某个模块更改了它。 否则,有其他问题(我不认为它可能是终端,而且我不知道它可能是什么)。

© www.soinside.com 2019 - 2024. All rights reserved.