简体   繁体   中英

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.

It has to be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM