How to transform url in Python [closed] - python

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.

Related

SyntaxError: Expected an indented block exception thrown [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
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.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I have write this code to collect all data from twitter for cities like London. I have tried to write a code using python and it's give me this error on the line:
def process_or_store(tweet):
print(json.dumps(tweet)
What can I do to fix this?
Set a tabulator or spaces in front of this line (depends on what you used in the above lines), so it looks like:
def process_or_store(tweet):
print(json.dumps(tweet))
Remind, that python does not use {} to determine where a function starts and ends. A function must be in one indentation level instead.
You also forgot to close brackets at print().
Take the above definition, its syntax is correct.
Be aware of mixing up tabs and spaces (some editors manage this automatically, but if not, this can lead to errors that are not obvious)
Update:
def process_or_store(tweet):
print(json.dumps(tweet)
To be:
def process_or_store(tweet):
print(json.dumps(tweet))
and then delete your question

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

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

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;

How to make this gaema demo running on google-app-engine? [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 3 years ago.
Improve this question
This is the package which has a webapp demo in it.
However, when I login use this demo, I get an error.
How to make this demo running on the gae-launcher?
Looks like a bug in gaema.
The line that's failing is trying to urlencode a dictionary of arguments that get passed to the OpenID endpoint. One or more of the values, perhaps your first or last name, has non-ASCII characters.
You might be able to work around it by replacing instances of this:
urllib.urlencode(args)
With this:
urllib.urlencode(dict([(k, args[k].encode('utf-8')) for k in args]))
For a more permanent fix, I would report the issue here:
http://code.google.com/p/gaema/issues/list

Categories