This is what I ended up with. Slightly different approach:
import urlparse
def sUrl(s):
page = group = ''
bits = urlparse.urlsplit(s)
url = '//'.join([bits[0],bits[1]]) + '/'
query = bits[2].split('/')
if '' in query: query.remove('')
if len(query) 1: page =
In practice, I had to change this:
if len(query) 0 and query[-1] == query[-1].capitalize(): group =
query.pop()
to this:
if len(query) 0 and query[-1][0] == query[-1].capitalize()[0]:
group = query.pop()
This is because I only wanted to test the case of the first letter of
the string.
--
I am working on a script that splits a URL into a page and a url. The
examples below are the conditions I expect a user to pass to the
script. In all cases, http://www.example.org/test/; is the URL, and
the page comprises parts that have upper case letters (note, 5 6 are
the same as earlier
Here is what I came up with:
def siftUrl(s):
s = s.split('//')[1]
bits = s.split('/')
if '' in bits: bits.remove('')
if len(bits) 1:
group = bits[-2]
page = bits[-1]
group.strip('/')
page.strip('/')
?
Skip
--
Ben Wilson
Mundus vult decipi, ergo decipiatur
--
http://mail.python.org/mailman/listinfo/python-list
You know, I have that for Perl, but seem never to have set up folding
for Python. I must remedy this tonight.
Ben
--
http://mail.python.org/mailman/listinfo/python-list
a python script is by using the .cgi extension. I'm
not sure if I want to stick with my host and just call my apps
index.cgi, or if I should move to a new server. If I were to move to a
new server, which would you recomend, and why?
Regards,
Ben Wilson
--
http://mail.python.org/mailman/listinfo/python
He said IDE. That means vim
--
http://mail.python.org/mailman/listinfo/python-list
Perhaps:
def dictionary_make_attributes(self, settings):
for k,v in settings:
setattr(self, k, v)
http://ftp.python.org/doc/lib/built-in-funcs.html#l2h-64
--
http://mail.python.org/mailman/listinfo/python-list
Yeah, I was going to say it's I-66, not Route 66, which has been
replaced in pertainent parts by I-40.
tuh-ple.
--
http://mail.python.org/mailman/listinfo/python-list
Well, my Perl way of doing it would be to have all attributes in a dict
(hash), then create the accessor vi a dynamic function. I knew Python
would have a right way to do it for Python, but when I went looking I
neglected to look at the core of the language. I suppose I'm just too
accustomed to
I would like to dynamically assign object attributes:
dict = {
a : 1,
b : 2,
}
for key,val in dict :
obj.key = val
To get:
print obj.a
1
I've googled to no effect, or maybe I'm needing to be hit with the
appropriately sized clue-by-four. Any assistance would be appreciated.
Regards,
Ben
That's it. I should spend more time R-ingTFM. I kept looking for some
class-based solution and there was a built in. Perfectly logical.
Thanks,
Ben
--
http://mail.python.org/mailman/listinfo/python-list
But the point is, the current situation is not newbie-friendly (I can
tell, I am a newbie)
I will agree to that, as I consider myself still new. _But_, it's a
stumbling stone only briefly. Get enough nagging error messages, and
you learn and move on. I agree with the grandparent poster that it is
I read somewhere else that Python was getting a ternary operator (e.g.
x = (true/false) ? y : z). I read the PEP about it and that the PEP had
been approved this past Fall. Has this been released into the wild yet?
IIRC, the operator is like:
x = y if C : else z
--
15 matches
Mail list logo