Results 1 to 5 of 5

Thread: Python Program Development - Indentations Issue

  1. #1
    Join Date
    Dec 2010
    Beans
    433

    Python Program Development - Indentations Issue

    I am writing a Python script in notepad++ on win10 to be copied onto my Ubuntu server machine via ssh (copy n paste). I set the EOL conversion in notepad++ to Unix. When I try to run my script, it complains about the tabbing, which looks fine in notepad++. What is the best way to develop like this, if the server does not have a gui?
    Error:
    Code:
        if os.path.isfile(snortRulesFileName+filename):                                                  ^
    IndentationError: unindent does not match any outer indentation level
    Graphical images of what the code looks like on both platforms. You can see the indentation does not properly get copied over.

    ubuntu2.png

    ubuntu1.png

  2. #2
    Join Date
    Jun 2009
    Location
    SW Forida
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Python Program Development - Indentations Issue

    Do not know notepad++.

    But with Ubuntu I use geany.
    But first thing is to change from tabs to 4 spaces in both preferences & projects. And set default to python. And a save file using spaces to replace all tabs.

    You might be able to set up geany for python, like mine, and import & save file to see if spacing is corrected.
    UEFI boot install & repair info - Regularly Updated :
    https://ubuntuforums.org/showthread.php?t=2147295
    Please use Thread Tools above first post to change to [Solved] when/if answered completely.

  3. #3
    Join Date
    Jul 2006
    Location
    UK
    Beans
    195
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Python Program Development - Indentations Issue

    Notepad++ is good for Windows but I've found the same issue with EOL when moving between OS.

    I find Geany to be much better for cross-platform development. As Oldfred says, set the tabs to 4 spaces.
    Registered Linux User #426227

  4. #4
    Join Date
    Jan 2010
    Location
    Wheeling WV USA
    Beans
    2,021
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Python Program Development - Indentations Issue

    notepad will put in tabs for indentations long enough that tabs can be used. generally this is 8 positions. the python world prefers spaces instead of tabs because tabs make the indentation harder to work with, such as moving a block of code over because of things like a "for" clause or "if" clause being added or removed. i am not surprised that it is now necessary in python. the Windows version of python may still allow tabs.

    there is a command called "expand" in Ubuntu which converts tabs to the proper number of spaces. do "man expand" in a command line terminal to read more about it. it can read filenames given to it as arguments but always writes the file to standard output, so the way to use it (after the file is on Ubuntu) is:
    Code:
    expand mything.py > mything.tmp
    mv mything.tmp mything.py
    Last edited by Skaperen; May 22nd, 2018 at 05:09 AM.
    Mask wearer, Social distancer, System Administrator, Programmer, Linux advocate, Command Line user, Ham radio operator (KA9WGN/8, tech), Photographer (hobby), occasional tweetXer

  5. #5
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Python Program Development - Indentations Issue

    I would suggest copying the file from Windows to Ubuntu rather than using copy & paste. e.g. use WinSCP.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •