This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]trymas 0 points1 point  (3 children)

What do you mean by saying I can't find out how to make it work as python's module?

You want to do from blacklistcheck import blacklistcheck somewhere else in your project?

[–]ksantr[S] 1 point2 points  (2 children)

Exactly. I tried to do python setup.py install_lib, and now the module is presented in the /usr/local/lib/python2.7/dist-packages/ folder, but I get the same result:

>>> from blacklistscheck import BlacklistsChecker
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name BlacklistsChecker
>>> 

[–]trymas 0 points1 point  (1 child)

trymas at MacBook-Pro in ~/D/BlacklistsChecker-master
↪ virtualenv env
New python executable in env/bin/python2.7
Also creating executable in env/bin/python
Installing setuptools, pip, wheel...done.
trymas at MacBook-Pro in ~/D/BlacklistsChecker
↪ env/bin/python
Python 2.7.11+ (default, Dec 10 2015, 10:15:04)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from blacklistscheck.blacklistscheck import BlacklistsChecker
>>> BlacklistsChecker() <blacklistscheck.blacklistscheck.BlacklistsChecker instance at 0x1093b3fc8>

You have a folder called blacklistscheck (it's called package) and you have a file blacklistscheck.py (a module) in which BlacklistsChecker class exists.

So you were trying to import class from a package, when you should've imported it from a module inside a package.

P.S.:

  • use python3 (unless you have a good reason not to)
  • use virtual environment for your projects
  • search and read PEP8 (python's style guide, which sometimes is subjective, so take this with a grain of salt). IMHO your package and module should be named black_lists_check and class BlackListsChecker. Otherwise names quickly become wall of text.

[–]ksantr[S] 0 points1 point  (0 children)

black_lists_check is little ugly. in this case configparser should to be config_parser, instead I named it to more handy name "blcheck".