Python Forum
How to import a file from outside the directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to import a file from outside the directory
#5
I give you my solver.py file, and then the error message.
#solver.py
import init
#import numbers
import os
import csv
from kudoSudoku import sudoku
from pprint import pprint
filename = os.path.abspath('C:/Users/Sylvain/numbers.csv')
with open(filename) as csvfile:
    creader = csv.reader(csvfile, delimiter=' ')
    for row in creader:
        #do something with data
        print(', '.join(row))


with open('numbers.csv', newline='') as csvfile:
    puzzle=csv.reader(csvfile, delimiter=' ', quotechar='|')
    for row in puzzle:#origin
        print(', '.join(row))#originr
        matrix=row

    for i in range(9):
        matrix[i]=eval(matrix[i])

    print('sylvain')
    print(matrix)
    pprint(matrix)

    table = sudoku(matrix)
    result = table.solve()
    pprint(result)
And now the error message:
Error:
λ python solver.py |[0,, 9,, 0,, 0,, 0,, 0,, 0,, 0,, 0]|, |[1,, 0,, 0,, 0,, 0,, 6,, 8,, 7,, 2]|, |[0,, 0,, 2,, 1,, 0,, 0,, 0,, 3, , 0]|, |[0,, 0,, 1,, 0,, 4,, 0,, 0,, 6,, 0]|, |[0,, 2,, 0,, 0,, 0,, 0,, 0,, 0,, 5]|, |[0,, 0,, 9,, 0,, 7,, 0,, 0,, 2,, 0]|, |[0,, 0,, 7,, 5,, 0,, 0,, 0,, 4,, 0]|, |[8,, 0,, 0,, 0,, 0,, 4,, 7,, 1,, 3]|, |[0,, 1,, 0,, 0,, 0,, 0,, 0,, 0,, 0]| Traceback (most recent call last): File "solver.py", line 16, in <module> with open('numbers.csv', newline='') as csvfile: FileNotFoundError: [Errno 2] No such file or directory: 'numbers.csv'
Reply


Messages In This Thread
RE: How to import a file from outside the directory - by sylas - May-10-2018, 07:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write variable in a python file then import it in another python file? tatahuft 4 1,156 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 1,347 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  import a function from another file using relative path paul18fr 6 3,941 Aug-01-2024, 06:40 AM
Last Post: paul18fr
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 7,409 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 8,648 Jun-27-2023, 01:17 PM
Last Post: diver999
Video doing data treatment on a file import-parsing a variable EmBeck87 15 6,158 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Import XML file directly into Excel spreadsheet demdej 0 1,686 Jan-24-2023, 02:48 PM
Last Post: demdej
  Extract file only (without a directory it is in) from ZIPIP tester_V 1 4,621 Jan-23-2023, 04:56 AM
Last Post: deanhystad
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 2,167 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  no such file or directory in SFTP saisankalpj 2 2,831 Nov-25-2022, 11:07 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020