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.
Related
This question already has answers here:
How do I execute a string containing Python code in Python?
(14 answers)
Closed 5 months ago.
This post was edited and submitted for review 5 months ago and failed to reopen the post:
Original close reason(s) were not resolved
How do I execute a string containing Python, without creating a new file, using excec() or using "os" module?
I've seen the similiar question, but the answeres always kind of created some "new file"(for example created something like this), or went out of the current code, but i want it to stay inside the code and execute it.
Example:
string_base64 = "eCA9ICJoZWxsbyBmZWxsb3ciCgoKcHJpbnQoeCkKeCA9ICJoZWxsbyBmZWxsb3ciCgoKcHJpbnQoeCkKeCA9ICJoZWxsbyBmZWxsb3ciCgoKcHJpbnQoeCkKeCA9ICJoZWxsbyBmZWxsb3ciCgoKcHJpbnQoeCk="
This b64 code has inside it strings and commands (+ For example imports) and it needs to run in the current file, without using exec() or modules
This Thread and the answers, didn't answer the question!
Buildin exec function seems to be doing exactly what you want:
https://docs.python.org/3/library/functions.html#exec
This question already has answers here:
Disable assertions in Python
(6 answers)
Closed 4 years ago.
I want to invalidate the "assert" in my Python codes when I run it as a release edition. Consider that a lot of "assert" may be used in my files in the developing procedure, but I want to skip the compiling of "assert" to enhance the efficiency. Is there some simple method like a pre_define of "NDEBUG" in c++ ?
Use command line option -O. As described in the docs:
In the current implementation, the built-in variable __debug__ is True
under normal circumstances, False when optimization is requested
(command line option -O). The current code generator emits no code for
an assert statement when optimization is requested at compile time.
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 .
This question already has answers here:
How do I execute a string containing Python code in Python?
(14 answers)
Closed 7 years ago.
I want to execute python code in my browser. Now I enter code in text-field in template, took it to view, where doing following:
source = request.POST.get('source', '').replace('"', r'\"')
result = commands.getoutput('python -c "%s"' % source)
I used python's module command for this, but I think it's don't correct way.
Correct way is using code module, but I don't understand how to get result of execution code and organise REPL. Can you give a little tip how to do it, please?
UPD: I want to start interactive shell in my browser with some variables. User can write some functions to manipulate this vars in browser and see that comes out of it. I understand the danger of this, but now it is not relevant.
You need to take a look at eval and exec also it is potentially very dangerous from security point of view.
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.