Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37259 > unrolled thread

Using filepath method to identify an .html page

Started byFerrous Cranus <nikos.gr33k@gmail.com>
First post2013-01-22 02:07 -0800
Last post2013-01-22 17:27 -0800
Articles 20 on this page of 92 — 15 participants

Back to article view | Back to comp.lang.python


Contents

  Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 02:07 -0800
    Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 11:31 +0000
      Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 03:53 -0800
        Re: Using filepath method to identify an .html page Chris Angelico <rosuav@gmail.com> - 2013-01-22 23:26 +1100
      Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 04:02 -0800
        Re: Using filepath method to identify an .html page Lele Gaifax <lele@metapensiero.it> - 2013-01-22 13:22 +0100
        Re: Using filepath method to identify an .html page Dave Angel <d@davea.name> - 2013-01-22 07:29 -0500
          Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 04:47 -0800
            Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 04:50 -0800
            Re: Using filepath method to identify an .html page Chris Angelico <rosuav@gmail.com> - 2013-01-22 23:59 +1100
            Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 04:50 -0800
          Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 04:47 -0800
            Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 13:04 +0000
              Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 05:57 -0800
                Re: Using filepath method to identify an .html page Chris Angelico <rosuav@gmail.com> - 2013-01-23 01:33 +1100
                  Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 06:55 -0800
                    Re: Using filepath method to identify an .html page Dave Angel <d@davea.name> - 2013-01-22 10:05 -0500
                      Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 07:21 -0800
                        Re: Using filepath method to identify an .html page Chris Angelico <rosuav@gmail.com> - 2013-01-23 02:27 +1100
                        Re: Using filepath method to identify an .html page Michael Torrie <torriem@gmail.com> - 2013-01-22 11:36 -0700
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:40 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:40 +0000
                            Re: Using filepath method to identify an .html page Michael Torrie <torriem@gmail.com> - 2013-01-22 17:07 -0700
                            Re: Using filepath method to identify an .html page MRAB <python@mrabarnett.plus.com> - 2013-01-23 00:40 +0000
                              Re: Using filepath method to identify an .html page rusi <rustompmody@gmail.com> - 2013-01-22 18:55 -0800
                            Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-23 02:50 +0000
                              Re: Using filepath method to identify an .html page rusi <rustompmody@gmail.com> - 2013-01-22 19:04 -0800
                                Re: Using filepath method to identify an .html page Chris Angelico <rosuav@gmail.com> - 2013-01-23 15:44 +1100
                            Re: Using filepath method to identify an .html page Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-22 22:15 -0500
                            Re: Using filepath method to identify an .html page MRAB <python@mrabarnett.plus.com> - 2013-01-23 03:35 +0000
                            Re: Using filepath method to identify an .html page Michael Torrie <torriem@gmail.com> - 2013-01-22 22:10 -0700
                            Re: Using filepath method to identify an .html page Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-23 01:13 -0500
                            RE: Using filepath method to identify an .html page "Leonard, Arah" <Arah.Leonard@bruker-axs.com> - 2013-01-23 16:33 +0000
                              Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-23 08:51 -0800
                                RE: Using filepath method to identify an .html page "Leonard, Arah" <Arah.Leonard@bruker-axs.com> - 2013-01-23 18:19 +0000
                                Re: Using filepath method to identify an .html page Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-01-23 18:36 +0000
                                Re: Using filepath method to identify an .html page Dave Angel <d@davea.name> - 2013-01-23 17:46 -0500
                              Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-23 08:51 -0800
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:34 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:35 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:34 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:36 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:36 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:37 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:39 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:38 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:39 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:37 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:38 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:39 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:36 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:35 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:37 +0000
                        Re: Using filepath method to identify an .html page Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-22 16:44 -0500
                      Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 07:21 -0800
                    Re: Using filepath method to identify an .html page Chris Angelico <rosuav@gmail.com> - 2013-01-23 02:07 +1100
                    Re: Using filepath method to identify an .html page Peter Otten <__peter__@web.de> - 2013-01-22 16:25 +0100
                      Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 07:46 -0800
                        Re: Using filepath method to identify an .html page Dave Angel <d@davea.name> - 2013-01-22 11:11 -0500
                        RE: Using filepath method to identify an .html page "Leonard, Arah" <Arah.Leonard@bruker-axs.com> - 2013-01-22 16:23 +0000
                          Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 10:13 -0800
                            Re: Using filepath method to identify an .html page Michael Torrie <torriem@gmail.com> - 2013-01-22 11:43 -0700
                          Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 10:13 -0800
                      Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 07:46 -0800
                      Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 07:59 -0800
                        Re: Using filepath method to identify an .html page Chris Angelico <rosuav@gmail.com> - 2013-01-23 03:11 +1100
                          Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 10:26 -0800
                            Re: Using filepath method to identify an .html page MRAB <python@mrabarnett.plus.com> - 2013-01-22 18:49 +0000
                            Re: Using filepath method to identify an .html page Michael Torrie <torriem@gmail.com> - 2013-01-22 11:49 -0700
                            Re: Using filepath method to identify an .html page Dave Angel <d@davea.name> - 2013-01-22 14:00 -0500
                            Re: Using filepath method to identify an .html page Peter Otten <__peter__@web.de> - 2013-01-22 20:16 +0100
                              Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 23:25 -0800
                                Re: Using filepath method to identify an .html page Michael Torrie <torriem@gmail.com> - 2013-01-23 08:25 -0700
                                  Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-23 07:56 -0800
                                  Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-23 07:56 -0800
                              Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 23:25 -0800
                          Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 10:26 -0800
                      Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 07:59 -0800
                        Re: Using filepath method to identify an .html page John Gordon <gordon@panix.com> - 2013-01-22 16:55 +0000
                          Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 10:07 -0800
                            Re: Using filepath method to identify an .html page John Gordon <gordon@panix.com> - 2013-01-22 18:37 +0000
                            Re: Using filepath method to identify an .html page Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-01-22 17:01 -0500
                            Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 23:23 +0000
                        Re: Using filepath method to identify an .html page rusi <rustompmody@gmail.com> - 2013-01-22 09:33 -0800
                          Re: Using filepath method to identify an .html page Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-01-22 17:54 +0000
                          Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 10:23 -0800
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 22:45 +0000
                          Re: Using filepath method to identify an .html page Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-22 22:44 +0000
                          Re: Using filepath method to identify an .html page Mitya Sirenef <msirenef@lightbird.net> - 2013-01-22 19:23 -0500
                  Re: Using filepath method to identify an .html page Ferrous Cranus <nikos.gr33k@gmail.com> - 2013-01-22 06:55 -0800
    Re: Using filepath method to identify an .html page Michael Torrie <torriem@gmail.com> - 2013-01-22 11:21 -0700
    Re: Using filepath method to identify an .html page alex23 <wuwei23@gmail.com> - 2013-01-22 17:27 -0800

Page 1 of 5  [1] 2 3 4 5  Next page →


#37259 — Using filepath method to identify an .html page

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-22 02:07 -0800
SubjectUsing filepath method to identify an .html page
Message-ID<adcfb222-a038-4700-8959-38e452c04b85@googlegroups.com>
Hello, i decided to switch from embedding string into .html to actually grab the filepath in order to identify it:

# =================================================================================================================
# open current html template and get the page ID number
# ===============================

f = open( page )

# read first line of the file
firstline = f.readline()

# find the ID of the file and store it
pin = re.match( r'<!-- (\d+) -->', firstline ).group(1)
=================================

This is what i used to have.

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

[toc] | [next] | [standalone]


#37260

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-01-22 11:31 +0000
Message-ID<50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com>
In reply to#37259
On Tue, 22 Jan 2013 02:07:54 -0800, Ferrous Cranus wrote:

> Hello, i decided to switch from embedding string into .html to actually
> grab the filepath in order to identify it:

What do you think "the filepath" means, and how do you think you would 
grab it?

I can only guess you mean the full path to the file, like:

/home/steve/mypage.html

C:\My Documents\mypage.html


Is that what you mean?


> # open current html template and get the page ID number
> f = open( page )
> # read first line of the file
> firstline = f.readline()
> # find the ID of the file and store it 
> pin = re.match( r'<!-- (\d+) -->', firstline ).group(1) 
>
> This is what i used to have.
> 
> Now, can you pleas help me write the switch to filepath identifier? I'am
> having trouble writing it.

I don't understand the question.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#37261

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-22 03:53 -0800
Message-ID<bed9a429-1e1e-4bd3-9b4b-e1e7a8e123ff@googlegroups.com>
In reply to#37260
# ==================================================
# produce a hash based on html page's filepath and convert it to an integet, that will be uses to identify the page itself.
# ==================================================

pin = int( hashlib.md5( htmlpage ) )


I just tried that but it produced an error.
What am i doing wrong?

[toc] | [prev] | [next] | [standalone]


#37264

FromChris Angelico <rosuav@gmail.com>
Date2013-01-22 23:26 +1100
Message-ID<mailman.783.1358857599.2939.python-list@python.org>
In reply to#37261
On Tue, Jan 22, 2013 at 10:53 PM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
> # ==================================================
> # produce a hash based on html page's filepath and convert it to an integet, that will be uses to identify the page itself.
> # ==================================================
>
> pin = int( hashlib.md5( htmlpage ) )
>
>
> I just tried that but it produced an error.
> What am i doing wrong?

First and foremost, here's what you're doing wrong: You're saying "it
produced an error". Python is one of those extremely helpful languages
that tells you, to the best of its ability, exactly WHAT went wrong,
WHERE it went wrong, and - often - WHY it failed. For comparison, I've
just tonight been trying to fix up a legacy accounting app that was
written in Visual BASIC back when that wouldn't get scorn heaped on
you from the whole world. When we fire up one particular module, it
bombs with a little message box saying "File not found". That's all.
Just one little message, and the application terminates (uncleanly, at
that). What file? How was it trying to open it? I do know that it
isn't one of its BTrieve data files, because when one of THEM isn't
found, the crash looks different (but it's still a crash). My current
guess is that it's probably a Windows DLL file or something, but it's
really not easy to tell...

ChrisA

[toc] | [prev] | [next] | [standalone]


#37262

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-22 04:02 -0800
Message-ID<f4298c6f-81a2-45c7-903b-015e9f17d5a7@googlegroups.com>
In reply to#37260
# ====================================================================================================================================
# produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself
# ====================================================================================================================================

pin = int( hashlib.md5( htmlpage ) )

This fails. why?

htmlpage = a string respresenting the absolute path of the requested .html file
hashlib.md5( htmlpage ) = conversion of the above string to a hashed string
int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number

Why this fails?

[toc] | [prev] | [next] | [standalone]


#37263

FromLele Gaifax <lele@metapensiero.it>
Date2013-01-22 13:22 +0100
Message-ID<mailman.782.1358857341.2939.python-list@python.org>
In reply to#37262
Ferrous Cranus <nikos.gr33k@gmail.com> writes:

> pin = int( hashlib.md5( htmlpage ) )
>
> This fails. why?
>
> htmlpage = a string respresenting the absolute path of the requested .html file
> hashlib.md5( htmlpage ) = conversion of the above string to a hashed string

No, that statement does not "convert" a string into another, but rather
returns a "md5 HASH object":

>>> import hashlib
>>> hashlib.md5('foo')
<md5 HASH object @ 0xb76dbcf0>

Consulting the hashlib documentation[1], you could learn about that
object's methods.

> int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number
>
> Why this fails?

Because in general you can't "convert" an arbitrary object instance (in
your case an hashlib.HASH instance) to an integer value. Why do you need
an integer? Isn't hexdigest() what you want?

>>> print _.hexdigest()
acbd18db4cc2f85cedef654fccc4a4d8

Do yourself a favor and learn using the interpreter to test your
snippets line by line, most problems will find an easy answer :-)

ciao, lele.

[1] http://docs.python.org/2.7/library/hashlib.html#module-hashlib
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

[toc] | [prev] | [next] | [standalone]


#37265

FromDave Angel <d@davea.name>
Date2013-01-22 07:29 -0500
Message-ID<mailman.784.1358857784.2939.python-list@python.org>
In reply to#37262
On 01/22/2013 07:02 AM, Ferrous Cranus wrote:
> # ====================================================================================================================================
> # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself
> # ====================================================================================================================================
>
> pin = int( hashlib.md5( htmlpage ) )
>
> This fails. why?
>
> htmlpage = a string respresenting the absolute path of the requested .html file
> hashlib.md5( htmlpage ) = conversion of the above string to a hashed string
> int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number
>
> Why this fails?
>

Is your copy/paste broken?  It could be useful to actually show in what 
way it "fails."

The md5 method produces a "HASH object", not a string.  So int() cannot 
process that.

To produce a digest string from the hash object, you want to call 
hexdigest() method.  The result of that is a hex literal string.  So you 
cannot just call int() on it, since that defaults to decimal.

To convert a hex string to an int, you need the extra parameter of int:

    int(mystring, 16)

Now, see if you can piece it together.


-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#37266

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-22 04:47 -0800
Message-ID<11312870-e6cc-4a2f-8fc5-a753aef06200@googlegroups.com>
In reply to#37265
Τη Τρίτη, 22 Ιανουαρίου 2013 2:29:21 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε:
> On 01/22/2013 07:02 AM, Ferrous Cranus wrote:
> 
> > # ====================================================================================================================================
> 
> > # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself
> 
> > # ====================================================================================================================================
> 
> >
> 
> > pin = int( hashlib.md5( htmlpage ) )
> 
> >
> 
> > This fails. why?
> 
> >
> 
> > htmlpage = a string respresenting the absolute path of the requested .html file
> 
> > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string
> 
> > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number
> 
> >
> 
> > Why this fails?
> 
> >
> 
> 
> 
> Is your copy/paste broken?  It could be useful to actually show in what 
> 
> way it "fails."
> 
> 
> 
> The md5 method produces a "HASH object", not a string.  So int() cannot 
> 
> process that.
> 
> 
> 
> To produce a digest string from the hash object, you want to call 
> 
> hexdigest() method.  The result of that is a hex literal string.  So you 
> 
> cannot just call int() on it, since that defaults to decimal.
> 
> 
> 
> To convert a hex string to an int, you need the extra parameter of int:
> 
> 
> 
>     int(mystring, 16)
> 
> 
> 
> Now, see if you can piece it together.
> 


htmlpage = a string respresenting the absolute path of the requested .html file 


What i want to do, is to associate a number to an html page's absolute path for to be able to use that number for my database relations instead of the BIG absolute path string.

so to get an integer out of a string i would just have to type:

pin = int( htmlpage )

But would that be unique?

[toc] | [prev] | [next] | [standalone]


#37268

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-22 04:50 -0800
Message-ID<c95c10cf-e602-4b89-aa1c-77c33e863429@googlegroups.com>
In reply to#37266
Τη Τρίτη, 22 Ιανουαρίου 2013 2:47:16 μ.μ. UTC+2, ο χρήστης Ferrous Cranus έγραψε:
> Τη Τρίτη, 22 Ιανουαρίου 2013 2:29:21 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε:
> 
> > On 01/22/2013 07:02 AM, Ferrous Cranus wrote:
> 
> > 
> 
> > > # ====================================================================================================================================
> 
> > 
> 
> > > # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself
> 
> > 
> 
> > > # ====================================================================================================================================
> 
> > 
> 
> > >
> 
> > 
> 
> > > pin = int( hashlib.md5( htmlpage ) )
> 
> > 
> 
> > >
> 
> > 
> 
> > > This fails. why?
> 
> > 
> 
> > >
> 
> > 
> 
> > > htmlpage = a string respresenting the absolute path of the requested .html file
> 
> > 
> 
> > > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string
> 
> > 
> 
> > > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number
> 
> > 
> 
> > >
> 
> > 
> 
> > > Why this fails?
> 
> > 
> 
> > >
> 
> > 
> 
> > 
> 
> > 
> 
> > Is your copy/paste broken?  It could be useful to actually show in what 
> 
> > 
> 
> > way it "fails."
> 
> > 
> 
> > 
> 
> > 
> 
> > The md5 method produces a "HASH object", not a string.  So int() cannot 
> 
> > 
> 
> > process that.
> 
> > 
> 
> > 
> 
> > 
> 
> > To produce a digest string from the hash object, you want to call 
> 
> > 
> 
> > hexdigest() method.  The result of that is a hex literal string.  So you 
> 
> > 
> 
> > cannot just call int() on it, since that defaults to decimal.
> 
> > 
> 
> > 
> 
> > 
> 
> > To convert a hex string to an int, you need the extra parameter of int:
> 
> > 
> 
> > 
> 
> > 
> 
> >     int(mystring, 16)
> 
> > 
> 
> > 
> 
> > 
> 
> > Now, see if you can piece it together.
> 
> > 
> 
> 
> 
> 
> 
> htmlpage = a string respresenting the absolute path of the requested .html file 
> 
> 
> 
> 
> 
> What i want to do, is to associate a number to an html page's absolute path for to be able to use that number for my database relations instead of the BIG absolute path string.
> 
> 
> 
> so to get an integer out of a string i would just have to type:
> 
> 
> 
> pin = int( htmlpage )
> 
> 
> 
> But would that be unique?

Another error even without hasing anyhting http://superhost.gr to view it please

[toc] | [prev] | [next] | [standalone]


#37269

FromChris Angelico <rosuav@gmail.com>
Date2013-01-22 23:59 +1100
Message-ID<mailman.786.1358859550.2939.python-list@python.org>
In reply to#37266
On Tue, Jan 22, 2013 at 11:47 PM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
> What i want to do, is to associate a number to an html page's absolute path for to be able to use that number for my database relations instead of the BIG absolute path string.
>
> so to get an integer out of a string i would just have to type:
>
> pin = int( htmlpage )
>
> But would that be unique?

The absolute path probably isn't that big. Just use it. Any form of
hashing will give you a chance of a collision.

ChrisA

[toc] | [prev] | [next] | [standalone]


#37273

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-22 04:50 -0800
Message-ID<mailman.788.1358861971.2939.python-list@python.org>
In reply to#37266
Τη Τρίτη, 22 Ιανουαρίου 2013 2:47:16 μ.μ. UTC+2, ο χρήστης Ferrous Cranus έγραψε:
> Τη Τρίτη, 22 Ιανουαρίου 2013 2:29:21 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε:
> 
> > On 01/22/2013 07:02 AM, Ferrous Cranus wrote:
> 
> > 
> 
> > > # ====================================================================================================================================
> 
> > 
> 
> > > # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself
> 
> > 
> 
> > > # ====================================================================================================================================
> 
> > 
> 
> > >
> 
> > 
> 
> > > pin = int( hashlib.md5( htmlpage ) )
> 
> > 
> 
> > >
> 
> > 
> 
> > > This fails. why?
> 
> > 
> 
> > >
> 
> > 
> 
> > > htmlpage = a string respresenting the absolute path of the requested .html file
> 
> > 
> 
> > > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string
> 
> > 
> 
> > > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number
> 
> > 
> 
> > >
> 
> > 
> 
> > > Why this fails?
> 
> > 
> 
> > >
> 
> > 
> 
> > 
> 
> > 
> 
> > Is your copy/paste broken?  It could be useful to actually show in what 
> 
> > 
> 
> > way it "fails."
> 
> > 
> 
> > 
> 
> > 
> 
> > The md5 method produces a "HASH object", not a string.  So int() cannot 
> 
> > 
> 
> > process that.
> 
> > 
> 
> > 
> 
> > 
> 
> > To produce a digest string from the hash object, you want to call 
> 
> > 
> 
> > hexdigest() method.  The result of that is a hex literal string.  So you 
> 
> > 
> 
> > cannot just call int() on it, since that defaults to decimal.
> 
> > 
> 
> > 
> 
> > 
> 
> > To convert a hex string to an int, you need the extra parameter of int:
> 
> > 
> 
> > 
> 
> > 
> 
> >     int(mystring, 16)
> 
> > 
> 
> > 
> 
> > 
> 
> > Now, see if you can piece it together.
> 
> > 
> 
> 
> 
> 
> 
> htmlpage = a string respresenting the absolute path of the requested .html file 
> 
> 
> 
> 
> 
> What i want to do, is to associate a number to an html page's absolute path for to be able to use that number for my database relations instead of the BIG absolute path string.
> 
> 
> 
> so to get an integer out of a string i would just have to type:
> 
> 
> 
> pin = int( htmlpage )
> 
> 
> 
> But would that be unique?

Another error even without hasing anyhting http://superhost.gr to view it please

[toc] | [prev] | [next] | [standalone]


#37267

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-22 04:47 -0800
Message-ID<mailman.785.1358858844.2939.python-list@python.org>
In reply to#37265
Τη Τρίτη, 22 Ιανουαρίου 2013 2:29:21 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε:
> On 01/22/2013 07:02 AM, Ferrous Cranus wrote:
> 
> > # ====================================================================================================================================
> 
> > # produce a hash string based on html page's filepath and convert it to an integer, that will then be used to identify the page itself
> 
> > # ====================================================================================================================================
> 
> >
> 
> > pin = int( hashlib.md5( htmlpage ) )
> 
> >
> 
> > This fails. why?
> 
> >
> 
> > htmlpage = a string respresenting the absolute path of the requested .html file
> 
> > hashlib.md5( htmlpage ) = conversion of the above string to a hashed string
> 
> > int( hashlib.md5( htmlpage ) ) = conversion of the above hashed string to a number
> 
> >
> 
> > Why this fails?
> 
> >
> 
> 
> 
> Is your copy/paste broken?  It could be useful to actually show in what 
> 
> way it "fails."
> 
> 
> 
> The md5 method produces a "HASH object", not a string.  So int() cannot 
> 
> process that.
> 
> 
> 
> To produce a digest string from the hash object, you want to call 
> 
> hexdigest() method.  The result of that is a hex literal string.  So you 
> 
> cannot just call int() on it, since that defaults to decimal.
> 
> 
> 
> To convert a hex string to an int, you need the extra parameter of int:
> 
> 
> 
>     int(mystring, 16)
> 
> 
> 
> Now, see if you can piece it together.
> 


htmlpage = a string respresenting the absolute path of the requested .html file 


What i want to do, is to associate a number to an html page's absolute path for to be able to use that number for my database relations instead of the BIG absolute path string.

so to get an integer out of a string i would just have to type:

pin = int( htmlpage )

But would that be unique?

[toc] | [prev] | [next] | [standalone]


#37270

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-01-22 13:04 +0000
Message-ID<50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com>
In reply to#37267
On Tue, 22 Jan 2013 04:47:16 -0800, Ferrous Cranus wrote:

> htmlpage = a string respresenting the absolute path of the requested
> .html file


That is a very misleading name for a variable. The contents of the 
variable are not a html page, but a file name.

htmlpage = "/home/steve/my-web-page.html"  # Bad variable name.

filename = "/home/steve/my-web-page.html"  # Better variable name.



> What i want to do, is to associate a number to an html page's absolute
> path for to be able to use that number for my database relations instead
> of the BIG absolute path string.

Firstly, don't bother. What you consider "BIG", your database will 
consider trivially small. What is it, 100 characters long? 200? Unlikely 
to be 300, since I think many file systems don't support paths that long. 
But let's say it is 300 characters long.

That's likely to be 600 bytes, or a bit more than half a kilobyte. Your 
database won't even notice that.


> so to get an integer out of a string i would just have to type:
> 
> pin = int( htmlpage )

No, that doesn't work. int() does not convert arbitrary strings into 
numbers. What made you think that this could possibly work?

What do you expect int("my-web-page.html") to return? Should it return 23 
or 794 or 109432985462940911485 or 42?

> But would that be unique?

Wrong question.


Just tell your database to make the file name an indexed field, and it 
will handle giving every path a unique number for you. You can then 
forget all about that unique number, because it is completely irrelevant 
to you, and safely use the path while the database treats it in the 
fastest and most efficient fashion necessary.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#37274

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-22 05:57 -0800
Message-ID<0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com>
In reply to#37270
Τη Τρίτη, 22 Ιανουαρίου 2013 3:04:41 μ.μ. UTC+2, ο χρήστης Steven D'Aprano έγραψε:

> What do you expect int("my-web-page.html") to return? Should it return 23 
> or 794 or 109432985462940911485 or 42?

I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test.


> Just tell your database to make the file name an indexed field, and it 
> 
> will handle giving every path a unique number for you. You can then 
> 
> forget all about that unique number, because it is completely irrelevant 
> 
> to you, and safely use the path while the database treats it in the 
> 
> fastest and most efficient fashion necessary.

This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this:

/home/nikos/public_html/varsa.gr/articles/html/files/index.html

In addition to that my counter.py script maintains details in a database table that stores information for each and every webpage requested.

My 'visitors' database has 2 tables:

pin --- page ---- hits     (that's to store general information for all html pages)

pin <-refers to-> page

pin ---- host ---- hits ---- useros ---- browser ---- date   (that's to store detailed information for all html pages)

(thousands of records to hold every page's information)


'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!!

So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path)

Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can).

So, that why i need to get a "unique" number out of a string. please help.

[toc] | [prev] | [next] | [standalone]


#37275

FromChris Angelico <rosuav@gmail.com>
Date2013-01-23 01:33 +1100
Message-ID<mailman.790.1358865192.2939.python-list@python.org>
In reply to#37274
On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
> Τη Τρίτη, 22 Ιανουαρίου 2013 3:04:41 μ.μ. UTC+2, ο χρήστης Steven D'Aprano έγραψε:
>
>> What do you expect int("my-web-page.html") to return? Should it return 23
>> or 794 or 109432985462940911485 or 42?
>
> I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test.

Just run python without any args, and you'll get interactive mode. You
can try things out there.

> This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this:
>
> /home/nikos/public_html/varsa.gr/articles/html/files/index.html

That's not big. Trust me, modern databases work just fine with unique
indexes like that. The most common way to organize the index is with a
binary tree, so the database has to look through log(N) entries.
That's like figuring out if the two numbers 142857 and 857142 are the
same; you don't need to look through 1,000,000 possibilities, you just
need to look through the six digits each number has.

> 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!!

Not that bad actually. I've happily used keys easily that long, and
expected the database to ensure uniqueness without costing
performance.

> So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path)

Is there any chance that you'll have more than 10,000 pages? If so, a
four-digit number is *guaranteed* to have duplicates. And if you
research the Birthday Paradox, you'll find that any sort of hashing
algorithm is likely to produce collisions a lot sooner than that.

> Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can).
>
> So, that why i need to get a "unique" number out of a string. please help.

Ultimately, that unique number would end up being a foreign key into a
table of URLs and IDs. So just skip that table and use the URLs
directly - much easier. In this instance, there's no value in
normalizing.

ChrisA

[toc] | [prev] | [next] | [standalone]


#37277

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-22 06:55 -0800
Message-ID<ec8f1a56-d0f7-46a6-a8a3-9425d3aabf8e@googlegroups.com>
In reply to#37275
Τη Τρίτη, 22 Ιανουαρίου 2013 4:33:03 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:
> On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
> 
> > Τη Τρίτη, 22 Ιανουαρίου 2013 3:04:41 μ.μ. UTC+2, ο χρήστης Steven D'Aprano έγραψε:
> 
> >
> 
> >> What do you expect int("my-web-page.html") to return? Should it return 23
> 
> >> or 794 or 109432985462940911485 or 42?
> 
> >
> 
> > I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test.
> 
> 
> 
> Just run python without any args, and you'll get interactive mode. You
> 
> can try things out there.
> 
> 
> 
> > This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this:
> 
> >
> 
> > /home/nikos/public_html/varsa.gr/articles/html/files/index.html
> 
> 
> 
> That's not big. Trust me, modern databases work just fine with unique
> 
> indexes like that. The most common way to organize the index is with a
> 
> binary tree, so the database has to look through log(N) entries.
> 
> That's like figuring out if the two numbers 142857 and 857142 are the
> 
> same; you don't need to look through 1,000,000 possibilities, you just
> 
> need to look through the six digits each number has.
> 
> 
> 
> > 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!!
> 
> 
> 
> Not that bad actually. I've happily used keys easily that long, and
> 
> expected the database to ensure uniqueness without costing
> 
> performance.
> 
> 
> 
> > So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path)
> 
> 
> 
> Is there any chance that you'll have more than 10,000 pages? If so, a
> 
> four-digit number is *guaranteed* to have duplicates. And if you
> 
> research the Birthday Paradox, you'll find that any sort of hashing
> 
> algorithm is likely to produce collisions a lot sooner than that.
> 
> 
> 
> > Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can).
> 
> >
> 
> > So, that why i need to get a "unique" number out of a string. please help.
> 
> 
> 
> Ultimately, that unique number would end up being a foreign key into a
> 
> table of URLs and IDs. So just skip that table and use the URLs
> 
> directly - much easier. In this instance, there's no value in
> 
> normalizing.
> 
> 
> 
> ChrisA

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....

[toc] | [prev] | [next] | [standalone]


#37278

FromDave Angel <d@davea.name>
Date2013-01-22 10:05 -0500
Message-ID<mailman.792.1358867171.2939.python-list@python.org>
In reply to#37277
On 01/22/2013 09:55 AM, Ferrous Cranus wrote:
> Τη Τρίτη, 22 Ιανουαρίου 2013 4:33:03 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:
>> On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
>>
>>> Τη Τρίτη, 22 Ιανουαρίου 2013 3:04:41 μ.μ. UTC+2, ο χρήστης Steven D'Aprano έγραψε:
>>
>>>
>>
>>>> What do you expect int("my-web-page.html") to return? Should it return 23
>>
>>>> or 794 or 109432985462940911485 or 42?
>>
>>>
>>
>>> I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test.
>>
>>
>>
>> Just run python without any args, and you'll get interactive mode. You
>>
>> can try things out there.
>>
>>
>>
>>> This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this:
>>
>>>
>>
>>> /home/nikos/public_html/varsa.gr/articles/html/files/index.html
>>
>>
>>
>> That's not big. Trust me, modern databases work just fine with unique
>>
>> indexes like that. The most common way to organize the index is with a
>>
>> binary tree, so the database has to look through log(N) entries.
>>
>> That's like figuring out if the two numbers 142857 and 857142 are the
>>
>> same; you don't need to look through 1,000,000 possibilities, you just
>>
>> need to look through the six digits each number has.
>>
>>
>>
>>> 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!!
>>
>>
>>
>> Not that bad actually. I've happily used keys easily that long, and
>>
>> expected the database to ensure uniqueness without costing
>>
>> performance.
>>
>>
>>
>>> So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path)
>>
>>
>>
>> Is there any chance that you'll have more than 10,000 pages? If so, a
>>
>> four-digit number is *guaranteed* to have duplicates. And if you
>>
>> research the Birthday Paradox, you'll find that any sort of hashing
>>
>> algorithm is likely to produce collisions a lot sooner than that.
>>
>>
>>
>>> Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can).
>>
>>>
>>
>>> So, that why i need to get a "unique" number out of a string. please help.
>>
>>
>>
>> Ultimately, that unique number would end up being a foreign key into a
>>
>> table of URLs and IDs. So just skip that table and use the URLs
>>
>> directly - much easier. In this instance, there's no value in
>>
>> normalizing.
>>
>>
>>
>> ChrisA
>
> 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....
>

I gave you every piece of that code in my last response.  So you're not 
willing to compose the line from the clues?


-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#37282

FromFerrous Cranus <nikos.gr33k@gmail.com>
Date2013-01-22 07:21 -0800
Message-ID<71c5445b-8100-42fb-bcfd-6b0a0886b46e@googlegroups.com>
In reply to#37278
Τη Τρίτη, 22 Ιανουαρίου 2013 5:05:49 μ.μ. UTC+2, ο χρήστης Dave Angel έγραψε:
> On 01/22/2013 09:55 AM, Ferrous Cranus wrote:
> 
> > Τη Τρίτη, 22 Ιανουαρίου 2013 4:33:03 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε:
> 
> >> On Wed, Jan 23, 2013 at 12:57 AM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
> 
> >>
> 
> >>> Τη Τρίτη, 22 Ιανουαρίου 2013 3:04:41 μ.μ. UTC+2, ο χρήστης Steven D'Aprano έγραψε:
> 
> >>
> 
> >>>
> 
> >>
> 
> >>>> What do you expect int("my-web-page.html") to return? Should it return 23
> 
> >>
> 
> >>>> or 794 or 109432985462940911485 or 42?
> 
> >>
> 
> >>>
> 
> >>
> 
> >>> I expected a unique number from the given string to be produced so i could have a (number <=> string) relation. What does int( somestring ) is returning really? i don;t have IDLE to test.
> 
> >>
> 
> >>
> 
> >>
> 
> >> Just run python without any args, and you'll get interactive mode. You
> 
> >>
> 
> >> can try things out there.
> 
> >>
> 
> >>
> 
> >>
> 
> >>> This counter.py will work on a shared hosting enviroment, so absolutes paths are BIG and expected like this:
> 
> >>
> 
> >>>
> 
> >>
> 
> >>> /home/nikos/public_html/varsa.gr/articles/html/files/index.html
> 
> >>
> 
> >>
> 
> >>
> 
> >> That's not big. Trust me, modern databases work just fine with unique
> 
> >>
> 
> >> indexes like that. The most common way to organize the index is with a
> 
> >>
> 
> >> binary tree, so the database has to look through log(N) entries.
> 
> >>
> 
> >> That's like figuring out if the two numbers 142857 and 857142 are the
> 
> >>
> 
> >> same; you don't need to look through 1,000,000 possibilities, you just
> 
> >>
> 
> >> need to look through the six digits each number has.
> 
> >>
> 
> >>
> 
> >>
> 
> >>> 'pin' has to be a number because if i used the column 'page' instead, just imagine the database's capacity withholding detailed information for each and every .html requested by visitors!!!
> 
> >>
> 
> >>
> 
> >>
> 
> >> Not that bad actually. I've happily used keys easily that long, and
> 
> >>
> 
> >> expected the database to ensure uniqueness without costing
> 
> >>
> 
> >> performance.
> 
> >>
> 
> >>
> 
> >>
> 
> >>> So i really - really need to associate a (4-digit integer <=> htmlpage's absolute path)
> 
> >>
> 
> >>
> 
> >>
> 
> >> Is there any chance that you'll have more than 10,000 pages? If so, a
> 
> >>
> 
> >> four-digit number is *guaranteed* to have duplicates. And if you
> 
> >>
> 
> >> research the Birthday Paradox, you'll find that any sort of hashing
> 
> >>
> 
> >> algorithm is likely to produce collisions a lot sooner than that.
> 
> >>
> 
> >>
> 
> >>
> 
> >>> Maybe it can be done by creating a MySQL association between the two columns, but i dont know how such a thing can be done(if it can).
> 
> >>
> 
> >>>
> 
> >>
> 
> >>> So, that why i need to get a "unique" number out of a string. please help.
> 
> >>
> 
> >>
> 
> >>
> 
> >> Ultimately, that unique number would end up being a foreign key into a
> 
> >>
> 
> >> table of URLs and IDs. So just skip that table and use the URLs
> 
> >>
> 
> >> directly - much easier. In this instance, there's no value in
> 
> >>
> 
> >> normalizing.
> 
> >>
> 
> >>
> 
> >>
> 
> >> ChrisA
> 
> >
> 
> > 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....
> 
> >
> 
> 
> 
> 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 to the 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?

[toc] | [prev] | [next] | [standalone]


#37285

FromChris Angelico <rosuav@gmail.com>
Date2013-01-23 02:27 +1100
Message-ID<mailman.797.1358868474.2939.python-list@python.org>
In reply to#37282
On Wed, Jan 23, 2013 at 2:21 AM, Ferrous Cranus <nikos.gr33k@gmail.com> wrote:
> 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

[toc] | [prev] | [next] | [standalone]


#37327

FromMichael Torrie <torriem@gmail.com>
Date2013-01-22 11:36 -0700
Message-ID<mailman.820.1358879802.2939.python-list@python.org>
In reply to#37282
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.

[toc] | [prev] | [next] | [standalone]


Page 1 of 5  [1] 2 3 4 5  Next page →

Back to top | Article view | comp.lang.python


csiph-web