How can I check the syntax of Python code in Emacs without actually executing it?

Python's IDLE has 'Check Module' (Alt-X) to check the syntax which can be called without needing to run the code. Is there an equivalent way to do this in Emacs instead of running and executing the code?


Asked by: Luke446 | Posted: 24-09-2021






Answer 1

python -m py_compile script.py

Answered by: Wilson222 | Posted: 25-10-2021



Answer 2

You can use Pyflakes together with Flymake in order to get instant notification when your python code is valid (and avoids a few common pitfalls as well).

Answered by: Roland688 | Posted: 25-10-2021



Answer 3

Or from emacs (or vim) you could run python -c 'import x' where x is the name of your file minus the .py extension.

Answered by: Blake838 | Posted: 25-10-2021



Answer 4

You can use pylint for such things and there seems to be a way to integrate it into emacs, but I've never done the latter b/c I'm a vim user.

Answered by: Michelle904 | Posted: 25-10-2021



Answer 5

You can use pylint, pychecker, pyflakes etc. from Emacs' compile command (M-x compile).

Hint: bind a key (say, F5) to recompile.

Answered by: Elian392 | Posted: 25-10-2021



Similar questions

python - Jupyter Lab not executing K-Fold Cross Validation

I am using 5 cross validation and the F1 metric to evaluate my Neural Network. However, when running my code in Jupyter Labs, it seems to load forever. Not producing any output, but running other tasks is fine. I have a total of 5 folds, and 500 epochs. Every 50 epochs, I output the Mean Squared Error loss value (x10 per fold). After 500 epochs (1 fold), I output the current F1 value of whatever test set I gi...


python - Django form fails validation on a unique field

I have a simple model that is defined as: class Article(models.Model): slug = models.SlugField(max_length=50, unique=True) title = models.CharField(max_length=100, unique=False) and the form: class ArticleForm(ModelForm): class Meta: model = Article The validation here fails when I try to update an existing row: if req...


python - Form Validation in Admin with Inline formset and Model form

I have a model, OrderedList, which is intended to be a listing of content objects ordered by the user. The OrderedList has several attributes, including a site which it belongs to. The content objects are attached to it via an OrderedListRow class, which is brought into OrderedList's admin via an inline formset in the admin. class OrderedList(GenericList): objects = models.Manager() publish...


python - Django file upload input validation and security

I'm creating a very simple django upload application but I want to make it as secure as possible. This is app is going to be completely one way, IE. anybody who uploads a file will never have to retrieve it. So far I've done the following: Disallow certain file extensions (.php, .html, .py, .rb, .pl, .cgi, .htaccess, etc) Set a maximum file size limit and file name character length...


python - method for creating a unique validation key/number

I'm using django for a web-magazine with subscriber-content. when a user purchases a subscription, the site will create a validation key, and send it to the user email address. The validation key would be added to a list of "valid keys" until it is used. What is the best method for creating a simple yet unique key? Can someone suggest a standard python library for key-creation/validation/ect? This might b...


python - Form validation in django

I just started to use django. I came across forms and I need to know which one is the better way to validate a forms. Would it be using django forms or should we use javascript or some client side scripting language to do it?


python - tkinter text entry validation

I'm trying to validate the entry of text using Python/tkInter def validate_text(): return False text = Entry(textframe, validate="focusout", validatecommand=validate_text) where validate_text is the function - I've tried always returning False and always returning True and there's no difference in the outcome..? Is there a set of arguments in the function that I need to inclu...


validation - Flexible numeric string parsing in Python

Are there any Python libraries that help parse and validate numeric strings beyond what is supported by the built-in float() function? For example, in addition to simple numbers (1234.56) and scientific notation (3.2e15), I would like to be able to parse formats like: Numbers with commas: 2,147,483,647 Named large numbers: 5.5 billion Fractions: 1/4 I did a bit of searching an...


python - Debugging Django Forms validation errors

One of my forms fails on form.is_valid() First time I debug a Django form so I am not too sure where to look forms.py class ImageForm(forms.ModelForm): def __init__(self,user,*args,**kwargs): super(ImageForm,self ).__init__(*args,**kwargs) # populates the form class Meta: model = KMSImageP fields = ('name', 'caption', 'image', )


validation - How can I validate a date in Python 3.x?

I would like to have the user input a date, something like: date = input('Date (m/dd/yyyy): ') and then make sure that the input is a valid date. I don't really care that much about the date format. Thanks for any input.


python - Clearing Django form fields on form validation error?

I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them. I've tried several methods for removing form.data, but I keep getting a This QueryDict instance is immutable exception message. Is there a proper way to clear individual form fields or the entire form data set from clean()? ...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top