Python Text substitute


 
Thread Tools Search this Thread
Top Forums Programming Python Text substitute
# 1  
Old 08-27-2015
Python Text substitute

I need to substitute only comma with dot in string like this:
Code:
<strong>5,4</strong>

but not sure how to do this.
This does not work:
Code:
text = sub('<strong>[0-9](,)[0-9]</strong>', '<strong>[0-9](.)[0-9]</strong>', text)


Last edited by Scrutinizer; 08-27-2015 at 12:23 PM.. Reason: quote tags -> code tags
# 2  
Old 08-27-2015
Code:
>>> text = "<strong>5,4</strong>"
>>> text = text.replace(',', '.')
>>> text
'<strong>5.4</strong>'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search and Replace+append a text in python

Hello all, I have a verilog file as following (part of it): old.v: bw_r_rf16x32 AUTO_TEMPLATE ( 1957 // .rst_tri_en (mem_write_disable), 1958 .rclk (clk), 1959 .bit_wen (dva_bit_wr_en_e), 1960 .din ... (5 Replies)
Discussion started by: Zam_1234
5 Replies

2. Shell Programming and Scripting

Python/GTK Text Wrap Question . . .

Greetings! After some cut-and-try, I've cobbled together the following bit of basic code:#!/usr/bin/python import gtk class PyApp(gtk.Window): def __init__(self): super(PyApp, self).__init__() self.set_size_request(250, 250) ... (0 Replies)
Discussion started by: LinQ
0 Replies

3. Programming

Python for text manipulating

Dear All, I am trying to write a python code for reading a fixed number of lines from a big file then save those pieces into another file as columns. I think sample file is necessary for understanding: Sample Input file: Epi. dist.(km)= 0.8100E+02 0.7466E-07 0.4942E-07 0.7133E-07 ... (10 Replies)
Discussion started by: johankor
10 Replies

4. Shell Programming and Scripting

Separate Text File into Two Lists Using Python

Hello, I have a pretty simple question, but I am new to Python and am trying to write a simple program. Put simply, I want to take a text file that looks like this: 11111 22222 33333 44444 55555 66666 77777 88888 and produce two lists, one containing the contents of the left column, one the... (0 Replies)
Discussion started by: Tyler_92
0 Replies

5. Programming

Python: Check 2 text files for string and print contexts

I have 2 text files: cities.txt San Francisco Los Angeles Seattle Dallas master.txt Atlanta is chill and laid-back. I love Los Angeles. Coming to Dallas was the right choice. New York is so busy! San Francisco is fun. Moving to Boston soon! Go to Seattle in the summer. ... (0 Replies)
Discussion started by: pxalpine
0 Replies

6. Shell Programming and Scripting

using awk to substitute data in a column delimited text file

using awk to substitute data in a column delimited text file hello i would like to use awk to do the following calculation from the following snippet. input file C;2390 ;CV BOUILLOTTE 2L 2FACES NERVUREES ;1.00 ;3552612239004;13417 ;25 ;50 ; 12;50000 ; ; ... (3 Replies)
Discussion started by: iindie
3 Replies

7. Shell Programming and Scripting

Find text containing paths and replace with a string in all the python files

I have 100+ python files in a single directory. I need to replace a specific path occurrence with a variable name. Following are the find and the replace strings: Findstring--"projects\\Debugger\\debugger_dp8051_01\\debugger_dp8051_01.cywrk" Replacestring--self.projpath I tried... (5 Replies)
Discussion started by: noorsam
5 Replies

8. Shell Programming and Scripting

Shell script: substitute value in text file

Hi gurus, I need help with shell script. I have various INSERT queries which inserts data into database. I want to insert 3rd column data into newline for one particular table. I have very time long txt file everytime and it have various INSERT/UPDATE queries but i have to done with it only one... (8 Replies)
Discussion started by: mirfan
8 Replies

9. Shell Programming and Scripting

In Help, Substitute Text ...

i'm writing a script that will extract and substitute a certain part of a data. i'm having trouble with the substituting part ... Here's my data looks like: 01/01/08-001-23:46:18-01/01/08-23:50:43 01/01/08-003-23:45:19-01/01/08-23:55:49 01/01/08-005-23:52:18-01/01/08-23:58:52 i want to... (6 Replies)
Discussion started by: solidhelix08
6 Replies

10. Shell Programming and Scripting

how to substitute more than one word in a text file?

well i have this file here: <XML> <pregate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <system_c>HPREGATE</system_c> <trans_c>HSPG</trans_c> <trans_dt>20060105161333</trans_dt> <user_id_m></user_id_m> <func_c>C</func_c> </pregate> </XML> i want to... (2 Replies)
Discussion started by: forevercalz
2 Replies
Login or Register to Ask a Question