[Tutor] Constructing a object

Dwight Hutto dwightdhutto at gmail.com
Wed Sep 12 06:30:01 CEST 2012


On Tue, Sep 11, 2012 at 10:23 PM, Ashley Fowler <afowler2 at broncos.uncfsu.edu
> wrote:

>  How do you construct a object using variables?
>
>  For instance I have to construct a student object, by first prompting
> the user to enter variables for the Student class (their first and last
> names, credits and gpa) then construct a Student object using those
> variables.
>



>   First you want to collect the variables from the user, like so:
>
>>> student_first_name = raw_input("Enter First Name: ")
Enter First Name: David
>>>

Then I would init the class with these variable, and return a tuple, or
dict.

If I'm getting the question you're asking correctly. Except I'd just use a
function to call(instead of a class, but this might be the assignment given
to you), and collect it there, then write the data to a db, or a custom db
file.


Or you could call the class without init, then go through the input in
different functions by defining them as self.first_name = raw_input("Enter
First Name: "), collect those into a return value, and pass them through
another function/class that inserted the data into a db.
-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120912/6ff89fc6/attachment-0001.html>


More information about the Tutor mailing list