Python字符串格式显示问题

时间:2015-05-14 03:07:11

标签: python

运行Python 2.6

我需要使用以下格式对jenkins进行api调用:

INSERT INTO `sporecount` (`IDSpore`, `TraceNum`, `TraceHour`, `Amount`, `Date`) VALUES ('C', 10, 1400, 1, '2015-05-14'), ('e', 4, 200, 1, '2015-05-14'), ('d', 8, 1800, 1, '2015-05-14'), ('r', 5, 0, 1, '2015-05-14'), ('t', 6, 2200, 1, '2015-05-14'), ('q', 2, 600, 1, '2015-05-14'), ('w', 3, 400, 1, '2015-05-14'), ('a', 1, 800, 1, '2015-05-14'), ('2', 12, 1000, 1, '2015-05-14'), ('y', 7, 2000, 1, '2015-05-14'), ('1', 9, 1600, 1, '2015-05-14'), ('A', 11, 1200, 1, '2015-05-14'), ('x', 9, 1630, 1, '2015-05-11'), ('z', 9, 1630, 1, '2015-05-11'), ('s', 9, 1630, 1, '2015-05-11'), ('s', 11, 1230, 1, '2015-05-11'), ('s', 1, 830, 2, '2015-05-11'), ('s', 2, 630, 1, '2015-05-11'), ('r', 10, 1430, 1, '2015-05-11'), ('d', 9, 1630, 1, '2015-05-11'), ('q', 6, 2230, 1, '2015-05-11'), ('q', 10, 1430, 2, '2015-05-11'), ('s', 8, 1830, 1, '2015-05-11'), ('t', 10, 1430, 1, '2015-05-11'), ('x', 11, 1230, 1, '2015-05-11'), ('x', 12, 1030, 2, '2015-05-11'), ('w', 6, 2230, 1, '2015-05-11'), ('w', 10, 1430, 1, '2015-05-11'), ('w', 11, 1230, 2, '2015-05-11'), ('x', 6, 2230, 2, '2015-05-11'), ('w', 2, 630, 1, '2015-05-11'), ('w', 5, 30, 1, '2015-05-11'), ('u', 7, 2030, 1, '2015-05-11'), ('y', 7, 2030, 1, '2015-05-11'), ('t', 7, 2030, 2, '2015-05-11'), ('v', 12, 1030, 2, '2015-05-11'), ('q', 5, 30, 2, '2015-05-11'), ('h', 7, 2030, 1, '2015-05-11'), ('a', 11, 1230, 1, '2015-05-11'), ('a', 12, 1030, 1, '2015-05-11'), ('a', 1, 830, 1, '2015-05-11'), ('a', 2, 630, 2, '2015-05-11'), ('T', 3, 430, 1, '2015-05-11'), ('S', 3, 430, 1, '2015-05-11'), ('R', 3, 430, 1, '2015-05-11'), ('D', 3, 430, 1, '2015-05-11'), ('1', 4, 230, 1, '2015-05-11'), ('C', 3, 430, 1, '2015-05-11'), ('4', 4, 230, 1, '2015-05-11'), ('3', 4, 230, 2, '2015-05-11'), ('a', 10, 1430, 1, '2015-05-11'), ('a', 8, 1830, 1, '2015-05-11'), ('h', 1, 830, 1, '2015-05-11'), ('g', 1, 830, 2, '2015-05-11'), ('e', 9, 1630, 1, '2015-05-11'), ('e', 10, 1430, 1, '2015-05-11'), ('e', 2, 630, 1, '2015-05-11'), ('e', 5, 30, 1, '2015-05-11'), ('d', 6, 2230, 1, '2015-05-11'), ('d', 8, 1830, 1, '2015-05-11'), ('d', 2, 630, 1, '2015-05-11'), ('c', 8, 1830, 1, '2015-05-11'), ('c', 12, 1030, 1, '2015-05-11'), ('a', 6, 2230, 1, '2015-05-11'), ('2', 4, 230, 1, '2015-05-11'); INSERT INTO `sporesfungi` (`IDSpore`, `Name`, `Type`) VALUES ('', '', ''), ('0', 'Basidiosporas', 'Fungus'), ('1', 'Ascosporas', 'Fungus'), ('2', 'Penicillum/Aspergillus', 'Fungus'), ('3', 'BasidiosporasPleurotus', 'Fungus'), ('4', 'Other', 'Fungus'), ('5', 'Cladospori', 'Fungus'), ('6', 'Coprinus/A', 'Fungus'), ('7', 'Basidio Tr', 'Fungus'), ('8', 'Ganoderma', 'Fungus'), ('9', 'Cecropia', 'Fungus'), ('A', 'Delitschia', 'Fungus'), ('C', 'Rumex', 'Trees'), ('D', 'Smut/Myxomycete', 'Fungus'), ('E', 'Spegazzinia', 'Fungus'), ('F', 'Sporomiella (A)', 'Fungus'), ('G', 'Torula', 'Fungus'), ('H', 'Pollen', 'Grass'), ('I', 'Arthrinium', 'Fungus'), ('J', 'Arbol', 'Trees'), ('K', 'Arthrocarpus', 'Trees'), ('L', 'Casuarina/Myrica', 'Trees'), ('O', 'Xylariae', 'Fungus'), ('P', 'Botrytis', 'Fungus'), ('Q', 'Spondylocladiella', 'Fungus'), ('R', 'Tetraploa', 'Fungus'), ('S', 'Diatrypaceae', 'Fungus'), ('T', 'Ulocladium', 'Fungus'), ('U', 'Amphisphaeria (A)', 'Fungus'), ('W', 'Stemphylium', 'Fungus'), ('X', 'Mimosa', 'Trees'), ('Y', 'Agrocybe-type', 'Fungus'), ('Z', 'Mangle', 'Trees'), ('a', 'Fusarium', 'Fungus'), ('b', 'Pleospora', 'Fungus'), ('c', 'Leptosphaerulina', 'Fungus'), ('d', 'Helocomyces', 'Fungus'), ('e', 'Periconia', 'Fungus'), ('f', 'Acrodictys', 'Fungus'), ('g', 'Alternaria', 'Fungus'), ('h', 'Bipolaris', 'Fungus'), ('i', 'Poaceae', 'Grass'), ('j', 'Cerebella', 'Fungus'), ('k', 'Dreshlera/Helmitosporum', 'Fungus'), ('l', 'Epicoccum', 'Fungus'), ('m', 'Rusts Puccinia', 'Fungus'), ('n', 'Nigrospora', 'Fungus'), ('o', 'Hifas Fragmentos', 'Fungus'), ('p', 'Curvularia', 'Fungus'), ('q', 'Ustilago', 'Fungus'), ('r', 'Helicoma', 'Fungus'), ('s', 'Helicomina', 'Fungus'), ('t', 'Leptosphaeria-Like', 'Fungus'), ('u', 'Chaetomiun', 'Fungus'), ('v', 'Pithomyces', 'Fungus'), ('w', 'Cercospora', 'Fungus'), ('x', 'Exserohilum', 'Fungus'), ('y', 'Tetrapyrgos', 'Fungus'), ('z', 'Erysiphe/Oidium', 'Fungus');

我需要传递两个变量j.build_job('My Job Name', {'BRANCH_NAME': 'xyz', 'VERSION': '12.2' })branch,但在将输出显示为测试时,它不会将分支名称插入第一个字段。

version

以下代码:

('My Job Name', {'BRANCH_NAME': '{0}', 'VERSION': '12.2'})

2 个答案:

答案 0 :(得分:0)

试试吧。

branch="xyz"
version="12.2"

print ('My Job Name', {'BRANCH_NAME': '{0}'.format(branch) , 'VERSION': '{0}'.format(version) })
# ('My Job Name', {'BRANCH_NAME': 'xyz', 'VERSION': '12.2'})

或者在dict中设置变量:

print ('My Job Name', {'BRANCH_NAME': branch , 'VERSION': version})
# ('My Job Name', {'BRANCH_NAME': 'xyz', 'VERSION': '12.2'})

答案 1 :(得分:-1)

你的字符串不应该是这样的。

print ('My Job Name {BRANCH_NAME: {0}, VERSION {1}}'.format(branch,version))