473,325 Members | 2,805 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,325 software developers and data experts.

Reading selected data from text files

Hello Pythoners!

There are a lot of files containing data such as:

file1:
0950 1550

file22:
0952 1552

file3:
1000 1020 1050 1130 1150 1200 1245 1600

file4:
1002 1022 1052 1132 1152 1202 1247 1602

file5:
1005 1025 1055 1135 1155 1205 1250 1605

I want to read from them only that data which produce a following sequence
of data:
=> 0950 0952 1000 1002 1005
=> 1555 1557 1600 1602 1605
--
...:: sjf ::..
"Linux is like Wigwam. No gates, no windows... Apache inside ;-)"
Jul 18 '05 #1
6 1640
>>>>> "..:: sjf ::.." <sj*@autograf.pl> (SJF) wrote:

SJF> Hello Pythoners!
SJF> There are a lot of files containing data such as:

SJF> file1:
SJF> 0950 1550

SJF> file22:
SJF> 0952 1552

SJF> file3:
SJF> 1000 1020 1050 1130 1150 1200 1245 1600

SJF> file4:
SJF> 1002 1022 1052 1132 1152 1202 1247 1602

SJF> file5:
SJF> 1005 1025 1055 1135 1155 1205 1250 1605

SJF> I want to read from them only that data which produce a following sequence
SJF> of data:
SJF> => 0950 0952 1000 1002 1005
SJF> => 1555 1557 1600 1602 1605

How do you get at these values, as 1555 and 1557 aren't in your input files?
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.***********@hccnet.nl
Jul 18 '05 #2
Użytkownik "Piet van Oostrum" <pi**@cs.uu.nl> napisał w wiadomości
news:wz************@Ordesa.local...
>> "..:: sjf ::.." <sj*@autograf.pl> (SJF) wrote:


SJF> Hello Pythoners!
SJF> There are a lot of files containing data such as:

SJF> file1:
SJF> 0950 1550

SJF> file22:
SJF> 0952 1552

SJF> file3:
SJF> 1000 1020 1050 1130 1150 1200 1245 1600

SJF> file4:
SJF> 1002 1022 1052 1132 1152 1202 1247 1602

SJF> file5:
SJF> 1005 1025 1055 1135 1155 1205 1250 1605

SJF> I want to read from them only that data which produce a following
sequence SJF> of data:
SJF> => 0950 0952 1000 1002 1005
SJF> => 1555 1557 1600 1602 1605

How do you get at these values, as 1555 and 1557 aren't in your input
files?


ups...
of course it should be:
=> 0950 0952 1000 1002 1005
=> 1600 1602 1605
--
...:: sjf ::..
"Linux is like Wigwam. No gates, no windows... Apache inside ;-)"

Jul 18 '05 #3
"..:: sjf ::.." <sj*@autograf.pl> wrote in message
news:c1**********@nemesis.news.tpi.pl...
Hello Pythoners!

There are a lot of files containing data such as:

file1:
0950 1550

file22:
0952 1552
<snip> --
..:: sjf ::..
"Linux is like Wigwam. No gates, no windows... Apache inside ;-)"

Try this:

import sets
import os

uniqueElems = sets.Set()

testdata = """
0950 1550
0952 1552
1000 1020 1050 1130 1150 1200 1245 1600
1002 1022 1052 1132 1152 1202 1247 1602
1005 1025 1055 1135 1155 1205 1250 1605
"""
for line in testdata.split("\n"):
uniqueElems.update( line.split() )
# if running Python 2.3.1 or later, replace previous line with
# uniqueElems |= line.split()

print uniqueElems
elemList = list(uniqueElems)
elemList.sort()
print elemList

# to process all files in directory fileDir
#
#for fnam in os.listdir(fileDir):
# for line in file(fnam):
# uniqueElems.update( line.split() )
Good luck,
-- Paul
Jul 18 '05 #4
Użytkownik "Piet van Oostrum" <pi**@cs.uu.nl> napisał w wiadomości
news:wz************@Ordesa.local...
>> "..:: sjf ::.." <sj*@autograf.pl> (SJF) wrote:


SJF> Hello Pythoners!
SJF> There are a lot of files containing data such as:

SJF> file1:
SJF> 0950 1550

SJF> file22:
SJF> 0952 1552

SJF> file3:
SJF> 1000 1020 1050 1130 1150 1200 1245 1600

SJF> file4:
SJF> 1002 1022 1052 1132 1152 1202 1247 1602

SJF> file5:
SJF> 1005 1025 1055 1135 1155 1205 1250 1605

SJF> I want to read from them only that data which produce a following
sequence SJF> of data:
SJF> => 0950 0952 1000 1002 1005
SJF> => 1555 1557 1600 1602 1605

How do you get at these values, as 1555 and 1557 aren't in your input
files?


ups...
of course it should be:
=> 0950 0952 1000 1002 1005
=> 1550 1552 1600 1602 1605
--
...:: sjf ::..
"Linux is like Wigwam. No gates, no windows... Apache inside ;-)"

Jul 18 '05 #5
Użytkownik "Paul McGuire" <pt***@users.sourceforge.net> napisał w wiadomości
news:MV*****************@fe2.texas.rr.com...
"..:: sjf ::.." <sj*@autograf.pl> wrote in message
news:c1**********@nemesis.news.tpi.pl...
Hello Pythoners!

There are a lot of files containing data such as:

file1:
0950 1550

file22:
0952 1552

<snip>
--
..:: sjf ::..
"Linux is like Wigwam. No gates, no windows... Apache inside ;-)"

Try this:

import sets
import os

uniqueElems = sets.Set()

testdata = """
0950 1550
0952 1552
1000 1020 1050 1130 1150 1200 1245 1600
1002 1022 1052 1132 1152 1202 1247 1602
1005 1025 1055 1135 1155 1205 1250 1605
"""
for line in testdata.split("\n"):
uniqueElems.update( line.split() )
# if running Python 2.3.1 or later, replace previous line with
# uniqueElems |= line.split()

^^^^^^^
OK, but what is that?
--
...:: sjf ::..
"Linux is like Wigwam. No gates, no windows... Apache inside ;-)"

Jul 18 '05 #6
"..:: sjf ::.." <sj*@autograf.pl> wrote in message
news:c1**********@atlantis.news.tpi.pl...
Użytkownik "Paul McGuire" <pt***@users.sourceforge.net> napisał w wiadomości news:MV*****************@fe2.texas.rr.com...
"..:: sjf ::.." <sj*@autograf.pl> wrote in message
news:c1**********@nemesis.news.tpi.pl...
Hello Pythoners!

There are a lot of files containing data such as:

file1:
0950 1550

file22:
0952 1552

<snip>
--
..:: sjf ::..
"Linux is like Wigwam. No gates, no windows... Apache inside ;-)"

Try this:

import sets
import os

uniqueElems = sets.Set()

testdata = """
0950 1550
0952 1552
1000 1020 1050 1130 1150 1200 1245 1600
1002 1022 1052 1132 1152 1202 1247 1602
1005 1025 1055 1135 1155 1205 1250 1605
"""
for line in testdata.split("\n"):
uniqueElems.update( line.split() )
# if running Python 2.3.1 or later, replace previous line with
# uniqueElems |= line.split()

^^^^^^^
OK, but what is that?

In 2.3.1, the Set() class defines a "|=" operator that will add all elements
of a list to the set.

Also, update() is deprecated in 2.3.1 in favor of union_update(),
intersection_update(), and, um, some other update() that I can't recall off
the top of my head, something like "negative_intersection_update" or
something.

-- Paul
Jul 18 '05 #7

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

Similar topics

1
by: Magnus | last post by:
allrite folks, got some questions here... 1) LAY-OUT OF REPORTS How is it possible to fundamentaly change the lay-out/form of a report in access? I dont really know it that "difficult", but...
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
0
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
12
by: SAL | last post by:
Hello, Is it possible to read a CSV from the Client, and bind my Datagrid to the data in the CSV file without uploading the file to the Server first? I have tried and in Debug mode on my...
10
by: Tyler | last post by:
Hello All: After trying to find an open source alternative to Matlab (or IDL), I am currently getting acquainted with Python and, in particular SciPy, NumPy, and Matplotlib. While I await the...
2
by: Ed | last post by:
Hope someone can help me out... I have been tasked to read some image data from an sql database and save the files to flat files. OK, sounds easy as I'v used BLOBs before. But this is an old...
6
by: John Wright | last post by:
I am trying to read the data from a device on a serial port. I connect just fine and can receive data fine in text mode but not in binary mode. In text mode the data from the device comes in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.