Thread: Readfile error

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Readfile error


    DELIM = "," # deliminator for the file to read
    SSN = "S/N" # Key SSN to search up
    DOBMonth = "DOB-MO" # Key DOB-Month to search
    DOBDay = "DOB-DA" # Key DOB-Day to search
    DOBYear = "DOB-YR" # Key DOB-Year to search
    PATH = "P:\work" # Directory Of search
    FILTERFILE = ".csv" # Files to search up


    def main():
    SSNAllInfo = {}
    listing = os.listdir(PATH) # read a directory and get the list of files
    for infile in listing: # go thru the list of files
    if infile.endswith(FILTERFILE): # only get the specific filter file
    SSNNewInfo = readFile(PATH + infile) # read that file

    for key in SSNNewInfo:
    if key in SSNAllInfo:
    SSNAllInfo[key] = SSNNewInfo[key]
    else:
    SSNAllInfo[key] = SSNNewInfo[key]

    print(SSNAllInfo)







    When I tried runninng this..
    i get this error message.
    can someone help me?

    PS P:\work> python readfile.py
    Traceback (most recent call last):
    File "readfile.py", line 128, in <module>
    main()
    File "readfile.py", line 27, in main
    SSNNewInfo = readFile(PATH + infile) # read that file
    File "readfile.py", line 52, in readFile
    for line in fileinput.input(StringFileName):
    File "C:\Python27\lib\fileinput.py", line 253, in next
    line = self.readline()
    File "C:\Python27\lib\fileinput.py", line 345, in readline
    self._file = open(self._filename, self._mode)
    IOError: [Errno 2] No such file or directory: 'P:\\workSN_427007_Welded.csv'
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    You will need to
    Code:
    import os
    ####.....
    SSNNewInfo = readFile(os.path.join(PATH,infile))
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by b49P23TIvg
    You will need to
    Code:
    import os
    ####.....
    SSNNewInfo = readFile(os.path.join(PATH,infile))
    okay, i tried that.
    it reduced my error..but now i see this


    PS P:\work> python readfile.
    File "readfile.py", line 2
    def main {
    ^
    SyntaxError: invalid syntax
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    By chance did you delete from your readfile. file the text in red? That would be bad. Bad enough to cause the problem you report.
    Code:
    def main(): 
        SSNAllInfo = {}
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo