Input Error in Python IDE


#1

Hey,

I’m currently using Atom as a Python IDE. I’m on Ubuntu with a Gnome DE.
Whenever I use the input function, I encounter an error.

This is the code that I used:
name = input("enter your name: ")
print(“Hello” + name + “!”)

enter your name: Traceback (most recent call last):

File “/home/prowl/Desktop/Nishant/Code/Tutorial/test code”, line 1, in <module>

name = input("enter your name: ")

EOFError: EOF when reading a line

These are the packages that I use:







#2

atom-python-run isn’t able to handle input. script and atom-runner aren’t, either. Your options are to download a package that creates a terminal (like atom-ide-ui, termination, or terminal-tab), or to use process-palette to spawn an external terminal and run the script just like you would in a normal command line environment.

If it’s too much of a pain to run things in a command line, I recommend prototyping your code in a REPL. In addition to being able to rapidly iterate on your code, it’s a hygienic coding practice to test individual blocks of logic in a white-room environment before bolting them into the superstructure of your project. If you are diligent about a practice like this, you can completely avoid the embarrassing situation where you keep coming back to a bit of nothing code you wrote last week that was wrong in a way you didn’t anticipate.


#3

Can I import and use data from my computer when using REPL?

P.S. I’m a newb at this, so could you walk me through running a script in an atom terminal?


#4

Not with repl.it, but you can copy and paste what you need into a virtual file. If you use a REPL on your computer, like the default one that you get when you type python into the command line, then yes.

P.S. I’m a newb at this, so could you walk me through running a script in an atom terminal?

First, you should rename your file because it doesn’t have a file extension; it has to end in .py. I recommend not using a space in the filename, because command line instructions are punctuated by spaces and a space in a filename requires that the path to the file always be wrapped in quotes. This isn’t hard, but as a newbie it might be something that you forget until it bites you in the ass, and I know for a fact that the script package will give an error because it doesn’t handle the space correctly.

Out of the packages I listed, I think termination is the most straightforward. If you download that package and open its view, you’ll see a command line prompt appear in Atom. The current working directory should be the first project folder you have open in Atom (the one at the top of the tree view). If that folder contains your script, all you have to do is type python test-code.py, or if you want to keep the space it can be python 'test code.py'. If your script is in a child folder, you can use cd Tutorial to change the directory.


#5

He’s using Linux, so technically he doesn’t need to rename the file. Linux uses the file contents rather than the extension to determine what to do with it.

In his case:

  • it needs to be executable
  • and it needs to have the Python hashbang (#!/usr/bin/env python) as the first line

Unless you want to call it with python my_script_name. In that case, it doesn’t even need that.

You are correct that it’s usually good practice to use correct filename extensions though. As an organisational aid. So that you, the user, can easily identify the different file types on your hard drive.