Where should my Python 3 modules be?

I recently installed Python 3 on my Mac OSX 10.6.8, and so far I have had no problems with modules or import. I am writing a function that checks if a triangle has a right angle based on the length of the sides, and the manual in which the exercise was performed has a bunch of equalities to check so I can see if this works:

testEqual(is_rightangled(1.5,2.0,2.5), True) testEqual(is_rightangled(4.0,8.0,16.0), False) testEqual(is_rightangled(4.1,8.2,9.1678787077), True) testEqual(is_rightangled(4.1,8.2,9.16787), True) testEqual(is_rightangled(4.1,8.2,9.168), False) testEqual(is_rightangled(0.5,0.4,0.64031), True) 

I have to explicitly import a function called testEqual (a, b, c) from a module called test, since the sample program in the manual starts with from test import testEqual , but when I typed this into my file, I got this message:

  from test import testEqual ImportError: cannot import name testEqual 

I believe that I should indicate the path to the test module, but I can not find it in my Python 3 library anywhere on my computer - only those 2.x that were installed with the computer, located in /Library/Python , import turtle and import math , so it should be somewhere.

+4
source share
2 answers

The test module in stdlib Python does not contain a function called testEqual() . Its documentation begins with

Note. The test package is intended for internal use only by Python. This is documented for the benefit of major Python developers. Any use of this package outside of the Pythons standard library is not recommended; the code mentioned here may be changed or removed without notice between Python releases.

Are you sure that in this guide you do not have your own test.py program that you should use instead?

+5
source

When you write the testEqual () function, pay attention to the directory in which you work. For example, on my mac, I created a directory (folder) in the documents, so my path looks like this: / Users / myName / Documents / python. Save your function (module) as testEqual.py and when you write test.py script import testEqual after the shebang line. After you debug your scripts, your modules will be located in a folder created under the name python pycache , do not delete it, because it is compiled. Now, while you are working in the same directory as your module, you do not need to do anything other than use the import statement.

0
source

Source: https://habr.com/ru/post/1495213/


All Articles