By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

formating elements in a string

P: 54
Lets say I get a results that yields

stats = ['1', '2', '3', '4', '5', '6', '7', '8']

is there a way I can i can get it to print out as:

stats = [ '1', '2', '3', '4'
'5', '6', '7', '8']

Thanks
pc
May 25 '07 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
Lets say I get a results that yields

stats = ['1', '2', '3', '4', '5', '6', '7', '8']

is there a way I can i can get it to print out as:

stats = [''1', '2', '3', '4'
'5', '6', '7', '8']

Thanks
pc
Expand|Select|Wrap|Line Numbers
  1. print "stats = %s,\n%s%s" % (repr(stats[0:4]).rstrip(']'), ' '*9, repr(stats[4:8]).lstrip('['))
>>> stats = ['1', '2', '3', '4',
'5', '6', '7', '8']
>>>

There's probably an easier way.
May 26 '07 #2

Expert 100+
P: 511
Lets say I get a results that yields

stats = ['1', '2', '3', '4', '5', '6', '7', '8']

is there a way I can i can get it to print out as:

stats = [ '1', '2', '3', '4'
'5', '6', '7', '8']

Thanks
pc
Expand|Select|Wrap|Line Numbers
  1. >>> s = "stats = ['1', '2', '3', '4', '5', '6', '7', '8']"
  2. >>> print s.replace("'4',", "'4',\n")
  3. stats = ['1', '2', '3', '4',
  4.  '5', '6', '7', '8']
  5. >>> 
  6.  
May 26 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.