Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7531235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:07:09+00:00 2026-05-30T05:07:09+00:00

I have a function that takes 2 returned variables from another function to write

  • 0

I have a function that takes 2 returned variables from another function to write them with a little bit more padding text to an external text file.

The code that I am using to write to the text file is below but it is being called automatically at runtime with the if statement at the bottom of the program

def function1()
# Some code

def function2()
# Some code
return startNode
return endNode

def function3(var)
# Some code
return differentVariable

def createFile(startNode, endNode):
    outputFile = open('filename.txt','w')                   # Create and open text file
    start = chr(startNode +65)                              # Converts the int to its respective Char
    end = chr(endNode +65)                                  # Converts the int to its respective Char
    outputFile.write('Route Start Node: ' + start + '\n')   # e.g Route Start Node: B
    outputFile.write('Route end node: ' +  end + '\n')      # e.g Route End Node: F
    outputFile.write('Route: ' + Path + '\n')               # e.g Path: B,A,D,F
    outputFile.write('Total distance: ' + Distance)         # e.g Total Distance: 4
    outputFile.close                                        # Close file


if __name__ == "__main__":
    function1()
    function3(function2())
    createFile( # Don't Know What Goes Here  )

At the moment I am only able to run this function by manually calling it and entering createFile(1,5) where the 1 is the startNode value and the 5 is the endNode value

But if I am to put createFile(startNode, endNode) in the if statement to call the function, it tells me NameError: name 'startNode' is not defined and then it would obviously give me the same error for endNode too

How do I call that function properly without having to enter the values manually because they can change depending on what the startNode and endNode values are at the start of the program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:07:10+00:00Added an answer on May 30, 2026 at 5:07 am

    You can’t return two variables as you’ve done in your example of function2. Execution will exit the function at the first return value, and never make it to the second. Instead, you need to return a tuple:

    def function2():
        # set the values of startNode and endNode here
        # e.g.
        startNode = 1
        endNode = 5
        return (startNode, endNode)
    

    Then when you call function2, do as Ade described:

    if __name__ == "__main__":
        startNode, endNode = function2()
        createFile(startNode, endNode)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that takes variadic arguments, that I obtain from func_get_args() .
I wrote the following simple function that takes two parameters mostly coming from another
I have been looking for an elegant way to write a function that takes
I have a function that takes, amongst others, a parameter declared as int privateCount
I have a function that takes a struct, and I'm trying to store its
I have a function that takes pointer to pointer to struct. struct ABC; void
I have a function that takes a string-like argument. I want to decide if
I have a function that takes a const D3DVECTOR3 *pos , but I have
I have a function that takes 2 parameters : 1 = XML file, 2
I have a function that takes longitude and latitude and converts it to x

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.