I am trying to write a Python script that automatically draws out some plots and scatters on visit using my CFD results. I have the .visit file and it all works fine when I do it manually but I would like a python script to do it so I don't have to set everything up every time.
This is the code I wrote:
variable = ('nvrh','nvpr','nvtp') # define variables
OpenDatabase("runs/movie.visit") # open the data
for x in variable:
print "Drawing variable : ", x
AddPlot("Pseudocolor", x)
p = PseudocolorAttributes()
#p.colorTableName = "caleblack"
#SetPlotOptions(p)
DrawPlots()
and I run it on the terminal as:
visit -cli -s draw.py
which works just fine, but, the problem is it only creates a window and it fails to create the main window that you get when you normally launch visit. So i tried to launch it normally then add plots like so:
Launch()
variable = ('nvrh','nvpr','nvtp')
OpenDatabase("../runs/run2/movie.visit")
however when I do this, it launches an instant of visit then ignores the subsequent code and only when I close visit it does the same thing as before and launches only a single window.
What I am wondering is if there is a way of launching just the Main Window (the small menu thing) by the Python script.
Sorry if my question is a bit confusing and I am praying for experienced visit users as the community seems to be non-existent. Thanks for the help!
Related
recently I switched from Spyder to VScode and I miss getting the output of python scripts in console. By that I mean:
Let's say I have a script as follow:
x = []
def append_func(x):
for i in range(10):
x.append(i)
return x
y = append_func(x)
and when I ran that script in Spyder, x would be generated, append_func would be declared and y would be generated as well. Then in console (outside of the script) I would write:
sum(y)
len(x)
len(y)
and get informations that may interest me after running the script.
So I would like play with my variables that were generated inside the script without editing the script and rerunning it.
Similar functionality is in Matlab - whenever we run the script, all of the variables and functions defined in a script are accessible in console, so we can transform/calculate/reuse them, check how some variables look like or what are their types, (...).
It's very handy when the scripts has kinda long execution time and we want to check some statistics of variables we didn't think about before.
Is such functionality in VS Code?
Screen from Spyder. As we can see x and y got saved into memory and can be used in the console:
Please use the python interactive. There are two ways in vscode, one is terminal and the other is window.
Right-click and select Run Current File in Interactive Window to open an interactive window and run the current script. You can continue to enter python code in the input box below and execute it with Shift+Enter.
Or use Shift+Enter to open a python interactive terminal, then select all the code in the file and press Shift+Enter to run code in the terminal, then you can continue to type python code and press Enter to execute.
If you want to look at the variables, clicking Variables in the interactive window will open a variables panel for you to look at.
There are more detailed instructions in the official documentation.
In addition, as you can see, there is a shortcut key conflict by default. If you want to use the shortcut key Shift+Enter to open an interactive window, you need to modify the corresponding shortcut key settings.
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.
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.
I have written code in a New file window in IDLE.
When I run the code there is no output.
Instead a dialog box appears showing a window accessing Python Folder 37-32.
When i closed the dialog box and the file I tried to create a new simple code below but I when I ran the code I got the same Dialog box.
What is wrong?
sum = 2+3 print(sum)
I have attached a screenshot showing the code and the dialog box that appears when the Module is run
Before you can execute your code, your first need to save the file. Thats the dialog box that popped up.
You should have seen a popup box like below. Did you? Is is unclear?
Save Before Run or Check
? Source Must Be Saved
OK to Save?
[OK] [Cancel]
One reason to require saving is that exception tracebacks refer to the file and line of lines that lead to the exception.
If you had saved, sum = 2+3 print(sum) would be a SyntaxError.
You can run single statements in Shell without saving.
The RESTART lines says that the shell re-initialized the environment for executing your code.
You should normally not save your code buried in the installation Scripts directory. Better to make a directory in your user directory, for instance, C:/Users/yourname/py/.
Yes, one should usually open a new question for unrelated questions. But without access to your machine, it is hard to know what happened with 'new'. It may be that IDLE could create a file under .../appdate/.../Scripts/, but your code cannot. If the open call did not raise and exception, it was likely created somewhere. Until you are more experienced, better to use absolute paths, such as C:/Users/yourname/py/new.txt.
If I want to make a button in Kodi's menu and run a local python script upon clicking it, what's the best way to go about it?
file_path = xbmc.translatePath(os.path.join('insert path here to file you want to run'))
xbmc.executebuiltin("XBMC.RunScript("+file_path+")")
Very late reply but saw no one else had answered so though i'd put in just in case