I want to use a SublimeText2 as IDE for developing applications in Python.
I have the following problem :
When I make a new file, save it as a python and do Tools -> Build System -> Python
CTRL + B
I get this error:
Please type your name and press enter: Traceback (most recent call last):
File "/Users/strielok/Desktop/hello.py", line 1, in <module>
personsname = raw_input("Please type your name and press enter: ")
EOFError: EOF when reading a line
[Finished]
Here is the code of the program:
personsname = raw_input("Please type your name and press enter: ")
print "Hello " +personsname
However when I run this code from terminal (I am on Mac), it works perfectly.
Any idea what the problem might be ?
Install sublimeREPL and then choose Tools->sublimerepl->python.
Reference:http://gimo.me/sublime-text2-skills/
Taken from Sublime Text's forums, seems that stdin will not be connected with anything so it's expected.
Source: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=1519&p=6908&hilit=python+input#wrap
I've written a plugin which allows builds in sublime text to take input. It's a bit rough around the edges, but it works on my machine.
Related
When the following code is executed line by line on shell, it is giving the expected output :
>>> name=input("Please give your full name : ")
Please give your full name : ins vikranth
>>> ListName=name.split(' ')
>>> outputString=ListName[1]+' '+ListName[0]
>>> print(outputString)
vikranth ins
The code is not running in total as a file but runs line by line on the shell.
The code is :
name=input("Please give your full name : ")
ListName=name.split(' ')
outputString=ListName[1]+' '+ListName[0]
print(outputString)
The error message is :
Please give your full name : ins vikranth
Traceback (most recent call last):
File "ReverseName.py", line 1, in <module>
name=input("Please give your full name
File "<string>", line 1
ins vikranth
^
SyntaxError: unexpected EOF while parsing
Why is this happening?
the reason why this is happening is your python version ... your IDLE is python 3.X while your file is being "translated" ( Interpret ) using python 2.X ... so there are 2 simple solutions:
1/ stick with python 3.X - your code is not going to change, just change Interpreter
2/ edit it to be compatible with python 2.X :
name=raw_input("Please give your full name : ")
also here are 2 online compilers, where you can see the difference:
Python 3.7 -> https://www.onlinegdb.com/online_python_compiler
Python 2.7 -> https://repl.it/languages/python
#Babu brother code seems to okey for me but you might forget somepoint.If person have a middle name it will cause an error. You have 2 array locations when user types more than 2 words it cause an unexpected end of file due to lack of location like Kevin Prince Boateng a footballer. You might want to look this https://docs.python.org/2/c-api/memory.html for a dynamical memory management
I am following zed shaw's book LPTHW and stuck on ex25. I have typed the code accordingly without errors. If I understand it right he has asked to run it first normal in powershell but when I put the command:
C:/mystuff> python ex25.py ,
It enters to next line without any output.
I tried importing ex25 in python interpreter this is the error i get:
>>import ex25
>>sentence = "All good things come to those who wait."
>>words = ex25.break_words(sentence)
After this I get an error:
Traceback <most recent call last>:
file stdin in line 1 <module>
file ex25.py line 3 in break_words
words = stuff.split(' ')
Value error: empty separator.
what am I doing wrong? Also i experimented for over half hour now trying different solutions , make it work. I guess the powershell wont respond because the program is basically a bunch of functions , without any input. But in the interpreter we do give an input of a sentence , then why the error? Doing my head-in.
the code link for LPTHW: http://learnpythonthehardway.org/book/ex25.html
I don't know your code for ex25 but here is mine for the line it says you have error on
def break_words(stuff):
"""This function will break up words for us."""
words = stuff.split(' ')
return words
It works for me you can make a new file and put that portion of your code and mine then compare them if they are exactly the same with 0 difference then tell me. if you can can you post that part of your code in the question
I would like to test programs online, as the place where I work does not have a python compiler. There are many online sites such as ideone, codepad and complieonline. However, I have noticed that codepad does not accept input data and although ideone input data, it only accepts one entry data at a time. For example I wanted to test this program on complileonline
PREFIX = 'Simon says '
line = raw_input('Enter: ')
while line:
if line.startswith(PREFIX):
print line[len(PREFIX):]
line = raw_input('Enter: ')
I entered my input and separated them by pipeline (as stated on the website instructions) but kept getting this error message
Executing the code....
$python /tmp/135731949523855.py
Enter: Enter: Enter: Traceback (most recent call last):
File "/tmp/135731949523855.py", line 9, in ?
line = raw_input('Enter: ')
EOFError: EOF when reading a line
How can I enter multiple entries to test my program? How can I enter multiple entries onto these online websites, otherwise is there another, example testing with my code without the requirement of user input.
Well, consider to use hard-coded inputs inside your code (turn the "raw_input" function into something you except to get from the user). It can be great solution.
One of the options you have which is pretty close to raw_input, is to use sys.argv:
import sys
print sys.argv[1]
Compileonline provides you the option, below of your code, to add command line arguments.
However, on PythonAnywhere.com your code seems to run just fine :) You might want to try it there.
Good luck:)
I'm reading an online python tutorial book from here. The code is listed below. When I execute the code, I can type words into it but then it gave me the error below. What is the wrong with the code?
On a related note, if you have a better resource for leaning python, please let me know. I'm looking for one that is online and updated often (ex: railstutorial.org). The resource I am using have plenty of errors even this early in the book. Thanks.
Enter something : programmig is fun
Traceback (most recent call last):
File "break.py", line 5, in <module>
s = input('Enter something : ')
File "<string>", line 1, in <module>
NameError: name 'programmig' is not defined
#!/usr/bin/python
# Filename: break.py
while True:
s = input('Enter something : ')
if s == 'quit':
break
print('Length of the string is', len(s))
print('Done')
This is python 3 code. It seems like you're running it with python 2.
Run python --version to check which version of python you are using.
input() doesn't get a string, so it thinks that programmig is a variable. You can type the input you want in quotes to solve this.
A better way however, is to use raw_input, which returns a string.
So either do Enter something : 'programmig is fun', not recommended, or do s = raw_input('Enter something : ') recommended way
The cause of the confusion is that the book is probably for python 3, which has a different input, and also a different print, while you are using python 2.x.
I am a python noob, and am having problems running programs with open() functions in cmd prompts. The code runs as expected in the python shell with IDLE, but everytime I open it by doubleclicking the icon coresponding to the script( I have .py associated with python), I get errors like
what file test.txt (I entered input)
file 2 atest2.txt (I entered intput)
Traceback (most recent call last):
File "C:\Users\Matthew\Desktop\file_io\find_differences_in_files.py", line 3,
in <module>
f=open(c,"r") # open c
IOError: [Errno 22] Invalid argument: 'test.txt\r'
Similar problems occur in multiple similar programs, but here is a sample of code( FYI, this code finds the first difference in two .txt files) that worked in IDLE but not in cmd. Anybody have any clue what is going wrong?
c=input("what file") # get file 1
d=input("file 2") # get file 2
f=open(c,"r") # open c
g=open(d,"r") # open d
p=f.readlines() # get every line of f
q=g.readlines()
i=0
while i<len(p) and i<len(q):
if p[i]!=q[i]:
break # stop counting up
i+=1
x=p[i] # store different line
y=q[i] # store different line
j=0
while j<len(x) or i<len(y):
if x[j]!=y[j]:
break # stop counting up
j+=1
print("The difference is in line %s column %s" % (i+1,j+1))
c=input("press enter")
You're not handling end-of-line characters correctly, and IDLE gives you the end-of-line in one format, while the cmd.exe sends another.
I suggest stripping whitespace from both ends of the input in this case.