TypeError unsupported operand type s for NoneType and str

0 votes

Hi guys i have below code . trying to separate number,alphabet,alphanumeric from the string

import re

test_str = " Delivery Centre Strategy & Operations  - 17762-DCSO"

 

def manipulate(test_str):

    label = test_str.lstrip()

    number =''

    albhabet=''

    res = re.split(r'[-_&\s]\s*', label)

    print(res)

    while("" in res):

        res.remove("")

    print(res)

    for i in res:

        i=i.lstrip()

        print("i ->", type(i),i )

        if i.isalpha():

            albhabet +=i

            albhabet +=' '

        elif i.isdigit():

            print(type(i))

            number = number + i

            print(type(number))

        elif i.isalnum:

            al=''

            nu=''

            for k in range(0,len(i)):

                if i[k].isdigit():

                    nu +=i[k]

                elif i[k].isalpha():

                    al +=i[k]

            number +=nu

            albhabet +=al

            albhabet +=" "

      if not number:

            number = None

    return number,albhabet

result = manipulate(test_str)

app_name = result[1]

ARI = result[0]

print (ARI,app_name)

i am getting the below error for this code :

number = number + i
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Could you suggest why i getting this error as i am sure that 'i' is of string type

Oct 30, 2019 in Python by sumanth
• 190 points
8,349 views

I tried the code, worked fine for me. Here's the output:

['Delivery', 'Centre', 'Strategy', '', 'Operations', '', '17762', 'DCSO']
['Delivery', 'Centre', 'Strategy', 'Operations', '17762', 'DCSO']
i -> <class 'str'> Delivery
i -> <class 'str'> Centre
i -> <class 'str'> Strategy
i -> <class 'str'> Operations
i -> <class 'str'> 17762
<class 'str'>
<class 'str'>
i -> <class 'str'> DCSO
17762 Delivery Centre Strategy Operations DCSO 

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
3 answers

TypeError: unsupported operand type(s) for -: 'str' and 'str'

& is "bitwise and" operand in Python, you ...READ MORE

answered Dec 11, 2020 in Python by Rajiv
• 8,880 points
53,920 views
0 votes
1 answer

TypeError: unsupported operand type(s) for -: 'list' and 'int'

Hey, @William For me the code is working ...READ MORE

answered Mar 11, 2020 in Python by Roshni
• 10,480 points
1,649 views
+1 vote
0 answers

TypeError: unsupported operand type(s) for /: 'list' and 'list'

This is my part of code, why ...READ MORE

May 17, 2020 in Python by anonymous
• 220 points

edited May 18, 2020 by Gitika 583 views
0 votes
0 answers

TypeError: unsupported operand type(s) for *: 'CommentedMap' and 'CommentedMap' Hatam bu nasıl çözebilirim ?

from ruamel import yaml from scipy import spatial import ...READ MORE

Sep 29, 2020 in Python by anonymous
• 120 points

edited Sep 29, 2020 by Gitika 140 views
0 votes
0 answers

How can I solve it? TypeError: unsupported operand type(s) for /: 'float' and 'list'

I am trying to calculate numerical integration ...READ MORE

Nov 17, 2020 in Python by asimsek
• 120 points
2,941 views
0 votes
1 answer

Test Failed: unsupported operand type(s) for -: 'tuple' and 'list'

Hi, @There, Check what are you passing.. the ...READ MORE

answered Oct 5, 2020 in Python by Gitika
• 65,910 points
1,016 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,188 views
0 votes
0 answers
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,648 views