Depends on what the program should do. If he just prints whether he got the URL, he sys.argv[1].startswith('http://')can do it. If you really have to use the url for something useful, do
from urllib2 import urlopen
try:
f = urlopen(sys.argv[1])
except ValueError: # invalid URL
f = open(sys.argv[1])
source
share