|
Is there a similar function in python that takes search(array) and replace(array) as a parameter? Then takes a value from each array and uses them to do search and replace on subject(string).
I know I can achieve this using for loops, but just looking...
Started by Mohamed on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
replace in edits: s = s.replace(search, replace)
Even if python did have a str_replace -style; replace = ['Making', 'Python', 'one-liners', 'fun!'] >>> reduce(lambda s, p: s.replace(p[0],p[1]),[subject....
|
|
I want to use some Python libraries to replace MATLAB. I'd like to know how could I import excel data in Python (for example using numpy) to use them. I don't know if Python is a credible alternative to MATLAB, but I want to try it. If you have any tutorial...
Started by clowny on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Depending on what kind of computations you are doing with... .
Here's a tutorial about replacing Matlab with Python.
But since you want to replace Matlab, you're to csv).
Hundreds of ways you could import text data into Python.
|
|
I was having trouble implementing 'namedtuple._replace()', so I copied the code right off of the documentation:
Point = namedtuple('Point', 'x,y') p = Point(x=11, y=22) p._replace(x=33) print p
and I got:
Point(x=11, y=22)
instead of:
Point(x=33, y=22...
Started by Peter Stewart on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
._replace....
_replace() returns a new tuple with your modifications:
p = p._replace(x=33)
Yes it does, it works exactly as documented.
A tuple is immutable.
Namedtuple._replace() returns a new tuple; the original is unchanged.
|
Ask your Facebook Friends
|
I have a project where I have folders, subfolders, and files. I need to replace the word Masi by the word Bond in each files.
I run the following Sed script called replace unsuccessfully
s/Masi/Bond/
in Zsh by
sed -f PATH/replace PATH2/project/**
It gives...
Started by Masi on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Don't want to replace the files' contents inline (which is what the -i will do) you can do exactly/replace
Lots of options, but do not write an entire perl script for this (I'll give the one-liner to comment:
grep -rl Masi PATH/project/....
|
|
I'm a Python beginner, and I have a utf-8 problem.
I have a utf-8 string and I would like to replace all german umlauts with ASCII replacements (in German, u-umlaut 'ü' may be rewritten as 'ue').
u-umlaut has unicode code point 252, so I tried this:
&...
Started by Frank on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
You can just use str.replace(unichr(252), 'ue') to replace the ü') u'ueber'
There's no need to use repr....
So, it's a string that literally contains \xfcber , instead of a string that contains über .
Back in as Python to get the string back.
|
|
Hello,
how do I convert some text to a link? Back in PHP, I used this piece of code that worked well for my purpose:
$text = preg_replace("#(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)#is", "\\1<a href=\"\\2\" target...
Answer Snippets (Read the full thread at stackoverflow):
Import re pat1 = re.compile.
For more information, please see the Python Regular Expression HOWTO .
You should confirm that it actually does what you want .
The code below is a simple translation to python.
|
|
Python Newbie. I am looking for a way to replace the SRC attribute in all IMG tags not using Regular expressions. (would like to use any out-of-the box HTML parser included with default Python install) I need to reduce the source from what ever it may...
Started by CPCase on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Doing this kind.
There is a HTML parser in the Python standard library, but it's not very useful and it's deprecated since Python 2.6.
You'll probably want to use BeautifulSoup for parsing HTML.
|
|
What's the easiest way to do a case-insensitive str.replace in Python?
Started by Adam Ernst on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
>>> import re >>> insensitive_hippo = re.compile('hippo', re.IGNORECASE) >>> insensitive_hippo... .
You're probably best off using the regular expression sub method with the re.IGNORECASE option .
The string type doesn't support this.
|
|
I have a html text like this:
<xml ... >
and I want to convert it to something readable:
<xml ...>
Any easy (and fast) way to do it in Python?
Started by Alexandru on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
Http://docs.python.org/library/htmlparser.html
>>> import HTMLParser >>> pars = HTMLParser.HTMLParser() >>> pars.unescape('© €') u'\xa9 \u20ac' >>> print _ © €
There is a function here that does it, as linked... .
|
|
I have 2 csv files. I need to replace a column in one file with a column from the other file but they have to stay sorted according to an ID column.
Here's an example:
file1:
ID, transect, 90mdist 1, a, 10, 2, b, 20, 3, c, 30,
file2:
ID, transect, 90mdist...
Started by FS on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
It allows you to read and write CSV lists, one easy way to replace a column in one matrix with another would be to transpose the matrices, replace the row, and then transpose....
The CSV Module in the Python Library is what you need here.
|