You are not logged in.

#1 2008-07-08 16:00:24

rostoQ
Member
Registered: 2008-06-25
Posts: 40

[ Python / web.py ] URL-2-Array

Im fiddling around with python and web.py.

My problem:

If i go to localhost:8080/generatearray/value1/value2/.../valueN/
I want that the class "generatearray" generates an array with the values given in the path.

Im far from advanced in python or programming at all, so it would be nice if someone could give me a hint.

Offline

#2 2008-07-08 16:28:05

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: [ Python / web.py ] URL-2-Array

I haven't used webpy in ages, but I believe this will work.

In your urls variable you can create something like so:

urls = (
    '/generatearray/(.*)', 'generatearray'
)

And now anything that follows generatearray/ in the address will be matched.

On to the generatearray class:

class generatearray:

    def GET(self, stuff):
        my_array = stuff.split('/')

etc

So now a call to localhost:8080/generatearray/one/two/three should make my_array there ['one', 'two', 'three']


Cthulhu For President!

Offline

#3 2008-07-08 17:22:50

rostoQ
Member
Registered: 2008-06-25
Posts: 40

Re: [ Python / web.py ] URL-2-Array

ouch i thought in the totally wrong direction... your approach works great! thank you!

Offline

Board footer

Powered by FluxBB