[Tutor] Importing data from a file.

Dave Angel davea at davea.name
Thu Mar 21 15:03:45 CET 2013


On 03/21/2013 09:43 AM, Shall, Sydney wrote:
> I have an elementary question provoked by another post today.
>
> 1. Is it the case that ALL imported data from a file is a string?

No, the imported data is a module.   For example
     import sys
     print type(sys)

<type 'module'>


At this point, sys is a object of type module.

Perhaps you really mean data returned by the readline() method of the 
file object.  In that case, it's a list of strings.

Or data returned from the readline() method of the file object.  That is 
a string.

Or data returned from the read() method of the file object.  The return 
type of that depends on the version of Python.

Be more specific, since the answer greatly depends on how you read this 
data.


> 2. Does this therefor imply that said data has to be processed
> appropriately to generate the data in the form required by the program?

Again, you have to be specific.  The program might well want exactly 
what one of these methods returns.


> 3. Are there defined procedures for doing the required processing?
>

Sure, hundreds of thousands of them, most of them to be found in other 
people's programs.

Sorry, but your questions are so vague as to defy definitive answers.


-- 
DaveA


More information about the Tutor mailing list