user2837162
user2837162

Reputation:

Can't Take in Multiple Text File

Hello this is a problem I am having. The following program doesn't allow me to take in multiple outplane data but it allow to take in multiple in plane data according to the function in call_Controller. Is there something wrong with the program?

you can try by creating this 4 text file in a folder.
run the program and press Clt to take in both hello.txt and bye.txt
follow by hello1.txt and bye1.txt and you will know the error 
somebody please help me with this problem..
hello.txt | hello1.txt
bye.txt   | bye1.txt

Error Message:

Traceback (most recent call last):
File "C:\ProjectMAPG\TRYPYTHON\src\OldPythonTry.py", line 100, in <module>
Name = call_Controller(file_path_IP, InputfilesListOoplane)
File "C:\ProjectMAPG\TRYPYTHON\src\OldPythonTry.py", line 67, in call_Controller
with open(InputfilesListOoplane) as f1:
IOError: [Errno 22] invalid mode ('r') or filename: u'C:/Users/zhenhui/Desktop/bye1.txt C:/Users/zhenhui/Desktop/hello1.txt'

function to extract the file name:

def extractFilename(FileNameOnly):
    stripText = string.split(FileNameOnly, " ")
    FileName = stripText[0]   
    return (FileName)
    pass

I think the problem is here. As the outplane have doesn't allow me to take in multiple folder:

def call_Controller(file_path_Inplane, InputfilesListOoplane):
    FileNameOnlyIP = splitext(basename(file_path_Inplane))[0]
    Name = extractFilename(FileNameOnlyIP)
    #Extract raw inplane
    with open(file_path_Inplane) as f:
        f.readline()      
    #Extract raw outplane
    with open(InputfilesListOoplane) as f1:
        f1.readline()
    return Name

Start of the program:

if __name__ == '__main__': #start of program
    win = Tk.Tk()  #Open up connection and declare button and label  
    master=win
    initial_dir = "C:\VSM"

    #Create Directory if its not there
    try:
            if not os.path.exists(newDirRH[0]):os.makedirs(newDirRH)
    except: pass

    #Open to select multiple files for files
    file_path_Inplane= tkFileDialog.askopenfilename(initialdir=initial_dir, title="Select VSM Files", multiple =1)
    if file_path_Inplane != "": pass
    else:
        print "You didn't open anything!"
    InputfilesListInplane =  win.tk.splitlist(file_path_Inplane)

    #Open to select multiple files for outplane 
    file_path_Ooplane = tkFileDialog.askopenfilename(initialdir=initial_dir, title="Select Out of Plane Files", multiple = 1)
    if file_path_Ooplane != "": 
        pass
    else:
        print "You didn't open anything!"
    InputfilesListOoplane =  file_path_Ooplane#master.tk.splitlist(file_path_Ooplane)


    for file_path_IP in InputfilesListInplane:
        Name = call_Controller(file_path_IP, InputfilesListOoplane)

    print "Done " + Name

Upvotes: 0

Views: 81

Answers (2)

Michael Kazarian
Michael Kazarian

Reputation: 4462

Prolem here:

IOError: [Errno 22] invalid mode ('r') or filename: u'C:/Users/zhenhui/Desktop/bye1.txt C:/Users/zhenhui/Desktop/hello1.txt'

Check correct place of delivery your path. Next potential pronlem here initial_dir = "C:\VSM". Must initial_dir = "C:\\VSM" or initial_dir = "C:/VSM". Furthermore use path-related functions from os.path module.

Upvotes: 0

Aaron Digulla
Aaron Digulla

Reputation: 328614

I'm not sure what "in multiple outplane data" might be but the error message explains quite clearly:

'C:/Users/zhenhui/Desktop/bye1.txt C:/Users/zhenhui/Desktop/hello1.txt'

is not a valid file name. For me, this looks like two file names that you appended with a space between them.

When you open files, neither Python nor the OS will try to read your mind. Use a single file name per operation.

Upvotes: 1

Related Questions