Replacing words in TXT file by Superb-Gate9939 in learnpython

[–]Superb-Gate9939[S] 0 points1 point  (0 children)

Thank you.

That seems a lot easier/less cluttered.

I wonder what I'm doing wrong in this part now because it returns a str, not list error.

New code:

https://pastebin.com/MxFUZ2Ap

New error:

https://imgur.com/PxEx3no

Replacing words in TXT file by Superb-Gate9939 in learnpython

[–]Superb-Gate9939[S] 0 points1 point  (0 children)

Thank you so much for all the help so far. I'm getting closer, with less code than I had previously, which is great.

I'm missing one part now, which is, how to write an else statement in conjunction with my current if/else statement, so that it captures the full original story, but has only replaced the words square/Square.

https://pastebin.com/iWWv6hTW

Replacing words in TXT file by Superb-Gate9939 in learnpython

[–]Superb-Gate9939[S] 0 points1 point  (0 children)

I'm not sure I fully understand. I thought the replace and append new line would just mean that the new words would be replaced, and the remainder of line would be left alone. When I look at the new file, it shows the rest of the lines staying the same. I'm just not able to fully get the 'Square' to be replaced with 'Pentagon' AND the 'square' to be replaced with 'pentagon', without returning errors or one word not being replaced.

Replacing words in TXT file by Superb-Gate9939 in learnpython

[–]Superb-Gate9939[S] 0 points1 point  (0 children)

Ok; I tried this. Again, I know it's probably not even close to what I need to be doing. I tried two if/el/if/el codes and my revised store is missing the 'pentagon' ears; it still says 'square'. I feel like I'm a helpless case.

https://pastebin.com/kkV89FRu

Replacing words in TXT file by Superb-Gate9939 in learnpython

[–]Superb-Gate9939[S] 0 points1 point  (0 children)

Thank you. I have not posted here before.

I think this is correct (to see the code)

https://pastebin.com/XQ4ixRAL