1π
β
The solution is:
with open('/home/usr/dev/Django/rulebase/test_pattern_tmp.rb', 'r') as pattern_reading:
with open('/home/usr/dev/Django/rulebase/test_pattern.rb', 'w') as pattern_writing:
for line in pattern_reading:
out=line.replace('pattern="Default"','Now').replace('input="Default"','This')
pattern_writing.write(out)
Hi, there are two issues:
- you are reading the whole file into memory (which is not necessarily an error)
- A file object may be considered as an iterator. As soon as you have reached the end of file in your first iteration the secon iteration does nothing
π€ProfHase85
0π
Its writing one value because your lines
list only contains the last replacement; you need to loop over lines
in the second statement where you replace input = "Default"
.
π€Burhan Khalid
- [Answer]-How to use Django JSON and GeoJSON Serializer?
- [Answer]-Not able to compare and update a form field and model field django
- [Answer]-Cannot serve static files, Django 1.6
Source:stackexchange.com