Using filepath method to identify an .html page

Michael Torrie torriem at gmail.com
Tue Jan 22 13:36:31 EST 2013


I'm sorry you are getting so frustrated.  There's obviously a language
barrier here, but also your frustration is preventing you from thinking
clearly.  You need to take a step back, breath, and re-read everything
that's been written to you on this thread.  All your questions that can
be answered have been answered.  If you are being paid to develop this,
then we don't want to do your work for you since we're not the ones
being paid.  If you're doing this for a class assignment, then again we
don't want to do it for you because that would defeat the purpose of
your education.  But if you're willing to learn, then I think the others
have said on this thread will help you learn it.

You can't learn Python by developing CGI scripts and running them on the
server.  You need to try out snippets of code in an interactive way.
You've been told how to do this, and you don't need IDLE.  Although
nothing prevents you from installing IDLE on your local machine.  I hope
you have the python interpreter on your local workstation.  If not,
download it and install it.  You will need it.  Use the python standard
library reference online (or download it).  You will need it.

On 01/22/2013 08:21 AM, Ferrous Cranus wrote:
> Why the hell
>
> pin = int ( '/home/nikos/public_html/index.html' )
>
> fails? because it has slashes in it?

That line fails because the string you passed it simply cannot be parsed
into a number.  Just for simplicity's sake here, suppose we define a
number as any number of digits, 0-9, followed by a '.' or a ','
depending on locale, and some more digits, 0-9.  This is very simplistic
but it will server our purpose for this example.  So given that a number
is defined as above, we expect that we can parse the following strings:

int('123.433') == int(123.433) == 123

but '/home/nikos/public_html/index.html' contains nothing that is
recognizable as a number.  There are no 0-9 digits in it, no periods or
commas.  So rather than returning 0, which would be absolutely
incorrect, int() throws an exception because you've passed it a string
which does not contain a recognizable number.

If you really want to get a number to identify a string you'll have to
create a hash of some kind.  You were on the right track with hashlib.
Except that int() again cannot work with the hash object because nothing
in the hash object's string representation looks like a number.  If you
would follow the link you've already been given on the documentation for
hashlib you'd find that the object returned by md5 has methods you can
call to give you the hash in different forms, including a large number.



More information about the Python-list mailing list