[Tutor] Odd problem with variable substitution and command execution

2005-04-13 Thread Robert, Andrew
Hi Everyone,

I am trying to do an MQ inquiry but I am having mixed results.

If I do the command direct via a print statement like the one below, it
works,


print 'Queue Description:\t' , q.inquire(CMQC.MQCA_Q_DESC)


When I try to cycle through an array of command line supplied keys, it
fails.


while counter < arg_array_size:
arg1=valid_keys[sys.argv[counter]]
arg2 = 'q.inquire(CMQC.'+valid_keys[sys.argv[counter]]+')'
print arg1," ",arg2
counter = counter +1

Variable arg1 successfully mines the dictionary to return the key it is
looking for.

Variable arg2 successfully forms the q command like you see in the print
statement above.

When I do the print statement, the value of arg2 is printed instead of
being executed.

Does anyone know how to get around this problem?

Thank you, 
Andrew Robert 
Systems Architect 
Information Technologies
MFS Investment Management
Phone:  617-954-5882 
Pager:   781-945-1742
E-mail:  [EMAIL PROTECTED] 
Linux User Number: #201204 



"MFS Relay Service" made the following
 annotations on 04/13/2005 11:02:45 AM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problem installing the Pymqi module

2005-04-07 Thread Robert, Andrew
Hi Everyone,


I've tried installing the pymqi Python module on Windows but no luck so
far.

Has anyone had any success in doing this?

Any help you can provide on this would be greatly appreciated.


To install the module under Python v2.4, I did the following steps:

1. Download MinGW Gcc from http://mingw.org

2. Install MinGW GCC

3. Edit path and add GCC area c:\MinGW\bin

4. Verify that GCC is functioning

   c:\ gcc --version

5. Download pexports from
http://starship.python.net/crew/kernr/mingw32/. 

6. Extract pexports to C:\pexports

7. Add C:\pexports\pexports-0.42h\bin to path 

8. Locate the file python2?.dll 

   On windows XP with Python v2.4 installed, it is typically found as 
C:\WINDOWS\system32\python24.dll

9. Open a command prompt

10. Change your working directory to C:\WINDOWS\system32

11. Extract all of the symbols from the Python library


C:\WINDOWS\system32\ pexports python24.dll > python24.def 

12. Create a new python library

C:\WINDOWS\system32\dlltool --dllname python24.dll --def
python24.def --output-lib libpython24.a


The dlltool command is part of the MinGW utilities

13. Copy the newly created python library to its permanent location

C:\WINDOWS\system32\copy libpython24.a C:\Python24\lib


14. Download pymqi from
http://prdownloads.sourceforge.net/pymqi/pymqi-0.5c.tar.gz?download and
extract to c:\pymqi

15. Edit the file C:\pymqi\pymqi-0.5c\setup.py and change include_dirs
to the following path and save


C:/Program Files/IBM/WebSphere MQ/Tools/Lib


16. Open command prompt and change working directort to
C:\pymqi\pymqi-0.5c

17. Initiate a client or server build


For a client:

setup.py build -cmingw32 client

For a server:

setup.py build -cmingw32 server

In either case, I received the following compile errors.


pymqe.c:78:18: cmqc.h: No such file or directory
pymqe.c:79:19: cmqxc.h: No such file or directory
pymqe.c: In function `pymqe_MQCONN':
pymqe.c:130: `MQHCONN' undeclared (first use in this function)
pymqe.c:130: (Each undeclared identifier is reported only once
pymqe.c:130: for each function it appears in.)
pymqe.c:130: parse error before "handle"
pymqe.c:131: `MQLONG' undeclared (first use in this function)
pymqe.c:137: warning: implicit declaration of function `MQCONN'
pymqe.c:137: `handle' undeclared (first use in this function)
pymqe.c:137: `compCode' undeclared (first use in this function)
pymqe.c:137: `compReason' undeclared (first use in this function)
pymqe.c: In function `pymqe_MQCONNX':
pymqe.c:162: `MQHCONN' undeclared (first use in this function)
pymqe.c:162: parse error before "handle"
pymqe.c:163: `MQLONG' undeclared (first use in this function)
pymqe.c:166: `MQCNO' undeclared (first use in this function)
pymqe.c:166: parse error before "connectOpts"
pymqe.c:181: `options' undeclared (first use in this function)
pymqe.c:186: `MQCD_CURRENT_LENGTH' undeclared (first use in this
function)
pymqe.c:199: `connectOpts' undeclared (first use in this function)
pymqe.c:199: `MQCNO_VERSION_2' undeclared (first use in this function)
pymqe.c:201: `MQCD' undeclared (first use in this function)
pymqe.c:201: parse error before ')' token
pymqe.c:205: warning: implicit declaration of function `MQCONNX'
pymqe.c:205: `handle' undeclared (first use in this function)
pymqe.c:205: `compCode' undeclared (first use in this function)
pymqe.c:205: `compReason' undeclared (first use in this function)
pymqe.c: In function `pymqe_MQDISC':
pymqe.c:220: `MQHCONN' undeclared (first use in this function)
pymqe.c:220: parse error before "handle"
pymqe.c:221: `MQLONG' undeclared (first use in this function)
pymqe.c:223: `handle' undeclared (first use in this function)
pymqe.c:227: warning: implicit declaration of function `MQDISC'
pymqe.c:227: `compCode' undeclared (first use in this function)
pymqe.c:227: `compReason' undeclared (first use in this function)
pymqe.c: In function `pymqe_MQOPEN':
pymqe.c:250: `MQHCONN' undeclared (first use in this function)
pymqe.c:250: parse error before "qmgrHandle"
pymqe.c:251: `MQOD' undeclared (first use in this function)
pymqe.c:251: `qDescP' undeclared (first use in this function)
pymqe.c:254: `MQLONG' undeclared (first use in this function)
pymqe.c:254: parse error before "options"
pymqe.c:255: `MQHOBJ' undeclared (first use in this function)
pymqe.c:258: `qmgrHandle' undeclared (first use in this function)
pymqe.c:259: `options' undeclared (first use in this function)
pymqe.c:262: `MQOD_CURRENT_LENGTH' undeclared (first use in this
function)
pymqe.c:266: parse error before ')' token
pymqe.c:268: warning: implicit declaration of function `MQOPEN'
pymqe.c:268: `qHandle' undeclared (first use in this function)
pymqe.c:268: `compCode' undeclared (first use in this function)
pymqe.c:268: `compReason' undeclared (first use in this function)
pymqe.c: In function `pymqe_MQCLOSE':
pymqe.c:285: `MQHCONN' undeclared (first use in this function)
pymqe.c:285: parse error before "qmgrHandle"
pymqe.c:286: 

RE: [Tutor] German Totorial!?!

2005-01-05 Thread Robert, Andrew
How about:

 http://starship.python.net/crew/gherman/publications/tut-de/


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of michael
Sent: Wednesday, January 05, 2005 1:42 PM
To: tutor@python.org
Subject: [Tutor] German Totorial!?!

Hello,
Im a German peaople whou would learn Python.

But I cant find a german tutorial.

So you know a German Tutorial?

Daer Michael

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 01/05/2005 01:46:36 PM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] O.T.

2004-12-29 Thread Robert, Andrew
 I'm a father of two girls, living in Massachusetts.


Professionally, I've been a VMS/Unix Systems Admin for the last 17 years.

This includes designing high availability, fault tolerant configurations and 
management of disparate fiber storage area networking solutions.

As an admin, I do a good amount of  DCL, shell/Perl scripting and C/C++ 
development in support of production cycles.

Recently, I've been doing work with IBM's WebSphere MQSI messaging but that's 
still in its infancy.

I hope to use Python as the scripting language to interface with this.

A module called pymqi, http://pymqi.sourceforge.net/, will be the step off 
point for much of this.



Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gonçalo Rodrigues
Sent: Wednesday, December 29, 2004 7:39 AM
Cc: tutor@python.org
Subject: Re: [Tutor] O.T.

Jacob S. wrote:
> I hate to sound weird...
> 
> But who are you all, what are you're ages, what do you do, marriage status,
> etc?
> You obviously don't have to answer, I'm just curious who I'm boldly sending
> emails to.
> 
> Jacob Schmidt
> 
> P.S.
> I'm a student. 14 years. Play the piano better than I write scripts. Single.
> etc.
> 

G. Rodrigues, 32 years, single and available. I'm a Mathematician, doing 
research and teaching (but more of the first). My general area of 
expertise is Category Theory although, since I'm working on things 
related to theoretical physics I end up meddling in a lot of other stuff.

So how did I end up in Python Tutor's list, hein? Well, I have done here 
  and there some small programming jobs and since I had the freedom I 
ended up choosing Python. I also know Java, C++ and Scheme, but it 
really is Python where I'm most comfortable. One thing led to another 
and well, I ended up here answering this or that email.

Oh, btw, living in Portugal and planning to go to Australia for a postdoc.

Best regards,
G. Rodrigues
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/29/2004 08:02:16 AM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Hi I made a mistake

2004-12-21 Thread Robert, Andrew
Good morning Julias,

The python tutor list is a give and take of python information.

If can contribute to an explanation or resolve a problem, then please do
so.

Additionally, you can read the e-mail messages and learn from others on
how they handle things.



Thank you,
Andrew Robert
Systems Architect
Information Technologies
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Julius
Sent: Tuesday, December 21, 2004 10:01 AM
To: [EMAIL PROTECTED]
Subject: [Tutor] Hi I made a mistake

I am a beginner with Python, I originally tried to sign up to "GET"
help, not to become a tutor,  now i have alot of email everyday of
people asking me questions, please take my name off the list, i won't
be able to help, and please let me know how to sign up to get help :)
-- 
Julius
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/21/2004 10:23:04 AM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] hello i need help

2004-12-16 Thread Robert, Andrew
I recommend you use vim.

You can get it at http://www.vim.org/download.php


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jason Child
Sent: Thursday, December 16, 2004 2:43 PM
To: [EMAIL PROTECTED]
Subject: Re: [Tutor] hello i need help

alex biggerstaff wrote:

> is it possible 2 write a script for wordpad or something, i only 
> started so i dont know much
> i do know a little about if ($1 == hi)  && (£2 == m8)
> but im not sure how 2 make this apply to other programs. i can only 
> write scripts on a thing called mIRC.
> ne help would b great
> thnxs
>
> * ALL-NEW Yahoo! Messenger * 
>  * - 
> all new features - even more fun!* * *
>
>
>
>___
>Tutor maillist  -  [EMAIL PROTECTED]
>http://mail.python.org/mailman/listinfo/tutor
>  
>

I do not belive that Notepad supports scripting. Take a look at: 
http://www.python.org/moin/PythonEditors

in particular you may want to look at JeXt, Syn or Zues.


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/16/2004 03:01:08 PM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Difference between for i in range(len(object)) and for i in object

2004-12-09 Thread Robert, Andrew
 Good morning Kumar,

I believe you need to do something like:

   #
   # Read from command line supplied input file
   #
   for line in open(sys.argv[1]).xreadlines():

#
# Remove \n from end of line
#
line=line[:-1]

#
# Break line by tab delimiter and feed to list
#
split_line_by_tab=line.split('\t')
  

You should then be able to print out list items relatively easily.


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of kumar s
Sent: Thursday, December 09, 2004 11:51 AM
To: [EMAIL PROTECTED]
Subject: [Tutor] Difference between for i in range(len(object)) and for
i in object

Dear group, 
  

My Tab delimited text looks like this:

HG-U95Av2   32972_at432 117
HG-U95Av2   32972_at499 631
HG-U95Av2   32972_at12  185
HG-U95Av2   32972_at326 83
HG-U95Av2   32972_at62  197


I want to capture: columns 2 and 3 as tab delim. text:


Here is my code:
>>> spot_cor=[]
>>> for m in cor:
... cols = split(cor,'\t')
... spot_cor.append(cols[2]+'\t'+cols[3])
...
...
Traceback (most recent call last):
  File "", line 2, in ?
  File "/usr/local/lib/python2.3/string.py", line 121,
in split
return s.split(sep, maxsplit)
AttributeError: 'list' object has no attribute 'split'

Here is 2nd way:


>>> test_cor=[]
>>> for m in cor:
... cols = split(cor,'\t')
... x = (cols[2]+'\t'+cols[3])
... test_cor.append(x)
...
Traceback (most recent call last):
  File "", line 2, in ?
  File "/usr/local/lib/python2.3/string.py", line 121,
in split
return s.split(sep, maxsplit)
AttributeError: 'list' object has no attribute 'split'



Here is my 3rd way of doing this thing:
>>> for m in range(len(cor)):
... cols = split(cor[m],'\t')
... spot_cor.append(cols[2]+'\t'+cols[3])
...
>>>
>>> len(spot_cor)
2252
>>>



My question:
 Many people suggested me to avoid  iteration over  a
object using (range(len)) its index and use instead
'Python's power' by using for i in object, instead. 

However, when I tried that using some data, as
demonstrated above, I get error because append method
does not work on list.  In method 2, i tried to append
an object instead of string elements. In both ways the
execution failed because  'List object has no
attribute split'.


Can you help me making me clear about his dogma. 


Thank you. 

Kumar.



--- Guillermo Fernandez Castellanos
<[EMAIL PROTECTED]> wrote:

> Cheers,
> 
> I think your mistake is here:
> if x == y:
>for ele3 in spot_int:
>if y in ele3:
>   
> out.write(ele3)
>   
> out.write('\n')
> Each time you find an element that is the same
> (x==y) you don't write
> only y, you write *all* the elements that are in
> spot_init instead
> only the matching one! And it's not what you are
> looking for! :-)
> 
> I'll also change a bit your code to make it look
> more "pythonic" :-)
> 
> > for ele1 in spot_cor:
> > for ele2 in spot_int:
> > cols = split(ele2,'\t')
> > y = (cols[0]+'\t'+cols[1])
> > if ele1 == y:
> > for ele3 in spot_int:
> > if y in ele3:
> >
> out.write(ele3)
> >
> out.write('\n')
> 
> What changes I did:
> 
> for ele1 in range(len(spot_cor)):
>x = spot_cor[ele1]
> 
> can be writen like:
> for ele1 in spot_cor:
> x = ele1
> 
> Furthermore, as you only use x once, I changed:
>  if x == y:
> 
> with
> if ele1 == y:
> 
> and deleted the line:
> x = ele1
> 
> I also don't understand why you do this:
> cols = split(ele2,'\t')
> y = (cols[0]+'\t'+cols[1])
> 
> It seems to me that you are separating something to
> put it again
> together. I don't really see why...
> 
> Enjoy,
> 
> Guille
> 




__ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/09/2004 12:05:50 PM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its co

RE: [Tutor] Connecting to interactive program

2004-12-07 Thread Robert, Andrew
 
Have you considered redirecting input from the terminal session itself?


On Linux, I think you can test against sys.stdin.isatty() and assign a
variable to /dev/tty.

The methodology is similar on Windows but you need to import msvcrt and
grab msvcrt.getche().


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Vincent Nijs
Sent: Tuesday, December 07, 2004 2:38 PM
To: [EMAIL PROTECTED]
Subject: Re: [Tutor] Connecting to interactive program

Has anyone ever tried to send commands to a running interactive python
session from, say, the command line or another app?

If so, please let me know how you achieved this.

Vincent


On 12/1/04 4:10 PM, "Vincent Nijs" <[EMAIL PROTECTED]>
wrote:

> Hi,
> 
> I am trying to send information from an editor (vim) to an interative
> program (say the Python commandline, R, Matlab, etc.).
> 
> I have tried to connect a named pipe to the interactive program using
> mkfifo. For some reason this doesn't work properly however (
seems to
> be the first thing sent).
> 
> Could anyone provide a very very simple example where from a terminal
> command line I could send, say, 'x=3' to an open interactive python
session?
> I'd like to have something that works on WinXP and Mac (or Linux).
> 
> Thanks!
> 
> Vincent

-- 



___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/07/2004 03:00:42 PM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Create a binary for a python game

2004-12-03 Thread Robert, Andrew
 Sure is.

Try cx_freeze.

It can be found at
http://starship.python.net/crew/atuining/cx_Freeze/index.html .

I've used it with great success.


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of David Holland
Sent: Friday, December 03, 2004 3:11 PM
To: [EMAIL PROTECTED]
Subject: [Tutor] Create a binary for a python game

I have created a simple python game and I would like
to convert it into a binary  executable that can be
used to play it in Linux without needing the various
libraries (pygame etc).  Is this possible ?



___ 
Win a castle for NYE with your mates and Yahoo! Messenger 
http://uk.messenger.yahoo.com
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/03/2004 03:23:18 PM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Creating & Handling lots of objects

2004-12-03 Thread Robert, Andrew
Although I have never done so, I believe you can also store/manipulate
objects in a database.

Has anyone ever worked this option?


Thank you,
Andrew Robert
Systems Architect
Information Technology - OpenVMS
Massachusetts Financial Services
Phone:  617-954-5882
Pager:   781-764-7321
E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Kent Johnson
Sent: Friday, December 03, 2004 7:42 AM
To: Python Tutor
Subject: Re: [Tutor] Creating & Handling lots of objects

If you want to be able to access the objects by name, you can put them
in a dict. For example,
MyObjects={}
l=["a","b","c"]
for i in l:
MyObjects[i] = MyClass(i)

Then you can refer to MyObjects["a"]

If all the operations on the objects are done to all objects in a batch,
putting them in a list 
might work. Then you can use list iteration to access all of them:
MyObjects=[]
l=["a","b","c"]
for i in l:
MyObjects.add(MyClass(i))

then to process all the objects:
for myObj in MyObjects:
 # do something with myObj

Kent


Matt Williams wrote:
> Dear Tutor-list,
> 
> I'm sorry for this appallingly dumb question, but I'm having a little
> problem with objects.
> 
> I've written a class, with some methods. I then want to be able to
call
> the class repeatedly, to create some objects. The number of objects,
and
> some of their initialisation parameters need to be specified later
(i.e.
> at run-time).
> 
> When I generate all these objects, how do I keep track of them. For a
> finite (and small) number I can do this:
> 
> a=MyClass("a")
> b=MyClass("b")
> 
> but this is obviously not scaleable. If I use a list, I can do:
> 
> MyObjects=[]
> l=["a","b","c"]
> for i in l:
>   MyObjects.add(MyClass(i))
> 
> but then I have to search the list (MyObjects) for the object where
> Object.name="a".
> 
> The only other option seems to be finding objects via their hash
codes,
> which I'm sure isn't right
> 
> I'd like to be able to automate something closer to the a=MyClass("a")
> but don't know how to do itIt may be that I'm trying to do it very
> badly, which is Python seems to make it hard for me.
> 
> Thanks,
> 
> Matt
> 
> 
> 
> ___
> Tutor maillist  -  [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


"MFS Relay Service" made the following
 annotations on 12/03/2004 08:05:23 AM
--
This email communication and any attachments may contain proprietary, 
confidential, or privileged information.  If you are not the intended 
recipient, you are hereby notified that you have received this email in error 
and that any review, disclosure, dissemination, distribution or copying of it 
or its contents is prohibited.  The sender does not waive confidentiality or 
any privilege by mistransmission.  If you have received this email in error, 
please notify the sender immediately, delete this email, and destroy all copies 
and any attachments.
==

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor