create object base on text file

Dave Angel d at davea.name
Fri Jan 25 08:04:31 EST 2013


On 01/25/2013 07:06 AM, moonhkt wrote:
> Hi All
>
> Python 2.6.x on AIX
>
> Data file
>
> PrinterA
>        print Production batch1
>               xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>        print Production batch2
>               xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>        print Production batch3
>             xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> PrinterB
>       print Production batch4
>             xxxxxxxxxxxxxxxxxxxxxxxxxxx
>        print Production batch5
>            xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
>
> What to using python create object base on date file ? I know how to
> read text file.
>
> object["PrinterA"] have  batch1,  batch2,  batch3
>
> object["PrinterB"] have  batch4, batch5
>
> moonhkt
>

What Python version are you targeting?

It would save everyone a lot of time if you quoted the homework 
assignment directly.  Also, be more careful about typos.  Is it a date 
file, or a data file?

You can create an object very easily.  a = object().  You can add 
attributes to many objects by simply saying
     a.attrib = 42

Unfortunately you can't do that to an "object" class instance.  So you 
need to clarify.

Now, you used dictionary syntax, so perhaps you didn't mean create an 
object, but create a dict.

a = dict()
a["PrinterA"] = "batch1", "batch2", "batch3"
print a

produces
{'PrinterA': ('batch1', 'batch2', 'batch3')}


What part of the assignment is giving you trouble?  What have you 
written so far?


-- 
DaveA



More information about the Python-list mailing list