Hello everyone,

I've been working with some python scripts for few days now,
what editor i've been using? the answer is Notepad, but then
i move to Notepad++ which is the one i use to edit batch files
php files, and many other programming files formats, but just now
i'ma having a problem, i am getting a SyntaxError, the problem or
the error pointed to a Non-ASCII character in my file on line 22...
then i checked and everything looks okay, that line have two ## which
mean that the code is not reading, is just my description of that line
of code, but when i edited that line, i changed just two letters and a
space, and after that i started to get this syntax error.

Now from these two programs "Notepad++" and "EditPlus Text Editor"
which one is the best to edit and rewrite python files?
before i was thinking that to program python files and all of that,
most any text editor will do the job, but after having this problem,
i started to think diferent.

I learn that this is an operating system thing, not a Python thing.
but i am not sure, thats why i was wondering if i can get a hand on this.

A little more detail on my problem...
All i did is do some changes in my script and thats it,

something similar to editing the fallowing file...

#!/usr/bin/python

"""
"""

import os,struct,sys

## Print results

## print "[INFO] Then all i did is make this section smaller, thats all %x" % pos

and for what i know thats like when in Visual Basic we add a info line like this:
'This is the example of the code.
or like in batch files, we use this :This is the example of the code.
so python use ## This is the example of the code. and so on like any
other language, but i don't get it why python files are so delicated in this matter.

Any help will very appreciate.

Dani AI

Generated

Two things are most likely happening here: an encoding/hidden-byte problem introduced by the Windows editor, and a Python-version mismatch. Both can produce a seemingly mysterious SyntaxError on a line that looks fine.

Quick diagnostic & fixes

  • Confirm which interpreter actually runs on the Ubuntu side (the exact Python executable and its version). The behavior of print and some bytes rules differs between Python 2 and 3.
  • Check file encoding and hidden characters. Save the file as UTF-8 without a BOM (many Windows editors add a BOM that Python on Unix can treat as a non-ASCII first character). In a pinch, add an explicit encoding declaration on the first or second line so CPython knows how to decode the source:
# -*- coding: utf-8 -*-
from __future__ import print_function

The first line tells the interpreter the file encoding; the second makes print() behave the same in Python 2 and 3 (useful if you edit on Windows but run on a different Python version).

Editor tips and workflow

  • Notepad++ and EditPlus both work fine if you set the encoding to "UTF-8 without BOM" and enable "show all characters" to spot stray bytes. Notepad++: Encoding -> Convert to UTF-8 (without BOM).
  • Lightweight checks: run python -m py_compile yourfile.py or run the script with the target interpreter to get the full traceback and exact error location. As noted, the full traceback plus the Python version are what you need to diagnose syntax failures.
  • 's point about IDLE is valid for beginners: it uses the same interpreter and highlights syntax issues immediately. Spyder/PyScripter are fine too, but Spyder may complain if its expected interpreter/engine isn't available (that's an environment/config issue, not a source-code problem).

Checklist

  • Ensure interpreter version matches the code style (2 vs 3).
  • Save as UTF-8 without BOM or add a coding header.
  • Use an editor that shows invisible characters and run the file with the exact interpreter to capture the traceback.

Recommended Answers

All 7 Replies

There is no error i code you posted.
Post code with Traceback you get.

so python use ## This is the example of the code. and so on like any

Yes you can use 1 # or two ##..,to make comments in code.

Now from these two programs "Notepad++" and "EditPlus Text Editor"
which one is the best to edit and rewrite python files?

Using a IDE editor like Pyscripter or Spyder will help you more.
These editors will mark out error like SyntaxError in code.

Hello there Snippsat,

Those two editors sounded very nice, but i just donwload one of them,
and is very annoying when you try to do something that you think is
going to be okay, but then you get this error here, and another error
over there, and so on, thats the case with "Spyder v 2.1.9" i donwload
this program, and is giving me an error:

spyder 2.1.9 Setup
Python 2.7 is not installed on your computer
OK

But what the heck is wrong with this program, i already have python installed!
But thank you for the two suggestions regarding the editors programs, i'll
try the other one to see what happend.

There is no error i code you posted.
Post code with Traceback you get.

I was getting that syntax error on my other laptop with ubuntu on it,
but is just one line of text saying what i post, syntax error on line 22
then i look at line 22 and i saw what i edited a while ago, thats all.

Hey Snippsat, is okay to give this program access to the internet?
because i did not, and then i got this error message, but i thought
that after clicking in the OK button was not gonna let me opened :-)
but it did, and i like it, no installation required, and i can see
that the code can be run to do a test or something, or am not sure.
this is the error:

Error

Could not connect to the remote Python engine server.

The remote interpreter and debugger is not available.
Abort

Okay Snippsat, this is one of the few errors:

Error
SyntaxError: invalid syntax (line 22, offset 78): 'print "[INFO] Header of ROM %x" % pos'
OK

Why don't use IDLE's text editor?
Its fairly nice and also auto-indents and follows a good color scheme to differentiate between functions,keywords,builtins,etc.
In my opinion, IDLE's text editor is the best.

Hello utkarshsahu,

I see that option when i right-click on the script file,
i see the option if i would like to edit the file using
that option you telling me about, i don't know if thats
the one you've talking about.

And as for you snippsat, i don't konw what you talking about,
i've been posting the syntax error exactly as i get it in the
program, i don't know what exactly you want me to post in here.

and as for the "Install 2.7" i wanted to tell you that i've been
doing all of this in Windows XP not in Ubuntu, i mean, the project
is in Ubuntu, but i am editing the project in Windows, then testing
in ubuntu, i do it faster in Windows. so regarding that download...
thats an Ubuntu .deb format, i tried to install the first one tha
you suggested me, the executable installation package, but i could
not installed due to the error message i received, but is okay now
i'am using the PyScripter one, looks okay.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.