Using filepath method to identify an .html page

F

Ferrous Cranus

Τη ΤÏίτη, 22 ΙανουαÏίου 2013 5:05:49 μ.μ. UTC+2, οχÏήστης Dave Angel έγÏαψε:
I gave you every piece of that code in my last response. So you're not

willing to compose the line from the clues?

I cannot.
I don't even know yet if hashing needs to be used for what i need.

The only thing i know is that:

a) i only need to get a number out of string(being an absolute path)
b) That number needs to be unique, because "that" number is an indicator tothe actual html file.

Would you help me write this in python?

Why the hell

pin = int ( '/home/nikos/public_html/index.html' )

fails? because it has slashes in it?
 
P

Peter Otten

Ferrous said:
I insist, perhaps compeleld, to use a key to associate a number to a
filename. Would you help please?

I dont know this is supposed to be written. i just know i need this:

number = function_that_returns_a_number_out_of_a_string(
absolute_path_of_a_html_file)

Would someone help me write that in python coding? We are talkign 1 line
of code here....

Since you insist:
.... return int(absolute_path_of_a_html_file.encode("hex"), 16)
....14669632128886499728813089146L

As a bonus here is how to turn the number back into a path:
'/foo/bar/baz'

;)
 
C

Chris Angelico

Why the hell

pin = int ( '/home/nikos/public_html/index.html' )

fails? because it has slashes in it?

What do you expect it to return? 141592653589793?

Go through the Python tutorial. Better yet, find a book that
distinguishes between technology and magic, and sets out clearly what
each one's field is.

Then go here, and read. http://www.catb.org/esr/faqs/smart-questions.html

Then go back to your project. Have another shot at things. Put your
new-found knowledge and understanding to work. You'll be far better
able to figure things out, and better able to understand what we've
all been saying.

ChrisA
 
F

Ferrous Cranus

Thank you but the number needs to be a 4-digit integer only, if its to be stored in the database table correctly.

pin = int( htmlpage.encode("hex"), 16 )

I just tried whayt you gace me

This produces a number of: 140530319499494727...677522822126923116L

Visit http://superhost.gr to see that displayed error. I think it

Why did you use "hex" for? to encode the string to hexarithmetic? what for?
 
F

Ferrous Cranus

Thank you but the number needs to be a 4-digit integer only, if its to be stored in the database table correctly.

pin = int( htmlpage.encode("hex"), 16 )

I just tried whayt you gace me

This produces a number of: 140530319499494727...677522822126923116L

Visit http://superhost.gr to see that displayed error. I think it

Why did you use "hex" for? to encode the string to hexarithmetic? what for?
 
F

Ferrous Cranus

Τη ΤÏίτη, 22 ΙανουαÏίου 2013 5:25:42 μ.μ. UTC+2, οχÏήστης Peter Otten έγÏαψε:
Ferrous Cranus wrote:








Since you insist:




... return int(absolute_path_of_a_html_file.encode("hex"), 16)

...


14669632128886499728813089146L



As a bonus here is how to turn the number back into a path:




'/foo/bar/baz'



;)

Thank you but no...no that would be unnecessary complex.

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 :(
 
F

Ferrous Cranus

Τη ΤÏίτη, 22 ΙανουαÏίου 2013 5:25:42 μ.μ. UTC+2, οχÏήστης Peter Otten έγÏαψε:
Ferrous Cranus wrote:








Since you insist:




... return int(absolute_path_of_a_html_file.encode("hex"), 16)

...


14669632128886499728813089146L



As a bonus here is how to turn the number back into a path:




'/foo/bar/baz'



;)

Thank you but no...no that would be unnecessary complex.

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 :(
 
C

Chris Angelico

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 :(

Either you are deliberately trolling, or you have a major
comprehension problem. Please go back and read, carefully, all the
remarks you've been offered in this thread. Feel free to ask for
clarification of anything that doesn't make sense, but be sure to read
all of it. You are asking something that is fundamentally
impossible[1]. There simply are not enough numbers to go around.

ChrisA
[1] Well, impossible in decimal. If you work in base 4294967296, you
could do what you want in four "digits".
 
D

Dave Angel

Thank you but the number needs to be a 4-digit integer only, if its to be stored in the database table correctly.

pin = int( htmlpage.encode("hex"), 16 )

I just tried whayt you gace me

This produces a number of: 140530319499494727...677522822126923116L

Visit http://superhost.gr to see that displayed error. I think it

Why did you use "hex" for? to encode the string to hexarithmetic? what for?

There are plenty of people (but not me) giving you database advice, but
you don't want it.

Apparently you do have web access, so why aren't you looking up the
functions that don't behave the way you think they should?

This page has the built-in functions:
http://docs.python.org/2/library/functions.html

To get quickly to a particular function, follow the link from the
function name at the top of that page.

""""""
int(x=0)
int(x, base=10)
Convert a number or string x to an integer, or return 0 if no arguments
are given. If x is a number, it can be a plain integer, a long integer,
or a floating point number. If x is floating point, the conversion
truncates towards zero. If the argument is outside the integer range,
the function returns a long object instead.

If x is not a number or if base is given, then x must be a string or
Unicode object representing an integer literal in radix base.
Optionally, the literal can be preceded by + or - (with no space in
between) and surrounded by whitespace. A base-n literal consists of the
digits 0 to n-1, with a to z (or A to Z) having values 10 to 35. The
default base is 10. The allowed values are 0 and 2-36. Base-2, -8, and
-16 literals can be optionally prefixed with 0b/0B, 0o/0O/0, or 0x/0X,
as with integer literals in code. Base 0 means to interpret the string
exactly as an integer literal, so that the actual base is 2, 8, 10, or 16.

The integer type is described in Numeric Types — int, float, long, complex.
""""""""

Are there words in there which are unclear? A filename is a string, but
it doesn't represent an integer literal in any base, and especially not
in base 10.
 
L

Leonard, Arah

Thank you but the number needs to be a 4-digit integer only, if its to bestored in the database table correctly.

Okay, I think we need to throw the flag on the field at this point. What you're asking for has gone into a realm where you clearly don't even appear to understand what you're asking for.

What is the reason for your integer being limited to only 4 digits? Not even databases are limited in such a way. So what are you doing that imposesthat kind of a limit, and why?
 
J

John Gordon

In said:
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
 
R

rusi

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 :(

I just need a way to eat my soup with a screwdriver.
No I WONT use a spoon.

Im starving
HELP
 
M

Mark Lawrence

I just need a way to eat my soup with a screwdriver.
No I WONT use a spoon.

Im starving
HELP

Unfortunately a spoon wouldn't help in this case as the soup is being
served in a basket. However I still absolutely insist that a Python
solution to this problem is found.
 
F

Ferrous Cranus

Τη ΤÏίτη, 22 ΙανουαÏίου 2013 6:55:02 μ.μ. UTC+2, οχÏήστης John Gordon έγÏαψε:
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

(e-mail address removed) B is for Basil, assaulted by bears

-- Edward Gorey, "The Gashlycrumb Tinies"

No, because i DO NOT WANT to store LOTS OF BIGS absolute paths in the database.

And the .html files are not even close 10.000
 
F

Ferrous Cranus

Τη ΤÏίτη, 22 ΙανουαÏίου 2013 6:23:16 μ.μ. UTC+2, οχÏήστης Leonard, Arah έγÏαψε:
Okay, I think we need to throw the flag on the field at this point. Whatyou're asking for has gone into a realm where you clearly don't even appear to understand what you're asking for.



What is the reason for your integer being limited to only 4 digits? Not even databases are limited in such a way. So what are you doing that imposes that kind of a limit, and why?


a) I'am a reseller, i have unlimited ftp quota, hence database space
b) I'am feeling compelled to do it this way
c) i DO NOT want to use BIG absolute paths to identify files, just small numbers , shich they are easier to maintain.

Your solution i know it works and i thank you very much for providing it tome!

Can you help please on the errors that http://superhost.gr gives?
 
F

Ferrous Cranus

Τη ΤÏίτη, 22 ΙανουαÏίου 2013 6:23:16 μ.μ. UTC+2, οχÏήστης Leonard, Arah έγÏαψε:
Okay, I think we need to throw the flag on the field at this point. Whatyou're asking for has gone into a realm where you clearly don't even appear to understand what you're asking for.



What is the reason for your integer being limited to only 4 digits? Not even databases are limited in such a way. So what are you doing that imposes that kind of a limit, and why?


a) I'am a reseller, i have unlimited ftp quota, hence database space
b) I'am feeling compelled to do it this way
c) i DO NOT want to use BIG absolute paths to identify files, just small numbers , shich they are easier to maintain.

Your solution i know it works and i thank you very much for providing it tome!

Can you help please on the errors that http://superhost.gr gives?
 
M

Michael Torrie

Now, can you pleas help me write the switch to filepath identifier?
I'am having trouble writing it.

Unfortunately this isn't the way to go either. Apache uses its own
config and rules to map a url to a "filepath." There's no way for
Python to do this without interrogating Apache. And it's not necessary
anyway. Urls to paths are mapped in a fairly static way by Apache.
Just put your files in the right folders and generate the appropriate
urls. It's not hard. You're struggling because you either don't
understand how apache works, or you're trying to work against it. I've
been deploying web sites for years and I've never had to do any of the
things you are trying to make Python do.
 
F

Ferrous Cranus

Τη ΤÏίτη, 22 ΙανουαÏίου 2013 7:33:00 μ.μ. UTC+2, οχÏήστης rusi έγÏαψε:
I just need a way to eat my soup with a screwdriver.

No I WONT use a spoon.



Im starving

HELP

That was funny!
 
F

Ferrous Cranus

Τη ΤÏίτη, 22 ΙανουαÏίου 2013 6:11:20 μ.μ. UTC+2, οχÏήστης Chris Angelico έγÏαψε:
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 :(



Either you are deliberately trolling, or you have a major

comprehension problem. Please go back and read, carefully, all the

remarks you've been offered in this thread. Feel free to ask for

clarification of anything that doesn't make sense, but be sure to read

all of it. You are asking something that is fundamentally

impossible[1]. There simply are not enough numbers to go around.



ChrisA

[1] Well, impossible in decimal. If you work in base 4294967296, you

could do what you want in four "digits".

Fundamentally impossible?

Well....

OK: How about this in Perl:

$ cat testMD5.pl
use strict;

foreach my $url(qw@ /index.html /about/time.html @){
hashit($url);
}

sub hashit {
my $url=shift;
my @ltrs=split(//,$url);
my $hash = 0;

foreach my $ltr(@ltrs){
$hash = ( $hash + ord($ltr)) %10000;
}
printf "%s: %0.4d\n",$url,$hash

}


which yields:
$ perl testMD5.pl
/index.html: 1066
/about/time.html: 1547
 
F

Ferrous Cranus

Τη ΤÏίτη, 22 ΙανουαÏίου 2013 6:11:20 μ.μ. UTC+2, οχÏήστης Chris Angelico έγÏαψε:
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 :(



Either you are deliberately trolling, or you have a major

comprehension problem. Please go back and read, carefully, all the

remarks you've been offered in this thread. Feel free to ask for

clarification of anything that doesn't make sense, but be sure to read

all of it. You are asking something that is fundamentally

impossible[1]. There simply are not enough numbers to go around.



ChrisA

[1] Well, impossible in decimal. If you work in base 4294967296, you

could do what you want in four "digits".

Fundamentally impossible?

Well....

OK: How about this in Perl:

$ cat testMD5.pl
use strict;

foreach my $url(qw@ /index.html /about/time.html @){
hashit($url);
}

sub hashit {
my $url=shift;
my @ltrs=split(//,$url);
my $hash = 0;

foreach my $ltr(@ltrs){
$hash = ( $hash + ord($ltr)) %10000;
}
printf "%s: %0.4d\n",$url,$hash

}


which yields:
$ perl testMD5.pl
/index.html: 1066
/about/time.html: 1547
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top