Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 0.69 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Multi line string with arguments. How to declare?
  2. cmd = """line 1
  3.       line 2
  4.       line 3"""
  5.        
  6. cmd = """line %d
  7.       line %d
  8.       line %d""" % (1, 2, 3)
  9.        
  10. cmd = """line %d
  11.       line %d
  12.       line %d""" % (
  13.       1,
  14.       2,
  15.       3)
  16.        
  17. '''line {0}
  18. line {1}
  19. line {2}'''.format(1,2,3)
  20.        
  21. args = (1,2,3)
  22. '''line {0}
  23. line {1}
  24. line {2}'''.format(*args)
  25.        
  26. args = {'arg1':1, 'arg2':2, 'arg3':3}
  27. '''line {arg1}
  28. line {arg2}
  29. line {arg3}'''.format(**args)
  30.        
  31. cmd = "line %dn"%1 +
  32.       "line %dn"%2 +
  33.       "line %dn"%3
  34.        
  35. cmd = "n".join([
  36.       "line %d"%1,
  37.       "line %d"%2,
  38.       "line %d"%3])
  39.        
  40. cmd = """line %d
  41.       line %d
  42.       line %d""" % (
  43.           1,
  44.           2,
  45.           3
  46.       )