因为特殊需要需要把打印的东西保存下来,因此记笔记:
# 创建一个txt文件,文件名为save_result.txt
def text_create(name):
# 此处是服务器地址,可以改为本地
desktop_path = "/home/xxx/GraphNN/"
# 新创建的txt文件的存放路径
full_path = desktop_path + name + '.txt' # 也可以创建一个.doc的word文档
file = open(full_path, 'w')
filename = 'save_result'
text_create(filename)
output = sys.stdout
outputfile = open(
"/home/xxx/GraphNN/" + filename + '.txt', 'w')
sys.stdout = outputfile
print('result = ', b.argsort()[:, ::-1], file=outputfile)
outputfile.close() # close后才能看到写入的数据