Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37659 > unrolled thread

create object base on text file

Started bymoonhkt <moonhkt@gmail.com>
First post2013-01-25 04:06 -0800
Last post2013-01-25 07:28 -0800
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  create object base on text file moonhkt <moonhkt@gmail.com> - 2013-01-25 04:06 -0800
    Re: create object base on text file Dave Angel <d@davea.name> - 2013-01-25 08:04 -0500
      Re: create object base on text file cxleung@gmail.com - 2013-01-25 07:28 -0800
      Re: create object base on text file cxleung@gmail.com - 2013-01-25 07:28 -0800

#37659 — create object base on text file

Frommoonhkt <moonhkt@gmail.com>
Date2013-01-25 04:06 -0800
Subjectcreate object base on text file
Message-ID<c52b8fa5-1289-40e9-92e1-66c51c6e3ef1@qi8g2000pbb.googlegroups.com>
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

[toc] | [next] | [standalone]


#37660

FromDave Angel <d@davea.name>
Date2013-01-25 08:04 -0500
Message-ID<mailman.1034.1359119092.2939.python-list@python.org>
In reply to#37659
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

[toc] | [prev] | [next] | [standalone]


#37673

Fromcxleung@gmail.com
Date2013-01-25 07:28 -0800
Message-ID<c0d7e406-02c7-4164-8427-cb1646f688d5@googlegroups.com>
In reply to#37660
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


[toc] | [prev] | [next] | [standalone]


#37674

Fromcxleung@gmail.com
Date2013-01-25 07:28 -0800
Message-ID<mailman.1042.1359128462.2939.python-list@python.org>
In reply to#37660
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


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web