alwbtc
alwbtc

Reputation: 29445

Python string operation

I want to get the following output:

"my_www.%first_game_start_time%("REN", "233_736")" 

Would you please tell me what is wrong in code below:

u = "my_www.%%first_game_start_time%%(%s, %s)" %("REN", "233_736")

Best Regards

Upvotes: 0

Views: 173

Answers (3)

John La Rooy
John La Rooy

Reputation: 304117

If you are asking how to embed " in the string, triple quotes is an easy way

u = """my_www.%%first_game_start_time%%("%s", "%s")"""%("REN", "233_736")

Another way is to escape the " with a \

u = "my_www.%%first_game_start_time%%(\"%s\", \"%s\")"%("REN", "233_736")

Since you have no ' in the string, you could also use those to delimit the string

u = 'my_www.%%first_game_start_time%%("%s", "%s"))'%("REN", "233_736")

Upvotes: 4

Yusuf X
Yusuf X

Reputation: 14633

I'm going to guess that you want this:

c = "222"
u = "my_www." + first_game_start_time("REN", "233_736", c)

Upvotes: 0

Andrew Gorcester
Andrew Gorcester

Reputation: 19953

Generally you need to post your expected output and point out the difference between that and the output you receive, or include an error message you are receiving, to get a usable answer. But, I suspect the problem is that you want the value of c to be inserted into the string u and instead the literal letter c is being inserted. If that is the case, the solution is:

c = "222"
u = "my_www.%%first_game_start_time%%(%s, %s, %s)" %("REN", "233_736", c)

Upvotes: 1

Related Questions