0

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

2
  • 1
    code seems to be OK but maybe is not doing what you want. What do you try to achieve? Maybe you want 'c' to be replaced with the value of c? Commented May 15, 2012 at 6:28
  • 1
    I suppose that depends on your goals Commented May 15, 2012 at 6:28

3 Answers 3

4

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")
Sign up to request clarification or add additional context in comments.

5 Comments

u = """my_game.%%first_game_start_time%%("%s", "%s")""" %("ISS", "320_757") what is wrong with this one?
@alwbtc, That outputs my_game.%first_game_start_time%("ISS", "320_757"). Is that not what you were expecting?
I expect "my_game.%first_game_start_time%("ISS", "320_757")". But it doesn't output that. Instead, it outputs the previous value assigned to u.
@alwbtc, without seeing your code I can only guess. Perhaps you are printing the value before you reassign it
"%s" is unlikely to be what is desired, in my opinion. Doing that sort of thing is what leads to bugs and related security holes. Do something which makes sure that stray ' or " characters won't cause trouble. Python's string repr is one such, which can be invoked as %r in string formatting.
1

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)

Comments

0

I'm going to guess that you want this:

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

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.