PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, May 12, 2022

[FIXED] When trying to append a string to a list I get an error

 May 12, 2022     append, list, nonetype, python     No comments   

Issue

I am coding a script in python that automatically writes a file which you can use in the DecentSampler plugin, I am running into an error right now which I am not understanding.

        noteGroups = []
        firstGroup = True

        print(noteGroups)

        for file in files:          #Writes all the files in the pack.
            rfeS = ""

            strFile = str(file)

            rfe = strFile.split(".", 1)
            rfe.pop(-1)
            for rfeX in rfe:
                rfeS += rfeX
            filesSplit = rfeS.split("_", 1)

            note = filesSplit[0]
            rr = filesSplit[1]

            noteList = note.split("delimiter")
            print(noteList)

            if note not in noteGroups:
                noteGroups = noteGroups.append(note)
                print(noteGroups)
                if firstGroup:
                    dsp.write("\n    </group>")
                    firstGroup = False
                dsp.write("\n    <group>")
                dsp.write("\n      <sample path=\"" + dir + "/" + file + "\" volume=\"5dB\" rootNote=\"" + note + "\" loNote=\"" + note + "\" hiNote=\"" + note + "\" seqPosition=\"" + rr + "\" />")
            else:
                
                print(noteGroups)
                dsp.write("\n      <sample path=\"" + dir + "/" + file + "\" volume=\"5dB\" rootNote=\"" + note + "\" loNote=\"" + note + "\" hiNote=\"" + note + "\" seqPosition=\"" + rr + "\" />")

        print(noteGroups)

I am getting the error

File "D:\Python\GUI-test\dshgui.py", line 109, in dspWrite
    if note not in noteGroups:
TypeError: argument of type 'NoneType' is not iterable

But if I try this:

noteGroups = ["test", "test"]

note = "A2"

noteGroups.append(note)
print(noteGroups)

It does function properly... Does anyone know why? And how I can fix it?


Solution

The problem is this line:

noteGroups = noteGroups.append(note)

append modifies the list in-place and then it returns None. Don't assign that None value back to the name of the original list. Just do:

noteGroups.append(note)


Answered By - Samwise
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing