gpt4 book ai didi

Python 字符串格式化在 print 语句上创建随机新行

转载 作者:太空宇宙 更新时间:2023-11-03 15:24:23 26 4
gpt4 key购买 nike

这是我的功能。试图将这一切打印到一行。

这是输出 ->

config::$var['pdf']['meta']['staff_member_name']
= ";"

由于某种原因,字符串的 = ";" 部分打印到控制台中的新行?

这完全只是一个个人技巧,旨在帮助满足重复的工作要求,因此我并不是在寻找任何花哨的东西。

这是我的函数 ->

def auto_pdf_config(file):
with open(file) as f:
content = f.readlines()
kill = " = array("
start = "config::$var['intake']"
new_line = ""
for line in content:
if kill not in line:
pass
elif start in line:
new_line = line
x = new_line.replace(kill, "")
y = x.replace(start,"")
pdf_end = ' = ";" '
z = "config::$var['pdf']['meta']{}{}".format(y,pdf_end)
print(z)

最佳答案

看来你的“y”变量中有新行。你可以尝试把它剥掉。

y = x.replace(start,"").strip('\n')

关于Python 字符串格式化在 print 语句上创建随机新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43265429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com