Solvo
Solvo

Reputation: 3

Python -- variable manipulation string.replace()?

Sorry if I'm going down the wrong path... I tried to search for a solution for the past couple days, and not sure if I'm searching the right topic.

I'm trying to do an useradd script, and I'm getting close. However, I'm stuck on the following:

>>> HASH_PASSWORD = '$1$AMWteFb7$pD/0oisRcD.6lSvtrjNmb1'
>>> print HASH_PASSWORD
$1$AMWteFb7$pD/0oisRcD.6lSvtrjNmb1
>>> HASH_PASSWORD = HASH_PASSWORD.replace("\$","\\\$")
>>> print HASH_PASSWORD
$1$AMWteFb7$pD/0oisRcD.6lSvtrjNmb1

I just need to add a "\" in front of the "$". Can't seem to find a way to do that.

Thanks in advance for all your help.

Upvotes: 0

Views: 96

Answers (1)

user568109
user568109

Reputation: 47993

It has to be

>>> HASH_PASSWORD = HASH_PASSWORD.replace("$","\\$")
>>> print HASH_PASSWORD
\$1\$AMWteFb7\$pD/0oisRcD.6lSvtrjNmb1

Upvotes: 2

Related Questions