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
11,974 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,910 points
80,528 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,520 points
3,474 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 2,856 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 789 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
13,723 views
0 votes
1 answer

Unsupported operand type(s) for +: 'int' and 'str'

You seem to be trying to train ...READ MORE

answered Feb 23, 2022 in Python by Aditya
• 7,680 points
3,391 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,394 views
0 votes
1 answer
+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,790 points
3,997 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP