[Tutor] RE: Am stuck help please

Karthik Gurumurthy karthikg@aztec.soft.net
Sun, 6 Jan 2002 19:20:27 +0530


sorry! within seconds of sending the mail i got the answer
using eval() helped me here.

movies = [apply(Movie,(title,eval(rate))) for title,rate in titles.items()]

karthik.

-----Original Message-----
From: karthik Guru [mailto:karthikg@aztec.soft.net]
Sent: Sunday, January 06, 2002 7:18 PM
To: tutor@python.org
Subject: Am stuck help please
Importance: High



consider a class Movie with static fields.

class Movie:
	REGULAR = 1
	CHILDREN = 0
	NEW_RELEASE = 2

	def __init__(title = 'Gladiator',rating = REGULAR):
		print rating

Now the data for constructing Movie objects come from a text file
who contents will be like this:

Gladiator:Movie.REGULAR
Rain Man:Movie.REGULAR
Shrek:Movie.CHILDREN

after getting these things out, i construct the movie objects,
I store the read data in a dict say titles then i do

movies = [apply(Movie,(title,rate)) for title,rate in titles.items()]

The PROBLEM! : the value Movie.REGULAR etc are being treated as strings and
not int.
How do i make the interpreter treat them as ints (rather as static fields of
Movie)
and send to the constructor?..i mean a neat pythonic way

using if-elif and re-assigning the values is fine. am looking for a better
way.

thanks,
karthik.





-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Kirk D Bailey
Sent: Sunday, January 06, 2002 10:42 AM
To: tutor@python.org
Subject: [Tutor] TLlistmaster.py


To whoever feels like it;
I have got TLlistmaster.py almost complete. There is one minor bug in
there. Regretfully, it's a tiny little stinkbug and it is driving me
crazy(ier).

First, take a look at the script as it stands this very instant- page
inherently self updates.

http://www.howlermonkey.net/TLlistmaster.shtml

Second, there is no error code, but it fails to see the presence of
the subject line in the pending file.

Here is the screen capture from a sample run:
(beware wordwrap)
ns# ./TLlistmaster.py < testfile
From:= highprimate@howlermonkey.net
Subject field as extracted:='Re: join highprimate@howlermonkey.net
evil-humor 1010287984'
CLEANED UP subject line='join highprimate@howlermonkey.net evil-humor
1010287984'
command='join'
oldfrom='highprimate@howlermonkey.net'
listname='evil-humor'
Pending action='join testcode@howlermonkey.net testlist3 1010173860'
This person wants to join'evil-humor' list!
cannot find subject in pending file!
ns#

I included a LOT of print statements in the program to generate all
these status reports. The language's interpeter is not creating ANY
errors.

I am stumped for the moment, and tired, and battling with a cranky
isp, so I think I will smoke a house pipe and drink some fine coniac
and go night night, but feel free to look at this, and write me some
questions, answers, suggestions, pithy things to double check, evil
jokes, etc...

So close... SO close...












end

In total confusion,
                   Kirk D Bailey

 +----------------------------------------------------+
 |   Providing Excellent email service for free!!     |
 |    Webmaster, Howlermonkey Email services Co.      |
 | highprimate@howlermonkey.net www.howlermonkey.net/ |
 +----------------------------------------------------+

ODD#1.8.01/kdb/sigme


Refill your inkjet cartridges. Same top quality print. Low Low price. <a
href="http://www.inkwellkits.com/cgi-bin/at.pl?a=147030">Click Here.</a>
(They have a nice affiliate program too!)


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