Python Forum
Passing variable to another function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing variable to another function
#4
All I'm trying to do here is give the variable more scope without using the global function.
Sorry guys I thought I could solve this. At first I just did as you asked Michael. Removed the 2 function calls and placed the function inside the other. As I mentioned - this caused it to print:

Quote:Mylocation
Mylocation

So I removed the "return"

And I got

Quote:Mylocation
None

After a series of attempts my last one is below
This weirdly prints
Quote:Mylocationfoo
Mylocationfoo
I though it would print
Quote:Mylocationfoo
Mylocation

I thought only the second one was going to have the foo
def dataread():
    test_file = open('Database.txt', 'r')
    test_lines = test_file.readlines()
    test_file.close()
    #Print line
    liner = (test_lines[1])
 
    colon = liner.find(":")
    semi = liner.find(";")
    comma = liner.find(",")
    length = len(liner)
 
    name = (liner[colon+1:semi])
    location = (liner[semi+1:comma])
    gps = (liner[comma+1:length])
 
    htmlwr(location)
    return location
 
 
def htmlwr(location):
   Tester = location + "foo"
   print(tester)
 

htmlwr(dataeread())
If I remove the "return value" from this one it prints
Quote:Mylocationfoo
Error

It's as if the things looping inside itself. Which I'm sure might be a useful trait at some point. But not with this

Lastly I tried to switch the functions
dataeread(htmlwr())
But it gave me a position error
Reply


Messages In This Thread
RE: Passing variable to another function - by JonnyDriller - Feb-03-2020, 10:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to call the variable inside the if/elif function mareeswaran 3 599 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  Variable for the value element in the index function?? Learner1 8 2,983 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 1,618 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 7,521 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 2,187 Aug-07-2023, 05:58 PM
Last Post: Karp
  passing dictionary to the function mark588 2 1,973 Dec-19-2022, 07:28 PM
Last Post: deanhystad
  Retrieve variable from function labgoggles 2 1,818 Jul-01-2022, 07:23 PM
Last Post: labgoggles
  Cant transfer a variable onto another function KEIKAS 5 2,941 Feb-09-2022, 10:17 PM
Last Post: deanhystad
  passing php variable to python file jerald 1 3,960 Jul-07-2021, 11:46 AM
Last Post: Larz60+
  Passing flags to python script, through a function xbit 4 5,641 Apr-20-2021, 06:32 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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