Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Best way to use globally format Date: Sun, 03 May 2015 17:21:32 +0200 Organization: Decebal Computing Lines: 21 Message-ID: <87wq0pk7pf.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="1e75f8f7bcfe2945d0316cb03b0f6951"; logging-data="13451"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IA5qIKh7qmU119bejIywV2s1f3MAGFsY=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Homepage: http://www.decebal.nl/ X-Face: "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR,v+Pti8=Vi/Z"g^?b"E Cancel-Lock: sha1:UYt0iT2AmGdARARxLgxKaD1M6o4= sha1:us9Ym5c65rrS+9scgLSW+5D0QTs= Xref: csiph.com comp.lang.python:89872 I have a file where I used a lot of {0}, {1} and {2}. Most but not all are changed to {0:.3E}, {1:.3E} and {2:.3E}. But when I want to change the format I come in dependency hell. I could do something like: format = ':.3E' fmt0 = '{0' + format + '} fmt1 = '{1' + format + '} fmt2 = '{2' + format + '} and replace occurrences of: 'before {0} after' with: 'before ' + fmt0 + ' after' But that does not really make me happy. Is there a better way? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof