my first python script (tm).

John Hunter jdhunter at ace.bsd.uchicago.edu
Tue May 4 23:17:20 EDT 2004


>>>>> "ronan" == ronan  <ronanm at gmail.com> writes:

    ronan> I'm a along time PHP developer but recently I have branched
    ronan> out and started to play with Python. I'm new to this list,
    ronan> so I'm not sure about the code pasting etiquette, I've
    ronan> attached it.

    ronan> It's officially my first Python script (brought to you with
    ronan> a little help from Mark Pilgrim's book) but it has a small
    ronan> problem. What ever variable's I give it for url or title
    ronan> the 'except' always seems to be triggered (the
    ronan> directory/file isn't made and the error message is echoed).

    ronan> Any idea's where I'm going wrong?

When you catch the IOError, it helps to print the exception message so
you know why you are failing.  In this case

	except IOError,msg:
		print "Fail: this URL doesn't work.",msg

When I run your script, with the improved diagnostics, eg

~/tmp $ python snuf.py test http://yahoo.com
Fail: this URL doesn't work. [Errno 2] No such file or directory: '/04/may/04/test/index.html'

The error message indicates that the save path does not exist.  Hint:
you need to create the directory structure that you are trying to save
into.  See os.makedirs in the standard library.

JDH




More information about the Python-list mailing list