0

i have a url, which have to alter base on output from other function.

rogues_detail_url = https://foo.bar.com/api/list_view.json?list=rogue_ap&fv_id=0&page_length=500&sort_col=acknowledged&sort_descend=false&start_row=0
rogues_detail_url.replace("500",foo())

foo() returns an integer value.

just in case if i was doing it wrong i also tried rogues_detail_url.replace("500","1000")

Neither of them seem to work. Printing the url after i execute the statement, prints the same url

MR.i
  • 115
  • 1
  • 7

1 Answers1

0

In python, strings are never modified in-place. In fact, strings can't be modified at all. As such, methods such as string.replace return a modified copy.

In python, string methods generally do the following:

  1. copy the original
  2. modify the copy in some way
  3. leave the original alone.
  4. return the modified copy

You want to write: new_string = old_string.replace("500","1000")

If you write only write old_string.replace("500","1000") then you just ignored/discarded the new modified string. old_string cannot be modified by replace or any other string method.

Toothpick Anemone
  • 4,290
  • 2
  • 20
  • 42