Automatic indentation for Python in Notepad++ - python

I've been googling lots and this is getting really frustrating. It doesn't act like idle.
Example:
else:
name = 'World'
print 'Howdy', name
print 'yay'
but in Notepad++
else: # i press enter and this is what it does
lands me here
But I want to be able to do like in idle: after the : I can just press enter and keep on going. My English isn't that great.
I have my filetype set to Python etc. and my format to unix.

This is what you want:
Settings > Preferences > MISC. > Auto-Indent (checkbox)
--
Sometimes people ask, "How can I do x in program y?"
I have a dream that one day "Use program z instead" will not be the most popular response.

I played a bit with python in Notepad++ and I had a problem with the tab.
Since in python your indentation is really important but notepad ++ put space instead of a tab.
So to change to tab you need to go in notepad ++ Menu Settings > Preferences... then select Tab Settings Then select python in the Tab Settings box and uncheck Use default value and check Replace by space.
Like the other answer, you might want to consider another ide.
I personally use eclipse with the pydev plugin and django plungin.
Erik is nice too.

I found the Python Indent plugin on the official plugin page, and it worked fine!
http://docs.notepad-plus-plus.org/index.php/Plugin_Central#P

Well, here is a updated answer:
Notepad++ >> Plugins >> plugin manager >> show plugin manager >> find (python indent) click install >> should be downloaded you need to reach to enable again from Plugins>>python indent>>enable

Go to Settings > Preferences > Language
Then on the "Tab Settings" box select "python"
and tick the "Use default value" checkbox.
You're welcome.
P.S. Yeah, I know this a little old. I really just couldn't help it.
Anyway, this is for version v7.3.2.

-- For Newer Versions , Goto Settings>>Preferences>>Auto-Completion>>Auto-Indent(checkbox)
-- For Older Versions , Goto Settings > Preferences > MISC. > Auto-Indent (checkbox)
By the time of this post, The newest Version of Notepad++ is v7.8.7.(tested)

Click on Settings
Click Preferences...
Browse drop-down menu to find MISC.
Tick the box which says Auto-indent
After that, you should be fine.

Restart Notepad++ after, and then it works.

This is for Notepad++ version v8.1.9.3 (the latest as of today)
Before starting this, save your work... but no need to close any open tab
First; install the plugin
Plugins > Plugins Admin > Search: Python Indent > Python Indent (check box) > Install > Yes
Notepad++ will restart... it will take 10 seconds or so
Second; enable the plugin
Plugins > Python Indent > Enable
Third; Have fun!
Do a test... and let me know

None of the above solutions worked for me but this worked:
Install latest version of notepad++ (as of Feb 2022)
Goto Settings -> Preferences -> Language -> Tab Settings -> Select Python -> Uncheck (Default Value) and make sure that the 'Replace by space' is selected with 4 as the count
Next, goto Settings -> Preferences -> Auto-Completion -> Enable Auto-Indent (if it's not already enabled)
This should work as expected as it's working for me.

In Notepad++ version v8.4.4
The Auto Indent is located in Settings->Preferences->Auto-Completion
and no longer in MISC.
However, for Python indentation it didn't work for me.
What worked is to use the Python Indent plugin (set to Enable).

A better ide might be spyder. http://code.google.com/p/spyderlib/ its about the best IDE I have found.

Geany is a fast and light-weight cross-platform IDE, it supports auto-completion and auto-identation for python code, execute run your program , integrated console , plus has a symbol list side pannel that lets you visualize and browse you code easily, you can jump directly to function definitions and the likes using the context menu, plus it's open source
How ever for a full fledged IDE i would recommand Eric4

I've found Notepad++ to live up to the task of being a better basic text editor than Notepad, but it isn't really designed to be as smart as a proper programming IDE.
It might be possible to get it to do what you're asking for, but I certainly don't know how to set it up that way.

Emacs has python-mode which (also) does it. Grab it and prepare for life-time enjoyment.

Related

VS Code: Analyzing in the background

When I start a python project in vs code (with the microsoft python extension) it starts "Analyzing in the background" and python keep crashing. It also uses a ton of memory.
Anyone knows how to fix this? Or is it supposed to do this?
This seems to have fixed it for me: https://github.com/Microsoft/vscode-python/issues/4990#issuecomment-477628947
You can disable the new Python Language Server by opening settings in VSCode (Ctrl+, ) and set "python.jediEnabled": true. Then reload the window and/or restart VSCode.
I had the same issue; the only solution that worked for me was to open settings.json (ctrl + Shift + P) and change
"python.languageServer": "Microsoft"
to
"python.languageServer": "Pylance"
Then one gets a pop-up that asks whether one wants to reload the window which one should confirm by pressing "OK".
Then everything works normally again (IntelliJ, autocomplete etc).
As #Vasco pointed out in the comments Microsoft is no longer supported as explained in this thread.
High memory usage: https://github.com/Microsoft/python-language-server/issues/832
Jedi is an autocompletion tool for Python that can be used in IDEs/editors. Jedi works. Jedi is fast. It understands all of the basic Python syntax elements including many builtin functions. So you can switch Jedi instead of Python Language Server.
Process:
set "python.jediEnabled": true
disable the Visual Studio IntelliCode plugin
delete the .vscode directory
Can solve this by either disabling the extension as suggested in previous answers, or excluding large directories (e.g. containing data) from its search path, by adding to your workspace settings an python.workspaceSymbols.exclusionPatterns key, like so:
settings.json:
{
"python.workspaceSymbols.exclusionPatterns": [
"**/site-packages/**",
"your_pattern_or_directory_to_exclude"
]
}
See also the vscode extension docs.
Here is how I solved this issue:
Go to File > Preferences > Settings > TYPE "python.language server"
If set to 'Microsoft' change your language server to 'Pylance'
Python: Language Server
Define Type of the Language Server
SELECT: Pylance
Reload your Visual Studio Code
Try importing your libraries causing the issues again:
import numpy as np
import pandas as pd

Keyboard messed up when using Pycharm as an IDE?

Don't get me wrong, Pycharm is an amazing IDE, and with its faults, I've still continued to use it and adapt to its way of working. But its getting pretty tedious not being able to do what I want.
Like in other IDE's, I can CTRL+A to select all the text, somehow it almost always messed up in Pycharm, copying all text will result in what ever the INSERT key does, and deletes my content.
Clicking backspace doesn't delete the highlighted content, instead I have to deliperatly click the delete key, and this isn't exactly wrong, but it doesn't fit in with other IDE's.
I noticed when switching from Pycharm to another IDE, I was doing what I did in Pycharm and it just felt unnatural, is there a way to make Pycharm work like other IDE's?
If you go into File->Settings and select Keymap, there is a drop-down menu where you can select the emulation that you prefer including Emacs, Netbeans, and Visual Studio
Found this in another forum:
"Please disable IdeaVim plugin on the File | Settings | Plugins tab."
Worked for me.

Prevent PyCharm from opening the browser/new tab on run

I found a number of people who want PyCharm to open the browser/a new tab every time you click run.
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206590705-How-do-I-setup-Run-Debug-Config-to-open-browser-automatically-for-Flask-
Django manage.py runserver doesn't open browser
Well, I click run often and already have the tabs open I need. It's quite frustrating to have to close the new ones, and I want to turn it off. I have looked thru all the menus and I can't find the Run browser setting some people talk about.
I also tried disabling all Django support for browsers in Settings -> Tools -> Browsers, but this made no difference.
Versions:
PyCharm 2017.1.1
Python 3.5.x
Django 1.10
edit run configurations(right next to the play button at the top of the editor) and uncheck the box that says open new window on run .... – #Joran Beasley
P/s: Just comment again.
For version 2018.3
Go to File | Settings | Build, Execution, Deployment | Console.
Check the option Use existing console for "Run with Python console".
2018 :
Edit run configurations (at the left to the play button at the top of the editor, click on the list of configuration then edit configurations) and check the box that reads single instance only

"Edit with IDLE" option missing from context menu

I have Python 2.7.5 that installed with ArcGIS 10.2.2. When I first right-clicked a .py script I'd previously written it listed the "Edit with IDLE" option in the context menu. However, this option no longer appears when I right-click a .py file.
I have read numerous threads concerning this issue and attempted some of them, such as modifying/removing registry keys and then reinstalling/repairing the software. I am not interested in using an IDE at this point, though many will be happy to know I intend to use an IDE later on. Right now, the purpose is to fix the problem rather than avoid and work around it.
I appreciate the help I've gotten from the online community in the past, and I'm confident someone will come through with a solution for me.
How do I get "Edit with IDLE" back in the context menu?
Most of the time when this problem occurs, people will read answers directing them into the windows registry, often unnecessarily.
In the majority of cases, the registry key
HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command
will already exist and have the correct value, but it will only be used by Windows shell context menu if .py files are set by default to open with python.exe.
This is the first thing to check, and solves the problem in the majority of cases:
right click on a .py file
open with...
choose default program...
tick always use the selected program to open this kind of file
choose python.exe
This runs the script in a terminal, but also sets the filetype back to python.
Now check the right click menu again.
As a newer update, for people that are having the "missing idle" issue with Windows 10 using Python 3.6 (64-bit).
From my experience, this happens when you install other python editors, and you change your default app to open with that editor.
The easiest way to fix this issue is to click the "start" button, then navigate to settings --> System --> Default Apps --> "Choose default apps by file type". Scroll down till you find ".py" file type and click on the icon and choose "Python"(has a little rocket ship in the icon). This will change your default app back to "Python.exe", and the context menu "edit with idle" will appear once again on your ".py" files.
Hope this helps!
Directly from: https://superuser.com/questions/343519/python-idle-disappeared-from-the-right-click-context-menu
Here's a reg file to add the command to edit with IDLE for Python.File (.py) and Python.NoConFile (.pyw) file types. It's for Python 2.7, installed in C:\Python27, so substitute the paths to pythonw.exe and idle.pyw that are relevant to your installation. Save it to a .reg file. Then right-click and choose Merge.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command]
#="\"C:\\Python27\\pythonw.exe\" \"C:\\Python27\\Lib\\idlelib\\idle.pyw\" -e \"%1\""
[HKEY_CLASSES_ROOT\Python.NoConFile\shell\Edit with IDLE\command]
#="\"C:\\Python27\\pythonw.exe\" \"C:\\Python27\\Lib\\idlelib\\idle.pyw\" -e \"%1\""
Another option would be to just open the file with the idle by choosing open with:
C:\Python27\ArcGIS10.3\Lib\idlelib\idle.bat
as the default program.
I got the "Edit with IDLE" back with the option "Repair" of the deinstallation-menu.
Adding a little more detail to Teodorico Levoff's answer for those who need a little more explanation, like myself.
Open a text editor, such as Notepad, and copy/paste the following, but be sure to modify the paths to pythonw.exe and idle.pyw so that they match the paths in your own system:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command]
#="\"C:\Python27\pythonw.exe\" \"C:\Python27\Lib\idlelib\idle.pyw\" -e \"%1\""
[HKEY_CLASSES_ROOT\Python.NoConFile\shell\Edit with IDLE\command]
#="\"C:\Python27\pythonw.exe\" \"C:\Python27\Lib\idlelib\idle.pyw\" -e \"%1\""
Save this text file as idle.reg in the Python27 folder, so you now have a file that resembles this (with your own file path, of course):
C:\Python27\idle.reg
Right-click the idle.reg file, and in the context menu, click Merge. A couple instructions may appear or notices that require a Yes or Continue that I selected. In the end, my .py files give me the option to "Edit in IDLE" again.
I hope these explanations are helpful. Big thank you to those who've solved this problem before and shared there solutions.
For opening your file in IDLE mode or in python exe mode u can follow this simple steps. Works for me in my windows 7 system.
For IDLE mode:
Select the file and press right mouse
press open with---->choose default program
press browse and go to the folder where your python programm is installed
in python folder search IDLE and select the batch file
press open and your file will be open in IDLE edit mode
For python.exe mode:
In command prompt write "where python"
copy the path from cmd
Select the file and press right mouse
press open with---->choose default program
press browse and go to the selected path
press open and your file will be open in IDLE edit mode
As click to save button to save your python code there will be Two Extensions...1) .py and 2) .pyw.
So for Python 2 you have to save python program using extension .pyw.
I think the majority of cases are caused by the Py launcher that comes with Python 3. When you install Python 3 alongside Python 2.x, the *.py and *.pyw files are associated to run with the new Py launcher. Since *.py and *.pyw files are no longer associated with Python.exe, that breaks the "Edit with IDLE" and similar context menu options, despite all relevant registry entries being present and correct.
Right clicking a file and choosing Python.exe and selecting "always use the selected program to open this kind of file" option fixes the problem (even if Python.exe seems to be already set as the default program) but then you lose the Py launcher functionality. This may well be considered a bug with the Python 3.x installer and I think should be fixed at that level by the Python developers.
Meanwhile, I'm sure registry wizards can find a workaround for this but unfortunately, that's beyond me at the moment.
I followed Teodorico Levoff's directions above, as well as Abyx's from the following page:
https://superuser.com/questions/280636/trying-to-edit-a-python-file-but-the-edit-with-idle-has-disappeared-when-i-rig
However, it only works partially. When I right-click on a .py file, no 'Edit with IDLE' shows up. Choosing 'Edit' opens the file with IDLE. Also, the python icon is not associated with .py files. I decide to associate it with Notepad, then associate it with Python again. That works the magic. The icon is back, and so is the 'Edit with IDLE' option. Hope it helps.
This issue is arising because of the problem in the registry of Python installation. While one may edit the registry and resolve the issue, the simple solution for this can be:
DELETE ALL THE REGISTRIES pertaining to the py extensions and
Re-install Python and let installation take its course of action.
The problem will definitely resolve.
Happy Programming
After uninstalling both 2.7 and 3.6, reinstalling 3.6, I ran the init.py ,main.py, and idle.pyw found in C:\Program Files\python\Lib\idlelib and the edit with menu reappeared

How to use Emacs with Python

I am new to emacs and I want to use emacs for python development. I am using Ubuntu 9.10. I frustrated to getting emacs work with python. I use GNU Emacs 23.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.18.0).
Here what I did.
*
Emacs come with python mode but it is confusing there are two types of mode one is python-mode.el and other one is python.el. I use emacs 23 so mine is python.el (I think). Do I need python-mode too? Code completion does not work when I press M-Tab , instead of it window manager works. I tried Esc-Tab but it says "No match" . How can I enable code completion?
After that I installed ropemacs
sudo aptitude install python-ropemacs
Then I created .emacs file at ~/.emacs
and I added followings to .emacs file
(require 'pymacs)
(pymacs-load "ropemacs" "rope-")
(setq ropemacs-enable-autoimport t)
Then when I hit M-/ (Alt-/) it doesn't work when I cick from the menu Rope->Code assist it opens a file dialog for choosing root project folder. I choose current folder which has there are some python code. When I try again Code assist from menu it says
"Completion for x: " nothing but empty set. How can make emacs python code completion work?
Then I downloaded anything.el, anything-config, anything-match-plugin to ~/.emacs.d folder Then I added following lines to .emacs file
(require 'anything-config)
(require 'anything-match-plugin)
(global-set-key "\C-ca" 'anything)
(global-set-key "\C-ce" 'anything-for-files)
Guess what it didnt work. I tried "M-x anything" again I get No match.(I guessed may me combination of C-ca (First control-a then e ) might work it says it isnt defined). Could you explain code completion for python with clear explanations (step by step) to someone dummy as me. Thanks.
Edit: I able emacs work with python with the link. Thanks all for answering
I haven't tried anything, and I haven't had much luck with rope (giant source tree causes my emacs to hang upon any file save). Instead, I find the default completion works well enough for my purposes.
The default completion keybinding is M-/. That runs dabbrev-expand which expands the current word to "the most recent, preceding word for which this is a prefix." It's not perfect: It won't parse types, and it won't search imports, but it works in 90% of the cases.
(You'll have to deactivate rope.)
I think you do want the package python-mode installed! The ropemacs variants appears to be for refactoring only, and pymacs is allows Python as an Emacs-extension language -- neither of which is what you need for standard support.
I'm not really sure you had to do anything fancy to get Python development to work. On gNewSense deltah (fork of Ubuntu 8.04) all I did was edit a .py file with the first line being:
#!/usr/bin/python
And then Emacs just figures it out and gives you python mode options. I didn't have to install anything beyond Emacs.
Then again, this may not be helpful as gNewSense pre-installs Emacs by default. I'll have to do it on one of my vanilla Ubuntu installs.
Emacs worked out of the box for me on Ubuntu 9.10.
Did you try C-c TAB (update imports) before trying code completion? I don't think it work unless you do that.

Categories

Resources