Using "learning python the hard way." string formatting issue -


is code wants me enter fails

from sys import argv  script, user_name = argv prompt = '> '  print "hi %s, i'm %s script." % (user_name, script) print "i'd ask few questions." print "do me %s?" % user_name likes = raw_input(prompt) 

is code modified after seeing errors , knowing uses python 2, i've been making corrections code find them online.

from sys import argv  script, user_name = argv prompt = '> '  print ("hi" user_name: %s, "i/'m the", %s: script.) print ("i;d tok ask few questions") print ("do me %s") % (user_name) likes = input(prompt) 

all %s, %d %r have failed me. python 2 convention? should using else?

for example

foo = bar  print ("the variable foo %s fundamental programming issue.) 

i have tried using tuples? in:

print ("the variable foo", %s: foo, "is fundamental programming issue.") 

with no success

you should try use string.format()

for example:

some_string = 'my name {name} , live in {location}' some_params = {     'name': 'tim',     'location': 'germany' }  print(some_string.format(**some_params)) 

which result in

my name tim , live in germany 

for more specific documentation, @ format specification mini-language

nevermind, problems in second example are:

  • remove gap between print , starting bracket (
  • build strings before print statement. looks there missing &, * , %s's

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -