Using filepath method to identify an .html page

John Gordon gordon at panix.com
Tue Jan 22 11:55:02 EST 2013


In <mailman.801.1358870401.2939.python-list at python.org> Ferrous Cranus <nikos.gr33k at gmail.com> writes:

> I just need a way to CONVERT a string(absolute path) to a 4-digit unique
> number with INT!!! That's all i want!! But i cannot make it work :(

Given your requirements, I don't think it *can* work.  There's just no
way to do it.

How can the computer guarantee that billions of possible inputs (file paths)
map to 10,000 unique outputs (4-digit numbers)?  It's not possible.

It might be possible if you had control over the format of the input strings,
but it doesn't sound like you do.

Can you maintain a separate database which maps file paths to numbers?
If so, then this is an easy problem.  Just keep a lookup table, like so:

  filepath                                         number
  --------                                         ------
  /home/files/bob/foo.html                         0001
  /home/files/bob/bar.html                         0002
  /home/files/steve/recipes/chocolate-cake.html    0003
  /home/files/mary/payroll.html                    0004

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list