Skip to main content
added 213 characters in body
Source Link
MarianD
  • 2k
  • 1
  • 11
  • 20

One tip: Instead of gluing constant and variable parts into string with + as e. g. in your statement

print " "*2 + "%s:" % (day[0]), from_to.rjust(5) + u'\u00b0' + "C -", "%s" % (day[3])

use the format() method with placeholders {} in formatted string:

print "  {} {:>5}{}C - {}"     .format(day[0], from_to, u'\u00b0', day[3])

(I visually separated the resulting string with placeholders from the format() method),
or - more descriptively - use names in {} placeholders

print "  {day0} {from_to:>5}{degree_sign}C - {day3}" \
    .format(day0=day[0], from_to=from_to, degree_sign=u'\u00b0', day3=day[3])

Format specifier >5 after : does the same thing as .rjust(5) in your code.


Edit:

For Unicode symbols (as u'\u00b0' in your code) use their hexadecimal value (0x00b00x00b0) and type c in the placeholder:

print "  {} {:>5}{:c}C - {}"     .format(day[0], from_to, 0x00b0, day[3])

See Format Specification Mini-Language

One tip: Instead of gluing constant and variable parts into string with + as e. g. in your statement

print " "*2 + "%s:" % (day[0]), from_to.rjust(5) + u'\u00b0' + "C -", "%s" % (day[3])

use the format() method with placeholders {} in formatted string:

print "  {} {:>5}{}C - {}"     .format(day[0], from_to, u'\u00b0', day[3])

(I visually separated the resulting string with placeholders from the format() method),
or - more descriptively - use names in {} placeholders

print "  {day0} {from_to:>5}{degree_sign}C - {day3}" \
    .format(day0=day[0], from_to=from_to, degree_sign=u'\u00b0', day3=day[3])

Format specifier >5 after : does the same thing as .rjust(5) in your code.


Edit:

For Unicode symbols (as u'\u00b0' in your code) use their hexadecimal value (0x00b0) and type c in the placeholder:

print "  {} {:>5}{:c}C - {}"     .format(day[0], from_to, 0x00b0, day[3])

One tip: Instead of gluing constant and variable parts into string with + as e. g. in your statement

print " "*2 + "%s:" % (day[0]), from_to.rjust(5) + u'\u00b0' + "C -", "%s" % (day[3])

use the format() method with placeholders {} in formatted string:

print "  {} {:>5}{}C - {}"     .format(day[0], from_to, u'\u00b0', day[3])

(I visually separated the resulting string with placeholders from the format() method),
or - more descriptively - use names in {} placeholders

print "  {day0} {from_to:>5}{degree_sign}C - {day3}" \
    .format(day0=day[0], from_to=from_to, degree_sign=u'\u00b0', day3=day[3])

Format specifier >5 after : does the same thing as .rjust(5) in your code.


Edit:

For Unicode symbols (as u'\u00b0' in your code) use their hexadecimal value (0x00b0) and type c in the placeholder:

print "  {} {:>5}{:c}C - {}"     .format(day[0], from_to, 0x00b0, day[3])

See Format Specification Mini-Language

added 213 characters in body
Source Link
MarianD
  • 2k
  • 1
  • 11
  • 20

One tip: Instead of gluing constant and variable parts into string with + as e. g. in your statement

print " "*2 + "%s:" % (day[0]), from_to.rjust(5) + u'\u00b0' + "C -", "%s" % (day[3])

use the format() method with placeholders {} in formatted string:

print "  {} {:>5}{}C - {}"     .format(day[0], from_to, u'\u00b0', day[3])

(I visually separated the resulting string with placeholders from the format() method),
or - more descriptively - use names in {} placeholders

print "  {day0} {from_to:>5}{degree_sign}C - {day3}" \
    .format(day0=day[0], from_to=from_to, degree_sign=u'\u00b0', day3=day[3])

Format specifier >5 after : does the same thing as .rjust(5) in your code.


Edit:

For Unicode symbols (as u'\u00b0' in your code) use their hexadecimal value (0x00b0) and type c in the placeholder:

print "  {} {:>5}{:c}C - {}"     .format(day[0], from_to, 0x00b0, day[3])

One tip: Instead of gluing constant and variable parts into string with + as e. g. in your statement

print " "*2 + "%s:" % (day[0]), from_to.rjust(5) + u'\u00b0' + "C -", "%s" % (day[3])

use the format() method with placeholders {} in formatted string:

print "  {} {:>5}{}C - {}"     .format(day[0], from_to, u'\u00b0', day[3])

(I visually separated the resulting string with placeholders from the format() method),
or - more descriptively - use names in {} placeholders

print "  {day0} {from_to:>5}{degree_sign}C - {day3}" \
    .format(day0=day[0], from_to=from_to, degree_sign=u'\u00b0', day3=day[3])

Format specifier >5 after : does the same thing as .rjust(5) in your code.

One tip: Instead of gluing constant and variable parts into string with + as e. g. in your statement

print " "*2 + "%s:" % (day[0]), from_to.rjust(5) + u'\u00b0' + "C -", "%s" % (day[3])

use the format() method with placeholders {} in formatted string:

print "  {} {:>5}{}C - {}"     .format(day[0], from_to, u'\u00b0', day[3])

(I visually separated the resulting string with placeholders from the format() method),
or - more descriptively - use names in {} placeholders

print "  {day0} {from_to:>5}{degree_sign}C - {day3}" \
    .format(day0=day[0], from_to=from_to, degree_sign=u'\u00b0', day3=day[3])

Format specifier >5 after : does the same thing as .rjust(5) in your code.


Edit:

For Unicode symbols (as u'\u00b0' in your code) use their hexadecimal value (0x00b0) and type c in the placeholder:

print "  {} {:>5}{:c}C - {}"     .format(day[0], from_to, 0x00b0, day[3])
added 86 characters in body
Source Link
MarianD
  • 2k
  • 1
  • 11
  • 20

One tip: Instead of gluing constant and variable parts into string with + as e. g. in your statement

print " "*2 + "%s:" % (day[0]), from_to.rjust(5) + u'\u00b0' + "C -", "%s" % (day[3])

use the format() method with placeholders {} in formatted string:

print "  {} {:>5}{}C - {}"     .format(day[0], from_to, u'\u00b0', day[3])

(I visually separated the resulting string with placeholders from the format() method),
or - more descriptively - use names in {} placeholders

print "  {day0} {from_to:>5}{degree_sign}C - {day3}" \
    .format(day0=day[0], from_to=from_to, degree_sign=u'\u00b0', day3=day[3])

Format specifier >5 after : does the same thing as .rjust(5) in your code.

One tip: Instead of gluing constant and variable parts into string with + as e. g. in your statement

print " "*2 + "%s:" % (day[0]), from_to.rjust(5) + u'\u00b0' + "C -", "%s" % (day[3])

use the format() method with placeholders {} in formatted string:

print "  {} {:>5}{}C - {}"     .format(day[0], from_to, u'\u00b0', day[3])

(I visually separated the resulting string with placeholders from the format() method),
or - more descriptively - use names in {} placeholders

print "  {day0} {from_to:>5}{degree_sign}C - {day3}" \
    .format(day0=day[0], from_to=from_to, degree_sign=u'\u00b0', day3=day[3])

One tip: Instead of gluing constant and variable parts into string with + as e. g. in your statement

print " "*2 + "%s:" % (day[0]), from_to.rjust(5) + u'\u00b0' + "C -", "%s" % (day[3])

use the format() method with placeholders {} in formatted string:

print "  {} {:>5}{}C - {}"     .format(day[0], from_to, u'\u00b0', day[3])

(I visually separated the resulting string with placeholders from the format() method),
or - more descriptively - use names in {} placeholders

print "  {day0} {from_to:>5}{degree_sign}C - {day3}" \
    .format(day0=day[0], from_to=from_to, degree_sign=u'\u00b0', day3=day[3])

Format specifier >5 after : does the same thing as .rjust(5) in your code.

Source Link
MarianD
  • 2k
  • 1
  • 11
  • 20
Loading