Error using a function outside the Python script

Asked

Viewed 130 times

1

I created a function that uses other functions that are not in the same script, when running the program I find an error, stating that the function outside the script is not defined. All functions to be used must be in the same script? Script principal função circle e as funções fora do script distance e area.

  • 1

    I don’t quite understand, but the other functions are in another file, right? If so, use import nome_do_arquivo, and use nome_do_arquivo.distance(parametros) to call the function.

  • Instead of image the ideal if you put the code, the question is too obscure. In which file do you call "other functions"? how many files are there? can put an example with two minimum functions (Helo world, for example) one calling the other?

1 answer

0

No. You can simply leave the 2 scripts in the same directory, and whatever you run, write in the first line "import Dooutroscript" (without the quotes). For every other script that has functions you wanted to use, you must make an import. Or you can do "import script1,script2,script3,...,scriptN" (no quotes). Example:

import ScriptQueContemDistance, ScriptQueContemArea

#seu código aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.