Every time I open a Python file PyCharm will hide all imports and shows:
import ...
within the editor.
I have to manually unfold it to see the imports. Where do I find the setting to undo auto-hiding of import statements?
As this question may be useful for people who also are not looking for the term "code folding", I'll make my comment an answer.
As extracted from IntelliJ IDE Web Help, but also worked on PyCharm CE 3.4.1:
Open the IDE Settings (File > Settings, or Ctrl+Alt+S).
Under the "Editor" node, click "General" and then "Code Folding". The "Code Folding" page is displayed.
In the "Collapse by default list", select the check boxes to the left of the code constructs you want to be displayed collapsed. So here you can uncheck "Imports".
Apply changes.
The image below shows what it looks like:
Actually in pycharm 2016.1 it's Editor -> General -> Code Folding
Related
I have made a search in PyCharm with classical Ctrl+Shift+F, and I just want to set a breakpoint at every line in result for debugging at once.
Does exists some functionality in the IDE to do this?
There's no such feature, unfortunately. Though you can place breakpoints manually in "Find in Path" preview window for a given search item.
Feel free to create a feature request in PyCharm's bug tracker https://youtrack.jetbrains.com/issues/PY
I just installed Anaconda and running Spyder I cannot find the Object Inspector. Hitting Ctrl+I has no effect and in the View/Panes menu there is no item Object Inspector.
I have seen videos and tutorials that show the Object Inspector. What is happening?
The "Object Inspector" is now called "Help" (from Spyder version 3.0 onwards); see https://groups.google.com/forum/#!topic/spyderlib/pF7KmSKDFXc . However, the Ctrl-I shortcut has not been changed, so I'm not sure what's happening with that.
go to preferences > Help and enable the Automatic connections for Editor and restart the Spyder
This worked for me!!
Although it's given in the tutorials but I'll explain.
1) Object Inspector is now known as Help.
2) I'm using Spyder 3.6, here go to Tools-->Preferences-->Help-->Check on Editor in Automatic Connections
3) Select your parameter and Ctrl+I
That'll do it.
I had the same problem. I found the help and then discovered that I got a message saying No Documentation. I tried changing the setting from Rich Text to Plain Text and for some reason that worked and I'm able to use the Object Inspector.
Since they changed "Object Inspector" to "Help", as Jitse Niesen says, they might have changed the shortcut too. In my Mac version the shortcut for "Help" is Shift+Cmd+H so the combination you are looking for is probably Ctrl+H.
On mac using Spyder 3.3.1 run from Anaconda.
Cmd + I was not working for me at first to show the object inspector on the right pane for help on a particular function. So I typed in Cmd + , (which is to access preferences panel in any app on Mac), and went down to "Help" on the left side.
Then, I checked the boxes for "Editor" and "IPython Console" under the description that says
"This pane can automatically show an object's help information after a left parenthesis is written next to it. Below you can decide to which plugin you want to connect it to turn on this feature."
After checking these boxes and pressing OK, Cmd + I still did not work for getting the object information.
I restarted Spyder, closing it and reopening it from Anaconda navigator.
Now Cmd + I works and shows the information for whatever function I click on.
Hope this helps someone. I'm still not quite sure what happened here (since those checkboxes were for the left parenthesis function), but I still thought that sharing the steps will be useful to some people.
In Windows, Ctrl+Shift+H worked after making changes to preferences as suggested by Ibrahem
Go to preferences->Help and tick the option of showing object info on Editor , then ctrl+I will work with any object
One way to go about this is to go to View > Panes > Online Help. Then in the search box insert the module or package like so (sklearn.preprocessing.Imputer) and you will have all the docs related to the package.(**Shortest way: click on package....then Cmd + i )
Alternatively, right clicking the Object in the editor, select Go to Definition
Third way, in your console, type help(your class here) like help(Imputer) or just help() to get the interactive console then type your package there (sklearn.preprocessing.Imputer`).
Hope this help someone.
After pressing Ctrl+H , a help window will come in that in [Source] dropdown select Console
Please check the spelling of your command, if you type wrong spelling it wont display the help
Note that in Spyder version 3.2.4 under Tools>Preferences>Help>Automatic Connections it clearly now states: "This pane can automatically show an object's help information after a left parenthesis is written next to it. Below you can decide to which plugin you want to connect it to turn on this feature." Then you can select Editor and/or IPython Console.
When I tried this, placing a left parenthesis before the (term is the only way I could get the help to bring up an example and a definition.
Nothing worked from above. I can debug objects easy in Visual Studio Code, but I can not do it in Spyder 3.2.8 installed with Anaconda 5.2 for Windows. In IPython console during debugging I use following.
To inspect an object:
vars(my_object)
To list class objects:
[obj.name for obj in gc.get_objects() if isinstance(obj, my_class)]
This solution solved the problem and shows objects in Variable Explorer.
https://gitter.im/spyder-ide/public?at=5b69bac8e9ab53770ca018d0
Question:
How can I explore objects during debugging like I explore variables?
In IPython consle I use vars(my_object), this is a prompt way. I want a GUI way for Object like Variable explorer.
I want a GUI way for Object like Variable explorer.
Answer:
As a matter of fact, Spyder has one, exactly like the Variable Explorer: it's called...the Variable Explorer! If you can't see them, make sure Exclude unsupported data types is not selected under the "Gear" menu in the top right of the pane.
Most arbitrary objects should work, although there may occasionally be a few bugs for more esoteric ones. Even better support will be coming in Spyder 4.
Just left click on the top right corner, beside the close tab of editor and below the working directory tab
I tried it, and it successfully worked.
How do I enable indentation in Visual Studio Code?
I'm trying to learn Python (new to programming) and need auto-indentation. It worked with the first version I tried, but it doesn't indent after a colon (:) any more. How can I configure it to automatically indent?
You can install the Visual Studio Code Python extension which will provide intellisense, auto-completion, code formatting, and debugging.
Here is more information on the Python extension, here.
As said there is the Python extension which now do it out of the box, but still don't do a great job, and an example is when you copy and past a whole block into a function or so. It just indents the first line, and that's not a good behavior. Here are two good helpful solutions:
indent a whole block manually: select the whole block, and then click Tab. If you want to indent backward, you do it with Shift+Tab. That's it, and I think that can be useful in several places.
Python auto indent extension (https://marketplace.visualstudio.com/items?itemName=hyesun.py-paste-indent). It solves the problem when pasting. Just see how it works in the link. Now about setting it up: You need to set just one keybinding for the command "pyPasteIndent.pasteAndIndent" provided by the extension. Once done, you will have your own shortcut to paste and indent automatically (I have set it to Alt + P)
Here is how:
- Ctrl+SHIFT+P to open the command palette, then write "key"*, choose *"open keyboard shortcut", and then the keybinding page open, which it's the nice interface for the **keybindings.json. You can open keybindings.json the same way and by choosing "open keyboard shortcut file" (in place of just "open keyboard shortcut"). Give it a look if never have. But here I will go with the nice interface. Know also that you can open that going menu File → Preference → Keyboard Shortcut.
In the keybinding window, in the search bar, paste pyPasteIndent.pasteAndIndent, and then click the + button to add the shortcut and create the keybinding.
The image below shows well how it's done:
I installed this extension: Python Indent. It works very well.
Simple solution!
Click the tab size (may show "Spaces: 4") in the bottom right corner and choose Convert Indentation to Tabs or Convert Indentation to Spaces as per your requirement.
I faced similar issues while editing. Select the lines of code you wish to intend and press Ctrl + ] in Windows or CMD+] on Mac.
You can change the indent size in settings. Search for tab size in settings. I use two, by the way.
I faced similar issues switching from PyCharm. The Python Indent extension, which is available in the Visual Studio Code marketplace, works perfectly fine for me.
For me, "Convert Indentation to Tabs" has worked.
To do that:
Go to "Command Palette" Ctrl+Shift+P (View>Command Palette)
Type in & select "Convert Indentation to Tabs" and press Enter
I'm coming to PyCharm from Eclipse, and something that is annoying me is how I switch between open files in the editor.
In Eclipse, I had a hotkey set up to open the previous editor. A menu would appear with the files in order of most-to-least recently viewed. If I hit the key once quickly, it would switch to the last file viewed. Whatever I had been working on recently would always be readily available.
In PyCharm, the files are listed in the editor in seemingly random order. Control+left (or right) takes you to the next file in the listing, which may be near a file unrelated in any way. I can use the mouse to select a file, but I'm not used to this, and it makes me stop and think about what the file name was, what module it was in, etc.
Natural, quick, efficient, minimum of thought -- this is what I'm looking for in navigating between open files in the PyCharm editor. Does anyone know of a way I can achieve this?
Thanks!
Ctrl-Tab switches in most-recently-used order (like Alt-Tab for the desktop). Ctrl-E will show recent files.
You should look at Help > Default Keymap Reference, under the navigation heading, for more helpful shortcuts.
I'm just starting out learning python with GEdit plus various plugins as my IDE.
Visual Studio/F# has a feature which permits the highlighting on a piece of text in the code window which then, on a keypress, gets executed in the F# console.
Is there a similar facility/plugin which would enable this sort of behaviour for GEdit/Python? I do have various execution type plugins (Run In Python,Better Python Console) but they don't give me this particular behaviour - or at least I'm not sure how to configure them to give me this. I find it useful because in learning python, I have some test code I want to execute particular individual lines or small segments of code (rather then a complete file) to try and understand what they are doing (and the copy/paste can get a bit tiresome)
... or perhaps there is a better way to do code exploration?
Many thx
Simon
Yes, you use "external tools plugin"
http://live.gnome.org/Gedit/ToolLauncherPlugin
As an example,
Edit > Preferences
Plugins
Tick "External Tools"
Close the Preferences Window
Tools > Manage External Tools
Click the "Add new too" icon in the bottom left
Name it "Execute Highlighted Python Code"
give it a keyboard shortcut
change the input combo box to : "highlighted selection"
change the output to : "Display in Bottom Pane"
In the editor window for the tool, replace everything with :
.
#!/usr/bin/env python
import sys
result = eval(sys.stdin.read())
print expression, "=>", result, type(result)
.
If you wish to see the result of entire .py file, you can put this code in your new created external tool window
#!/usr/bin/env python
import sys
exec(sys.stdin.read())
and change the Input to Current document.
For python, You can use "external tools plugin":
#!/bin/sh
python3 "$GEDIT_CURRENT_DOCUMENT_PATH"
Option of external tool:
Save: Current Document
Input: Current Document
Output: Display in bottom panel
Language: Python or Python3
Don't forget the quotes around $GEDIT_CURRENT_DOCUMENT_PATH....
To answer your second question, and hopefully guide you in a direction you'll be happier with, I think you ought to consider trying some different editors. There are many with more powerful code exploration features than GEdit has. Check out this post:
What IDE to use for Python?
I installed iPython console in gedit and do most of my simple scripting in it, but gedit is a very simple editor, so it'll not have some advance feature like an IDE
But if you want code exploring, or auto completion, I recommend a real IDE like Eclipse.
If you just want a editor, KomodoEdit is fine.
What I do is keep a file called python_temp.py. I have a shortcut to it in my dock. I use it as a scratch pad. Whenever I want to quickly run some code, I copy the code, click the shortcut in the doc, paste in the text and hit f5 to run. Quick, easy, simple, flexible.
I think what you're looking for is http://live.gnome.org/Gedit/Plugins/BetterPythonConsole.
You hit F5 and it runs the code in your file in a IDLE-like console. I don't know if it can only run selected code. (I don't think it can) but you can always copy the needed code in a new window and run it from there.
Have a look through the plugin list for other interesting stuff: http://live.gnome.org/Gedit/Plugins
The closest to a decent IDE...
Install gedit-developer-plugins (through synaptic || apt-get) and don't forget to enable (what you need) from gEdit's plugins (Edit->Preferences [tab] plugins) and happy coding