Scripts overlapping while running in Pycharm - python

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.

Related

Problems with opening html

This must be the most weird and confusing problem I've ever seen. So I've been trying to open an html file with python using the:
import webbrowser
webbrowser.open_new_tab()
method, at first it worked as intended but then problems started to appear. When I ran the program the file would open, but after 1 second it would close. This would always happen when I ran the program with VS code but when I ran the python program in IDLE (v3.10.0) the program ran just fine. I'm out of my depth here and I have no idea what could be causing this problem.
def visit_website():
print('Would you like to visit our website ?')
def_a=input()
if def_a=='yes' or def_a=='Yes' or def_a=='ok' or def_a=='Ok' or def_a=='OK':
webbrowser.open_new_tab('demofile.html')

Running two python file at the same time in visual studio code

i have two files, and i want to run both. The first one is basically asking down the prices of stocks and writes them to a database, and the second one using python dash to create a webpage. This webpage is showing the data in real time from the database which is constantly refreshes. I tried to use threading but it does not work, because the two files basically function as two infinite while loop. How should i solve this problem?
The two functions im having problem with are
dataMiningScript= fd.financeData(database,1600)
and
if name == "main":
app.run_server(debug=True)
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
database=db.dataBase()
homepage=hp.homepage(database)
homepage.timeUpdateCallback(app)
homepage.gaugeRefreshCallback(app)
dataMiningScript= fd.financeData(database,1600)
app.layout = homepage.layoutMaker()
if __name__ == "__main__":
app.run_server(debug=True)
You can just create two terminals in visual studio code to run both files (see here). Or you can create a simple shell script which starts both programs (start a program in the background with a '&' at the end of the command line)
For some reason i cannot run two python programs at the same time in Visual Studio Code, but i managed to solve this problem with the solution of the first commenter:
I opened terminal and search my .py program. Then i write
python3 xy.py
Helpful discussion here: run multiple python scripts at the same time.
Covers the question posted at the title fairly well.
On new window I managed to run the necessary code by typing a command. Run Python File button remains tied too original window.

how to add execution time in atom terminal

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}]')

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