2
 str = ""
 for i in range(1,91):
 str = str + '-'
 print "+", '{:^90}'.format(str), "+"
 for elem in cursor:
 print "|", '{:^8}'.format(elem['classid']), \
 "|", '{:^8}'.format(elem['dept']), \
 "|", '{:^8}'.format(elem['coursenum']), \
 "|", '{:^8}'.format(elem['area']), \
 "|", '{:<46}'.format(elem['title']), \
 "|"
 print "+", '{:^90}'.format(str), "+"

I have the following code in place to try and print out the results of a db query. In a standalone file, it prints the following output:

+ ------------------------------------------------------------------------------------------ +
| centered | centered | centered | centered | 12 |
| centered | centered | centered | centered | 12 |
| centered | centered | centered | centered | 12 |
+ ------------------------------------------------------------------------------------------ +

When placed in a larger file within a function, it does not work however. We get the following error:

 File "reg.py", line 58, in printHumanOutput
 print "+", '{:^90}'.format(''), "+"
ValueError: zero length field name in format

Help?

asked Feb 23, 2011 at 19:29

1 Answer 1

6

Python 2.6 does not support zero-length field names in format strings.

print "+", '{0:^90}'.format(''), "+"
answered Feb 23, 2011 at 19:38
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.