我想使用python在格式化的输出中写入/追加到文件中,我怎么能用特定的颜色/粗体/斜体来编写文件中的文本..等等
text0 = sample
text1 = <property><name>hbase.regionserver.wal.codec</name><value>org.apache.hadoop</value>
recovery_directory = "warning":2147483648
text3 = recovery_dir
text4 = manager_log_dir
text0 = sample
text1 = <property>
<name>hbase.regionserver.wal.codec</name>
<value>org.apache.hadoop</value>
recovery_directory = "warning":2147483648
text3 = recovery_dir
text4 = manager_log_dir
def fappend(f,text):
check=os.path.isfile(f)
text=str(text) + "\n"
if check == False:
f1=open(f,'w')
else:
f1=open(f,'a')
f1.write(text)
f1.close()
return
def format(item,length):
out = item.ljust(length)
return out;
def main():
rname = api
for c in rname.get_config(view='full'):
name = c.name
val = c.value
if val != None:
text = format(config.name,5)
item = text + "= " + val
fappend(file, item)
if __name__ == "__main__":
main()