Pycharm Command Line Codes [duplicate] - python

This question already has answers here:
Pycharm and sys.argv arguments
(12 answers)
Closed 5 years ago.
I recently just downloaded PyCharm, and I want to get to know it better, however, codes that I would normally run through the terminal, like an argument parser, I no longer know how to do. Here is an example of what I would put into my command line:
python read_in_data -w wide_data_set -s row_number -o output_path
This would then run the code with my given arguments.
Any basic tips on PyCharm would be helpful, as I am very new to it.

(Top of your screen) Go to Run > Edit Configurations, then enter the command line arguments into the "Script parameters" box. These will then be used when you run the code.
For basic tips/an intro to PyCharm - see the tutorial videos on their website.

Related

how to run command line python scripts within my code [duplicate]

This question already has answers here:
How do I execute a program or call a system command?
(65 answers)
Closed 2 years ago.
there are some scripts that you have to run them from command line like
python run.py -u alex__a -p 123 -v -f
I want to work with them inside my code I don't know whats the name of them so I wasn't able to google about my question . sorry if it't so simple
You are looking for sys.argv to access them. Here is a tutorial:
https://www.pythonforbeginners.com/system/python-sys-argv
If you want to get more serious and use a package to do this more elegantly, you should research the argparse package which is excellent and very intuitive to use.

Spyder command line [duplicate]

This question already has answers here:
How to use argv with Spyder
(4 answers)
Closed 2 years ago.
I'm using spyder for python programing.
I've a file.py and I want to run code like:
--model=RNN --optimizer=SGD
but when I run it in the spyder console it gives this error:
SyntaxError: can't assign to operator
So how can I run this?
In Spyder, if you go into the Run menu, you'll find an option named Configuration per file. On my system, you can get directly to that entry with CTRL+F6 (the shortcut key may be different on other OSs).
Once you select the menu item, you'll get a dialog window with several options. The one you want is about halfway down, named Command line options. You will want to check the box, and put the arguments you showed above into the adjacent text field. Now when you run the file, the code will behave as if those options were passed to it on the command line (it will see them in sys.argv).

How to keep a terminal opened by Python alive? [duplicate]

This question already has answers here:
How to keep a Python script output window open?
(27 answers)
Closed 3 years ago.
In my Python script, I create a .bat file (many actually), and I run them via
os.startfile(blah)
Everything works like expected, however, those terminals die after finishing. I want to keep them open, so that I can type more commands manually in those opened terminals.
How?
You could try using the cmd command to run the batch file, and then use command line arguments for cmd to modify its behavior. For example:
os.startfile("cmd.exe /k blah.bat")
Documentation of the available command line arguments can be found here:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd

How to configure in .vimrc , execute current file python f9? [duplicate]

This question already has answers here:
Running Python code in Vim
(25 answers)
Closed 5 years ago.
I'm newbie in this editor but it's complex to configure vimrc. I know and understand that everything stay there but I don't understand how to configure, specifically the code. On the other hand, I am writing Python code using Vim. Every time I want to run my code, I type this inside Vim
:w !python
This gets frustrating, so I was looking for a quicker method to run Python code inside Vim. If somebody can I help me, I would be very grateful.
You've very close. The following works in my config:
nnoremap <F9> :w<cr>:!python %<cr>
First, it enters the command to save the file (:w). Then it tells the shell to have python (!python) run the current file (%).

Pydoc won't run on command prompt [duplicate]

This question already has answers here:
Pydoc is not working (Windows XP)
(8 answers)
Closed 8 years ago.
I'm working through this "Learn python the Hard Way" book and the book is now saying to run
'pydoc open'
I do this and get the response that pydoc is not an internal or external command etc.
I've trying adding 'C:\Python27\lib\pydoc.py' to PATH and restarting my computer but it still hasn't worked.
Python is probably not in your path. you must add it in your path either by using the GUI or something like this:
set PATH = PATH;/path/to/pydoc/
This is a windows example, but it should not be hard to convert to a *nix version. The export command can be used in that case.

Categories