Support Forums
How Can This Be Used? - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32)
+---- Thread: How Can This Be Used? (/showthread.php?tid=1645)



How Can This Be Used? - nevets04 - 10-16-2009

How would can you put this code to use?
Code:
x = "luck"
#replace the l in in luck with a d
y = x.replace("l", "d")
#Displays what y is equal to on the screen
print y
There is the code, but im thinking, why not just
Code:
print "duck"
So how would it be useful?


RE: How Can This Be Used? - mon3yexploit - 10-16-2009

maybe if you could describe where it came from. etc.. i could prob help.


RE: How Can This Be Used? - nevets04 - 10-16-2009

It didnt come from anywhere. To be more specific how does x.replace come in use


RE: How Can This Be Used? - Gaijin - 10-16-2009

(10-16-2009, 06:57 PM)nevets04 Wrote: It didnt come from anywhere. To be more specific how does x.replace come in use

Since Python is also good for web development, I think it can be used like PHP functions str_replace() or preg_replace(), for example bbCode to HTML


RE: How Can This Be Used? - Yoshi - 10-29-2009

Im a noob in python, but maybe a text encrypter, you could set it if there is an a then make it a c. Like this -


text = raw_input()
text = text.replace("a", "1")
text = text.replace("b", "2")
/There may be an easier way to do that but keep going a - z
print "Encrypted text is " text
/Now just reverse that so they can decrypt text.

I dont know if this helped or how well this will work but it is just a suggestion.


RE: How Can This Be Used? - dongblues - 10-29-2009

The replace code can be used to scramble words if you do not want others to understand some words.. In other words, to hide the real message.. using print = "duck" is of no use if the user sees the source code and not just the viewable program..


RE: How Can This Be Used? - uber1337 - 10-29-2009

Well, it can be used for many things but is most useful for website developers handling large documents. One example is when xhtml came about and people wanted to convert from html to xhtml. The following quotes are from www.w3schools.com

"A general "find-and-replace" function was executed to replace all uppercase tags with lowercase tags. The same was done for attribute names."

"Empty tags are not allowed in XHTML. The <hr> and <br> tags should be replaced with <hr /> and <br />.

A general "find-and-replace" function was executed to swap the tags."

hope this helped :].


RE: How Can This Be Used? - Fallen - 10-31-2009

to replace certain characters in an unkown variable, not everything is staticaly typed