TypeError:只能加入一个iterable python

TypeError:只能加入一个iterable python,python,typeerror,delimiter,Python,Typeerror,Delimiter,我试图将分隔符插入到由以前的函数ifwin_list创建的字符串中。我对\n或\t没有任何问题,但一旦我的代码进入join,它就会崩溃。我尝试了几种不同的解决方案,并在网站上浏览了类似的问题/答案,但我不断得到类型错误:只能加入iterable。如果您能为我提供任何帮助,我将不胜感激 #! /usr/bin/env python import os import sys import re delim = os.getenv("QWIKIFWLISTMGR_DELIMITER") in_li

我试图将分隔符插入到由以前的函数ifwin_list创建的字符串中。我对\n或\t没有任何问题,但一旦我的代码进入join,它就会崩溃。我尝试了几种不同的解决方案,并在网站上浏览了类似的问题/答案,但我不断得到类型错误:只能加入iterable。如果您能为我提供任何帮助,我将不胜感激

#! /usr/bin/env python
import os
import sys
import re  
delim = os.getenv("QWIKIFWLISTMGR_DELIMITER")
in_list = sys.argv

def delim(in_list):
    x = "screw python"
    x = os.getenv('QWIKIFWLISTMGR_DELIMITER')
    if 'BLANK' in x:
        x = ' '.join(ifw(in_list))
        return x
    elif 'TAB' in x:
        x = ifw(in_list)
        x = '\t'.join(x)
        return x
    elif 'NL' in x:
        x = ifw(in_list)
        x = '\n'.join(x)
        return x
    elif 'COMMA' in x:
        x = ','.join(str(x) for x in (ifw(in_list)))
        return 
    elif 'COLON' in x:
        x = ifw(in_list)
        x = ':'.join(x)
        return x
    elif 'SEMICOLON' in x:
        x = ifw(in_list)
        x = ';'.join(x)
        return x
    elif 'SLASH' in x:
        x = ifw(in_list)
        x = '/'.join(x)
        return x
    else:
        x = ifw(in_list)
        return





def ifw(in_list):
    usr_choice = (in_list)[1]
    if usr_choice == 'i':
        print(int_sort(in_list))
    elif usr_choice =='f':
        print(float_sort(in_list))
    elif usr_choice == 'w':
        print(word_sort(in_list))





def float_sort(in_list):
    float_sort = "test"
    sorted_float = "test"
    float_sort = in_list[2:]
    float_sort = ''.join(float_sort)
    #float_sort1 = " ".join(list((re.findall(r"((?<!\S)\d+(?!\S))", float_sort))))
    #float_sort2 = ' '.join(list(re.findall(r"(\d+\.\d+)", float_sort)
    float_sort = "  ".join(re.findall(r"\d*\.\d+|\d+", float_sort))
    sorted_float = sorted(float_sort, key=len)
    return float_sort

#print (float_sort(in_list))

def word_sort(in_list):
     word_sort = " 1a "
     word_sort = sorted(in_list[2:], key=len) #in_list must be 2 because the program will view usr input as a word
     for i in word_sort:
         punctuation = '.',',',';','!',' / ','"','?' #strips punctuation from words
         if i in punctuation: #removes punctuation
             word_sort = word_sort.replace(i," ")
     #word_sort= sorted(word_sort, key=lambda L: (L.lower(), L))
     word_sort= " ".join(sorted(word_sort, key=lambda L: (L.lower(), L))) #takes string and sorts by length giving priority to upper over lower when tied
     sorted_word = " 1a " #left for testing
     sorted_word = re.sub("\S+\d\S+", "", word_sort).strip() #removes any word with a number in it
     sorted_word = "".join(sorted_word) #joins the results back into a string
     return sorted_word




def int_sort(in_list):
    in_list = " ".join(in_list[1:]) # takes information from argv and creates a string with it
    int_sort = " ".join(list(reversed(re.findall(r"(?<!\S)\d+(?!\S)", in_list))))
    # find all looks for a pattern of anything but a space... any number. anything besides a space in the in_list and returns it
    #reveresd flips that return backwards
    # list turns that into a list and join makes it a string again
    return int_sort

#print int_sort(in_list)

#print (delim(in_list))
ifw函数没有返回语句,因此它不返回任何语句

所以这句话:

x = ','.join(str(x) for x in (ifw(in_list)))
变成

x = ','.join(str(x) for x in None)
python不能对None进行迭代。

您的ifw函数没有return语句,因此它不会返回None

所以这句话:

x = ','.join(str(x) for x in (ifw(in_list)))
变成

x = ','.join(str(x) for x in None)

python不能对任何对象进行迭代。

显示ifw函数为什么处理逗号的代码与其他代码有如此大的不同?或者,如果逗号是问题所在,我不明白为什么部分需要x的strx。@cricket\u 007添加了额外的code@JohnZwinck这是我试图解决错误时留下的。其他格式也给出了相同的错误。显示ifw函数为什么处理逗号的代码与其他代码有如此大的不同?或者,如果逗号是问题所在,我不明白为什么部分需要x的strx。@cricket_007添加了额外的code@JohnZwinck这是我试图解决错误时留下的。其他格式也给了我同样的错误。所以当OP说我对\n或\t没有任何问题时,我猜他们是错的?那么当OP说我对\n或\t没有任何问题时,我猜他们是错的?