0
def postLoadItemUpdate(itemid):
    r = requests.post("http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='".itemid."'")
    print(r.text)

what is wrong with '".itemid."'"

There seems to be an syntax error there.

6 Answers 6

1

In Python use + operator for string concatenation:

"http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='" + itemid + "'"

But for string concatenation itemid should be a string object, otherwise you need to use str(itemid).

Another alternative is to use string formatting, here type conversion is not required:

"http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='{}'".format(itemid)
Sign up to request clarification or add additional context in comments.

Comments

1

If you're looking to concatenate the strings, use the + operator:

r = requests.post("http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='" + itemid + "'")

Comments

1

To concatenate strings you have to use + and if itemid is not a string value, you might want to apply str to convert that to a string.

"http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id='" + str(itemid) + "'"

Comments

1

String concatenation in Python works like this

s + itemId + t

not like this:

s . itemid . t

Comments

1

Where to start: does "constant string".itemid."constant string 2" work in Python?

You need to concatenate strings differently. Interactive mode for Python is your friend: learn to love it:

    $ python
    Python 2.7.5 (default, Aug 25 2013, 00:04:04)
    [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> foo = "-itemid-"
    >>> "string1" + foo + "string2"
    'string1-itemid-string2'

That should give you a starting point.

Comments

1

Alternatively, you could also use format:

r = requests.post("http://www.domain.com/ex/s/API/r/postLoadItemUpdate?id={0}".format(itemid))

In your particular use case, formal seems to be more flexible, and url changes will have little impact.

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.