import prime answer = prime.checkIfPrime(13) print(answer) ''' If the imported python script (in this case prime.py) is in a separate folder Then follow should be added at the top of the script import sys if '<path to modules folder>' not in sys.path: sys.path.append('<path to modules folder>') '''
# Python3 # import system and add path to import modules # Only need to do this if not in same folder import sys if '/home/valdeslab/LearningPython/PythonModules' not in sys.path: sys.path.append('/home/valdeslab/LearningPython/PythonModules') # import module import prime # do stuff w/ module answer = prime.checkIfPrime(54) print (answer) print (prime.checkIfPrime(13))
def main(): answer = prime.checkIfPrime(13) print(answer)
from prime import checkIfPrime try: num = int(input("Please input a number: ")) print(checkIfPrime(num)) except ValueError: print("It is not a number.") except Exception as e: print("Unknown error: ", e) # print sys.path
#This doesn't work properly, needs some revision later import sys if '/Users/cherry/Desktop/repos/turtles-doing-things/misc/modules' not in sys.path: sys.path.append('/Users/cherry/Desktop/repos/turtles-doing-things/misc/modules') import prime numberToCheck = int(input('Please enter a number: ')) answer = prime.checkIfPrime(numberToCheck) print(answer) answer = prime.checkIfPrime(numberToCheck) print(answer)
import prime import sys if '/usr/rachel' not in sys.path: sys.path.append('usr/rachel') answer = prime.checkIfPrime(13) print (answer)