简体   繁体   English

如何在一行中打印 Python 对象的名称?

[英]How to print the name of a Python object in a single line?

I am trying to print the name of an object我正在尝试打印对象的名称

import pandas as pd
from sklearn.svm import SVC

pd.set_option('display.max_columns', None, 'display.width', 2500)

est = SVC(kernel='poly')
print(est)

The output is:输出是:

SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
  decision_function_shape='ovr', degree=3, gamma='auto_deprecated',
  kernel='poly', max_iter=-1, probability=False, random_state=None,
  shrinking=True, tol=0.001, verbose=False)

I would like to print this output in just 1 line (not 4).我想仅在 1 行(而不是 4 行)中打印此输出。 Do you know how to do that?你知道怎么做吗?

You can use str function :您可以使用str函数:

def print_line(obj)
    print( str(obj).replace('\n','') )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM