This question already has answers here:
Sublime Text 2 auto completion popup does not work properly
(4 answers)
Closed 9 years ago.
I'm trying to get Code suggestion (the drop-down box) to suggest properly.
Right now it does not. It only suggests, more or less, identifiers and modules
that are already in the file being edited (meaning in-file scope). If, for example, I try this:
import numpy <--- numpy is not suggested as I type it.
numpy.a <--- And here, nothing that begins with 'a' is suggested.
I've implemented a raft of things suggested at various sites, including the following, but
with no success in getting correct code-complete suggestions to appear,
or sometimes to appear at all:
- Installed SublimeRope
- "use_simple_completion": true (in SublimeRope.sublime-settings)
- "auto_complete_triggers": [ {"selector": "source.python - string - comment - constant.numeroc", "characters": "."} ] (in Pyhon.sublime-settings)
- etc.
Am I missing something (of course I am :)). Appreciate the suggestions.
Sublime's autocomplete is intended to match within the current file.
If you want to have code completion based on syntactic features of the language, you have many options, but I would suggest some combination of the following:
Install the CodeIntel package (package control instructions here)
Use snippets
Install Python snippets through package control (I like sublime-unittest).
Instructions for creating your own snippets.
Hope that helps.
Related
This question already has an answer here:
python IDLE shell appears not to handle some escapes correctly
(1 answer)
Closed 3 years ago.
There are several folks on here looking for backspace answers in Python. None of the questions I have searched have answered this for me, so here goes:
The Simple Goal: be able to print out a status string on one line, where the next status overwrites the first. Similar to a % complete status, where instead of scrolling a long line of 1%\n, 2%, ... etc. we just overwrite the first line with the newest value.
Now the question. When I type this in idle: print("a\bc") I get this as output: ac with what looks like an odd box with a circle between the 'a' and 'c'. The same thing happens when using sys.stdout.write().
Is this an Idle editor setting/issue? Does anyone even know if what I am trying is possible in the Idle Shell?
Thanks for any insight.
PS: Running Python 3.3.2 Idle on Windows 7, 64-bit system.
EDIT: Copying the output in Notepad++ is revealing that Python is printing out a 'backspace' character, and not actually going back a space. Perhaps what I am trying to accomplish is not possible?
Edit:
Apparently the carriage return \r and the backspace \b won't actually work within Idle because it uses a text control that doesn't render return/backspace properly.
You might be able to write some sort of patch for Idle, but it might be more trouble than it's worth (unless you really like Idle)
This doesn't answer your question in a literal fashion, but I think it might be useful to point out that generally interfaces like the one where you are describing (e.g., where one part of the screen is continuously updated, without newlines), it just generally implemented using a library like ncurses.
Python has a curses library built-in (http://docs.python.org/3.3/library/curses.html), which can more or less achieve your end goal.
This question already has answers here:
Tool to determine what lowest version of Python required?
(3 answers)
Closed 5 years ago.
One finds many small programs or sample code on the Internet, which do no not necessarily specify in which context they were written (shebang), and do not necessarily use obvious things as print statements.
They may crash with some or some other version of python, but this may not be due to fundamental incompatibilities but just due to missing libraries which might be hard to find.
There are some tools as mentioned in this question but the question here is: "What would be good criteria to decide if a code is compatible with either version of python ?"
There are at least :
The presence of the shebang (But it is often not present)
Print statements (without parenthesis) are from python2 or before (But you do not always have them, especially in GUI programs)
Integer division (//) is from python 3 and later (But not all programs compute integer divisions)
What else ?
#Mureinik, #JJJ, #Bear Brown, #Tempux, please remove duplicate flag.
Ideally a python script will include a shebang on the first line something like: #!/usr/bin python and/or comments telling you the minimum, (and possibly maximum), version that it will work with.
Other clues:
print Something # Python 2 Only
print(Something) # Python 3 Mostly
from __future__ import print_function # As first active code
print(Something) # Now works for both
Of course and well written code will either be compatible with many versions or specifically check for the versions that it requires.
If libraries are missing then the error messages are really clear but for the most part python code tends to "just run"™ so the real solution is to try the code with the versions of python that you have to hand.
You can refer from official documentation : Python Docs
I am assuming that you have an IDE for Python 3.x where you can try that piece of code.
As stated by Steve, You can differentiate by using the print function of python(x).
print "hello world"
So, if there is print statement(like above) in the code you will get:
SyntaxError: Missing parentheses in call to 'print'.
Thus, that piece of code was for 2.x python .
I'm trying to import existing project into PyCharm. I can refactor the code so that PyCharm will be pleased, but we like to have spaces around colons in dictionaries, like this: {"A" : "B"}. We also like aligning assignments:
a = 1
abc = 3
Is there a way to configure PyCharm, so that he'll ignore all errors/warnings related to this specific stuff?
Using PyCharm 5 (community edition), you can do the following: Code –> Inspect Code. Then select the required inspection error, and click on the "Suppress" option or "Ignore errors like this" option on right hand side.
Please look at the screenshot below:
When you choose the "Suppress" option, it adds a comment as shown in the screenshot below:
Suppressing can be done at the statement, or function/method, levels. If trying to suppress an argument to a function, the suppression only works at the function level (meaning it also suppresses other name reference violations that might exist within that function).
You also have the option of switching off "PEP8 coding style violations" altogether (by ticking the box shown below), or explicitly managing "Ignore Errors" manually. Screenshot given below:
In general, you should perhaps question why you are suppressing PEP8 guidelines. However, sometimes it appears necessary, for instance when using the pytest module, it is necessary to shadow variables, etc, which the PEP8 Inspection complains about in. In such cases, this feature in PyCharm is very helpful.
If you're ok to ignore all matching issues, you can just press Alt-Enter (or click on the lightbulb) and choose "Disable Inspection". Saves you going into the settings and trying to figure out the inspection rule that matches.
From http://iambigblind.blogspot.jp/2013/02/configuring-pep8py-support-in-pycharm-27.html
#Krzysztof Stanisławek, function is different as Pycharm follows the PEP8 coding style, so it is recommended that there is no whitespace between the function variables and ":", if you don't want this, you can disable it by
"Settings"-> "Editor"-> "Inspections"->"PEP8 coding style violation"
However, this is not recommended.
I got the same issue, and the neat solution has been pointed by #fantabolous, from configuring PEP8.py support in PyCharm 2.7
Example before
Adding the error code either manually or with "Alt+Enter" on error highlight
The error code can be found here
After the changes
It's great to select precisely some rules instead of disabling all warning from PEP8. Thanks to the previous comments.
to have spaces around colons in dictionaries, configure Settings > Editor > Python Spaces
Other > Before ':'
and
Other > After ':'
This question already has answers here:
How to save a Python session, including input and output, as a text?
(4 answers)
Closed 1 year ago.
All of the ways which discussed this question save the history of your commands in a file or you have to use an IDE ,I am using vim with python-mode (no mouse using) what I would like to do is to save my session as code I wrote and the python output ,So I dont have to use paper and pen to write my input and python output all what I have to do is to print out my session , I tried the code (.pystartup)
and it only save my input and I tried to redirect the output to a file and it only save the python output , is there a way to have both in one file ready to be printed out .
I really cherish vim, it'S a fantastic piece of work. Nevertheless, your requirements are easier with other tools.
Probably the best choice, in my oppinion, would be to use the ipython notebook. It offers really rich features, including graphics with mpl and much more, and for me is the perfect tool for "reproducible experiments". The full state of a notebook can be saved to disk, reloaded, exported, printed etc.
You should really give it a try.
The old "I use $EDITOR instead of $IDE because I don't want to use the mouse" bullshit… IDEs have shortcuts for everything and they all allow you to customize them to your liking. Learn them all and forget about your mouse.
Anyway, what you want is neither an editor nor an IDE; you want a REPL like bpython or ipython (possibly with its notebook feature mentioned above). Both tools allow you to save and restore your sessions and are far better at "getting" your python code than Vim.
This question already has answers here:
How to disable pylint 'Undefined variable' error for a specific variable in a file?
(8 answers)
Closed 9 years ago.
I have a problem with pylint, i.e. sometimes it repeats the same message for some variable/class/module etc. and I can't find a workaround for that. What I want is to say pylint
"don't check [message XXX|any message] for variable YYY in [this module|module "ZZZ"]" with some option or rcfile directive.
There's good-names=YYY for this, or for some advanced stuff you can modify the regex via variable-rgx.
According to the docs you enable and disable messages using lines like:
# pylint: disable=W0631
in the python code.
What you are asking for is not supported in the current version of Pylint.
You may want to get in touch with the maintainers and propose them a feature request and an implementation.