element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum what is equivalent command for GOSUB
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 5 replies
  • Subscribers 304 subscribers
  • Views 2172 views
  • Users 0 members are here
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

what is equivalent command for GOSUB

donb
donb over 11 years ago

In Basic there is a command gosub  (go to a subroutine). I can not find the proper command in Python to call another file, run it then come back to the next line in the main program where it went to the subroutine. What is the proper instruction?

  • Sign in to reply
  • Cancel
  • johnbeetem
    0 johnbeetem over 11 years ago

    I'm not a Python programmer, but I think you want to define a function using "def".

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • donb
    0 donb over 11 years ago in reply to johnbeetem

    thanks John I will read more on def.

     

    do I just code in def  (filename.py) and what gets me back to the main program?

    Anyone else care to give me advice. Can "call" be used and how?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • johnbeetem
    0 johnbeetem over 11 years ago in reply to donb

    Here's the chapter on defining and calling functions at Wikibooks: http://en.wikibooks.org/wiki/Python_Programming/Functions

     

    This is for calling functions within the same file.  I don't know how you'd call functions defined in another file.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • bheemarao
    0 bheemarao over 11 years ago in reply to johnbeetem

    Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module; definitions from a module can be imported into other modules or into the main module

     

    A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.

     

    for example: fibo.py has below lines of code


    deffib(n):# write Fibonacci series up to n

       a, b = 0, 1

       while b < n:

       print(b, end=' ')

       a, b = b, a+b

       print()

     

    def fib2(n): # return Fibonacci series up to n

       result = []

       a, b = 0, 1

       while b < n:

       result.append(b)

       a, b = b, a+b

    returnresult

    and you can create your main file in which you need to import this fibo.py

    import fibo

    and access the function by calling it as below:

    fibo.fib(1000)

    for more help you can refer to the below link chapter-6:

    The Python Tutorial — Python 3.4.0 documentation

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
  • donb
    0 donb over 11 years ago in reply to bheemarao

    thanks bheemarao

     

    I couldn't make these instructions work:

    Here is what I am trying to do:

    I have a stand alone program that will run using the command (on LX Terminal) sudo ./filename.py but if I try to write a main program to call this program nothing I have tried seems to work. I have read the Python tutorial section on Modules many times but can not come up with the correct way to call this standalone program then continue with the main program. I thank all of you for your input but am still at a loss.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube