/    Sign up×
Community /Pin to ProfileBookmark

Python Question

I have 50 files, all in the same sort of format, which I would like to read into arrays in python.

The files look like this:
xa “t” xb “” trapX “t” ext “t” absolute
: : : : :
: : : : :
: : : : :
N N N N N
There is a title line and then all other entries are doubles, separated by a tab delimeter
So what I want is an array for each of the entries in the file, like:

xa[50][0-N]
xb[50][0-N]
trapX[50][0-N] and so forth
the entreis should ideadlly be numpy duoubles.
The N, ie number of rows in each file may vary, but there is the same amount of data for each observable.
Files have names as: file.1.dat, file.2.dat etc

What is the best way of extracting the data out of these files? This will have to be done in python.

Thanks

to post a comment

1 Comments(s)

Copy linkTweet thisAlerts:
@armani_joeApr 17.2019 — You can read a file by line with the following method:
``<i>
</i>for line in open(filename):
listWords = line.split(" ")<i>
</i>
``
×

Success!

Help @Monev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...