How do you set up a stack?

kosh kosh at aesaeion.com
Tue May 8 23:17:05 EDT 2001


Umm. While this solution will work I think there are some things that need 
to be dealt with. Mainly you need to check f for items that should not be 
in there. eval will evaulatuate any valid piece of python code so the other 
things that can be done are large. This is a fairly large security risk at 
this point I think. At the very least I would check if it has any letter 
characters and if so not run then.

Tyler Eaves wrote:

> On Wed, 09 May 2001 02:01:35 GMT, the_2nd_coming
> <jpetzold at twmi.rr.com> wrote:
> 
> 
> try this code:
> 
> f=raw_input('>')
> print eval(f)
> 
> 
>>hello,
>>I am a python/programming newbie (Python is my first language),
>>and I am writing a program that will be able to take a mathematical
>>function, that, as of right now, is restricted to Multiply and Divide with
>>one operator, (2/4 or 3*7). I want to be able for the end-user to be able
>>to type the function at the python prompt and to have the program create a
>>list of the characters in the list, I am using raw_input and I think I
>>need
>>to implement a stack  in order to pass each character to the list as I pop
>>them off the stack. this is good and all, however, I do not know how to
>>implement this.
>>
>>this is what the layout is at this point:
>>
>>
>>
>>
>>        function = raw_input("put your function hear")
>>                        .
>>                        . #this is where the stack will be implemented and
>>                        the . # charactors will be placed in the list.
>>        operator = function_list[1] # item 1 will be the position of the
>>        operator
>>                                #in the list after any whitespace is
>>                                #striped.
>>        
>>        if operator == "*": #the operator is the astrik
>>                multiplication(function_list[0], Function_list[2])
>>        
>>        else:
>>                Division(Function_list[0], Function_list[2])
>>
>>        # the rest of the program
>>
>>so, how do I implement a stack, and, is there any other way I could
>>acomplish this task?
>>
>>thank-you in advance
>>
>>Jeremy Petzold
> 
> 




More information about the Python-list mailing list