社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

Python用新值替换列表中的str

Kasper Aamodt • 5 年前 • 1163 次点击  

我写了一个程序,使音乐专辑成文件,你可以搜索,为此,我需要一个str在文件中有一个特定的值,是在列表完成后作出的。你能回到那个列表中,用新值更改一个空白str吗?

我在网上搜索了一下,找到了一个名为words.replace的东西,但是它不起作用,我得到了一个属性错误。

def create_album():
    global idnumber, current_information
    file_information = []
    if current_information[0] != 'N/A':
        save()
    file_information.append(idnumber)
    idnumber += 1
    print('Type c at any point to abort creation')
    for i in creation_list:
        value = input('\t' + i)
        if value.upper == 'C':
            menu()
        else:
            -1file_information.append('')
            file_information.append(value)
    file_information.append('Album created - ' + file_information[2] +'\nSongs:')
    -2file_information = [w.replace(file_information[1], str(file_information[0]) + '-' + file_information[2]) for w in file_information]
    current_information = file_information

    save_name = open(save_path + str(file_information[0]) + '-' + str(file_information[2]) + '.txt', 'w')
    for i in file_information:
        save_name.write(str(i) + '\n')

    current_files_ = open(information_file + 'files.txt', 'w')
    filenames.append(file_information[0])
    for i in filenames:
        current_files_.write(str(i) + '\n')

    id_file = open(information_file + 'albumid.txt', 'w')
    id_file.write(str(idnumber))

-1是我放空行的地方

-2是我尝试用行0和行2的值替换列表中的行1的位置。

我收到的错误消息是int object没有属性replace

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53691
 
1163 次点击  
文章 [ 1 ]  |  最新文章 5 年前