473,887 Members | 2,286 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Help Parsing From File

Hi, I've got a Python program that I'm trying to edit, and I need some
help.

If I would like to read a matrix from a previously created text file
into a two dimensional array, how would I do that?

Like, if in the txt file, I had the following matrix formatted numbers
with 5 rows and 10 columns, and each number is separated by a single space:

11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60

How would I read this data from the file into a two dimensional array in
Python?
Dec 7 '06
12 1327
Gabriel Genellina <ga******@yahoo .com.arwrote:
For the Borland C++ 3.1 help (about 1991):
If "t" or "b" is not given in the string, the mode is governed by
_fmode.
If _fmode is set to O_BINARY, files are opened in binary mode.
If _fmode is set to O_TEXT, they are opened in text mode.
MSC used to have a similar flag (perhaps using the same name).
I assume you are using 'used to have' in the sense of 'still have, although
it is now deprecated in favour of the functions _get_fmode and _set_fmode'.

John Machin wrote:
Indeed, and their docs say that the default for _fmode is text mode.
Quite apart from the scope for the program to change the value at runtime,
the default may also be changed to binary mode by linking the program with
binmode.obj.
Dec 8 '06 #11
At Friday 8/12/2006 05:30, Duncan Booth wrote:
For the Borland C++ 3.1 help (about 1991):
If "t" or "b" is not given in the string, the mode is governed by
_fmode.
If _fmode is set to O_BINARY, files are opened in binary mode.
If _fmode is set to O_TEXT, they are opened in text mode.
MSC used to have a similar flag (perhaps using the same name).
I assume you are using 'used to have' in the sense of 'still have, although
it is now deprecated in favour of the functions _get_fmode and _set_fmode'.
I meant "I have no idea whether it's still the case or not" - thanks
for the info. And I was talking about the old MSC compiler, a quite
different product from the current MSVC.
--
Gabriel Genellina
Softlab SRL

_______________ _______________ _______________ _____
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
Dec 8 '06 #12
On 2006-12-07 04:20:48 +0100, John Frame <jf****@vt.edus aid:
Hi, I've got a Python program that I'm trying to edit, and I need some help.

If I would like to read a matrix from a previously created text file
into a two dimensional array, how would I do that?

Like, if in the txt file, I had the following matrix formatted numbers
with 5 rows and 10 columns, and each number is separated by a single
space:

11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60

How would I read this data from the file into a two dimensional array
in Python?
In case you have imported pylab:

myarray = pylab.load('tex tfile.txt')

Regards
Markus

Dec 10 '06 #13

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

Similar topics

2
3966
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home Canonicalpath-Directory4: \\wkdis3\ROOT\home\bwe\ You selected the file named AAA.XML getXmlAlgorithmDocument(): IOException Not logged in
0
1582
by: Doug R | last post by:
Hello, I have a system that I am writing to automaticly import Credit Transaction data into a SQL Server 2000 Database. I am using a VB.Net application to detect when the file arives and prep it for parsing. The file is aproximately 10Mb of relatively complex hierarchal data that is defined by 2 character tokens at the begining of each data line. The structure breaks out into aproximately 6 parent-child related tables with numerous...
1
1731
by: sommarlov | last post by:
Hi everyone >From one of our systems an xml file is produced. I need to validate this file before we send it to an external system for a very lenghty process. I cannot change the xml file layout. The solution i got today is very slow, and i need help to find another solution. Here is the xml file. It consists of a list of position ids (ESTOXX50 INDEX_BM_E and FTSE INDEX_BM_E), and below that a list of tags for each position id. What i...
4
4870
by: Rick Walsh | last post by:
I have an HTML table in the following format: <table> <tr><td>Header 1</td><td>Header 2</td></tr> <tr><td>1</td><td>2</td></tr> <tr><td>3</td><td>4</td></tr> <tr><td>5</td><td>6</td></tr> </table> With an XSLT styles sheet, I can use for-each to grab the values in
27
5166
by: comp.lang.tcl | last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML file into a TCL list as follows: attr1 {val1} attr2 {val2} ... attrN {valN} This is the TCL code that does this: set contents ]; close $fileID
9
1994
by: Paulers | last post by:
Hello, I have a log file that contains many multi-line messages. What is the best approach to take for extracting data out of each message and populating object properties to be stored in an ArrayList? I have tried looping through the logfile using regex, if statements and flags to find the start and end of each message but I do not see a good time in this process to create a new instance of my Message object. While messing around with...
2
1818
by: Anders B | last post by:
I want to make a program that reads the content of a LUA array save file.. More precicely a save file from a World of Warcraft plugin called CharacterProfiler, which dumps alot of information about your characters into that save file. Anyhow, I want to extract a couple of lines of it and save it into a database and I need help on figuring out a good way of reading the file. The problem is that the file can look pretty different depending...
25
3154
by: Jon Slaughter | last post by:
I have some code that loads up some php/html files and does a few things to them and ultimately returns an html file with some php code in it. I then pass that file onto the user by using echo. Of course then the file doesn't get seen by the user. Is there any command that essentially executes the code and then echo's it? something that will take a string like '<body>blah<?php echo 'Hello'; ?></body>' and actually interpret the php
4
1911
by: Tom | last post by:
I am trying to update another developers code, and am stuck in a cludge. It works like this: A user uploads a file from the web page. Our code reads from a NetworkStream to a Filestream, and writes out a temporary file. Then the file is parsed (The file contains HTML data + the actual binary file that was transmitted). As part of the parsing, once the main binary file is to be parsed out, it is written with a new Filestream,
6
1678
by: Damien87 | last post by:
Hi, I have a .data file which is essentially just a text file with a bunch of numbers. It's in the format "xx yy zzz abc ccf fffd sss xxx xx sss qq" Basically it is a random amount of numbers per line separated using spaces (not tabs or commas). What I need to do is parse the file to a format which would be more suitable to use for a SQl database system I am implementing. I need the output file to look like "1,xx 1,yy 1,zzz
0
9957
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9799
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
11173
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
10771
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
10434
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
7143
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5810
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
6011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4239
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.