[techtalk] Re: python re.sub help

Tricia Bowen bowen at starmedia.net
Wed Jan 26 17:38:37 EST 2000


balterdash! let me rephrase:
re.sub("(http://127.0.0.1)", 1, var_a)
how do i store the "(http://127.0.0.1)" part and reuse it in the
replacement variable?

On Wed, 26 Jan 2000, Tessa Lau wrote:

> 
> This appears to work for me (Python 1.5.2):
> >>> var_a = "http://127.0.0.1/email/logout"
> >>> var_b = "http://www.lazygirl.com"
> >>> var_a = re.sub("http://127.0.0.1", var_b, var_a)
> >>> var_a
> 'http://www.lazygirl.com/email/logout'
> 
> What do you think is wrong?
> 
> > var_a = re.sub("http://127.0.0.1", "%s", var_a) % var_b
> 
> The proper syntax would be
> 	var_a = re.sub("http://127.0.0.1", "%s" % var_b, var_a)
> 
> Also look at the urlparse module, for a cleaner way to do this kind of URL
> munging.
>  
> --Tessa
> 

-tricia

#-----------
Tricia Bowen
Applications Engineer
Starmedia Network
v: 212.520.6469
m: 917.578.3425



************
techtalk at linuxchix.org   http://www.linuxchix.org




More information about the Techtalk mailing list