Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > create object base on text file

Reply
Thread Tools

create object base on text file

 
 
moonhkt
Guest
Posts: n/a
 
      01-25-2013
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
 
Reply With Quote
 
 
 
 
Dave Angel
Guest
Posts: n/a
 
      01-25-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
 
Reply With Quote
 
 
 
 
cxleung@gmail.com
Guest
Posts: n/a
 
      01-25-2013
On Friday, January 25, 2013 9:04:31 PM UTC+8, Dave Angel wrote:
> 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


Thank I get the methods.
Python 2.6.2

I just leaning python , before using gawk/ksh.

#!/usr/bin/env python

a= dict()
a["PrintA"]= ["batch1","batch2","batch3"]
a["PrintB"] = ["batch4","batch5"]

a["PrintA"].append("batch6")

print a
for k in sorted(a.keys()):
for j in sorted(a[k]):
print k , j

Output
{'PrintA': ['batch1', 'batch2', 'batch3', 'batch6'], 'PrintB': ['batch4', 'batch5']}
PrintA batch1
PrintA batch2
PrintA batch3
PrintA batch6
PrintB batch4
PrintB batch5



 
Reply With Quote
 
cxleung@gmail.com
Guest
Posts: n/a
 
      01-25-2013
On Friday, January 25, 2013 9:04:31 PM UTC+8, Dave Angel wrote:
> 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


Thank I get the methods.
Python 2.6.2

I just leaning python , before using gawk/ksh.

#!/usr/bin/env python

a= dict()
a["PrintA"]= ["batch1","batch2","batch3"]
a["PrintB"] = ["batch4","batch5"]

a["PrintA"].append("batch6")

print a
for k in sorted(a.keys()):
for j in sorted(a[k]):
print k , j

Output
{'PrintA': ['batch1', 'batch2', 'batch3', 'batch6'], 'PrintB': ['batch4', 'batch5']}
PrintA batch1
PrintA batch2
PrintA batch3
PrintA batch6
PrintB batch4
PrintB batch5



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why should base class object points to derived class object (virtualfunction question) ? DanielJohnson C++ 7 01-17-2009 10:15 PM
slicing - copying or assigning derived object to base object subramanian100in@yahoo.com, India C++ 1 04-22-2008 02:55 PM
Assinging a base object to an inherited object bg_ie@yahoo.com C++ 2 04-02-2007 03:34 PM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Passing derived class object array in place of base class object array justanotherguy63@yahoo.com C++ 9 12-03-2004 10:57 PM



Advertisments