why o/p is different ???

asit lipun4u at gmail.com
Thu Jan 15 01:34:57 EST 2009


I recently faced a peculiar o/p.

My objective is to remove the command name(my script name) from
sys.argv[0].
I coded like this

import urllib
import sys


print "\n\n\t\tlipun4u[at]gmail[dot]com"
print "\t\t------------------------"

apppath = sys.argv[0].split("/")
appname = apppath[len(apppath)-1]
print appname

if len(sys.argv) not in [2,3]:
    print "Usage : " + appname + " <url> [options]"
    print "e.g. : " + appname + "www.google.com --verbose"
    print "\n\t[option]"
    print "\t\t--verbose/-V for verbose output"
    print "\t\t-r for recursive scan"
    sys.exit(1)

site = appname.replace("http://","").rsplit("/",1)[0]
site = "http://" + site.lower()
print site


It showed the required o/p in the IDLE
here is the o/p

		lipun4u[at]gmail[dot]com
		------------------------
linkscan.py
Usage : linkscan.py <url> [options]
e.g. : linkscan.pywww.google.com --verbose

	[option]
		--verbose/-V for verbose output
		-r for recursive scan

Traceback (most recent call last):
  File "I:/Python26/linkscan.py", line 18, in <module>
    sys.exit(1)
SystemExit: 1

But in command prompt the o/p is still faulty

                lipun4u[at]gmail[dot]com
                ------------------------
I:\Python26\linkscan.py
Usage : I:\Python26\linkscan.py <url> [options]
e.g. : I:\Python26\linkscan.pywww.google.com --verbose

        [option]
                --verbose/-V for verbose output
                -r for recursive scan

I:\Python26>

regards
asit dhal



More information about the Python-list mailing list