so I have been trying out various text editors and IDE's recently to see what I like. I really like the web developer side of Brackets, which is what I think it was designed for, but was also messing around with some of the extensions for building and running Python/Ruby programs.
I have tried this, which honestly doesn't seem to do anything from what I can tell:
https://github.com/vhornets/brackets-builder
And this, which adds a run button to Brackets for running the program:
https://github.com/jadbox/brackets-integrated-development
The latter seems to work alright... until you make a small program that asks for user input then the program never runs, the program disappears, and then you have to restart Brackets to get it back. The code I have used is the following:
puts"Please enter your name: "
n = gets. chomp
Or
n = input("Please enter your name: ")
Any idea what might be causing this? I asked the developer, but haven't heard back. I'd probably use Brackets exclusively if it wasn't for that issue.
Tried Sublime Text 3 for a little while, but didn't like the lack of a Brackets like live preview plugin. However, it looks like it runs Python/Ruby (in addition to Java and C/C++) code without issue.
You might want to try a generic extension for running command line tools, such as one of these:
Command Line Shortcuts
Brackets Build System
Command Runner
Brackets Shell access
Brackets Terminal
The Brackets Builder you mentioned above - looks like you choose Edit > Edit Builder to configure the commands you want, and then you can press Ctrl-Alt-B to run them.
Brackets Builder has worked best for me "right out of the box". However, I run into the same problem as you (when wanting to perform console inputs) in both Brackets AND Sublime, but NOT in SciTE.
A good clean work around inside Brackets, for when you need to test programs with console inputs, is to load the extension "Open project in terminal", which will allow you to open a terminal right from your current project folder and run your python script. This allowed me to run your case from Brackets with very little hassle, and of course, it works great in a real terminal.
To make this approach even easier, I've asked the developers on GitHub, thru a raised issue, if they can add support for more terminal programs in Windows, such as ConEmu, and if they could allow intial command line arguments to be loaded, which would make this type of work that you want to do even more seamless and fast. I'll update my post once I see any improvements or alternatives to all the above points.
Related
Disclaimer: Sorry if the question is stupid or repeated, I've tried to find similar ones that answer what I need to know but I couldn't. I've started to learn programming about 1 month ago and this is my second time on this website. Feel free to point out any errors or better ways to formulate my questions on stackoverflow, I'll be grateful.
Context:
I was trying to find out a way to print a string - in this case ' º ' - after my user's input - an angle -, on the same line.
I need an alternative way to do this, or help with the one I'm using.
What I got from my research is that, apparently, using the command os.system(cls) should erase the previous line, and putting \033[A before the string should move the cursor up one line. So using these two together should erase the previous line and then overwrite it.
Here's my try:
from os import system
cls = lambda: system('cls')
angle = float(input(f'Insert an angle:'))
cls()
print(f'\033[AInsert an angle:{angle}º')
Desired result on run:
Insert an angle: *60*º # being 60 the user's input
Actual result on pycharm:
Insert an angle:60
Insert an angle:60.0º # for some reason, you can't see it when paste it here, but there's a symbol of a crossed rectangle on the beginning of this line on Pycharm's run
How it looks on pycharm's run terminal
As you can see, the line isn't getting overwritten, only repeated.
What is weird is that when I run this program with Python 3.8 instead of Pycharm, it works as intended, but, on Pycharm, the line isn't overwritten. Instead, Pycharm just prints a crossed rectangle symbol.
Why does it work when executing the file with Python 3.8, but not when pressing "run" on pycharm?
Is there a way to avoid it?
Are there better alternatives to printing a string on the same line as an input?
In cases where I need special printing (ANSII escape codes, backspacing...), I use the actual Terminal, not the Python Console.
For whatever reason, interactive consoles, regardless of IDE, seem to have issues with handing specialties like that. With the normal Terminal, it works as expected:
I have never found a way of having the interactive console handle cases like this.
When reading a book or just coding on terminal/IDLE it's common to make typo, forgot brace or comma etc. After I got error and all what I wrote before is lost.
Then I have to write down code again..
Is there any way/option to return back all what write before and just edit mistake and continue to code?
In Idle (at least my version, Python 2.7.10 on windows), you can simply copy paste your code. In the python interpreter, you can't afaik, however you can use the up/down arrow keys to recall lines you previously "submitted" (i.e. typed and pressed enter).
If I understood correctly, IDLE is a GUI (graphical user interface - a visual representation of a program rather just through text) made to have a bit more features for programming in Python. You can use IDLE interactively, like in Terminal (a.k.a command line), or use it to write your script rather than in a separate text editor. Then once you save your script/program you can do neat things like run it directly from IDLE. There's nothing more special about the Terminal, you just have to do some more work.
Furthermore, all the code you have written on your GUI is on the cache memory which is used in system to store information recently accessed by a processor. So, I suggest you write again your code you can't recover them without saving.
To avoid these kind of problems use Git!
Git is a version control system that is used for software development and other version control tasks.
IDLE's Shell window is statement rather that line oriented. One can edit any line of a statement before submitting it for execution. After executing, one may recall any statement by either a) placing the cursor anywhere on the statement and hitting Enter, or b) using the history-next and history-prev actions. On Windows, these are bound, by default, to Alt-p and Alt-p. To check on your installation, Select Options => IDLE preferences on the menu. In the dialog, select the Keys tab. Under Custom Key Bindings, find the 'histor-xyz' actions in the alphabetical list.
For short, one-off scripts, I have a scratch file called tem.py. Since I use it often, it is usually accessible via File => Recent files.
I am new to python programming... Just wanted to know does IDLE has a concept of 'executing selected statements'??
F5 runs the whole program... Is there any way to do this?
No, not now. Since you are at least the second person to ask this, I added the idea to my personal list of possible enhancements. However, while running a selection would not be a problem, producing accurate tracebacks for exception would be. Doing so is an essential part of Python's operation.
Currently, one can disable code that you need to not run by commenting it out (Alt-F3) or by making it a string. One can stop execution after a particular statement by adding 1/0. Or you can copy code to a new editor window.
Do you have a specific use case in mind, or are you just wondering?
Install Spyder, with its dependecies, and you will have wonderful FREE IDE !
You will have another solution, is to use IPython Notebook, where you will be able to use your Internet Browser to run python codes!:
I've done a bit of research and I've played with different graphical kits and was wondering if there was a way to display a native windows command line in my application. So, it'd be something like the command line in Jetbrains products (I think eclipse has one too), but the goal is to have 4 of them.
I've found a piece of linux software demonstrating the core concept of what I want to do and I've attached it at the bottom. Basically, I just want four terminals, and I'm going to have the app handle specific key bindings for "ease of access" tasks. I've used the linked software before and like it, but I thought as I'm exploring python it'd be a good learning experience to write something like this for windows as well!
Thanks in advance!
Edit - Google searching "Windows Tkinter Command Line" and the likes haven't been fruitful :) I promise I googled a LOT before posting here.
I dont know if there is anything readymade for this. Basically, you will need to have a text widget and simulate the output with the subprocess module to directly pass user input to run system commands and append results to the same text widget. You could also consider two windows - one for text input and one for result output.
Here is a link: Calling an external command in Python
I am in the works of creating a python program similar to this
. Anyway what i want to do is have users be able to modify there own programs but i need help understanding how this works. I have looked through the source code and am confused where this happens even if someone could just point me towards that that would be very helpful. I know that the programs will not be sandboxed but that is not something im worried about at the moment. If you could point me in any direction that would be great! Thank you!
The "robot programs" are just stored as plain text files.
There's a general-purpose text editor in editor.py. When you open a robot in a given view, e.g., the Qt4 view in qt4view.py, it just instantiates a text editor and hands it the robot's file. Again, the fact that the robot's file is a Python script doesn't matter; it just edits it as a text file.
The battle code, meanwhile, opens the same robot files as Python code that the text editor opens as text files. You can see this code in game.py: It just uses the subprocess module to run Python, passing the robot file as an argument.
My other answer deals with what you actually asked. But I don't think it's what you really wanted to know.
You just want to know how to run some Python script, that you've got a pathname for, in a separate Python interpreter, right?
While it's possible to figure that out from the pybotwar code, there's a whole lot of extra stuff that will get in the way of understanding it—the conf.py file, the configurable extra flags, etc.
But the answer is simple: Use the subprocess module, just as you would for running any program. In this case, the Python interpreter is the executable (usually you want sys.executable, the same Python interpreter you're using), and the script you want to run as an argument. For example:
script_output = subprocess.check_output([sys.executable, script_path])
The subprocess documentation explains all the different options very nicely.