views:

1487

answers:

3

if i do :

string = raw_input('Enter the value')

it will come on shell.

Can i collect the value I entered in variable string ???

How to use that entered value in my program like :

if dict.has_key('string'): print dict[string]

???

+2  A: 

This is very confusing ... I'm not familiar with a raw_string function in Python, but perhaps it's application-specific?

Reading a line of input in Python can be done like this:

import sys
line = sys.stdin.readline()

Then you have that line, terminating linefeed and all, in the variable line, so you can work with it, e.g. use it has a hash key:

line = line.strip()
if line in dict: print dict[line]

The first line strips away that trailing newline, since you hash keys probably don't have them.

I hope this helps, otherwise please try being a bit clearer in your question.

unwind
+2  A: 

there's no raw_string function in python's stdlib. do you mean raw_input?

string = raw_input("Enter the value")     # or just input in python3.0
print(string)
SilentGhost
sorry my mistake
+1  A: 

Is this what you want to do?

string = raw_input('Enter a value: ')
string = string.strip()
if string in dict: print dict[string]
chills42