I got this program that will prompt the user to enter the number. I want to import a file and have it filled. How do I do that? -
from numarray import *
-
-
def clrscr():
-
print '\n'*50
-
return
-
-
def pressenter():
-
raw_input('Press the enter key to continue')
-
return
-
-
prompt=['Enter row first number ', 'Enter row second number ']
-
-
clrscr()
-
-
rows=int(raw_input('Enter the number of rows in the array '))
-
print
-
cols=3
-
print;print
-
-
marray=zeros([rows,cols],type='f')
-
-
for row in range(0,rows,1):
-
for col in range(0,cols-1,1):
-
marray[row,col]=float(raw_input(prompt[col]))
-
print
-
-
for row in range(0,rows,1):
-
marray[row,2]=marray[row,0]*marray[row,1]
-
-
for row in range(0,rows,1):
-
print marray[row,0],marray[row,1],marray[row,2]
-
1 1913
First you need a file (say) arrays.txt which has KNOWN GOOD data in it (it is easy to protect yourself from erronious data, but I'll keep this simple). Like:
12,34 23.34 34.45
45.56 56.67 78.99
then you need to open that file: -
arrayFile = open('arrays.txt') # get file object
In order to dimension the array statically, you'll need the number of lines in the file and you need the lines later, so you might as well make it into a list: - arrayList = arrayFile.readlines()
-
arrayFile.close()
-
nRows = len(arrayList) # now you can dimension your array from nRows
-
for i, row in enumerate(arrayList):
-
floatList = [float(f) for f in row.split()] # can be tabs or spaces. newlines are stripped off
-
for j, float in enumerate(floatList):
-
array(i,j) = float
That's the basics. There are better way and this has not been tested. See if you can make it work with your arrays.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Steve Holden |
last post by:
I'm trying to load module code from a database, which stores for each
module its full name, code, load date and a Boolean indicating whether
it's a package or not.
The following simple program:...
|
by: osmethod |
last post by:
Hello,
I'd appreciate any help which is offered to my problem. I'm using
Acess 97.
I have a flat text file which lists names and addresses. Sometimes,
these can be 4 lines and sometimes 5...
|
by: musicloverlch |
last post by:
I need to import 60 text files all in one folder. Can I use VBA to
cycle through all the files, without having to import them one by one?
Does anyone have an example?
Thanks in advance.
Laura
|
by: maxim mat |
last post by:
Hi
I need to build client for web service.
But when I'm using Visual Studio .NET to add Web Reference, I get error:
"Custom tool error: Unable to import WebService/Schema. Unable to import...
|
by: scythetleppo |
last post by:
I am new thanks for the help.
I have a text file set up like this:
word1a<tab>word2a<tab>word3a<tab>word4a
word1b<tab>word2b<tab>word3b<tab>word4b
word1c<tab>word2c<tab>word3c<tab>word4c
I...
|
by: jao.sanien |
last post by:
Hi all
I was wondering if it was possible to some how import .DAT files into
access form?
I have over 500 DAT files which contains infomation about various
components and I wouldn't want to...
|
by: DONE1 |
last post by:
Hello,
I am trying to import 4 separate csv files from 4 different servers into an excel sheet.I want to write a macro which will automate this.Also, i want to append the name of the server for each...
|
by: Kanis |
last post by:
Hi,
I am a Python beginner and using PyCrust to process data for my research work.
I found I not able to import a .py file directly. But I have to type in every lines every time. Or I can save...
|
by: Romulo NF |
last post by:
Greetings again to everyone,
Im back to show this grid componenet i´ve developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data,...
|
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: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |