473,836 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

split with "*" in string and ljust() puzzles

I have couple of puzzles in my code.

def load_headers( group_info ):

if os.path.isfile( group_info.poin ter_file ):
ptr_file = open( group_info.poin ter_file, "r" )
else:
print group_info.mess _list
return
linecount = 0
ptr_file.seek( 512 )
print ptr_file.tell()
line = ptr_file.readli ne()
while line != "" :
if line[0:1] == "<":
print linecount
print len(line), line
print line.split( " ", 3 )

group_info.mess _list.append( line.split( " ", 3 ) )
line = ptr_file.readli ne()
ptr_file.close( )

when reading the following line from file:
<Jo************ ***@newsfe2-gui.ntli.net> 2338 * Re: PCB Pad Size for TQFP Package??

the split command returns
['<Jo*********** ****@newsfe2-gui.ntli.net> ','','','2338 * Re: PCB Pad Size for TQFP Package??']

instead of
['<Jo*********** ****@newsfe2-gui.ntli.net>, '2338', '*','Re: PCB Pad Size for TQFP Package??']

I have just (finally) realized that it is splitting and removing on single space but that seams useless, and split items 1 and 2 are empty strings not spaces?? regex somewhere it shouldn't be?

The other problem
is in this piece of code which is trying to pad the first 512 bytes:

line = group_info.grou p_name+" sf"+ group_info.firs t + " sl"+ \ group_info.last + " sc" + group_info.coun t + "dt" + \ group_info.date _checked + group_info.time _checked
line = line + "\n"
line = string.ljust( line, 512 - len(os.linesep) )
print len( os.linesep )
line += "\n"
print len( line )
ptr_file.write( line )
print "**** "+repr(ptr_file .tell())+ " ****"
print "message list\n"

the ljust function returns string 511 bytes long, besides the fact that the logic is not exactly correct what is going on here. Is ljust trying to be smart about the EOL inside the string already?

I have tried the following, which should be about right ( account for the 1 bytes added after justification and two added by file write.)

line = string.ljust( line, 512 - len(os.linesep) - len(os.linesep) - 1 )

But, in this case I end up 2 bytes short of 512.

Thanks for any help.
Jun 14 '06 #1
3 1526
Sambo wrote:
I have just (finally) realized that it is splitting and removing
on single space but that seams useless, and split items
1 and 2 are empty strings not spaces??


What is useless for you is worth $1,000,000 for somebody else ;)
If you have comma separated list '1,,2'.split(', ') naturally returns
['1', '', '2']. I think you can get what you want with a simple regexp.

Jun 15 '06 #2
Serge Orlov wrote:
Sambo wrote:
I have just (finally) realized that it is splitting and removing
on single space but that seams useless, and split items
1 and 2 are empty strings not spaces??


What is useless for you is worth $1,000,000 for somebody else ;)
If you have comma separated list '1,,2'.split(', ') naturally returns
['1', '', '2']. I think you can get what you want with a simple regexp.


No need for regexp in this case, just use None to specify one or more
whitespace chars as delimiter: line.split(None ,3)

George

Jun 15 '06 #3
George Sakkis wrote:
Serge Orlov wrote:

Sambo wrote:
I have just (finally) realized that it is splitting and removing
on single space but that seams useless, and split items
1 and 2 are empty strings not spaces??


What is useless for you is worth $1,000,000 for somebody else ;)
If you have comma separated list '1,,2'.split(', ') naturally returns
['1', '', '2']. I think you can get what you want with a simple regexp.

No need for regexp in this case, just use None to specify one or more
whitespace chars as delimiter: line.split(None ,3)

George

AHA! Thank You.
Jun 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
31187
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it will split myString up using the delimiter of 1 space so that
1
2486
by: Sam Johnson | last post by:
Hi I've seen that the string classes in the .net framework have a cool (new?) function: splitting strings and returning the substrings in an array. Is there any equivalent to this in "old-style" MFC C++? Thanks Sam
0
507
by: pmarisole | last post by:
I am using the following code to split/join values in a multi-select field. It is combining all the values in All the records into one long string in each record in recordset. Example: I have a recordset with 2 records. The 1st contains the split/joined values: Alan Smir, Jeff Karl The 2nd contains the value: Keith Robb When it updates database, it will put Alan Smir, Jeff Karl, Keith Robb into each record in the recordset
6
3446
by: py_genetic | last post by:
Hi, I'm looking to generate x alphabetic strings in a list size x. This is exactly the same output that the unix command "split" generates as default file name output when splitting large files. Example: produce x original, but not random strings from english alphabet, all lowercase. The length of each string and possible combinations is
12
3338
blazedaces
by: blazedaces | last post by:
Hello again. I'm trying to take as an input an ArrayList<String> and utilize String's .spit(delimiter) method to turn that into a String. I'm getting some kind of error though (I'll post the code and error lower down). Here's a simple example: Input ArrayList would be: ArrayList<String> temp = new ArrayList<String>(2); temp.add("headerTest\\headerSectionTest\\"); temp.add("headerTest\\start-time\\sameLastPartTest"); ...
7
3497
by: Johny | last post by:
I have a string of a variable length and I need to split the string in strings of 6 characters . But if the 6th character is not space then I must split the string at possition before the 6th character. For example: if the main string S is S='abcde fghc ijkl mnop'
5
2536
by: shaiful | last post by:
Hi all I have a simple problem with string. I want to split string, such as: dim s as string dim k(3) as string s="aa1,bv1,cc1,dt1" i want to split the value in k, k(0)=aa1 k(1)=bv1 k(2)=cc1 k(3)=dt1
7
5394
by: spoken | last post by:
Hi, I'm trying to read a file with data seperated by "|" character. Ex: 3578.27|2001|Road Bikes|Metchosin|Canada 3399.99|2001|Mountain Bikes|Pantin|France 3399.99|2001|Mountain Bikes|Lebanon|United States After reading the first line, I'm trying to split the string into an array by doing
4
10284
by: dmitrey | last post by:
hi all, howto split string with both comma and semicolon delimiters? i.e. (for example) get from string "a,b;c" I have tried s.split(',;') but it don't work Thx, D.
4
7736
by: N9 | last post by:
Hi Anyone who can help about split string. string text = "History about a boy, who loves to play baseball with his friends." I like to find indexOf "play" and read the string 10 char left and 10 char right
0
9671
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10846
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10551
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9379
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7793
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4021
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.