I made a sample file that uses a class called Names
. It has its initialization function and a few methods. When I create an instance of the class it retrieves the instance's first name and last name. The other methods greet the instance and say a departure message. My question is: how do I import this file into the Python shell without having to run the module itself?
The name of my file is classNames.py and the location is C:\Users\Darian\Desktop\Python_Programs\Experimenting
Here is what my code looks like:
class Names(object):
#first function called when creating an instance of the class
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
#class method that greets the instance of the class.
def intro(self):
print "Hello {} {}!".format(self.first_name, self.last_name)
def departure(self):
print "Goodbye {} {}!".format(self.first_name, self.last_name)
But I get the error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import classNames.py
ImportError: No module named classNames.py