python实现打印类的所有属性和方法

 更新时间:2022年05月19日 10:01:19   作者:ACE-Mayer  
这篇文章主要介绍了python实现打印类的所有属性和方法,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

打印类的所有属性和方法

利用dir(obj)方法获得obj对象的所有属性和方法名,返回一个list。

for item in dir(top_k_metergroup):  #top_k_metergroup是某类的一个实例化对象
    print(item)
__class__
__delattr__
__dict__
__dir__
__doc__
__eq__
__format__
__ge__
__getattribute__
__getitem__
__gt__
__hash__
__init__
__init_subclass__
__le__
__lt__
__module__
__ne__
__new__
__reduce__
__reduce_ex__
__repr__
__setattr__
__sizeof__
__str__
__subclasshook__
__weakref__
_aggregate_metadata_attribute
_check_kwargs_for_full_results_and_sections
_collect_stats_on_all_meters
_convert_physical_quantity_and_ac_type_to_cols
_energy_per_meter_with_remainder
_meter_generators
_plot_area
_plot_energy_bar
_plot_sankey
_plot_separate_lines
_prep_kwargs_for_sample_period_and_resample
_replace_none_with_meter_timeframe
_set_sample_period
activation_series
activity_histogram
all_meters
appliances
available_ac_types
available_physical_quantities
available_power_ac_types
average_energy_per_period
building
call_method_on_all_meters
clear_cache
contains_meters_from_multiple_buildings
correlation
correlation_of_sum_of_submeters_with_mains
dataframe_of_meters
dataset
describe
disabled_meters
dominant_appliance
dominant_appliances
draw_wiring_graph
dropout_rate
energy_per_meter
entropy
entropy_per_meter
fraction_per_meter
from_list
from_other_metergroup
get_activations
get_labels
get_timeframe
good_sections
groupby
identifier
import_metadata
instance
is_site_meter
label
load
load_series
mains
matches
matches_appliances
meters
meters_directly_downstream_of_mains
min_off_duration
min_on_duration
mutual_information
name
nested_metergroups
on_power_threshold
pairwise
pairwise_correlation
pairwise_mutual_information
plot
plot_activity_histogram
plot_autocorrelation
plot_good_sections
plot_lag
plot_multiple
plot_power_histogram
plot_spectrum
plot_when_on
power_series
power_series_all_data
proportion_of_energy
proportion_of_energy_submetered
proportion_of_upstream
proportion_of_upstream_total_per_meter
sample_period
select
select_top_k
select_using_appliances
simultaneous_switches
sort_meters
submeters
switch_times
total_energy
train_test_split
union
upstream_meter
uptime
use_alternative_mains
values_for_appliance_metadata_key
vampire_power
when_on
wiring_graph

python中更多种类的打印

1.print("." * 10) 是输出10个 "." 

把每个字母相加输出就可以得到相应的字符串。

print("Mary had a little lamb.")
print("Its fleece was white as {}." .format('snow'))   #将snow放入字符串的相应位置
print("And everywhere that Mary went.")
print("." * 10)              # what'd that do?
 
end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r"
 
# watch that comma at the end. try removing it to see what happens
print(end1 + end2 + end3 + end4 + end5 + end6, end = ' ' )  # end = ' ' 为连接前后的成分,使其不换行
print(end7 + end8 + end9 + end10 + end11 + end12)

运行结果:

2.用了一个自定义的函数 formatter

其作用是:

<1>.取第1行定义的 formatter 字符串。

<2>.调用它的 format 函数,这相当于告诉它执行一个叫 format 的命令行命令。

<3>.给 format 传递4个参数,这些参数和 formatter 变量中的{}匹配,相当于将参数传递给了 format 这个命令。

<4>.在 formatter 上调用 format的结果是一个新字符串,其中的{}被4个变量替换掉了,这就是 print 现在打印出的结果。

formatter="{} {} {} {}"
 
print(formatter.format(1,2,3,4))
print(formatter.format("one","two","three","four"))
print(formatter.format(True,False,False,True))
print(formatter.format(formatter,formatter,formatter,formatter))
print(formatter.format(
    "Try your",
    "Own text here",
    "Maybe a poem",
    "or a song about fear"       
))

运行结果:

3.这个主要是讲定义的字符串可以直接打印出来

“\n” 是换行符。

# Here's some new strange stuff, remember type it exactlyself.
 
days = "Mon Tue Wed Thu Fri Sat Sun"
months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
 
print("Here are the days: ", days)
print("here are the months: ", months)
 
print("""
  There's something going on here.
  With the three double-quotes.
  we'll be able to type as much as we like.
  Even 4 lines if we want, or 5, or 6.
   """)

运行结果:

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • python GUI多行输入文本Text的实现

    python GUI多行输入文本Text的实现

    这篇文章主要介绍了python GUI多行输入文本Text的实现方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-06-06
  • python代码实现猜拳小游戏

    python代码实现猜拳小游戏

    这篇文章主要为大家详细介绍了python代码实现猜拳小游戏,以文本文件存储与调用信息,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-11-11
  • Flask response响应的具体使用

    Flask response响应的具体使用

    在flask中,想要给前端页面返回数据,必须是Response的对象,本文介绍了Flask response响应的使用,感兴趣的可以了解一下
    2021-07-07
  • Pycharm-community-2021版安装和配置

    Pycharm-community-2021版安装和配置

    pycharm-community-PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,本文就来介绍一下Pycharm-community-2021版安装和配置,感兴趣的可以了解一下
    2023-11-11
  • Python中的pygal安装和绘制直方图代码分享

    Python中的pygal安装和绘制直方图代码分享

    这篇文章主要介绍了Python中的pygal安装和绘制直方图代码分享,具有一定借鉴价值,需要的朋友可以参考下。
    2017-12-12
  • 解决python将xml格式文件转换成txt文件的问题(xml.etree方法)

    解决python将xml格式文件转换成txt文件的问题(xml.etree方法)

    从数据分析的角度去看xml格式的数据集,具有简单性,结构和内容分离、可扩展性的特征,今天通过本文给大家分享python将xml格式文件转换成txt文件的问题及解决方法(xml.etree方法),感兴趣的朋友一起看看吧
    2021-09-09
  • 文件上传服务器-jupyter 中python解压及压缩方式

    文件上传服务器-jupyter 中python解压及压缩方式

    这篇文章主要介绍了文件上传服务器-jupyter 中python解压及压缩方式,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-04-04
  • python批量翻译excel表格中的英文

    python批量翻译excel表格中的英文

    本文主要介绍了python批量翻译excel表格中的英文,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-02-02
  • Django中数据在前后端传递的方式之表单、JSON与ajax

    Django中数据在前后端传递的方式之表单、JSON与ajax

    Django从后台往前台传递数据时有多种方法可以实现,下面这篇文章主要给大家介绍了关于Django中数据在前后端传递的方式之表单、JSON与ajax的相关资料,需要的朋友可以参考下
    2022-10-10
  • Python按要求从多个txt文本中提取指定数据的代码示例

    Python按要求从多个txt文本中提取指定数据的代码示例

    本文给大家介绍了Python如何按要求从多个txt文本中提取指定数据,遍历文件夹并从中找到文件名称符合我们需求的多个.txt格式文本文件,文中有相关的代码示例供大家参考,具有一定的参考价值,需要的朋友可以参考下
    2023-12-12

最新评论