how to add execution time in atom terminal - python

script output panel doesn't take input from user so I have to use the platformio terminal plugin in atom but it doesn't show the program finished time or execution time, I know, there are some packages to show the execution time like given below. But I don't wanna use the same code in each of my file so is there any way to add if somewhere in the plugin or making some kind of modification in plugin's code file, I have looked up for this but didn't get any relevant solution regarding this. If anyone could please tell me work around this issue.it is necessary to show the execution time in terminal to show the efficiency for the code.
import time
starttime=time.time()
for i in range(1,10000):
print(i)
endtime=round(time.time()-starttime,2)
print(f'Finshed [{endtime}]')

Related

Python how to paste clipboard not in terminal [duplicate]

I am trying to code a very basic code where I copy some text from one program and then paste it in a different program. I'm not sure how to do this as Pyperclip only seems to paste the text on the command window where I run the code. I want to be able to click on the text-editing program and then have my code paste the text there. I'm attaching my code
import pyperclip
import time
pyperclip.copy('testing')
time.sleep(5)
pyperclip.paste()
When I run this code nothing actually happens. It doesn't paste anything, not even on the command window. I have the sleep function there because that's when I take the time to click on the text-editing program so that Python pastes the text there but it doesn't work.
If all you want to do is copy content to another text editor, then try using pyautogui module. This module allows mouse/keyboard automation via python code.
Code:
import pyautogui
import time
time.sleep(5)
a = "testing"
pyautogui.typewrite(a)
The above code will start typing the word testing after 5 seconds of program execution, so you will have to open your text editor during that duration.
The best part (or the worst) about pyautogui module is that it is focus independent i.e. it works regardless of whether the current application has focus control or not.
Just a sidenote don't use pyperclip for copying/changing/accessing clipboard data, rather try win32clipboard, if you're on windows, as it allows a lot better control over the clipboard.
Although this is a rather old question the answer cost me several hours. My goal was to input a number into another program. That program however is autocompleting the input and therefore using typewrite() (write() in the current version of pyautogui) leads to unexpected behaviour.
However pyautogui helped me in the end, together with pyperclip. Here is the code I am using:
import pyperclip
import time
pyperclip.copy('hello')
time.sleep(5)
with pyautogui.hold('ctrl'):
pyautogui.press(['v'])
This solution is dirty, but it works.

VS Code clear previous output before each run

Extensions installed: Python, Code Runner
The problem is I was trying to enable the "clear previous output before each run setting"
But when I try running a simple code the output (in terminal) becomes glitchy.
The code I am running is:
print('hello')
a=input()
print(a)
Here is the first time I run the code in completely Blank terminal
The first attempt is pretty normal.
Here is the what happens when I run the code again
There is a lot of blank space in the terminal which becomes worse the third time I run the code
This blank space worsens till the 5th attempt and here is what happens on the sixth attempt.
Basically the blank space vanishes and all the previous attempts can be seen in the terminal. But that means the initial setting I intended did not apply and terminal does not get cleared before each run.
Can someone tell how to automatically clear terminal before each run.
"code-runner.clearPreviousOutput": true works well in OUTPUT panel, but does not work in the terminal.
Someone else has submitted a feature request for it. You can refer to this page and upvote it.

Scripts overlapping while running in Pycharm

screenshot of my pycharm interface
Hey everyone. When I run this simple code (the tab 'youtubeyf.py
is to print 'hello world'), it produces the intended result but also another script (with the tab name "yfinance.py") result as well. In fact, the "yfinance.py" script doesn't need to be open in order for that result to appear too. It is almost as if it runs in the background, parallel without being open.
Goal: I want to run "print 'hello world'" without the dataframe from the other script appearing.
Problem: the dataframe is appearing without actually running or being open.
Troubleshoot attempts so far: I have "Alphabetted" and searched on StackOverflow, JetBrains on topics regarding reconfiguring the "run configurations", "parallels", and nothing yet.
Thank you for your time.
Edit 1: this does not solve my problem. for one, my issue isn't importing. in fact, everything is "running" smoothly, but that the results are two in one. It is analogous to two chefs preparing one meal each, say shrimp lo main and pizza, and then placing both meals onto one plate. I don't want that; I want to have shrimp lo main on Tuesday night, and then pizza Wednesday.
When importing yfinance, it could be possible that in that module, your code is structured such that when you import the module it runs a function or other code. In yfinance, you should delete any extraneous function that doesnt need to be run everytime you import yfinance somewhere else.
Edit: what you can do, if you dont want to change much of the structure yfinance.py, is wrap all the code that runs in that python file inside a main function and add the following:
if __name__=="__main__":
main()
This makes it so that python only runs main if you're actually running yfinance.py , and doesnt run main when you're importing it.

What does it mean to "restart" a program (in my case IDLE)?

This answer on Stack Overflow offers a solution I am trying to implement. In particular, see the sections "Installation Instructions" and "How to Use".
Can anyone tell me the steps required to "restart" IDLE?
New Information:
Just as people have suggested I thought this simply meant closing the program and opening it back up again...but I already tried that.
The other twist to my situation is that I'm working on a virtual machine so I was unable to do the installation of IDLE2HTML.py myself. My work's Help Desk had to do it so I cannot speak for the accuracy of their work. For now I'm assuming they did it correctly, but when I go to the "Options" menu there is no option to "Save as HTML".
My only guess at this point is that I still need to "restart IDLE".
Just wanted to double check if there was something else I could do before going back to my Help Desk department.
IDLE reads the idlelib/config-xyz.def files, including config-extensions.def, just once, when it starts. So any changes to config-extensions.def only takes effect the next time you start IDLE.
If you do not see 'Save as HTML' after starting IDLE, the extension is not installed properly.
It means you need to close the IDLE so that any changes made by the script can affect the IDLE
Simply close the IDLE either via the X, Ctrl+Q or File>Exit, then open the IDLE again.
If you are using idlelib module from a Python program then close your program and run it again.

Make a full terminal window application like Vim/Mutt/Cmus

I'm not sure quite how to word this, which is probably why I'm having trouble finding an answer.
I have a command line script that runs a rummy game, I want it to take over the terminal kind of like how Vim or Mutt does, so that each round is refreshed in the full terminal window rather than just printing out row after row of text.
Can someone tell me what that is called, so I can research it and find out how to do it?
Repo: https://github.com/sarcoma/Cards
You're looking for a console user interface. One of the best libraries for python would be http://urwid.org/
As mentioned in a comment "pythons curses module does what you require".
This is what you need to take over the terminal: https://docs.python.org/3.9/howto/curses.html

Categories