mercredi 27 février 2019

How to upload file from local machine to the browser using python?

I am using python to upload a file from my local disk to the web browser for an automation work. The folder name is "docs" which is in C directory. Docs folder contains 2 files "textnex.txt" and "safe.txt" so i want "textnext.txt" to upload on a web page. Here is my python code as below:

    # os for file management
import os
# Build tuple of (class, file) to turn in
submission_dir = r'C:\Users\Sonu\docs'
dir_list = list(os.listdir(submission_dir))
for directory in dir_list:
    file_list = list(os.listdir(os.path.join(submission_dir, 
directory)))
    if len(file_list) != 0:
        file_tup = (directory, file_list[0])

print(file_tup)

When i run this code it is not printing the files. I want textnex.txt to be uploaded on the web page. Have a look at the screenshot for the current result which is very weird to me. Can anyone help me here? Thanks in advance. Its showing .anaconda and navigator. I am confused




Aucun commentaire:

Enregistrer un commentaire