force sequenz with only one item?

William Park parkw at better.net
Sat Jun 12 07:27:58 CEST 1999


On Thu, Jun 10, 1999 at 12:03:58PM +0000, Holger Jannsen wrote:
> 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

One item list is '[A]'
One item tuple is '(A,)'




More information about the Python-list mailing list