Freshman AttributeError: No attribute in a module

419 Views Asked by At

just new to python, and I believe this is not a big deal but because I am a freshman. Basically, this is a simple program plotting a FM signal in time domain. I write a module by myself.

def FreqMod (fc,fm,t_domain)

    pi=py.pi  
    if fc>fm:
       delta=fc-fm
    else:
        delta=fm-fc
    return py.cos(2*pi*fc*t_domain+ (delta/fm)*py.sin(2*pi*fm*t_domain))


def AmpMod(fc,fm,t_domain):

    pi=py.pi
    return py.cos(2*pi*fc*t_domain)*py.cos(2*pi*fm*t_domain)

And import it in another program

import numpy as py
import mylib 
import matplotlib.pyplot as plt


pi=py.pi
y=mylib.FreqMod(5,1000,t=py.arange(0,2*pi,pi/4000))
plt.plot(y)

The lib file is located as the same directory as the program. But I Got this later:

Traceback (most recent call last):

  File "...(The directory)...", line 14, in <module>
    y=mylib.FreqMod(5,1000,t=py.arange(0,2*pi,pi/4000))

AttributeError: module 'mylib' has no attribute 'FreqMod'

It seems like I didn't import the module successfully. I have compared it with examples in how to write and import a module, but yet can't figure out why. This really confuse me as a beginner in python.

0

There are 0 best solutions below