Please verify!!

M

Manish Sharma

Hi I am new to python language. On my first day, somebody told me that
if any python script file is opened with any editor except python
editor, the file is corrupted. Some spacing or indentation is changed
and script stops working. I was opening the script file in Windows
using Notepad++ but I didn't save anything and closed it. Still it was
suggested to never open the python file in any other editor.

Can anybody please verify this? Can opening a python script in any
editor other than python editor corrupt the script? Did anybody ever
face such type of issue or its just misunderstanding of the concept.

I hope this group is the best place to ask this. Please reply !

:)
Manish
 
B

Ben

They are telling you not to switch between editors that use tabs as tabs and ones that use spaces as tabs. Python gets all wonky. No big, use one editor or have your preferred editor highlight your non-preferred whitespace.

FWIW, I use spaces.
 
D

Dave Angel

Hi I am new to python language. On my first day, somebody told me that
if any python script file is opened with any editor except python
editor, the file is corrupted. Some spacing or indentation is changed
and script stops working. I was opening the script file in Windows
using Notepad++ but I didn't save anything and closed it. Still it was
suggested to never open the python file in any other editor.

Can anybody please verify this? Can opening a python script in any
editor other than python editor corrupt the script? Did anybody ever
face such type of issue or its just misunderstanding of the concept.

I hope this group is the best place to ask this. Please reply !

:)
Manish

That is nonsense. I've used at least a dozen text editors, from Windows
Notepad to emacs on Linux. And since I know of no program called
"python editor," I'm sure none of them was that one.

Of course, there are editors that are broken, or can be configured to be
broken. I certainly wouldn't try wordpad, even in text mode. But a
good editor with a good configuration can be much nicer to use than Notepad.

First thing I'd do is to disable tab logic in the editor. When you
press the tab key, there's no excuse for an editor to actually put a tab
in the file. It should adjust the column by adding the appropriate
number of spaces. The main place you get in trouble is when a file has
tabs in some lines, and uses spaces for indenting on other lines. Since
tabs are not interpreted the same way in various utilities, it's just
better not to use them at all.

As Amirouche has pointed out, line endings can be inconsistent between
different operating systems, and not all editors can handle the
differences. But the python compiler/interpreter doesn't care about
which line ending is used.

One other issue could be files that have non-ASCII characters. Since a
text file has no standard way to indicate what format it uses (utf8,
ucs2, or dozens of "extended ASCII" encodings), another editor might not
deal with it correctly. There is a standard way to indicate to Python
how to interpret non-ascii characters, so if you either 1) always use
ASCII1 2) always use the same character encoding, or 3) have your editor
look for the declaration and honor it, you'd have no trouble.

If these problems do occur, they'll be pretty easy to spot. And you can
always revert to an earlier version, by using your revision control
system. Enabling one of those is about as important as choosing your
editor.
 
J

Joshua Miller

Wasn't supposed to be private, just something went funky with gmail
when i sent it out, oddly enough
 
A

Andrew Berg

First thing I'd do is to disable tab logic in the editor. When you
press the tab key, there's no excuse for an editor to actually put a tab
in the file. It should adjust the column by adding the appropriate
number of spaces.
Unless, of course, you know, you actually /want/ to use tabs (the
horror!). The decision whether to use tabs or spaces shouldn't be made
for the novice programmer. Make an argument, explain the
advantages/disadvantages, whatever, but don't state your opinion like
it's fact. Even worse, you brought it up in the context of editor
issues, making it sound like using tabs is a common source of problems.
Much of it is personal preference (I could give objective reasons in
support of tabs in Python, but I don't intend to start the whole spaces
vs. tabs discussion again).
The main place you get in trouble is when a file has
tabs in some lines, and uses spaces for indenting on other lines.
I wouldn't call it the main problem, but yes, that happens. It's not
terribly difficult to convert all indentation to tabs or spaces (unless
the number of spaces used to indent is inconsistent).
As Amirouche has pointed out, line endings can be inconsistent between
different operating systems, and not all editors can handle the
differences. But the python compiler/interpreter doesn't care about
which line ending is used.
Yes. However, there are many editors for various platforms that handle
the different line endings just fine. In fact, Notepad is the only
editor I can think of off the top of my head that has an issue.
One other issue could be files that have non-ASCII characters. Since a
text file has no standard way to indicate what format it uses (utf8,
ucs2, or dozens of "extended ASCII" encodings), another editor might not
deal with it correctly. There is a standard way to indicate to Python
how to interpret non-ascii characters, so if you either 1) always use
ASCII1 2) always use the same character encoding, or 3) have your editor
look for the declaration and honor it, you'd have no trouble.
I recommend using UTF-8 always unless there's some reason not to.
If these problems do occur, they'll be pretty easy to spot. And you can
always revert to an earlier version, by using your revision control
system. Enabling one of those is about as important as choosing your
editor.
I don't think you can really go wrong outside of Git, Bazaar, or
Mercurial. Which of those 3 is best is mainly personal preference.
CVS/SVN should be considered legacy and not suitable for new projects.
 
A

Andrew Berg

Are you referring to novice programmers – who, by any reasonable
definition of “noviceâ€, don't have an opinion on the tabs-versus-spaces
indentation debate?

Or are you talking about people who are experienced enough to have an
opinion and expect their editor to allow them the choice?
The former. Opinion doesn't necessarily come with experience - habit
will usually override any minor reason to change. My point is that one
should have an opinion on it, not just be told which is better. I should
clarify that I mean that in a general sense as well, since it may have
come across as a bit of an overreaction.
The reason is the same: spaces for indentation and UTF-8 for encoding
will both allow them the best chance of ignoring the issue as
irrelevant, by enabling the smoothest collaboration with the vast
majority of other programmers who have to work with them.
If by that, you mean that using spaces is better because it's what the
majority of programmers use, and it makes things much smoother when
working with others, then I agree. When working in a team, it's
definitely not something to argue over.
And in both those issues, I think it's ludicrous to expect the novice
programmer to care enough about the matter to have an opinion and select
a configuration option. The editor authors should choose the best option
for them as a default, and let most users sail on, happily ignorant of
the flame wars they have avoided.
A valid point. I think one should have an opinion, but I can see why one
would avoid the issue.
 
A

Andrew Berg

The original question was about Notepad++ which is nothing at all like
Notepad.
And I did give the OP an answer about Notepad++ specifically in another
message.
 
S

Steven D'Aprano

The former. Opinion doesn't necessarily come with experience - habit
will usually override any minor reason to change. My point is that one
should have an opinion on it, not just be told which is better. I should
clarify that I mean that in a general sense as well, since it may have
come across as a bit of an overreaction.

"My opinion is that we shouldn't use either tabs or spaces, but capital
Zs instead, 'cos I like Zs and we don't use enough of them!"

Opinions need to be informed to be better than useless. By definition
newbies don't have the experience to have informed opinions. You are
encouraging people who lack the experience to make an informed decision
to take sides in the "tabs vs spaces" question on the basis of... what?
Gut feeling? Astrology? Feng shui? Whether they find it easy to say the
word "space" or have a lisp and prefer "tab" instead?

There are many times that we can't afford to sit on the fence. Lacking
experience to decide between spaces and tabs, we can't just say "I won't
use either", or "I'll use both" (unless you do so in separate files). So
how can we make a decision?

The usual way is to listen to others, who do have the experience to make
a decision (even if only imperfectly). But you've just told us off for
passing on our experience/opinions to newbies, so in effect you're saying
that people shouldn't learn from the experiences of others.

That, I think, is a terrible philosophy. Life is too short to gain an
opinion for ourselves about everything, and too difficult to sit on the
fence.

The right way is to encourage newbies to listen to the arguments put
forth, and *then* make up their own mind, or in the absence of easily
understood arguments (let's face it, many technical decisions only make
sense after years of study, experience or careful reasoning) on the basis
of any consensus amongst experts. Often there may be no absolutely right
or wrong answers.

Personally, I prefer tabs for theoretical reasons and spaces for
practical ones. I think that the world would be better off if we all
standardised on tabs instead of spaces, but since that's not going to
happen, I can interoperate better with the mass of broken tools out
there, and with other people, by using spaces.

I wonder whether Windows users tend to be more sympathetic to tabs than
Unix/Linux users, and if so, I wonder what if anything that means.
 
A

Andrew Berg

Opinions need to be informed to be better than useless. By definition
newbies don't have the experience to have informed opinions.
I thought I had implied that I meant informed opinions, but apparently not.
There are many times that we can't afford to sit on the fence. Lacking
experience to decide between spaces and tabs, we can't just say "I won't
use either", or "I'll use both" (unless you do so in separate files). So
how can we make a decision?

The usual way is to listen to others, who do have the experience to make
a decision (even if only imperfectly). But you've just told us off for
passing on our experience/opinions to newbies, so in effect you're saying
that people shouldn't learn from the experiences of others.
I don't mean that no one should ever give an opinion. Saying you prefer
spaces because you've had to deal with broken editors that don't handle
tabs well is quite different from saying an editor is wrong/broken if it
isn't using space-tabs. Giving an opinion and presenting an argument are
perfectly fine; I don't agree with calling things inherently wrong if
they aren't what you prefer. I had (and have) no problem with Dave
preferring spaces and giving reasons. I have a problem with him implying
that editors should always use space-tabs and never real tabs,
especially in the context of this thread.
 
C

Chris Angelico

Personally, I prefer tabs for theoretical reasons and spaces for
practical ones. I think that the world would be better off if we all
standardised on tabs instead of spaces, but since that's not going to
happen, I can interoperate better with the mass of broken tools out
there, and with other people, by using spaces.

At work, since we have a fairly small core of developers, we
standardized on tabs - mainly because of a couple of devs who
disagreed on how much indentation looked right (I'm of the opinion
that 1 space is insufficient), and having tab characters in the file
allows us to configure our editors differently. I'm definitely in
favour of using tabs where possible, but if you can't close your
environment, spaces are far safer.

ChrisA
 
M

Mark Lawrence

At work, since we have a fairly small core of developers, we
standardized on tabs - mainly because of a couple of devs who
disagreed on how much indentation looked right (I'm of the opinion
that 1 space is insufficient), and having tab characters in the file
allows us to configure our editors differently. I'm definitely in
favour of using tabs where possible, but if you can't close your
environment, spaces are far safer.

ChrisA

Oo, thou sinner, fancy violating PEP 8 and standardising on tabs.

OTOH if that's your standard and you stick to it fine.

What I can't stand is the "I've always done it this way an I ain't movin
jus cos sum standard says so" attitude.

Yes I have seen this in real life and the person responsible should be
sacked.
 
C

Chris Angelico

Oo, thou sinner, fancy violating PEP 8 and standardising on tabs.

PEP 8 applies only to Python code, our standard is across all our
languages :) But yes, I'm a horrible sinner and I like tabs. They
separate the display (do you want tabs to show as four-space indent,
two-centimeter indent, or fifty-pixel indent?) from the structure
(this line is indented two levels). Spaces merge those.

ChrisA
 
D

Dave Angel

PEP 8 applies only to Python code, our standard is across all our
languages :) But yes, I'm a horrible sinner and I like tabs. They
separate the display (do you want tabs to show as four-space indent,
two-centimeter indent, or fifty-pixel indent?) from the structure
(this line is indented two levels). Spaces merge those.

ChrisA

If tabs were ever implemented consistently and reasonably in both an
editor and a matching language, then I'd consider leaving tabs in the
file. But to me, they're just a crude way to compress the file, and the
space they save is no longer worth the pain they cause (I came to this
conclusion 30 years ago, and have re-evaluated it dozens of times as new
editors and new languages changed the rules. At that time, I had one of
my developers write an editor (shipped with our MSDOS system, instead of
Edlin) that implemented it.)

Some time when i have a lot more time, I'll state one of (many possible)
the ways that tabs could be made acceptable in a limited environment.
Almost 40 years ago, I wrote an editor and assembler whose file format
used a separation character between fields. I used A0 because our
screens at the time ignored the high bit, so a file was sort-of readable
right out of the box. And the way that the developer jumped between
fields was the semi-colon key, of course, since that's the position of
the skip key in the keypunch we were replacing.

However, I don't intend to foist my opinions on others, just to state
them as opinions. At the office, we use special comment fields at
end-of-file to tell Emacs how to deal with a mixture of tabs and
spaces. Code written by a dozen people over a dozen years, and nobody
wanted to enforce a conversion to something common.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top