Problem with terminating input function of python in sublime text 3 - python

Thank you if you are reading this and for help me.
I wrote a python script in sublime text 3, which uses a input function to take string and to display it using a print function.
I run the script with ctr + B, input command executed, now I write a string and hit enter. Cursor goes in next line and input function did not terminated.
Help me to solve this problem. Thank you.

Sublime Text does not support inputting data into a program .
How to solve this problem
Create a build system that first opens a terminal and then runs your program inside of the terminal
Use SublimeREPL to run your code in Sublime
Use Terminus in your build system; it allows you to create an actual interactive terminal directly within Sublime.
I would generally recommend Terminus for this; it's very easy
Quick Solution outside sublime :
can use separate cmd(Windows) or Terminal(Mac/Linux)
python name_file.py

Click the Sublime Text icon to launch it, or search for Sublime Text in
your system’s search bar and then launch it. Go to Tools Build System4
New Build System, which will open a new configuration file for you. Delete
what you see and enter the following:
{
"cmd": ["python3", "-u", "$file"],
}

Related

Python SUblime Text 3 Curses

I am trying to run a python file named cursesDb.py, but I get an error. That File import curses library, but when I use the sublime text editor, I can't run my program because an error occurs in this file: /usr/lib/python3.7/curses/__init__.py. I am using Linux Ubuntu 19 as my OS.
Somebody could tell me how could fix this? I am a beginner in python, exactly in these lines:
setupterm(term=_os.environ.get("TERM", "unknown")
**fd=_sys.__stdout__.fileno())**
The error occurs when I build ctr + b in sublime text, as follows below:
_curses.error: setupterm: could not find terminal
thanks!
Most likely this is due to the fact that curses is trying to determine what terminal type to use to do things like output colors and manipulate the cursor position.
When you use a standard build system in Sublime Text, all it does is capture the output of your program and dump it to a panel; that is, it's not a terminal at all. So there's likely no TERM variable set, and even if there was it would be meaningless because curses isn't going to work anyway.
An important note in this regard is that the "dumb terminal" that Sublime uses to dump output doesn't accept input, so if your program is expecting to gather some sort of input from the user to do something, that will also fail.
To solve both of these problems, you can do something like this:
Install the Terminus package, which provides a terminal inside of Sublime
Open up your sublime-build file and add the following keys inside of the { } characters (anywhere within there is fine).
"target": "terminus_exec",
"cancel": "terminus_cancel_build",
Now when you run the build, Terminus will open an actual terminal and run your code inside. This is more the sort of environment that curses is expecting, and is also needed if your program needs to be in any way interactive.
More details can be found in this video on making any build system interactive with Terminus if needed. This may be of particular benefit if you're not sure how to find and open the build file that you're using.

How to run python script without writing command on cmd again and again

I am practicing python code and executing it through command line. each time i have to execute my python file i go to cmd and write
D:\PythonPractice>python myClass.py
Is there any standard and comfortable way available to execute python code quickly?
If you are executing the same command, with no changes to arguments or anything, you can pack it in a .bat file (windows executable)
Name it something like myscript.bat
D:\PythonPractice>python C:\path\to\myClass.py
Put full path inside it. Now double click will do.
Use PyCharm Software by JetBrains (same company who developed Android studio and Kotlin language), it will help you in many ways .
Run Python with single press of a button.
Add modules easily just with some clicks.
Debugging the code as smooth as possible.
It is Awesome, I am using it for past couple of months.
you can change file association which controls what to do when invoking filename in command line. For instance, when you just type text filename in cmd, notepadd will be opened, for word docs Word or other document editor.
Have a look into following link from google or you can fiddle by yourself starting from Control Panel > Control Panel Home > Default Programs > Set Associations. Select a file type in the list and click Change Program.
Alternatively,you can use any of Python IDE (PyCharm,PyDev etc.) so you will be able to run directly scripts from editor.
With Notepad++, you can also create a shortcut to be able to launch your python script :
Menu Run > Run (or press F5)
Choose the python .exe (default in C:\Program Files (x86)\Python36-32\python.exe
Then add this code next to the path : "$(FULL_CURRENT_PATH)"
This will allow to execute the current file
example of command with Python 3.6 :
"C:\Program Files (x86)\Python36-32\python.exe" "$(FULL_CURRENT_PATH)"
Then save the command, by assigning a shorcut key, it's better with a modifier like SHIFT (SHIFT + F10)
Now you can launch any script with this shortcut.

How to run code directly from python interpreter in Sublime Text 2?

I'm running a python script using Sublime Text 2. To run the script, I use command B--this works great until I want to explore some variable by typing it into the python interpreter, as the interpreter does not appear to be interactive. Is there any way to be able to input code into Sublime Text 2's interpreter in order to test ideas and code snippets before I add them to the main script?
I don't think sublime support it. I know you can use SublimeREPL when you need pass some users inputs.

Getting user input while running a python script in atom

Not really sure whether I'm just not looking in the right place or whether this feature is yet to be implemented, but after installing the atom script package and testing it out on a program that requires user input, I realize that I can't type in anything for input() the way I can when running the program from the shell. I stumbled upon this thread which makes me suspect that the feature hasn't been added, but I just wanted to be sure. Isn't this a pretty basic thing to be able to do? Or do I have to stick to using atom purely as a text editor and running the file from the CLI?
Some text-editors (including Atom and Sublime) don't like user input (raw_input()). Yes, you'd have to run the file from CLI.
You could, however, get around this problem by using other text editors like Notepad++ (see this answer to run Python in notepad++ - How to Execute a Python File in Notepad ++?), where user input works fine.
If you prefer to switch to Sublime (which also has a problem with user inputs), see this answer - Sublime Text 2 console input.
If you'd want to stick with Atom, an alternative, of course, would be to hard-code the variables you are looking for in raw_input while debugging/developing (but don't forget to switch back to raw_input after debugging).
Install atom-shell-commands .
Look up at the Running in a new window sample in the linked page.
Edit the config file like this :
"atom-shell-commands":
commands: [
{
name: "run with python 3"
command: "cmd"
arguments: [
"/C"
"start"
"$your_folder$/launch_python3.cmd"
"{FileName}"
]
options:
cwd: "{FileDir}"
keymap: 'ctrl-3'
}
]
Note : I saved the launch_python3.cmd in my user folder /.atom, but you can save it elsewhere, it should not be an issue.
The cmd file contents :
#echo off
REM used by atom-shell-commands to launch python 3 in a new window
$your_python_path$\python.exe %1
pause
exit
Now, you'll find a 'run with python 3' under Packages > Atom Shell Commands.
Edit the name and the keyboard shortcut as you see fit.
Clicking on the menu, a new command prompt window is displayed : it supports also user input.
Worked for me.

Using Python Shell with any text editor

I use Sublime Text and am using the terminal to run my code.
I would prefer to use the Python Shell to run my code, as it has color and is not so hard to look at.
Is there any easy way to do this other than saving then opening in IDLE?
You can use ctrl-b to run your python in sublime. If you want to use a different interpreter you can customise under Tools -> Build System
I suggest you check out IPython. You can run it through your terminal or through an IPython Notebook in your browser.
Stick with Sublime text. It's a popular text editor with syntax highlighting for several different programming languages. Here's what you need to do:
Press Ctrl + Shift + P to bring up command palette and enter "python".
Choose the option that says something like "Set syntax to Python".
Enter Python code then Ctrl + Shift + B to build the project.
Code will run below in another view(you will probably be able to move it to the side).
This is the standard procedure for a python setup in sublime text, but you may need to install
SublimeREPL for python in order to get user input. Just give it a Google search.

Categories

Resources