force sequenz with only one item?

Holger Jannsen holger at phoenix-edv.netzservice.de
Thu Jun 10 08:03:58 EDT 1999


High,

I think it's easy to solve, but I couldn't get it right now.
Take a look at the command-line source below:

>>> A = 0
>>> B = 1
>>> seq=raw_input("?")
?A,B
>>> print seq
A,B
>>> print eval(seq)
(0, 1)
>>> seq=raw_input("?")
?A
>>> print eval(seq)
0
>>> A in seq
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: string member test needs char left operand
>>> A in eval(seq)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: 'in' or 'not in' needs sequence right argument
>>>

Ok? Check it out?
That's what I want to do with it:
There's a file I'm parsing over special keywords per line, e.g.:
Action = CREATE, VERBOSE, APPEND
When read the line I put the right term to a variable, e.g:
anAction = eval(rightTerm)
Then I want to test for that keywords (global integer variables in 
source, e.g.: CREATE = 0):
if CREATE in anAction:
	pass #do something

But how could I force python to accept one-item sequences (see below!)?

Thanx for comin' with me...

Ciao,
Holger




More information about the Python-list mailing list