0

I am new to python. I am reading about the crypt() function for UNIX passwords.

import crypt
crypt.crypt("egg","HX")

Here is what I get after running my program

File "...", line 2, in <module> crypt.crypt("egg","HX")
TypeError: 'module' object is not callable

I've read several posts on google and stackOverflow and found that I have to import the library so:

from crypt import *
crypt.crypt("egg","HX")

but now I am getting this error:

Traceback (most recent call last):
File "crypt.py", line 1, in <module>
from crypt import *
File "...", line 2, in <module>
crypt.crypt("egg","HX")
NameError: name 'crypt' is not defined

How can this error be resolved? And what is the difference between

import smth 

and

from smth import smth1?

Thank you!

John P
  • 1,159
  • 2
  • 18
  • 44
  • which OS you are using? – Karthikeyan KR Mar 30 '17 at 10:45
  • I'm using macOS Sierra – John P Mar 30 '17 at 10:45
  • 2
    The problem is that you named your program `crypt.py`. So when it does `import crypt` it imports _itself_. – PM 2Ring Mar 30 '17 at 10:48
  • add it as an answer so that I can mark it as accepted – John P Mar 30 '17 at 10:53
  • 1
    The question I linked talks about the `requests` module, but it's the _exact same thing_ that's happening for you with the `crypt` module: you gave your program the same name as the module you're trying to import, and Python finds your program first before it finds the other module with the same name. – PM 2Ring Mar 30 '17 at 10:55
  • 1
    You may also like to take a look at [this answer](http://stackoverflow.com/questions/32180949/turtle-module-in-python-not-importing) on this topic, which I wrote before my friend idjaw wrote the question & answer I linked above. – PM 2Ring Mar 30 '17 at 11:01

0 Answers0