Python help for a C++ programmer

mlimber mlimber at gmail.com
Wed Jan 16 09:23:10 EST 2008


I'm writing a text processing program to process some survey results.
I'm familiar with C++ and could write it in that, but I thought I'd
try out Python. I've got a handle on the file I/O and regular
expression processing, but I'm wondering about building my array of
classes (I'd probably use a struct in C++ since there are no methods,
just data).

I want something like (C++ code):

 struct Response
 {
   std::string name;
   int age;
   int iData[ 10 ];
   std::string sData;
 };

 // Prototype
 void Process( const std::vector<Response>& );

 int main()
 {
   std::vector<Response> responses;

   while( /* not end of file */ )
   {
     Response r;

     // Fill struct from file
     r.name = /* get the data from the file */;
     r.age = /* ... */;
     r.iData[0] = /* ... */;
     // ...
     r.sData = /* ... */;
     responses.push_back( r );
   }

    // Do some processing on the responses
    Process( responses );
 }

What is the preferred way to do this sort of thing in Python?

Thanks in advance! --M



More information about the Python-list mailing list