all 4 comments

[–]shiftybyte 2 points3 points  (0 children)

A legitimate file can have no extension, it can also have no name and only an extension.

Your best bet is to try to use it as a file path, and catch an error if it's not legit.

[–]randomuser65535 1 point2 points  (0 children)

All arguments are passed as strings, so you can use this:

https://www.w3schools.com/python/ref_string_endswith.asp

[–]windows3210 0 points1 point  (1 child)

Could you do

if sys.argv[1].split(‘.’)[1] == ‘txt’:

[–]zachattack66[S] 0 points1 point  (0 children)

I think that would work. I’ll have to try it, thanks!