As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I know PyCharm is young IDE but id like to know if you guys have found some candy while using it. I know from experience that JetBrains IDE's are filled with candy and can't wait to find it all.
Please list your tips, perhaps something you did not first expected to be there.
As the lead developer of PyCharm, I can tell you that we don't usually hide features in random places, and there are a few reliable ways to discover most of them.
Try Ctrl-clicking on everything (methods, functions, template tag names and parameters, etc.)
If Ctrl-clicking works, usually so does completion (Ctrl-Space), rename (Shift-F6) and Find Usages (Alt-F7)
Look through the menus and try out the actions that seem interesting
Look at Settings | Inspections to configure the warnings which can be highlighted by PyCharm, and note that many of the inspections have quickfixes to correct the problems automatically
Read the blog and try out the features highlighted there.
I have recently discovered an option (I think it's off by default):
Surround selection on typing quote or brace
Basically if you can quickly make a string from anything, just press Ctrl-W to select and then type quote. Awesome :)
PS: To enable this use settings search function, search for: surround
I like ctrl-w, the select block function. I've never ran across this before I think it's great to be able to select a function/if block by just pressing ctrl-w a couple of times.
This isn't PyCharm specific, I actually discovered it in IntelliJ but I though the PyCharm users should benefit too...
Try Alt+Click (Ctrl+Alt+Click if using Gnome default keymap) and drag to select text. It will select bounded blocks instead of complete lines using word wrap. These selected blocks can be used to type repetitive text or delete many parts of a line at once. Try it, you will find uses for it more often than you think!
I don't know if this is a hidden feature really but when you know about it makes testing so much easier.
If you run your tests through PyCharm you can click on the names and lines of the backtrace to take you to the exact line in your python code. Makes testing so much easier.
Control-clicking a view method in a URLconf will open views.py and bring you right to that method. Similarly, control-clicking template names in a view, and in other templates (like in the extends tag) will bring you to that template.
Not hidden, but when editing a CSS file, it shows the colors in the gutter for any styles that use color. I love that. Also for CSS: code insight offers optimizations of tags, as well as graying out unused tags.
When editing an HTML file, moving the mouse towards the top-right of the editor will display icons for several browsers...clicking those will open the current HTML in the respective browser. Not as useful if you're using Django templates, but another piece of IDE-candy nonetheless.
Auto-import is also probably one of my favorite features. It still needs a bit of work, though. This is just a preview release, so I'm sure it'll continuously get better.
Well done, JetBrains!
Something I recently had to figure out was how to pass hardcoded arguments to a Python program when running it. I wanted to do it in the IDE rather than having to switch back and forth to a command window to run the program.
In PyCharm 1.5.2, you can click on Run, then Edit Configurations. The third textbox from the top, labeled Script parameters, allows you to hardcode program parameters. These will be used each time the program is run from PyCharm.
Related
I have written a Python script which models an academic problem which I wish to publish. I will put the source on Github and some academics that just happen to know Python may get my source and play with it themselves. However there are probably more academics that may be interested in the model but that are not python programmers and I would like them to be able to run my model too. Even though they are not programmers they could at least try out editing the values of some of the parameters to see how that affects the results. So now my question is how could I arrange for a non-python programmer to run a Python program as easily (for them) as possible. I would guess that my options may be...
google colab
an online python compiler like this one
compiling the program into an exe (and letting the user set parameters via a config file)
something else?
So now a couple of complications that makes my problem trickier.
The output of the program is graphical and uses matplotlib. As I understand it, the utilities that turn python scripts into exe files struggle or fail altogether when it comes to matplotlib.
The source is split into two separate files, one small neat file which contains the model and the user might like to have a good look at it and get the gist of it even if they're not really a python programmer. And a separate large ugly file which just handles the graphics - an academic would have no interest in this and I'd like to spare them the gory details.
EDIT: I did ask a related question here - but that was all about programmers that won't mind doing things like installing python and using pip... this question is in relation to non-programmers who would not be comfortable doing things like that.
Colab can handle the 2 problems, but you may need to adapt some code.
Matplotlib interface: Colab can display plots just fine. But you may want user to interact with slider, checkbox, dropdown menu. Then, you need to use Colab's own Form UI, or pywidgets. See an example here
2 separate python files: you can convert one of them to a notebook. Then import the other. Or you can create a new notebook that import both files. Here's an example.
I've been searching everywhere for an answer to this but to no avail. I want to be able to run my code and have the variables stored in memory so that I can perhaps set a "checkpoint" which I can run from in the future. The reason is that I have a fairly expensive function that takes some time to compute (as well as user input) and it would be nice if I didn't have to wait for it to finish every time I run after I change something downstream.
I'm sure a feature like this exists in PyCharm but I have no idea what it's called and the documentation isn't very clear to me at my level of experience. It would save me a lot of time if someone could point me in the right direction.
Turns out this is (more or less) possible by using the PyCharm console. I guess I should have realized this earlier because it seems so simple now (though I've never used a console in my life so I guess I should learn).
Anyway, the console lets you run blocks of your code presuming the required variables, functions, libraries, etc... have been specified beforehand. You can actually highlight a block of your code in the PyCharm editor, right click and select "Run in console" to execute it.
This feature is not implement in Pycharm (see pycharm forum) but seems implemented in Spyder.
I'm using PyCharm Community Edition 4.5.4, and I hate how it notifies me of every little "mistake" I make even when I have full intention of fixing it within 30 seconds.
My style is to kind of write everything at once (instead of finishing one thing before moving to the other), and thus every second word in my code gets highlighted as variable 'x' is not used or Unresolved reference 'x' because I already moved to an other section of my code, intenting to finish the for loop later. If I do something like:
for x in my_list:
pass
And then move to define my_list on top of the file, it will instantly highlight Local variable 'x' is not used. I wish to write my whole code freely, and then after hitting save, I wanna know what mistakes I made.
Is there any way to disable the PEP8 checker, so it would only check when I actually save the file, instead of when I type anything at all?
I have had problems with this issue too.
Unfortunately, there seems to be no documented way of doing what you're requesting. The PyCharm Articles on Code Inspection and Configuring Inspections really don't hint at any such possibility.
Additionally the config file in ~/.PyCharm40/config/inspection/Default.xml isn't what you would call rich in options (note: I have no idea if more options exist, couldn't really find appropriate documentation).
Since pep8.py is apparently ran continuously as a background process in PyCharm, I also checked whether a configuration of these processes was possible. Unfortunately (again), no useful results were found.
To make things worse, there seems to be no relevant plugin available in their plugin repository to allow for further tweaking of the inspection tool.
The other option I tried was by changing the settings in PyCharm and resort to manual calls to pep8. I unselected the inspections for pep8 from Settings | Editor | Inspections | Python tab and then ran the manual inspection by pressing Ctrl + Alt + Shift + I and entering the two pep options. It does not seem to catch the same coding convention errors.
You probably have two options now, one is switching to another IDE as Adam Smith suggested (or noted, actually) and second is trying to maybe get some help on the PyCharm forum.
Is there any way to enable code hiding (hides the details of a class or a function just shows the definition) and line numbers in IDLE ?
Don't think so. It was discussed briefly on the mailing lists, but I don't believe anything's come out of it since.
If you're interested in code folding, look into slightly more powerful editors - Geany (GTK) and Sublime Text both support code folding.
A code/line folding feature was asked before in that Python Issue. It was closed and rejected but with good reasons.
If you know this features of IDLE you maybe do not need code folding anymore.
Module Browser:
To get an outline view of a file's classes and functions, use File => Module Browser (ALT+C).
Code Context:
To get a dynamic view of nested compound statement headers with Options => Code Context.
I am using a Solarized theme for (g)vim, and having an issue with small difference between the screenshot on the site and what I am actually having.
The screenshot for python on the theme's site is here:
(source: ethanschoonover.com)
, and mine is
They have a small difference (that I can see) in import statement (color is different). It sort of drives me crazy. Is my case correct, and that's what supposed to happen, or my settings are wrong?
I've installed the theme using vim-addon-manager plugin system.
Thanks.
The first thing you can check is what :highlight groupings are being applied to your import statement, I have a key mapping for a function which can do this:
" Show the stack of syntax hilighting classes affecting whatever is under the
" cursor.
function! SynStack()
echo join(map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")'), " > ")
endfunc
nnoremap <F8> :call SynStack()<CR>
If you :source a file containing this or put this in your .vimrc and reopen vim, we can now check what highlighting is being applied to import.
When I press F8 on an import I receive the message pythonInclude, now if you don't see that there may be something wrong with the parsing of python file and the keyword import hasn't been picked up on. We can then look at what rules are being applied to that-
:highlight pythonInclude
This gives me-
pythonInclude xxx links to Include
If we follow this then we can see what rules are being applied to Include group. This will probably go deeper, Include xxx links to PreProc. If you get this far your highlighting groups are probably correct. If you didn't link to PreProc there maybe another plugin overwriting the highlight group, or a similar issue. You can then check what colors the PreProc is setting. You can override a highlight group link, :highlight link pythonInclude Function this will now display imports as the same color as Functions!
You can also modify the colors and formatting applied to different highlight groupings however I will leave you to discover those on your own. Much more help can be found in :h :highlight, but I hope this helps start your debugging process!