Python reading from a file


 
Thread Tools Search this Thread
Top Forums Programming Python reading from a file
# 1  
Old 06-26-2013
Python reading from a file

Hello everyone,
I've been learning some python (I was using other commercial software before), and doing plots from data stored on files as X and Y pairs has not been an issue. Know, I have some files that look like this:
Code:
<Descriptive string>
<some "random" number>
<number of X values:nx>
<Number of Y values:ny>
X1 X2 X3 X4 X5
X6 X7 X8 X9 X10
...
... Xnx
Y1 Y2 Y3 Y4 Y5
Y6 Y7 Y8 Y9 Y10
...
... Yny
Z(X1,Y1) Z(X1,Y2) Z(X1,Y3) Z(X1,Y4) Z(X1,Y5)
Z(X1,Y6) Z(X1,Y7) Z(X1,Y8) Z(X1,Y9) Z(X1,Y10)
...
... 
Z(X1,Yny) Z(X2,Y1) Z(X2,Y3) Z(X2,Y4) Z(X2,Y5)
...
...
Z(X2,Yny) ...
...
...
Z(Xnx,Yny)

So, I have not been able to read properly through the X values and store them in a list, the Y values, store them in a list and finally the Z values and store them accordingly... at the end I want to create a contour plot... but I think that won't be the biggest problem once I understand how to read this values and store them. They are written in like this, using five columns, and there is a new line (not blank, just starts a new line) when it changes from X to Y to Z.
Thank you very much,
Moderator's Comments:
Mod Comment This duplicate thread is closed.

Last edited by Don Cragun; 06-26-2013 at 05:32 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

creating separate output file for each input file in python

Experts, Need your help for this. Please support My motive is to create seperate output file for each Input Files(File 1 and File2) in another folder say(/tmp/finaloutput) Input files File 1(1.1.1.1.csv) a,b,c 43,17104773,3 45,17104234,4 File 2(2.2.2.2.csv) a,b,c 43,17104773,1... (2 Replies)
Discussion started by: as7951
2 Replies

2. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies

3. Shell Programming and Scripting

Python: Redirecting to tty and reading from tty

In bash, you can do something like this: #!/bin/bash echo -n "What is your name? " > /dev/tty read thename < /dev/tty How can I do the same in python? I have a python script that has the following content: #!/usr/bin/python2.7 import getpass import sys import telnetlib import... (2 Replies)
Discussion started by: SkySmart
2 Replies

4. Programming

Decimals reading Python

Hello, i'm new in python. Consider that i have this function that read me some data from a serial : def GetData(): line = open(serialx).read() hash = line.find("#") when = line count = line # print when, count, line return (float(when), int(count)) it gives me the result... (2 Replies)
Discussion started by: Board27
2 Replies

5. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

6. Programming

Python Reading Individual files and Regex through them

As a newbie to Python, I am trying to write a script in which is will add all the log files (*.log) from within a directory to a list, open the files and search for an ip using a regex and single it out (appending the ip's to the list). So far, I have: import re, os def list_files() content = ... (4 Replies)
Discussion started by: metallica1973
4 Replies

7. Programming

Python reading from a file

Hello everyone, I've been learning some python (I was using other commercial software before), and doing plots from data stored on files as X and Y pairs has not been an issue. Know, I have some files that look like this: <Descriptive string> <some "random" number> <number of X values:nx>... (0 Replies)
Discussion started by: jaldo0805
0 Replies

8. Shell Programming and Scripting

Help Reading XML files in Python: Urgent

OK so my objective is to create a python program that will parse an XML file(input.xml), then the program will create an mxml(output.mxml) file. In the program (.py) i need to read between CDATA so that I would get an output the CDATA code in the input.xml INPUT.XML <!]> ... (2 Replies)
Discussion started by: dcfivesixfive
2 Replies

9. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies
Login or Register to Ask a Question