Replacing words in text file using a dictionary

前端 未结 6 1455
青春惊慌失措
青春惊慌失措 2021-01-12 13:25

I\'m trying to open a text file and then read through it replacing certain strings with strings stored in a dictionary.

Based on answers to How do I edit a text file

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 13:33

    If You are more familiar with Python, You can use tips from Official documentation:

    7.1. string — Common string operations

    And subclass, the Template class, in which you define somehow that every single world will be a new placeholder, and then with safe_substitute() You could get a nice and reliable solution.

提交回复
热议问题