0

I have created a class called Functions which contains many functions I define this function:

def distance(self,seq1,seq2,seq3)

In another file I want to call the function of this class.

I have defined three DNA sequences:

a=Functions()
a.distance(seq1,seq2,seq3)

When I try to call Functions(), I get the following error:

name 'Functions' is not defined
7
  • 1
    You need to import it. from myfile import Functions Commented Jan 19, 2014 at 23:55
  • First, make sure the files are in the same directory. Second, in the 2nd file, you have to import the first one. Commented Jan 19, 2014 at 23:56
  • 1
    why people vote this down? Commented Jan 20, 2014 at 0:09
  • @Elisha: I don't know. There are ways you could make it better (including a complete example, post the full traceback instead of just part of the error, etc.), but it doesn't seem downvote-worthy to me. Some people seem to think that questions that are too "elementary" are automatically bad. Personally, I think there are good, decent, and bad questions at every level of knowledge, and yours is a decent elementary question. Commented Jan 20, 2014 at 0:29
  • @abarnert, first, this is not my question. second, I also feel like sometimes people mixed between elementary questions and bad questions, that what made me comment about it. it is better to say in a comment where can be improved on the question then immediately vote it down. Commented Jan 20, 2014 at 7:01

1 Answer 1

6

Usually, if the file is named distance.py for example, you just:

import distance
a = distance.Functions()

Or if you feel lazy:

from distance import Functions
a = Functions()

Or if you feel very lazy:

from distance import *
a = Functions()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.