Python Forum

Full Version: format dtype
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, 
I am struggling with a very basic problem. While reading or writing a data file, some times I need to define the format... normally I can do it as dype = float, or dtype = 'U6' etc. however if there is several columns, like say 20, I do not want to write dype = float, float, float .... 20 times. But I am unable to write it in a format like float*20 or float,20...  I found that I can write (float,20), which gives no error. But then the data that I read takes all the entries as 1 column, instead of reading it as 20 separate columns. 
If I have confused the question, I am giving an example:
I want to read say a file like this 3 rows and 3 columns:

'cow'  'book'  'top'
'dog'  'pen'  'down'
'lion'  'paper'  'left'


The dtype = 'U4','U4','U4'  reads a matrix of 3 rows and 3 columns, where as dype = ('U4',3) reads 3 rows with 1 column in each row. 
Any suggestion is very welcome. Thanks in advance.
What's a dtype? Are you using some sort of external library for reading files?
Do you mean DWORD ? (As in C)