Visual Studio, Python not auto-indenting - python

This is probably a simple issue but something is wrong with my Python tools for visual studio. When I first started using VS2015 for Python it would auto-indent whenever I used a colon. Now VS2015 is just acting like a text editor with syntax highlighting. I tried uninstalling and reinstalling the Python tools but that did not work. How do I fix Visual Studio to auto-style as I write Python again?

Tools -> Options -> Text editor -> Python -> Tabs and set it to Smart

http://stevedower.id.au/blog/smart-indentation-for-python/
However, the most common (and default) mode is “Smart.” Unlike the other two modes, which are built into the editor, smart indentation is provided by a language service (which are also responsible for providing syntax highlighting and completions). Because they are targeted to a specific language, they can help the programmer by automatically adding and removing extra indentation in ways that make sense.

Try this in Visual Studio
Tools -> Option -> Text Editor -> Python -> Tabs
Disable the "Keep the Tabs"
Select "Insert Spaces"
Select "Indenting" as "Smart"

Related

Python Visual Studio extension doesn't show errors

I'm used to use VS to code C++ and Eclipse to code python but lately I have tried VS for both languages.
I found something very difficult to understand that while VS autocompletes it doesn't warn you about errors before runtime.
There is no warning regarding non existent variables or methods. I can't believe that VS does not warn about this kind of typical coding issues as it does for C++ code (as every IDE does).
What am I missing?
I tested this with VS2013 and VS2015.
I'm expecting something like:
Thanks
In order to get the python detailed IntelliSense support in VS2015 you have to install python tools for visual studio which provide the following:
CPython, PyPy, IronPython and more
Detailed IntelliSense
Interactive debugging
Integrated with Visual Studio features
Free and open-source
And the best thing, it's completely free.
Just download it from here:
https://www.visualstudio.com/en-us/features/python-vs.aspx
I hope it supports your question.
Update after comment:
You just need to refresh the Database. It works for me. Check to make sure the environment options are set (specifically path variable to PYTHONPATH) and the DB is refreshed.
Sometimes Deleting the __init__.py file in my source root directory did the trick
It seems that with a regular Python installation (2.x or 3.x in 32bit or 64bit) there are limited "warnings" (hovering over an undefined variable gives "unknown type"), but Syntax Highlighting / Intellisense doesn't seem to work.
Intellisense NOT Working:
Getting Intellisense to Work:
After some research I tried installing another Python interpreter for Visual Studio to work with. I went with Iron Python because it is "tightly integrated with the .NET Framework".
Download it from here --> http://ironpython.codeplex.com/downloads/get/970325
After installing IronPython open Visual Studio and set it as the "Default Environment for New Projects". You can set it in "Tools" --> "Python Tools" --> "Python Environments" (or by pressing Ctrl + K + `)
Make sure to refresh the database and Syntax Highlighting will start working. It doesn't seem very thorough, but it is there.
See photo below:

How to provide Python syntax coloring inside Webstorm?

I have a Python project, and I use WebStorm as my Editor. The problem is that Python's syntax doesn't get colored.
How can I display Python pages with a nice syntax? I am not searching more than than. I'm not going to develop pages in Python, but I do want them to get displayed nicely in Webstorm.
Your ONLY option in WebStorm is to use TextMate bundles support plugin with Python bundle -- it will provide syntax highlighting (no completion or syntax checking etc).
This official article (with pictures) is for PhpStorm, but it should work the same for WebStorm as well: http://confluence.jetbrains.com/display/PhpStorm/TextMate+Bundles+in+PhpStorm
There are several TextMate bundles available for Python: https://github.com/textmate?utf8=%E2%9C%93&q=python
Alternative solution: migrate to PyCharm Pro -- it does all what WebStorm does + Python.
UPDATE: 2019-06-18
2019.2 version will come bundled with syntax highlighting for about 20 languages (all done via the aforementioned TextMate bundles plugin).
https://blog.jetbrains.com/webstorm/2019/05/webstorm-2019-2-eap/
In WebStorm 2019.2, we’re adding syntax highlighting for over 20 different programming languages, including PHP, Python, Ruby, and Java. It just works – no additional configuration needed.
With this change we want to improve the experience of our users who occasionally have to look through some code written in different languages that are not supported in WebStorm. But WebStorm is still primarily an IDE for JavaScript and TypeScript developers, so we don’t plan to extend the support for these other languages beyond syntax highlighting.
Syntax highlighting for these languages is built using TextMate grammars, and WebStorm bundles a collection of grammar file for different languages. Currently they are shipped as part of the TextMate Bundles plugin (so you can see a full list of supported languages under Preferences | Editor | TextMate Bundles), but they are going to be moved to the IntelliJ Platform soon.
You can use the Perl syntax which is very similar to Python.
Go to Preferences => File Types
Search for Perl
Add *.py under Registered Patterns
Another option is to use PyCharm, the community version is free.
Python might be missing in Preferences -> Editor -> File Types. After adding the Python, make sure to add a *.py registered pattern.

Python Syntax Highlighting in Notepad++

I know Notepad++ supports Python but under the language menu I cannot find it! At "P," it only lists
Pascal, Perl, PHP, Postscript, PowerShell, and strangely, Properties. I am writing some Python scripts and I want the
syntax to be highlighted. How can I activate Python highlighting?
Maybe it's disabled. Check in Preferences | Language Menu/Tab Settings if it's not among the disabled items.
Weird. I have Notepad++ v6.3 on this PC and it is there:
Try to uninstall and reinstall Notepad++. Be sure to get the latest version from SourceForge -
http://sourceforge.net/projects/notepad-plus/
Please make sure it is not disabled. I happens to me too.
To check go to preferences, click on language items in the left and make sure that python is not in disabled languages.
Reboot notepad++ after applying changes.
Try to uninstall and install the new version form Notepad++
On mine, notepad++ v7.5.8, Python is not in the P section but it is in the bottom of languages menu.
This is the default arrangement for my version of notepad++ so all bets are off if you changed it under settings.
Yes, python is at the bottom of language list (not under P item - I believe it was moved out of P after I played with Settings) .

Using VIM for Python IDE in Windows?

I am turning to Python from .NET world. And Visual Studio was something a great tool i used.
In python world we do have basic IDLE and another one is VIM. I have seen that a lot of developers have configured VIM to a great IDE. Using basic VIM in Windows 7 seems of less use.
So i want to moderate my VIM to a level which has file explorer, syntax highlighting, search, error highlighting etc. So that it gives feel of Visual Studio and more productive.
But all hacks/tips available are for Linux/Ubuntu users mostly, which i may use later but as of now i need to make my VIM in Windows more productive, visual.
Please Suggest some Tips/Hacks/Resources to look around for VIM configuration?
Thanks
This question addresses your low level issue: coding Python with an IDE that is not VS.
There are a few popular blog posts addressing your high level issue: setting up Vim for Python development. They are a quick google away…
I feel the need to point out that Vim is not an IDE. You can customize it a lot and end up with something that looks like an IDE but you won't get an IDE. Only an over-customized text editor.
Anyway, here are a few tips for starting out with Vim:
Do $ vimtutor as many times as needed to feel comfortable with the basics.
Get familiar with Vim's buit-in documentation: the answers to most of your questions are somewhere inside. :help gets you to the front page, :help 'option' shows the documentation for option, :help :command shows the documentation for command… Hit <C-]> on a colored word to jump to its definition.
Don't use Janus or SPF13 or whatever pre-packaged set of plugins. You'll only grow bad habits. Similarly, don't copy other people's vimrc wholesale.
Ctags is an external code indexer that is used by Vim to "jump to definition" with <C-]>. cscope is another option, it's more powerful but also a little more complex. See :help tags.
Related to ctags, TagList and TagBar are two popular plugins used to display more or less the equivalent of the Object Browser in VS.
NERDTree is another popular plugin that mimicks the file tree found in many IDEs/editors. But Vim comes with netrw (:Ex) by default, try it before installing NERDTree.
Read :help motion.txt as soon as possible.
Watch Drew Neil's laser-guided vimcasts.
Don't rush it.
you can use vim plugins on windows, http://www.vim.org/scripts/index.php, typing "vim {your feature here}" into google will come up with lots of results.
popular file explorer is nerdtree,
syntax highlighting can be turned on with
syntax on in your vimrc
searching open file is easy to do using reg exes . Initialize search with /.
Searching directory is easy to do using grep.
I don't develop on windows but i have read that Cygwin might be worth installing for some linux tools if not already installed.
I am in no way an evangelist of any Editor/IDE.
But, if you are a newbie to Python I would suggest trying out Sublime Text 2 http://www.sublimetext.com/ . It is a very light weight yet powerful editor with a great following and it has a free evaluation version with no deadline.
But, if you intend to work using frameworks such as Django/ GAE then I would suggest using PyCharm from JetBrains
http://www.jetbrains.com/pycharm/
Finally, these tools are all just personal choices until you get comfortable with one or two of them.
Thanks,
-Hari
One possible compromise is to use your favorite IDE with a vim emulator plugin. For example, in Eclipse you can use Vrapper, PyCharm has IdeaVim and so forth. Lighttable also has vim key-bindings. The plug-ins (or key-binding options) give you some of the benefits of editing in Vim while still having the powerful debugging / navigation features, etc. of a full-blown IDE. BTW, Vrapper works with PyDev.
Using an emulator in an IDE allows you to gain the "muscle-memory" necessary for effective vim editing, without getting bogged down in "configuration hell" associated with turning an editor into an IDE (which auto-complete plugin do I use?..etc.?). Once you have mastered the vim keystrokes for normal and visual mode, used along with insert mode, you may decide to continue on into pure Vim and face those issues.
I wouldn't recommend to learn VIM in 2012 (despite it being a great editor). If you must, this blog post will get you started.
But VIM isn't an IDE, it's a text editor.
If you really want a powerful IDE, try IntelliJ IDEA or Eclipse. Both have great plugins to turn them into Python IDEs (along with code completion and all the other nice time savers). For Eclipse, try PyDev. For IntelliJ, search for Python in the plugin preferences pages.

Notepad++ indentation messes up

I'm coding in Python and I really like Notepad++. However, off late when I use tab to indent, it seems fine in Notepad++, but when I run the program I get an indentation error, and when I check my code in Emacs or something, I find that Notepad++ actually adds more tab spaces than it shows on screen. What is happening?
There is no universal tab size, so I always make sure to replace tabs by spaces (so you know what you see is what you get everywhere else as well)
Go to Settings -> "Preferences..." -> Language Menu/Tab Settings and check 'Replace by space'
I would suggest going to View > Show Symbol > Show Whitespace and Tab to get an better idea of how your indentations look.
PEP 8 tells us to use spaces instead of tabs in Python for cross-editor compatibility and consistency:
http://www.python.org/dev/peps/pep-0008/
Have a look at this answer for how to change tabs to spaces in Notepad++
Convert tabs to spaces in Notepad++
Perhaps that will fix your problem
Tiny update - to get spaces as tabs, you now go to Settings>>Preferences>>Tab Settings and check the "Replace by space" box
I am new to python and started using Notepad++. But I faced the same issue as you... Indentation problems. On my senior's advice, I switched to PyCharm community edition. I pasted the code from Notepad++ to PyCharm and it highlighted the block with indentation problems... The issue was that, some of the lines used spaces and some used tabs. This happened because the code on which I was working was taken from the internet.
Checking for such inconsistencies would solve the problem. Or, there is a better alternative... Switch to PyCharm. It is exclusively built for python coding.. Hope this helps people like me searching for solutions for indentation issues in Notepad++
Use Python Indent Plugin for Notepad++:
I have used both Pycharm & Notepad++, and frankly - even though both are installed on my machine right now I prefer using Notepad++. So, if you want to continue using Notepad++ for Python development you should definitely install the 'Python Indent' Plugin. This plugin will automatically create tabs for you when writing Python code. The only downside to the plugin is you have to remember to Enable it (by going to Plugins --> Python Indent and then clicking 'Enable') when you want to use it.
To install the Python Indent plugin in Notepad++ just go to 'Plugins' --> 'Plugin Manager' and then click on 'Show Plugin Manager'. Then check off 'Python Indent' and click on the 'Install' button.
Additionally, you should Follow Python's Usage Guide:
Tab spacing can differ across programs and, following the recommendations of PEP8 (Python Enhancement Proposals Number 8 - which is Python's Accepted Styling and Usage Guide) you should use the space bar to make your indents. Check out the PEP8 Page about spacing here: https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces
Good luck!

Categories

Resources