Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing a module
#14
(Nov-05-2016, 08:39 PM)Barrowman Wrote: 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
Can also delete main() all together,dos not need that call when import it.
# File: chaos.py
# A simple program illustrating chaotic behavior.
def main():
   print("This program illustrates a chaotic function")
   inp = float(input("Enter a number between 0 and 1: "))
   for i in range(10):
       inp = 3.9 * inp * (1 -inp)
       print(inp)
Test import:
Output:
>>> import chaos >>> chaos.main() This program illustrates a chaotic function Enter a number between 0 and 1: .5 0.975 0.09506250000000008 0.33549992226562525 0.8694649252590003 0.44263310911310905 0.962165255336889 0.1419727793616139 0.4750843861996143 0.9725789275369049 0.1040097132674683
Look a little at at if __name__ == '__main__': and what it does.
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 355 Feb-18-2024, 02:24 PM
Last Post: deanhystad
  no module named 'docx' when importing docx MaartenRo 1 1,202 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,291 Oct-22-2022, 12:56 AM
Last Post: Larz60+
  Importing module in jupyter Noteboook ajitnayak1987 0 1,798 Jun-04-2021, 12:26 PM
Last Post: ajitnayak1987
  ERROR: importing desired module mbgamer28 0 1,732 Apr-05-2021, 07:46 PM
Last Post: mbgamer28
  importing module - not working jdhamblett 3 3,132 Jun-22-2020, 07:33 PM
Last Post: jdhamblett
  importing same python library in multiple custom module escape_freedom13 6 3,993 May-10-2020, 07:01 PM
Last Post: escape_freedom13
  Importing module from a package results in import error goghvv 2 2,490 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Please help: problem installing/importing langdetect module in Jupyter Notebook ledgreve 3 7,489 Dec-30-2019, 08:17 AM
Last Post: LeanbridgeTech
  Problem with importing and using collections module pythomdummy 3 5,972 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