All Questions
50 questions
0
votes
2
answers
50
views
Replace a certain part of the string which matches a pattern in python 2.7 and save in the same file
I am trying to achieve something of this sort
My input file has this kind of entries
art.range.field = 100
art.net.cap = 200
art.net.ht = 1000
art.net.dep = 8000
I am trying to match the pattern like ...
0
votes
4
answers
67
views
Removing part of a string between indices
I gotta write a function that when given a string, finds the first appearance of the
substring 'not' and 'bad'. If the 'bad' follows the 'not',it replaces the whole 'not'...'bad' substring with 'good'....
0
votes
3
answers
49
views
String Replacement Not Being Written to File
I need to edit a certain file for a DoE study. The file is in the format:
1 Wall1
roughness 0.0
velocity 0.0
temperature "temperature.file"
########
2 Wall2
roughness 0.0
velocity 0.0
temperature "...
0
votes
1
answer
189
views
Python 2.7 path replace string
I need to replace some string by others. I'm using function pathlib to do that it's working fine but I have a problem when there is two same string in my file and I need to change just one
My file (...
2
votes
2
answers
560
views
python replace string ignore new line
For example ,
str="dddabc
d
e
xxxx
123
345"
,want to replace "abcde" with null .
New str need to be
"ddd
xxxx
123
345"
What is the easy way to do it ?
If I drop the new line , the new string will ...
0
votes
2
answers
2k
views
How can I loop through a python dictionary and replace a substring value?
I want to loop through a dictionary with unknown keys and replace a specific substring value.
mydict = {
'Getting links from: https://www.foo.com/':
[
'+-BROKEN- http://www.broken....
2
votes
1
answer
51
views
Replacing multiple strings in Python [duplicate]
I currently have the below Python code which works well:-
caseURL = r"\\mydomain\abc\lp_t\GB\123456\Original Format"
caseURL = caseURL.replace("lp_t", "lp_i")
caseURL = caseURL.replace("Original ...
0
votes
3
answers
1k
views
How to replace a certain character from values of dicts in a list?
I am trying to replace a certain character from the given list but I am getting this error:
AttributeError: 'list' object has no attribute 'replace'
How I can solve this problem?
String=[{"id":"id1 ...
0
votes
1
answer
2k
views
How do I replace and update a string multiple times in Python?
I'm working on a quiz program and need some help. I'm trying to replace words one at a time, but Python isn't saving the previously replaced string. Here is a mini example of what I mean:
...
3
votes
4
answers
435
views
Python replace function outputs different results
s="|0000011111111|"
print s.replace(s[9:12],' ')
...output is |00000 11|
s="|0000012345678|"
print s.replace(s[9:12],' ')
...output is |00000123 78|
I only want to replace s[9:12] to ...
0
votes
3
answers
682
views
How to replace multiple strings with one string with downcase in python?
I need to write a function which replaces multiple format strings into downcase.
For example, a paragraph contains a word 'something' in different formats like 'Something', 'SomeThing', 'SOMETHING', '...
0
votes
1
answer
747
views
Replace multiple words in strings from a list of words in Python
I have a text file in the following format:
this is some text __label__a
this is another line __label__a __label__b
this is third line __label__x
this is fourth line __label__a __label__x __label__z
...
0
votes
1
answer
181
views
Python 2.7.13/3.6.1 str.replace changes original string inconsistently [duplicate]
In the python 3 documentation, str.replace is described as:
str.replace(old, new[, count])
Return a copy of the string with all occurrences of substring old replaced by new. If the ...
-1
votes
2
answers
51
views
s.replace within a for loop behaves strangely
I wrote this to replace all 'b's within 'babble' except for the first one.
s = 'babble'
for i in range(1, len(s)):
if s[i] == s[0]:
t = s.replace(s[i],'$')
print(t)
this prints '$a$$le'...
1
vote
1
answer
3k
views
Replacing special characters in a string
i'm trying to unittest a python function, but it seems to not replace any of the chars inside the function. even though the function should be working?
error message:
E AssertionError: assert '...