Replace numbers "4,16221E+13" [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a cvs file containing the following format of numbers 4,16221E+13 I don't really know what it means.
How can I replace them? is there a special function or script to do it?
Thank you,
Hani.

It means 4.16221 x 10^13, i.e. 41622100000000.
You can use:
float('4,16221E+13'.replace(',', '.'))
>>> 41622100000000.0
Python needs . as decimal point.

If you take the text, replace the , with an . then you can get the number it's likely supposed to be, eg:
>>> f = '4,16221E+13'
>>> float(f.replace(',', '.'))
41622100000000.0

Related

How to extract text between two markers? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 10 months ago.
Improve this question
I am trying to create a blogging site kind of like medium.com. The only problem I am facing is the headings in the blog. I want to do what stack overflow does with bold text.
**text**
But I can't seem to figure out how to make this. Sorry if this question is not detailed enough and Thanks for giving this question your time.
you can find string between two subStrings using python regular expression.
import re
s = '**text**'
result = re.search('\*\*(.*)\*\*', s)
print(result.group(1)) #output :==> text
you really should learn regular expression 😀.

Extracting a specific part of a string with regular expression in Python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have such a string below and I want to extract the url just after the imgurl:. How could you do in Python in handy way?
{ns:"images",k:"5049",mid:"551FC833EDC139718135AA91A46D6B09FE89E85C",surl:"http://www.thewritingnut.com/blog-challenge/az-day-25-yellow-symbolisms/",imgurl:"http://www.thewritingnut.com/wp-content/uploads/2011/04/yellow-rose-800.jpg",oh:"199",tft:"0",oi:"http://www.thewritingnut.com/wp-content/uploads/2011/04/yellow-rose-800.jpg"}
Here it is, using a regular expression:
data = '{ns:"images",k:"5049",mid:"551FC833EDC139718135AA91A46D6B09FE89E85C",surl:"http://www.thewritingnut.com/blog-challenge/az-day-25-yellow-symbolisms/",imgurl:"http://www.thewritingnut.com/wp-content/uploads/2011/04/yellow-rose-800.jpg",oh:"199",tft:"0",oi:"http://www.thewritingnut.com/wp-content/uploads/2011/04/yellow-rose-800.jpg"}'
re.search('imgurl:"([^"]+)', data).group(1)

How to transform url in Python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string in python, which is a URL:
http://weibo.com\/p\/aa\/weibo?from=bb&wvr=5.1&mod=weibomore#cc
I want to a real URL that I can paste it in my chrome:
http://weibo.com/p/aa/weibo?from=bb&wvr=5.1&mod=weibomore#cc
Please tell me how to chang it IN PYTHON~~~
It appears that you simply need to remove the backward slashes from your original string.
You can do that using replace as such..
url = string.replace("\\", "")
<your url string>.replace("\\","") will do the trick, but as has been pointed out, it would be better to fix the source of this.
The solution will also remove any backquotes ("\"). Even legitimate ones - so it's not a general solution. Backslashes are allowed in urls*, though its very unusual and causes problems
*Then again perhaps not: http://www.ietf.org/rfc/rfc2396.txt - it looks like this is a confusing question.

Python Regex: get everything except for string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following sentence:
Graft Concepts has partnered with\u00a0several sites\u00a0to offer customization options for backplates, so customers will be able to design their own with\u00a0
I'd like to get rid of all instances of "\u00a0", whether or not they are connected to other words, e.g. "with\u00a0several"
How would I do this using regex with python? I've tried experimenting with re.compile() and re.findall(), but I couldn't get this working?
Thanks.
You can just use .replace:
s = s.replace('\\u00a0', ' ')
This works under Python 2:
import re
st='''Graft Concepts has partnered with\u00a0several sites\u00a0to offer customization options for backplates, so customers will be able to design their own with\u00a0'''
st=re.sub(ur'\\u00a0','',st,re.UNICODE)
And this under Python 3:
st=re.sub(u'\\u00a0','',st,re.UNICODE)

python with tor and reddit "KeyError" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I found this code on github: https://github.com/Abrand88/Reddit-Tor-proxy-voting-bot/blob/master/reddit_proxy_voting_bot.py
I know that its a bot and potentially malicious but I thinks its cool nonetheless. From an educational perspective how do I get it working?: When I run the program it outputs "socket:" twice and then gives the error "KeyError: '127.0.0.1'"
Any thoughts?
it's using a dictionary and can't find the key for your local host.
this is probably causing the error breaking:
ip_hash={}; # the dictionary is made
and
ip_hash[ip] = 1; # the dictionary is incorrectly accessed
this part alone isn't a good idea:
if ip in ip_hash:
print " repeat " + ip;
else:
ip_hash[ip] = 1;

Categories