Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with .replace()
#1
Greetings,im really new to python and im trying to create a simple encryption program (basically ill input a text and it'll get converted to numbers, nothing complicated for now). Heres my code so far:
a = 1
b = 2
c = 3
d = 4
e = 5
f = 6
g = 7
h = 8
#just random letters and their respective numbers

fr = open('tryy.txt', 'r')
fw = open('tryy.txt', 'a')

for elem in fr:
    fw.write(elem.replace('a', str(a))) & fw.write(elem.replace('b', str(b)))

fr.close()
fw.close()
the problem is that when i try using this, (my basic example text is just "ab"), instead of converting both characters to "12" as it should, the program returns a text file like this:
ab

1b

a2
any advice on how to correct the code here?
Reply


Messages In This Thread
Need help with .replace() - by jasonikakis - Aug-01-2020, 03:39 PM
RE: Need help with .replace() - by pyzyx3qwerty - Aug-01-2020, 04:37 PM
RE: Need help with .replace() - by deanhystad - Aug-01-2020, 06:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search & Replace - Newlines Added After Replace dj99 3 3,441 Jul-22-2018, 01:42 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020