将输入分成线而不是限制线

时间:2014-03-19 16:14:48

标签: python irc command-line-interface

我正在制作一个配置文件生成器,需要将文本分解成多行,而不限制他们想要使用的行,因此他们拥有他们想要的数量。确切的例子是IRC上的/ admin命令,如下所示:输入和打印出来的内容:

    What are your admin {} lines? (delimited with some character.. lets say |)
    prompt> Nickname: Iota | Real Name: Fat Chance | Email: iota{at}electrocode.net
    .
    .
    .
    (after everything else is done its printed out/echoed or added to a file(what I plan on doing)
    admin {
        "Nickname: Iota";
        "Real Name: Fat Chance";
        "Email: iota{at}electrocode.net";
    };

    .
    .
    .

1 个答案:

答案 0 :(得分:0)

你是说这个吗?

user_input = raw_input("prompt>")
print 'admin {'
for line in user_input.split('|'):
    print '"{0}";'.format(line.strip())
print '}'