Please verify!!

Discussion in 'Python' started by Manish Sharma, Feb 23, 2012.

  1. 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
    Manish Sharma, Feb 23, 2012
    #1
    1. Advertising

  2. Manish Sharma

    Ben Guest

    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.
    Ben, Feb 23, 2012
    #2
    1. Advertising

  3. Manish Sharma

    Dave Angel Guest

    On 02/23/2012 05:13 PM, Manish Sharma wrote:
    > 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.

    --

    DaveA
    Dave Angel, Feb 23, 2012
    #3
  4. Wasn't supposed to be private, just something went funky with gmail
    when i sent it out, oddly enough

    On Thu, Feb 23, 2012 at 8:32 PM, Dave Angel <> wrote:
    > On 02/23/2012 07:15 PM, Joshua Miller wrote:
    >>
    >> When he/she said "python editor" i'm sure they meant IDLE which in
    >> some cases is the worst ide to use. Some ide's do mess with python
    >> files you just have to make sure to change their settings to
    >> accomadate python. Otherwise no it's a better idea to use  something
    >> other than IDLE. For windows generally people use eclipse with the
    >> pydev extension, pyscripter, or the several other IDE's that are known
    >> with a little help not to do what you are describing ;)
    >>

    >
    > I can't argue with anything you say here.  But you shouldn't have sent it
    > privately, as this is a public list.  And please don't top-post
    >
    > So I'm forwarding it to the list.
    >
    > --
    >
    > DaveA




    --
    ~ Josh Miller

    A young guy learning to program and develop websites all while still in school
    Joshua Miller, Feb 24, 2012
    #4
  5. Manish Sharma

    Andrew Berg Guest

    On 2/23/2012 4:43 PM, Dave Angel wrote:
    > 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.

    --
    CPython 3.2.2 | Windows NT 6.1.7601.17640
    Andrew Berg, Feb 24, 2012
    #5
  6. Manish Sharma

    Andrew Berg Guest

    On 2/24/2012 2:32 AM, Ben Finney wrote:
    > 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.

    --
    CPython 3.2.2 | Windows NT 6.1.7601.17640
    Andrew Berg, Feb 24, 2012
    #6
  7. Manish Sharma

    Andrew Berg Guest

    On 2/24/2012 5:21 AM, Duncan Booth wrote:
    > 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.

    --
    CPython 3.2.2 | Windows NT 6.1.7601.17640
    Andrew Berg, Feb 24, 2012
    #7
  8. On Fri, 24 Feb 2012 03:18:18 -0600, Andrew Berg wrote:

    > On 2/24/2012 2:32 AM, Ben Finney wrote:
    >> 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.


    "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.


    --
    Steven
    Steven D'Aprano, Feb 24, 2012
    #8
  9. Manish Sharma

    Andrew Berg Guest

    On 2/24/2012 6:20 AM, Steven D'Aprano wrote:
    > 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.

    --
    CPython 3.2.2 | Windows NT 6.1.7601.17640
    Andrew Berg, Feb 24, 2012
    #9
  10. On Fri, Feb 24, 2012 at 11:20 PM, Steven D'Aprano
    <> wrote:
    > 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
    Chris Angelico, Feb 24, 2012
    #10
  11. On 24/02/2012 20:41, Chris Angelico wrote:
    > On Fri, Feb 24, 2012 at 11:20 PM, Steven D'Aprano
    > <> wrote:
    >> 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


    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.

    --
    Cheers.

    Mark Lawrence.
    Mark Lawrence, Feb 25, 2012
    #11
  12. On Sat, Feb 25, 2012 at 11:49 AM, Mark Lawrence <> wrote:
    > 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
    Chris Angelico, Feb 25, 2012
    #12
  13. Manish Sharma

    Dave Angel Guest

    On 02/24/2012 08:25 PM, Chris Angelico wrote:
    > On Sat, Feb 25, 2012 at 11:49 AM, Mark Lawrence<> wrote:
    >> 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


    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.




    --

    DaveA
    Dave Angel, Feb 25, 2012
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Parnell

    Can You Verify Please??

    Mark Parnell, Jul 27, 2004, in forum: HTML
    Replies:
    4
    Views:
    432
    Toby Inkster
    Jul 28, 2004
  2. KK
    Replies:
    2
    Views:
    524
    Big Brian
    Oct 14, 2003
  3. Thomas Matthews

    please verify the code

    Thomas Matthews, Dec 17, 2005, in forum: C Programming
    Replies:
    16
    Views:
    481
    Default User
    Dec 23, 2005
  4. Jeremiah Johnson

    Win2K Tx Isolation - verify please

    Jeremiah Johnson, Mar 5, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    106
    Jeremiah Johnson
    Mar 6, 2004
  5. zig
    Replies:
    20
    Views:
    192
Loading...

Share This Page