I'm a newbie! I have a non-delimited data file that I'd like to
convert to delimited.
Example...
Line in non-delimited file:
0139725635999992000010100534+42050-102800FM-15+1198KAIA
Should be:
0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
What is the best way to go about this? I've looked all over for
examples, help, suggestions, but have not found much. CSV module
doesn't seem to do exactly what I want. Maybe I'm just missing
something or not using the correct terminology in my searches. Any
assistance is greatly appreaciated! Using Python 2.4 5 2301
* RyanL wrote (on 8/27/2007 10:59 AM):
I'm a newbie! I have a non-delimited data file that I'd like to
convert to delimited.
Example...
Line in non-delimited file:
0139725635999992000010100534+42050-102800FM-15+1198KAIA
Should be:
0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
What is the best way to go about this? I've looked all over for
examples, help, suggestions, but have not found much. CSV module
doesn't seem to do exactly what I want. Maybe I'm just missing
something or not using the correct terminology in my searches. Any
assistance is greatly appreaciated! Using Python 2.4
Since you have to know, a priori, how to break the input string I
assume that these fields are of fixed length. You can use the following
to do what you want:
>>a="0139725635999992000010100534+42050-102800FM-15+1198KAIA" print "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" %
(a[0:4],a[4:10],a[10:15],a[15:19],a[19:21],a[21:23],a[23:25],
a[25:27],a[27],a[28:34],a[34:41],a[41:46],a[46:51],a[51:])
which results in the following output:
0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
Mark
On Aug 27, 1:35 pm, Mark Elston <m.els...@advantest-ard.comwrote:
* RyanL wrote (on 8/27/2007 10:59 AM):
I'm a newbie! I have a non-delimited data file that I'd like to
convert to delimited.
Example...
Line in non-delimited file:
0139725635999992000010100534+42050-102800FM-15+1198KAIA
Should be:
0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
What is the best way to go about this? I've looked all over for
examples, help, suggestions, but have not found much. CSV module
doesn't seem to do exactly what I want. Maybe I'm just missing
something or not using the correct terminology in my searches. Any
assistance is greatly appreaciated! Using Python 2.4
Since you have to know, a priori, how to break the input string I
assume that these fields are of fixed length. You can use the following
to do what you want:
>>a="0139725635999992000010100534+42050-102800FM-15+1198KAIA"
>>print "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" %
(a[0:4],a[4:10],a[10:15],a[15:19],a[19:21],a[21:23],a[23:25],
a[25:27],a[27],a[28:34],a[34:41],a[41:46],a[46:51],a[51:])
which results in the following output:
0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
Mark
Or try this:
import struct
test = '0139725635999992000010100534+42050-102800FM-15+1198KAIA'
template = '4s6s5s4s2s2s2s2s1s6s7s5s5s4s'
the_line = struct.unpack(template,test)
print the_line
print ','.join(the_line)
## ('0139', '725635', '99999', '2000', '01', '01', '00', '53', '4',
'+42050', '-102800', 'FM-15', '+1198', 'KAIA')
##
##
0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
On Aug 27, 10:59 am, RyanL <ryanlaurit...@gmail.comwrote:
I'm a newbie! I have a non-delimited data file that I'd like to
convert to delimited.
Example...
Line in non-delimited file:
0139725635999992000010100534+42050-102800FM-15+1198KAIA
Should be:
0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
What is the best way to go about this? I've looked all over for
examples, help, suggestions, but have not found much. CSV module
doesn't seem to do exactly what I want. Maybe I'm just missing
something or not using the correct terminology in my searches. Any
assistance is greatly appreaciated! Using Python 2.4
I don't think you are going to find anything that will just do this
for you. You are going to have read the file, figure out where to
split the string, and reprint it delimited with commas. As for
suggesting code... I can't tell how you actually want to delimit the
stuff from the above example? Are the fields always a fixed number of
characters? If they aren't then is there some other method for
determining how many characters to group into a field? From the looks
of it you could split that string any way you want and get something
that looks right, but isn't.
Matt
On 2007-08-27, RyanL <ry***********@gmail.comwrote:
I'm a newbie! I have a non-delimited data file that I'd like to
convert to delimited.
Example...
Line in non-delimited file:
0139725635999992000010100534+42050-102800FM-15+1198KAIA
Should be:
0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
It looks like a fixed format data file, also called flat-record
files, in which fields are of fixed lengths, and records are
separated by newlines.
What is the best way to go about this?
Check out chapter 2 of _Text Processing in Python_ for one
solution. http://gnosis.cx/TPiP/chap2.txt
--
Neil Cerutti
Weight Watchers will meet at 7 p.m. Please use large double door at the side
entrance. --Church Bulletin Blooper
On Aug 27, 2007, at 10:59 AM, RyanL wrote:
I'm a newbie! I have a non-delimited data file that I'd like to
convert to delimited.
Example...
Line in non-delimited file:
0139725635999992000010100534+42050-102800FM-15+1198KAIA
Should be:
0139,725635,99999,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
What is the best way to go about this? I've looked all over for
examples, help, suggestions, but have not found much. CSV module
doesn't seem to do exactly what I want. Maybe I'm just missing
something or not using the correct terminology in my searches. Any
assistance is greatly appreaciated! Using Python 2.4
Is each data element a fixed size? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Lauren Quantrell |
last post by:
I have a stored procedure using Convert where the exact same Convert
string works in the SELECT portion of the procedure but fails in the
WHERE portion.
The entire SP is listed below....
|
by: Sydex |
last post by:
When I compile code I get error
C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double
(double)' to 'double (__cdecl *)(double)'
in this part :
double Integration::quad2d(double...
|
by: Convert TextBox.Text to Int32 Problem |
last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
|
by: simon |
last post by:
I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM"
Now I need to convert this to dateTime. Any function I use: Convert.ToDateTime(string) or Cdate(string), I get an error...
|
by: Friso Wiskerke |
last post by:
Hi all,
I'm creating a fixed length textfile with data which is sent out to a
third-party which in turn reads the file and processes it. Some of the
characters are not part of the lower ASCII...
| |
by: Steven Woody |
last post by:
somewhere in my code,
char* rtnStrs = { "ok", "error", NULL };
foo( rtnStrs );
here, foo was decleared as 'void foo( const char * rtnStrs ).
but the gcc compiler will report ' can not...
|
by: kyle.tk |
last post by:
I am trying to write a function to convert an ipv4 address that is held
in the string char *ip to its long value equivalent. Here is what I
have right now, but I can't seem to get it to work.
...
|
by: dorkrawk |
last post by:
I am having an issue with some VC++ I am writing. I have a struct and
I'm trying to call a function from it from a function in another
object.
here is the struct....
struct JNI_Interface
{...
|
by: xhy_China |
last post by:
Hi,I want to ask three questions(in vs.net and C#):
1. how can I know whether a bitmap is an indexed or non-indexed?
2. how can I convert a indexed bitmap to non-indexed bitmap?
3. how can I...
|
by: Tux SC |
last post by:
Hello,
I have a JavaScript function which receives as input a string which in
some cases contain non-UTF8 characters. The output of this function is
used by another utility which fails if it...
|
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,...
| |
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,...
|
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...
|
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...
|
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,...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |