Python Forum
Duplicate output when calling a custom function from the same file?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Duplicate output when calling a custom function from the same file?
#1
Hi folks,

I'm new to programming and python, and I don't understand why if you call a custom function from the same file it's defined in, you get duplicate output.

e.g. a file "question.py" containing the following:
def double(number):
    return number * 2

from question import double
print(double(1))
And if I were to manually input "double(2)" after running the module, the output seems perfectly normal (just one 4).
Why is that? And is there a way to avoid the duplicate apart from calling the function from a separate py file?

I know this must have been asked before, but I couldn't find it via forum search or Google (the queries all return questions related to list modification).

Thanks in advance for clearing up my confusion!
Reply


Messages In This Thread
Duplicate output when calling a custom function from the same file? - by road2knowledge - May-10-2019, 07:38 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 621 Nov-23-2023, 02:53 PM
Last Post: rob101
  problem in output of a function akbarza 9 1,239 Sep-29-2023, 11:13 AM
Last Post: snippsat
  calling external function with arguments Wimpy_Wellington 7 1,498 Jul-05-2023, 06:33 PM
Last Post: deanhystad
  Calling a function (which accesses a library) from another file mouse9095 4 839 Jun-07-2023, 08:55 PM
Last Post: deanhystad
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,134 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  How to print the output of a defined function bshoushtarian 4 1,337 Sep-08-2022, 01:44 PM
Last Post: deanhystad
Sad Iterate randint() multiple times when calling a function Jake123 2 2,086 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Calling a class from a function jc4d 5 1,857 Dec-17-2021, 09:04 PM
Last Post: ndc85430
  output correction using print() function afefDXCTN 3 11,142 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  python prints none in function output chairmanme0wme0w 3 2,247 Jul-07-2021, 05:18 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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