[Tutor] Writing elements of an array to a file using CSV module

2010-10-14 Thread Hanlie Pretorius
Hi, I have a numpy array ('data') that is the result of reading a netCDF file, and it typically looks like this: array([ 0., 0., 0., 0.], dtype=float32) I want to write this, after a date and time, to a CSV file, so the CSV file would have the entry: 2000-02-01,09:00,0.0,0.0,0.0,0.0 T

Re: [Tutor] Writing elements of an array to a file using CSV module

2010-10-14 Thread Hanlie Pretorius
Hi Evert, Thanks for the reply. I've tried your suggestion and am still getting an error (posted below code). Since my posting, I've also added the code to convert the numpy array to a list. My complete script is: - # -*- coding: utf-8 -*- import pupynere import os import csv import glob de

Re: [Tutor] Writing elements of an array to a file using CSV module

2010-10-14 Thread Hanlie Pretorius
Ok, now I see what I did. Legacy from when the get_rain_data function returned precipitation and error. I forgot to remove the brackets from the 'return [precip]' statement. It works perfectly now. Thanks for all the help. 2010/10/14, Evert Rol : >> Thanks for the reply. I've tried your suggestio

[Tutor] Accessing columns of a CSV file

2010-11-17 Thread Hanlie Pretorius
Hi, I'm reading a CSV file and I want to test the contents of its second column before I write it to an output file: >>> import csv >>> time_list=['00:00', '03:00', >>> '06:00','09:00','12:00','15:00','18:00','21:00'] >>> readfile='C8R004_flow.csv' >>> in_text=open(readfile,'rb') >>> cr=csv.read

[Tutor] Accessing a DLL from python

2011-03-01 Thread Hanlie Pretorius
Hi Python Tutors, I'm using a storm water modelling program, EPA SWMM, to model the hydrology and hydraulics of a study area. SWMM reports its results in a binary (.out) file that contains the results for each element in the model at each time step in the model run. According to the SWMM interfac

Re: [Tutor] Accessing a DLL from python

2011-03-01 Thread Hanlie Pretorius
I see that I have misread the manual and that I need to reproduce the code in the C example in python. The SWMM DLL doesn't contain ready-made functions to open files etc. Apologies for posting before I was completely sure of the problem. Hanlie 2011/3/1, Hanlie Pretorius : > Hi Pytho

Re: [Tutor] Accessing a DLL from python

2011-03-01 Thread Hanlie Pretorius
Can anyone perhaps suggest the easiest way of translating the C code into Python, bearing in mind that I'm rather a beginner? Thanks Hanlie 2011/3/1, Hanlie Pretorius : > I see that I have misread the manual and that I need to reproduce the > code in the C example in python. The SWMM

[Tutor] Reading .gz files

2011-07-29 Thread Hanlie Pretorius
Hi, I'm working on Windows XP with Python 2.6. I need to read and process hundreds of binary files that are in the .gz archive format. I found a site (http://www.doughellmann.com/PyMOTW/gzip/) and tried their code with two files: one of the hundreds of files that I need to process (f1 below) and