I often find a need to put paths in my code in order to find data or in some cases tool-specific modules. I've so far always used autotools because of ... |
I am trying to clean all of the HTML out of a string so the final output is a text file. I have some some research on the various 'converters' ... |
What am I doing wrong here?
import re
x = "The sky is red"
r = re.compile ("red")
y = r.sub(x, "blue")
print x # Prints "The sky is red"
print y # Prints "blue"
How ... |
What's the easiest way to do a case-insensitive str.replace in Python?
|
Say I have the string "blöt träbåt" which has a few a and o with umlaut and ring above. I want it to become "blot trabat" as simply as possibly. I've ... |
I'm dealing with cleaning relatively large (30ish lines) blocks of text. Here's an excerpt:
PID|1||06225401^^^PA0^MR||PATIENT^FAKE
R|||F
PV1|1|I|||||025631^DoctorZ^^^^^^^PA0^^^^DRH|DRH||||...
ORC|RE||CYT-09-06645^AP||||||200912110333|INTERFACE07
... |
I have a file opened in 'ab+' mode.
What I need to do is replacing some bytes in the file with another string's bytes such that:
FILE:
thisissomethingasperfectlygood.
string:
01234
So, for example, I seek for the ... |
|
I have a string like x = "http://query.yahooapis.com/v1/public/yql?q=select%20owner%2Curls%20from%20flickr.photos.info%20where%20photo_id%3D'%s'&format=json"
If I do x % 10 that fails as there are %20f etc which are being treated as format strings, so I have to ... |
In python, are strings mutable? The line someString[3] = "a" throws the error
TypeError: 'str' object does not
support item assignment
I can see why (as I could ... |
I am trying to replace newline characters in a unicode string and seem to be missing some magic codes.
My particular example is that I am working on AppEngine and trying to ... |
when i input some texts/strings, i want them to appear either as hidden or with some special characters(as we do while entering password). . . how can i implement it in ... |
I am trying to replace multiple string in a file.
fp1 = open(final,"w")
data = open(initial).read()
for key, value in mydict.items():
fp1.write(re.sub(key,value, data)
fp1.close()
But only my last key value get replaced. how ... |
"8,5,,1,4,7,,,,7,,1,9,3,6,,,8,6,3,9,,2,5,4,,,,,3,2,,,7,4,1,1,,4,,6,9,,5,,,,5,,,1,,6,3,,,6,5,,,,7,4,,1,7,6,,,,8,,5,,,7,1,,3,9,"
I'm doing a programming challenge where i need to parse this sequence into my sudoku script.
Need to get the above sequence into 8,5,0,1,4,7,0,0,0,7,0,1,9,3,6,0,0,8.........
I tried re but without success, help is appreciated, ... |
As asked and answered in HERE, I need to replace '[' with '[[]', and ']' with '[]]'.
I tried to use s.replace(), but as it's not in place change, I ran ... |
What am I doing wrong/what can I do?
import sys
import string
def remove(file):
punctuation = string.punctuation
for ch in file:
...
|
I have a string like this "1 1 3 2 1 1 1 ... |
In python 2.x versions there is a function named as PyString_AS_STRING to convert a pyobject pointer to a string or char pointer.
How can we achieve the same functionality in python 3?
... |
I need to replace a string in case sensitive way. For example
abc -> def
Abc -> Def
aBc -> dEf
abC -> deF
What can I do this with Python?
|
I need to replace some characters as follows : & -> \&, # -> \#, ...
I coded as follows, but I guess there should be some better way. Any hints?
strs = ...
|
Some background information: We have an ancient web-based document database system where I work, almost entirely consisting of MS Office documents with the "normal" extensions (.doc, .xls, .ppt). They are all ... |
I am using ConfigParser to save simple settings to a .ini file, and one of these settings is a directory. Whenever I replace a directory string such as D:/Documents/Data, with a ... |
My question is very simple, but I didn't get the answer from google.
There is a python string:
s = "123123"
I want to replace the last 2 with x. Suppose there is ... |
I capture the string from a html source file using regex:
f = open(rrfile, 'r')
p = re.compile(r'"name":"([^"]+)","head":"([^"]+)"')
match = re.findall(p, f.read())
And I've tried:
>>> u'\\u4f60\\u4f60'.replace('\\u', '\u')
u'\\u4f60\\u4f60'
>>> u'\\u4f60\\u4f60'.replace(u'\\u', '\u') ...
|
I have a SQL string, for example
SELECT * FROM benchmark WHERE xversion = 1.0
And actually, xversion is aliased variable, and self.alias has all the alias info something like
{'CompilationParameters_Family': 'chip_name',
... |
When creating a template in Mako, I would need to write things like : ${_('Hello, %(fname)s %(lname)s') % {'fname':'John','lname':'Doe'}}
I keep getting SyntaxException: (SyntaxError) unexpected EOF while parsing when writing that. Is ... |
I want to replace repeated instances of the "*" character within a string with a single instance of "*". For example if the string is "***abc**de*fg******h", I want it to get ... |
How can I open a file, Stud.txt, and then replace any occurences of "A" with "Orange"?
|
I have been working on an anagram solver in Python 2.7 and came across a curiosity that I haven't been able to find an explanation for. The program reads from a ... |
I'm parsing text from file with Python. I have to replace all newlines (\n) with cause this text will build html-content. For example, here is some line from file:
'title\n'
Now ... |
My code reads a directory and stores the filename with extention into a list. What I am trying to do is get rid of the extention with replace. However, ... |
I have some text coming from the web as such:
£6.49
Obviously I would like this to be displayed as:
£6.49
I have tried the following so far:
s = url['title']
s = s.encode('utf8')
s = s.replace(u'Â','')
And a ... |
I read the artist of a song from its MP3 tag, then create a folder based on that name. The problem I have is when the name contains a special ... |
So I can't seem to figure this out... I have a string say, "a\\nb" and I want this to become "a\nb". I've tried all the following and none seem to work;
>>> ...
|
Hi i need to replace value into null value in plpython, but how can i do that?Can somebody help?
for example inside plpython sql i wrote.
aa = 'World 123'
bb = aa.replace('World ', ...
|
I am trying to feed some text to a special pupose parser. The problem with this parser is that it is sensitive to ()[] characters and in my sentence in ... |
What does Python's string.replace return if no string substitution was made?
Does Python's file.open(f, 'w') always touch the file even if no changes were made?
Using Python, I'm trying to replace occurrences of ... |
I need to print something like this
"a=name1,b=name2,c=name1,d=name2"
While I have name1 and name2 in variable n1 n2
n1="name1"
n2="name2"
what I am trying to do
"a=%s,b=%s,c=%s,d=%s" % (n1,n2,n1,n2)
Is there a better way than this? way ... |
I have something like this:
text = 'This text is very very long.'
replace_words = ['very','word']
for word in replace_words:
text = text.replace('very','not very')
I would like to only replace the first ... |
Suppose we have a string a = "01000111000011" with n=5 "1"s. The ith "1", I would like to replace with the ith character in "ORANGE".
My result should look like:
b = "0O000RAN0000GE"
What ... |
I have a file with multiple lines, each having a long sequence of characters (no spaces).
For example in one line:
qwerrqweqweasdqweqwe*replacethistext*asdasdasd
qwerrqweqweasdqweqwe*withthistext*asdasdasd
The specific string I am looking for can happen any where ... |
I have a simple python utility code that modifies the string line by line. The code is as follows.
import re
res = ""
with open("tclscript.do","r") as f:
lines = ...
|
i know how to make string replacements in python but I need a way to replace only
if the sequence is located at the end of the word.
for example:
rule: at -> ate
so:
cat ...
|
Expected:
>>> removeVowels('apple')
"ppl"
>>> removeVowels('Apple')
"ppl"
>>> removeVowels('Banana')
'Bnn'
CODE (Beginner):
def removeVowels(word):
vowels = ('a', 'e', 'i', 'o', 'u')
for c in word:
if ...
|
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka \xe2 aka #8217). But when I run that line of code, I get this error:
SyntaxError: Non-ASCII character ...
|
I have a template file: 'template.txt' like below:
class Core_Model_DbTable_{table_name} extends YouNet_Db_Table
{
const TYPE_PRINTED = 1;
const ...
|
I have many string pairs and one large string (which is the content of a file). I need to replace each and every occurrence of the first member in each pair ... |
I am trying to put information available on the web, and to do so I am using string formatting:
fields = """{"fname" : %s, "lname" : %s, "email" : %s, "deptid" : ...
|
Actually my question is quite simple:
I have a string like: 101222_1_1_ab;
I hope to change it into: 101222_1_ab_1
What bash commands should I use? and what to do in python?
THanks
|
|
|
Hi, I coded a python script that lets me parse a csv file into html code with a certain format, but I would like to replace every "<" and ">" character that appears within each column entry of the csv file (they are parsed as strings) with the html equivalents of "<" and ">". example csv file row: "FIXED","All","Enable |
Hello, I am getting an error in my python script when I try to change a character in a string. But I dont know why or what to do to fix it? I have commented in my code where the error occurs def format_file(filename): HTML_file = open(filename,'r') HTML_source = HTML_file.read() HTML_file.close() x = 0 # Format all ID's & classes correctly ... |
|
The ulimtate purpose of the script will be to replace 1St with 1st, 2Nd with 2nd, ect in my address field of my .shp file. I want the script to find and replace a string in my adress field IF the adress City field is null. The script runs with no errors, but when I go look at the table, nothing ... |
|
|
So I have a text of the kind: "See *** for more information about the topic. Refer to *** in orde to..." I then have a list of strings which I wish to replace each *** with. So that the first *** is replaced by list[0], the second *** by list[1] and so forth. The pattern is always *** I've tried ... |
|
Code: Select all class TEST: def __init__(self): self.dotV = [u'_z1', u'_z2'] self.gzV = [u'_z2', u'-2*0.5*1*_z2-1**2*(_z1+0.1*_z1**3)'] def g_ki(self): """ ... |
That's just for demonstration purposes. A regular string containing backslashes often shows as a string with double backslashes, which can be confusing. So in order to show the "real" string used, I used the raw format. IOW, when a string comes in from a file, you can use it "as is", no conversion needed. Actually, it is already a "raw string" ... |
Why are you using a string to represent the board? If you use a list, and then you can do index replacements easily. You could even have a list of lists for more intuitive indexing. Generally when I'm making games in Python, I use a list or dictionary to represent the board, and then generate strings for user output as needed. ... |
You're welcome. That's not an error I've seen before, but I can think of a couple of things that might be causing it. Could you post the input text that causes errors, or make a reduced test-case that gives the error with just a small (postable amount) part of the input text? It's probably an encoding issue, but more information is ... |
|
|
Hello everyone! Im new to python however Ive written in loads of languages, so not very hot on python at the mo! What Im trying to do is read in a simple text file (version.as) and then process some string replacement and re-write the file. There will be a few different variables to change for example @BUILDDATE@ I have no problems ... |
def parseDataFile(fn, beginMk, endMk): f = open(fn) # skip to 'essential' section s = f.next() while s.strip() != beginMk: s = f.next() outList = [] for line in f: ... |
Hello, I'm a python beginner and I have the following problem: I need to replace SOME strings in a file, with strings in another file. It is a translation of a story from a language to the other. In practice I have: FILE1 in english, with some phrases to be replaced (not consecutive, can be even in middle of other things) ... |