Problem calling functions from other python files

Hi image.sc

I’m new to python and scripting and was hoping to get some help here. I want to make my code modular so I have added FileFunctions.py files that contain the functions I want to use under Fiji.app/jars/Lib/UrchinLib. My Main_.py file is under Fiji.app/scripts/UrchinPy.

Main_.py contains:

### Imagej Ops ###
#@ String (visibility=MESSAGE, value="Please enter image file location") msg1
#@ File   (label = "Input directory", style = "directory") srcFile
#@ String (visibility=MESSAGE, value="Please enter CVS file destination") msg2
#@ File   (label = "Output directory", style = "directory") dstFile

# Python Libraries
import sys
import time
import os
import inspect
import csv
import unicodedata

# User Libraries
from UrchinLib.FileFunctions import initializeCSV


def main():
	# Get source and destination paths
	srcDir = srcFile.getAbsolutePath()
	dstDir = dstFile.getAbsolutePath()

	# Get date and time for CSV naming
	localtime = time.localtime(time.time())
	timef = str(localtime.tm_mday) + str(localtime.tm_mon) + str(localtime.tm_year) + "_" + str(localtime.tm_hour) + str(localtime.tm_min) + str(localtime.tm_sec)

	initializeCSV(timef, dstDir)
	
	print timef
	
main()

and FileFunctions.py contains

import os
import csv

# Name: initializeCSV
# Inputs: timeStr - string containing time and date to name CSV file
#		  fdest - destination directory of file
def initializeCSV(timeStr, fdest):
	import os.path
	import csv
	
	print "Hi"
	# Check to see if destination directory exists
	if os.path.exist(fdest):
		print "is path"

I keep getting the error:

Traceback (most recent call last):
  File "C:\Users\Juliana\DOCUME~1\Fiji.app\scripts\UrchinPy\Main_.py", line 40, in <module>
    main()
  File "C:\Users\Juliana\DOCUME~1\Fiji.app\scripts\UrchinPy\Main_.py", line 36, in main
    initializeCSV(timef, dstDir)
  File "C:\Users\Juliana\Documents\Fiji.app\jars\Lib\UrchinLib\FileFunctions.py", line 15, in initializeCSV
    if os.path.exist(fdest):
AttributeError: 'module' object has no attribute 'exist'

But, if I comment out

if os.path.exist(fdest):
    print "is path"

from initializeCSV() then it works without a problem.

I have tried including import os.path inside the function but still get the same error. Thank you in advance for your help!

Regards,
Juliana

The function name is misspelled. It’s os.path.exists.

Thank you! That was it.