-1

I am running the code below on my ST3/Atom IDE, it raises the exception that the module 're' has no attribute 'split'. But, when I running the code in the cmd Python script it works well. Can anyone interpret this confusing trouble and give me some advice to make this module works on my IDE? Thanks in advance.

The simple code I tested:

import re
re.split(r'[;,\s]\s', 'hello;,world')
Googol.Ren
  • 1
  • 2
  • 6
  • Did you by any chance create another module/file `re.py` in the same directory? What does `dir(re)` or `re.__file__` say? – tobias_k Dec 19 '19 at 11:39
  • @tobias_k oh, god! I think I am so stupid now! This issue raised only because I have named this file with 're.py'!!! I should recognize this problem early, thank for your remind! – Googol.Ren Dec 19 '19 at 11:50

2 Answers2

0

This should work, unless you made the mistake of naming another file in the directory re.py in which case it will look through the re.py file (you created) for split instead of looking through the actual re module when you import re.

maestro.inc
  • 796
  • 1
  • 6
  • 13
-1

instead of the re module you can use the inbuilt features for string variables like:

string = "Some string to be splitted"
splitted_string=string.split(" ") # this will split the string from spaces, change the whitespaces to the characters like comma, colon, period, etc.
mylist = splitted_string

output:

['Some','string','to','be','splitted']

I hoped my answer helped you...

Nalin Angrish
  • 317
  • 5
  • 17