Reputation: 86
I'm new in Python and i cant to resolve one error. So i have two folders "Common" and "Parsers". In "Common"-folder there is a file - FileUtils.py:
import re
def get_filename(target):
pattern = "^.*\/(.*)$"
names = re.findall(pattern, target)
return names[0]
In "Parsers"-folder there is also one file - Parser.py:
import os
import urllib
import urllib.request
import re
from Common import FileUtils
#urls - list of strings
def parse_images(urls)
...
...
full_path = os.path.join(directory, FileUtils.get_filename(final_link))
...
And finally in root folder - Main.py:
from Parsers import Parser
def main():
url = ['http://www.example.com']
Parser.parse_images(url)
At first line of Main.py - "from Parsers import Parser" PyCharm throws an error - "ImportError: cannot import name 'Parser'".
Can someone explain me what i'm doing wrong? Thanks.
P.S. When all code in one file - program works fine.
Upvotes: 2
Views: 8887
Reputation: 3232
Have you set up your folders as Python packages? If you wish to import from a directory then you'll need a __init__.py
file inside to do so (an empty one will work).
Try creating an empty Parsers/__init__.py
file and see if that fixes it
Upvotes: 2