gpt4 book ai didi

python - 在python中格式化字符串

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

<分区>

我有以下模板,我正在将其写入 config 文件:

template = """mkdir /root/.ssh \
&& chmod go-rwx /root/.ssh \
&& apt-get install -y \
gcc \
libssl-dev \
python-pip \
openssh-server \
PATH=/usr/local/jdk1.8.0/bin:$PATH
"""
with open('config', 'w') as f:
f.write(template)

我得到以下格式:

mkdir /root/.ssh         && chmod go-rwx /root/.ssh         && apt-get install -y             gcc             libssl-            dev             python-pip             openssh-server

代替:

mkdir /root/.ssh \
&& chmod go-rwx /root/.ssh \
&& apt-get install -y \
gcc \
libssl-dev \
python-pip \
openssh-server \
PATH=/usr/local/jdk1.8.0/bin:$PATH

如何将我的字符串模板格式化为正确的格式?

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