Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing a module
#18
(Nov-05-2016, 09:17 PM)SrirachaSauceLover Wrote:
(Nov-05-2016, 08:39 PM)Barrowman Wrote: SrirachaSauceLover
All you do is delete the spaces in front of the text. In your code you had
       main()
which has 8 spaces in front of it. Just delete them

I do this and am greeted with:

SyntaxError: unindent does not match any outer indentation level

Okay so it seems you have some problem with making sure that everything is aligned as it should be so let's see if you can get it right.
>>>> Looking at the version I posted <<<< Just to remove any confusion.
When you create the function with def main():
it should start on a line with no spaces to the left of it.
The next line 
inp = raw_input("Enter a value between 0 and 1: ")
should have 4 spaces to the left of it.
After that x = float(inp)
and  
for i in range(10):
should each have 4 spaces in front of them.
Then 
x = 3.9 * x * (1 - x)
and
print x
should have 8 spaces in front of them
Finally 
main()
should have no spaces in front of it.
If you get all that right you will not get the error.

The interpreter needs this consistent format so it knows where the def ends and where the for loop ends.
Note that if the def is itself within another def such as 
class example(): 
 the def needs to have 4 spaces to the left of it and all the other bits need an extra 4 spaces to the left of them.
I have said 4 spaces and then 8 spaces because that is the standard way and a good habit to get into. You could use 3 and 15 or 7 and 11  and so on but whatever you use it has to be consistent or you will get the unindent error.
Often copy and paste can cause this error.
Reply


Messages In This Thread
Importing a module - by SrirachaSauceLover - Nov-05-2016, 03:20 PM
RE: Importing a module - by Barrowman - Nov-05-2016, 03:37 PM
RE: Importing a module - by SrirachaSauceLover - Nov-05-2016, 03:53 PM
RE: Importing a module - by Barrowman - Nov-05-2016, 03:59 PM
RE: Importing a module - by SrirachaSauceLover - Nov-05-2016, 04:30 PM
RE: Importing a module - by Larz60+ - Nov-05-2016, 04:29 PM
RE: Importing a module - by Barrowman - Nov-05-2016, 06:14 PM
RE: Importing a module - by SrirachaSauceLover - Nov-05-2016, 06:51 PM
RE: Importing a module - by nilamo - Nov-05-2016, 06:18 PM
RE: Importing a module - by metulburr - Nov-05-2016, 07:13 PM
RE: Importing a module - by snippsat - Nov-05-2016, 07:49 PM
RE: Importing a module - by Barrowman - Nov-05-2016, 08:39 PM
RE: Importing a module - by SrirachaSauceLover - Nov-05-2016, 09:17 PM
RE: Importing a module - by Barrowman - Nov-06-2016, 10:20 AM
RE: Importing a module - by snippsat - Nov-05-2016, 09:22 PM
RE: Importing a module - by Larz60+ - Nov-05-2016, 10:20 PM
RE: Importing a module - by SrirachaSauceLover - Nov-06-2016, 08:10 AM
RE: Importing a module - by nilamo - Nov-07-2016, 04:21 PM
RE: Importing a module - by metulburr - Nov-06-2016, 08:15 AM
RE: Importing a module - by SrirachaSauceLover - Nov-08-2016, 11:23 AM
RE: Importing a module - by snippsat - Nov-08-2016, 03:05 PM
RE: Importing a module - by ngltm - Jun-13-2018, 02:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  importing variables from module 8376459 1 325 Feb-18-2024, 02:24 PM
Last Post: deanhystad
  no module named 'docx' when importing docx MaartenRo 1 1,080 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  My code displays too much output when importing class from a module lil_e 4 1,252 Oct-22-2022, 12:56 AM
Last Post: Larz60+
  Importing module in jupyter Noteboook ajitnayak1987 0 1,782 Jun-04-2021, 12:26 PM
Last Post: ajitnayak1987
  ERROR: importing desired module mbgamer28 0 1,715 Apr-05-2021, 07:46 PM
Last Post: mbgamer28
  importing module - not working jdhamblett 3 3,103 Jun-22-2020, 07:33 PM
Last Post: jdhamblett
  importing same python library in multiple custom module escape_freedom13 6 3,911 May-10-2020, 07:01 PM
Last Post: escape_freedom13
  Importing module from a package results in import error goghvv 2 2,455 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Please help: problem installing/importing langdetect module in Jupyter Notebook ledgreve 3 7,414 Dec-30-2019, 08:17 AM
Last Post: LeanbridgeTech
  Problem with importing and using collections module pythomdummy 3 5,918 Nov-14-2019, 08:48 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020