-3

文字列を変更して変更された文字列を返そうとしているだけですが、変数を出力すると「なし」が返されます。

def AddToListTwo(self,IndexPosition):
    filename = RemoveLeadingNums(self, str(self.listbox1.get(IndexPosition))) #get the filename, remove the leading numbers if there are any
    print filename #this prints None
    List2Contents = self.listbox2.get(0, END)
    if(filename not in List2Contents): #make sure the file isn't already in list 2
        self.listbox2.insert(0, filename)

def RemoveLeadingNums(self, words):
    if(isinstance(words,str)):
        match = re.search(r'^[0-9]*[.]',words)
        if match: #if there is a match, remove it, send it through to make sure there aren't repeating numbers
            RemoveLeadingNums(self, re.sub(r'^[0-9]*[.]',"",str(words)).lstrip())
        else:
            print words #this prints the value correctly
            return words
    if(isinstance(words,list)):
        print "list"

編集 - 複数の人が、一致する場合は値を返さないとコメントしています。あるなら返したくない。繰り返している可能性があります (例: 1.2. itema)。したがって、本質的に再帰を使用してそれを削除し、値を返したいと思いました

4

2 に答える 2

1

RemoveLeadingNums返される条件は複数ありますNone。たとえば、if match:ブランチが取得された場合。おそらくそれは次のようになります。

if match: 
    return RemoveLeadingNums(...

None渡された文字列ではないデータ型がある場合にも返されます。

于 2013-01-30T16:23:25.387 に答える
1

一致した場合は何も返されません。そのはず:

return RemoveLeadingNums( ... )
于 2013-01-30T16:23:44.777 に答える