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

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

Any idea's where I'm going wrong?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: snuf.py
Type: application/octet-stream
Size: 486 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-list/attachments/20040504/c52dea23/attachment.obj

Search Discussions

  • John Hunter at May 5, 2004 at 3:17 am
    "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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 4, '04 at 10:54p
activeMay 5, '04 at 3:17a
posts2
users2
websitepython.org

2 users in discussion

Ronan: 1 post John Hunter: 1 post

People

Translate

site design / logo © 2022 Grokbase