Python Forum
re.findall HELP!!! only returns None
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
re.findall HELP!!! only returns None
#1
OK, I'm really new to python. I've only been learning for about two weeks now. I'm taking an online class to learn but I'm having a lot of trouble with one assignment. I'm coming here because I think it might be something other than y code because its really simple and I have even seen people successfully compile pretty much the exact same code.So im trying to find all the numbers in the string bellow using the re.findall() "function". I think my code works but every time I upload it regardless of any changes I make the output always comes back as 'None'. I don't know what to do and its been 2 days. Help please.

import re

y = 'We four guys, live at 2nd street of Malibeu. I had a cash of $248 in my pocket. I got a ticket with serial number 88796451-52.'
x = re.findall('[a-z]', y)
print(x)
And the output is just None not even a compiling error it just prints None
Reply
#2
For me, it shows
Output:
['e', 'f', 'o', 'u', 'r', 'g', 'u', 'y', 's', 'l', 'i', 'v', 'e', 'a', 't', 'n', 'd', 's', 't', 'r', 'e', 'e', 't', 'o', 'f', 'a', 'l', 'i', 'b', 'e', 'u', 'h', 'a', 'd', 'a', 'c', 'a', 's', 'h', 'o', 'f', 'i', 'n', 'm', 'y', 'p', 'o', 'c', 'k', 'e', 't', 'g', 'o', 't', 'a', 't', 'i', 'c', 'k', 'e', 't', 'w', 'i', 't', 'h', 's', 'e', 'r', 'i', 'a', 'l', 'n', 'u', 'm', 'b', 'e', 'r']
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#3
Do you know why. Im still just as confused.
Reply
#4
Know why what?

re.findall will never return None. If nothing is found it will return [], but there is no way you can make it return None. Therefore your problem is not that you run the code you provide and it prints "None".

How are you running this script? You say "I think my code works but every time I upload it". What do you mean by "upload it"?
Reply
#5
post your code verbatim. you speak of function in your original post, but there is no function in the code you show.
Also note that [a-z] patterns will not give you "all the numbers" anyway. Yo may use site like 101regex.com to experiment with RegEx
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
Im running it through PyCharm and I'm coming from a c Arduino background so I didn't mean upload. And I was just experimenting with [a-z] and no matter what I put there it just outputs the word None. Thats what Im having trouble with. Its not even showing [] just the word None. Whats a verbatim? Is there somthing I have to download like a library for 'import re' or can I just call it.
Reply
#7
verbatim means to show your code exactly as it is in pycharm. maybe even show a screenshot.
re module is part of Standard library, so no need to install anything
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
My guess is you wrote a function that uses regex and your function doesn't have a return. That would be easy to verify is you POSTED THE CODE instead of some different code that maybe includes some of the same words
Reply
#9
Since Im brand new to the forum and this is my first post I am not allowed to add attachments according to the forums rules. But again I will show exactly what my compiler is running maybe if someone could try running it on heir setup that would be great.
import re

y = 'We four guys, live at 2nd street of Malibeu. I had a cash of $248 in my pocket. I got a ticket with serial number 88796451-52.'
x = re.findall('[a-z]', y)
print(x)
Output:
C:\Users\h************\PycharmProjects\untitled4\venv\Scripts\python.exe C:/Users/h************/Desktop/PycharmProjects/regular_expressions_example.py None Process finished with exit code 0

sorry I meant the error was.

Output:
C:\Users\h************\PycharmProjects\untitled4\venv\Scripts\python.exe C:/Users/h************/Desktop/PycharmProjects/regular_expressions_example.py None Process finished with exit code 0
Reply
#10
(Jun-19-2020, 12:24 AM)Rusty Wrote: if someone could try running it on heir setup that would be great.

We did. @pyzyx3qwerty show the result already in post#2. Here again (just the string is shorter):

>>> import re
>>> y = 'We four guys, live at 2nd street of Malibeu'
>>> x = re.findall('[a-z]', y)
>>> print(x)
['e', 'f', 'o', 'u', 'r', 'g', 'u', 'y', 's', 'l', 'i', 'v', 'e', 'a', 't', 'n', 'd', 's', 't', 'r', 'e', 'e', 't', 'o', 'f', 'a', 'l', 'i', 'b', 'e', 'u']
As @deabhystad explained we suspect you have slightly different code and print None returned from a function. Especially because you mention function in your original post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  regex findall() returning weird result Radical 1 709 Oct-15-2023, 08:47 PM
Last Post: snippsat
  Python: re.findall to find multiple instances don't work but search worked Secret 1 1,265 Aug-30-2022, 08:40 PM
Last Post: deanhystad
  regex.findall that won't match anything xiaobai97 1 2,066 Sep-24-2020, 02:02 PM
Last Post: DeaD_EyE
  Regex findall() NewBeie 2 4,360 Jul-10-2020, 12:19 PM
Last Post: DeaD_EyE
  The "FindAll" Error BadWhite 6 4,507 Apr-11-2020, 05:59 PM
Last Post: snippsat
  Beginner question: lxml's findall in an xml namespace aecklers 0 2,962 Jan-22-2020, 10:53 AM
Last Post: aecklers
  Issue with re.findall alinaveed786 8 4,977 Oct-20-2018, 09:28 AM
Last Post: volcano63
  [Regex] Findall returns wrong number of hits Winfried 8 5,930 Aug-23-2018, 02:21 PM
Last Post: Winfried
  Combining the regex into single findall syoung 0 2,555 May-28-2018, 10:11 AM
Last Post: syoung
  unable to print the list when using re.findall() satyaneel 5 4,215 Sep-27-2017, 10:26 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020