I get a error like this when run it in my terminal

filename = open(input(), 'rb') 
input_file = filename
open(args.input_file, "rb").read()

This is output

File "<stdin>", line 1, in <module> TypeError: expected str, bytes or os.PathLike object, not NoneType```

This is also there in script 

parser = argparse.ArgumentParser();
parser.add_argument("-i", dest="input_file", help="no file with this name") 
args = parser.parse_args();```

The path i put is /storage/emulated/0/filrname.txt

1 Answers

DroidX86 On Best Solutions
filename = open(input(), 'rb')

This will open the filename that you entered in the terminal and return a file object, the filename object is not the name of the file.

open(args.input_file, "rb").read() 

args is not defined in the script you provided. Even if it was, args.input is probably not set. That might cause the TypeError.

I assume you're trying to open the file entered by the user, you can do it like this:

filename = input()
with open(filename, 'rb') as f:
    data = f.read()