473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

formating elements in a string

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
2 1058
bvdet
2,851 Expert Mod 2GB
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
ghostdog74
511 Expert 256MB
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

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

Similar topics

0
by: rodrigo guerra | last post by:
where i can change the code formating that visual studio does in the code.... like if i type: if ( ) { .... } visual studio changes to:
4
by: djc | last post by:
Is there a property or method of the textbox web server control that I can use to format the text in it a certian way. For example I am displaying a date value from a database in a text box. It...
3
by: Tina | last post by:
I have a datagrid where I specified {0:###,###,###} at design time. However sometimes I am putting percentages in the grid instead of money and I want to change the formating to {##%}. I've...
3
by: Smiley | last post by:
Hi, I know how to do confitional formating in Excel by clicking the wizard. Is this possible in MS Access ? If so, please directly where to look. I found example but nothing as to how to do it....
12
tolkienarda
by: tolkienarda | last post by:
hi all I am working on a content management service and i need some help keeping formating. what i am doing is recreating my site in an admin side and all of the articles on the site will...
1
by: Shawn Northrop | last post by:
I just read an article on kirupa.com about incorporating mySQL and PHP with flash. I am dynamically loading conent into a flash movie and am not sure how to format. In my php code i have: $y = "";...
0
by: Fonix | last post by:
I'm trying to make table border with pyExcelerator. As i can see there is only cell formating!? If i'm wrong pls tell me what is method to make more then one cell to have same format, other then...
2
by: sitko | last post by:
Hi, I'm in the process of converting a VB.net program into a C program so it can run on a unix like machine. I've been moving along at a nice pace, but this conversion has stumped me. I need...
1
by: nico | last post by:
Hi, I need to do a lot of string formating, and I have strings and/or unicode strings and when I do the following: "%s %s" % (u'Salut', 'H\xe4llo'), I get an exception : UnicodeDecodeError:...
4
by: =?Utf-8?B?QnJhc3NpY2FOaWdyYQ==?= | last post by:
Greetings, I am writing an application that prepares a quotation for a customer. The calculations are done in a SQL Server stored procedure. I use a datareader to fetch the record, but cannot...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.