python实现打印类的所有属性和方法
作者:ACE-Mayer 发布时间:2021-07-28 14:51:56
标签: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.
""")
运行结果:
来源:https://blog.csdn.net/sunmingyang1987/article/details/116228492
0
投稿
猜你喜欢
- 字典简介Python 中字典和集合也是非常相近的概念,而且从外观看上去,也有那么一丝丝的相似,Python 语言中字典类型是非常灵活的,在实
- 大家是否经常遇到在关闭网页的时候,会看到一个确定是否离开当前页面的提示框?想一些在线测试系统、信息录入系统等就经常会有这一些提示,避免用户有
- background-clip 和 background-origin 是 CSS3 中新加的 background module 属性,用
- 代码import xlrdimport os from prettytable import PrettyTableimport panda
- 我就废话不多说啦,还是直接看代码吧!try: print(a)except Exception as e: prin
- 所有标准的序列操作对字符串都适用,但字符串是不可变的字符串常量:单引号:‘spa"m'双引号:"spa'
- 建立完回归模型后,还需要验证咱们建立的模型是否合适,换句话说,就是咱们建立的模型是否真的能代表现有的因变量与自变量关系,这个验证标准一般就选
- 前言在python 中有时候我们用数组操作数据可以极大的提升数据的处理效率,类似于R的向量化操作,是的数据的操作趋于简单化,在python
- 前言MySQL 的权限表在数据库启动的时候就载入内存,当用户通过身份认证后,就在内存中进行相应权限的存取,这样,此用户就可以在数据库中做权限
- 在web.config文件中添加<connectionStrings><add name="SQLConnect
- 样式表是一种为超文本标签语言提供增强补充服务的技术,可对每一个html的标签做精雕细刻的修饰。只用html制作的网页,对页面内各部分的修饰能
- 在mysql中带了随机取数据的函数,在mysql中我们会有rand()函数,很多朋友都会直接使用,如果几百条数据肯定没事,如果几万或百万时你
- 目录1.python中的异常2.捕捉异常try-except多个except子句 一个except块捕捉多个异常 空ex
- pycharm from lxml import etree标红##原因:没有lxml这个包###解决方法:需要安装xlml包####下载地
- 点击获取后,返回2s后的鼠标位置,显示在文本框(需要用pip命令安装所需的的库)(pip install 模块名比如 安装pyautogui
- 一 描述720. 词典中最长的单词 - 力扣(LeetCode) (leetcode-cn.com)给出一个字符串数组 words
- 译者按:原文写于2011年末,虽然文中关于Python 3的一些说法可以说已经不成立了,但是作为一篇面向从其他语言转型到Python的程序员
- JS在firefox中的兼容性问题,自己也经常遇到.此文是网上资料,不过时间较久不记得原址了...1. document.form.item
- MySQL采用了基于开销的优化器,以确定处理查询的最解方式。在很多情况下,MySQL能够计算最佳的可能查询计划,但在某些情况下,MySQL没
- 想必很多初次接触python都会见到这样一个语句,if __name__ == "__main__":那么这个语句到底是