1

I want to pass url to my python via the console and then do the appropriate tasks. many of the links contain the character '&' in the link. python interprets that as ending the argument this however is not what I want. here is a sample of the code

import sys

external_id = sys.argv[1].encode("utf-8")
print external_id

And when I run the following:

python graph.py 2%60&7

I get:

2%60

How do I make python interpret the '&' as nothing more than another character in the url?

3
  • 2
    Throw an escape character in front, ie. \& Commented Jul 11, 2014 at 17:14
  • Seems like this isn't a python issue as much as a terminal issue. Commented Jul 11, 2014 at 17:15
  • You probably missed the fact that your shell displayed somewhere that little error message: bash: 7: command not found. That was a big clue ;) Commented Jul 11, 2014 at 22:11

2 Answers 2

6

This is not python, it's bash. You need to escape it:

python graph.py 2%60\&7
Sign up to request clarification or add additional context in comments.

Comments

5

Quoting this answer:

The & informs the shell to put the command in the background.

Python never receives that character because the shell takes care of it, thus this isn't an issue of Python. You can also wrap 2%60&7 with quotes to make it work

me@pc:~$ python3 script.py '2%60&7'
b'2%60&7'

Sometimes escaping & is a lot harder than doing this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.