raw_input and input in python 2.7 Programming Software Development by kouty … - with input python make return the result of the list comprehention b) an astonishment: - with raw_input python return 8. **A QUESTION… Re: raw_input and input in python 2.7 Programming Software Development by kouty … in the first example 8 is not a conversion of comprehention to string but an hybrid action. It is even a… Re: raw_input and input in python 2.7 Programming Software Development by Gribouillis When `[x * 3 for x in range(2, 10, 2)]` is evaluated as a result of the input function, the variable `x` takes the values `2, 4, 6, 8`. When the `x` is printed, its value is the last one, `8`. You can avoid this by using another variable name. Conclusion: don't use `input()` in python 2, it is too dangerous. Re: raw_input and input in python 2.7 Programming Software Development by vegaseat With Python2 input() uses eval() internally. The eval function can potentially evaluate a statement to erase your harddrive. With Python3 the former input() has been replaced with the functionallity of raw_input(). Re: raw_input and input in python 2.7 Programming Software Development by kouty @vegasteat Thank you for the accurate response! Sorry if i don't have the technical level to understand enough. You says that python 2's input() function makes the attribution eval() action, that is: 1- the input is a string 2- the eval function read the characters into the quotes as the interpreter read a code 3- the eval function return the same… Re: raw_input and input in python 2.7 Programming Software Development by Gribouillis Between the `raw_input()` and your printing `x`, there was an `input()`. This is where `x` was modified. About the dangers of `input()`, the point is that when a program writes `write a list!`, the user does not think that his input can have a malicious effect such as erasing files or starting unwanted programs, etc. There should be some mechanism… Re: raw_input and input in python 2.7 Programming Software Development by kouty @gribouillis Yes, your answer is phenomelogically verified: x = raw_input("write a list! utilisation of raw_input ") print x, "result of rawinputation" y = input("write a list! utilisation of input ") print y, "result of inputation" ............> <-----------------… Re: raw_input and input in python 2.7 Programming Software Development by Gribouillis If you input `[z * 5 for z in range(2, 10, 2)]`, it does not interfere. Re: raw_input and input in python 2.7 Programming Software Development by kouty @Gribouillis OK! You give me a bud of understanding. The name of the variable inside the input are names od **global variables**, not as in a functions. The last value of x in the liste inside the input function is 8. UNTIL NOW I can guess what is the 8. And if I write print x, the so called x variable is called; the computer will attribute to… Re: raw_input and input in python 2.7 Programming Software Development by vegaseat Actually, in Python2, unlike Python3, the list comprehension leaks. So in this case x (as its last value) becomes available outside the comprehension. Re: raw_input and input in python 2.7 Programming Software Development by kouty @vegaseat If I understand your comment, I can learn through him that list comprehension has a "function behaviour": ______________________________________________________________________ IN THE SNIPPET I PRESENTED AT BEGINING, There was a SECOND PROBLEM, beyond the awkward homonymy between the x in line 1 (i.e. x = raw_input etc) and … Re: raw_input and input in python 2.7 Programming Software Development by vegaseat A short test ... # Python2 mylist = [x * 3 for x in range(2, 10, 2)] # x leaks out and contains 8, the last value given to it print(x) ... and ... # Python3 mylist = [x * 3 for x in range(2, 10, 2)] # x does not leak out # gives NameError: name 'x' is not defined print(x) Re: raw_input and input in python 2.7 Programming Software Development by kouty @vegaseat Awesome! Thank's so much!