0
votes
3answers
57 views

Replacing characters within a list

I have to replace certain characters in each tuple in a list.I know how to do it with just a basic string. import string s = 'This:is:awesome' ss = s.replace(':', '/') print ss However, how would I ...
1
vote
2answers
64 views

PHP equivalent of Python's `str.format` method?

Is there an equivalent of Python str.format in PHP? In Python: "my {} {} cat".format("red", "fat") All I see I can do in PHP natively is by naming the entries and using str_replace: ...
0
votes
2answers
46 views

How do you replace a line of text in a text file (python) [duplicate]

i have a text file that looks like this: unknown unknown etc. How do you choose a specific line in the text file, delete that line than replace it with a specific string.
1
vote
3answers
62 views

Finding out Age in Months and Years given DOB in a CSV using python

I making several adjustments to an automatically gennerated CSV report. I am currently stuck on a part where I need to take a patient's DOB and convert that into an Age in Months and Years. There is ...
1
vote
3answers
49 views

replacing word with another word from the string in python

I have a string: "y, i agree with u." And I have array dictionary [(word_will_replace, [word_will_be_replaced])]: [('yes', ['y', 'ya', 'ye']), ('you', ['u', 'yu'])] i want to replace 'y' with ...
2
votes
3answers
43 views

Removing a Ton of Leading Spaces and Newline Characters from a String

I have a Python string that is printing out the following string in the shell: '\\n autonomy\\n . . sweeping\\n \\n ' How can I remove all of ...
0
votes
2answers
38 views

Replace characters in a string with whitespaces

I am writing a simple Python script that retrieves the latest tweet of any twitter user (in this case BBC) and uses the integrated text-to-speech system on Mac to read out the content of that ...
0
votes
2answers
47 views

Replacing substrings given a dictionary of strings-to-be-replaced as keys and replacements as values. Python

I have a dictionary with the strings to be replaced as keys and its replacement as values. Other than looking through the strings token by token, is there a better/faster way of doing the replacement? ...
1
vote
3answers
40 views

Fixing a CSV using Python

I am trying to clean up the formating on a CSV file in order to import it into a database, and I'm using the following to edit it: f1 = open('visit_summary.csv', 'r') f2 = open('clinics.csv', 'w') ...
5
votes
1answer
92 views

Python - how to replace 'p' in a number(4p5) with '.' (4p5->4.5)?

I have a program that prints out some data with 'p's in place of decimal points, and also some other information. I was trying to replace the 'p's with '.'s. Example output by the program: out_info ...
-4
votes
1answer
101 views

Python replace string in file

i need something to replace a string in a file wich is placed in that mktemp folder. this file is named autounattend.cfg and contains a string named %PASSWORD this string need to be replaced with ...
0
votes
2answers
86 views

In Python 2.7, how can i replace 't' with 'top' and 'h' with 'hop' only when 'th' is not visible

I am new here and python as well but i want to give it a try! I would like to replace 't' with 'top' and 'h' with 'hop' in a sentence , only when 'th' is not visible because 'th' will become 'thop'. ...
0
votes
0answers
45 views

Python alter lines for all files in folder, replacing existing files

I am trying to write a python script which goes through all files in a folder, and alters those lines containing a certain a href. I'm trying to get the script to add a .html extension to the href, ...
6
votes
3answers
90 views

Simultaneous .replace functionality

I have already converted user input of DNA code (A,T,G,C) into RNA code(A,U,G,C). This was fairly easy RNA_Code=DNA_Code.replace('T','U') Now the next thing I need to do is convert the RNA_Code ...
0
votes
2answers
43 views

Change all the occurrences of a particular value in a CSV file in Python

I have a CSV file that needs to be cleaned up. I wrote code with separate functions for each column to replace some value, say 'a' in column 1 with 'aaa', and ' ' (blank) in column 2 with '0'. Can we ...

1 2 3 4 5 24
15 30 50 per page