0

i'm trying to run python script which already ran on test environment. already checked if the path correct and if the file in it. checked in shell that the file exist.

current code is :

 # Open a file
 path = 'C:\\Users\\tzahi.k\\Desktop\\netzer\\'
 dirs = os.listdir( path )
 fileslst = []
 alertsCode = (some data)


 # loop over to search the relative file 
 for file in dirs:
    if "ALERTS" in file.upper()  :
       fileslst.append(file)
 fileslst.sort()

#open and modify the latest file
with open(fileslst[-1], 'rb') as csvfile:
    csvReader = csv.reader(csvfile)
    clean_rows = [row for row in csvReader if not any(alert in row[2] for alert in alertsCode)]

error :

IOError:error 2 no such file or directory:'file name'

when i debug in shell i see the path and files

what am i doing wrong?

1 Answer 1

1

os.listdir() lists the files relative to the directory.

You need to add the full directory path to the filename for it to be an absolute path again:

with open(os.path.join(path, fileslst[-1]), 'rb') as csvfile:
Sign up to request clarification or add additional context in comments.

1 Comment

thank's!! works great! but i still cannot understand why it's work in test env. and not in production?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.