Python Forum
Python function returns inconsistent results
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python function returns inconsistent results
#3
(Dec-20-2019, 04:00 PM)stullis Wrote: If you run it a third time, does it triple? What happens if you wait a couple minutes before running it again? The only way I see it doubling the number of instances rest on line 66. If there are multiple, identical Reservations; it would count duplicate instances. Trying printing the instance_list before the loop and run the script a couple of times.

On a side note, there are some code blocks here that can be simplified. In several places, the following pattern occurs:

if 'KeyName' in instance:
    key_name = instance['KeyName']
else:
    key_name = None
This effectively does the same thing as dict.get() with a default value included:

key_name = instance.get('KeyName', None)
There are others too, but that one stood out the most.

Ok thanks for your response! No, running it a third time, it reports the same number as before. It does that each time it's run. The first time it's run it reports correctly that there are 51 instances. Each time you up arrow and run it again it reports there are 102 (doubled).

I tried printing out the instance_list and I see that it does print out twice. Does that mean that there are two identical reservations? If so how can I deduplicate those results? Thanks for the tip on how to simplify my code I will definitely do that!
Reply


Messages In This Thread
RE: Python function returns inconsistent results - by bluethundr - Dec-20-2019, 04:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How returns behave in a function with multiple returns? khasbay 1 270 May-19-2024, 08:48 AM
Last Post: deanhystad
Bug New to coding, Using the zip() function to create Diret and getting weird results Shagamatula 6 1,575 Apr-09-2023, 02:35 PM
Last Post: Shagamatula
  Read csv file with inconsistent delimiter gracenz 2 1,325 Mar-27-2023, 08:59 PM
Last Post: deanhystad
  Inconsistent loop iteration behavior JonWayn 2 1,070 Dec-10-2022, 06:49 AM
Last Post: JonWayn
  function returns dataframe as list harum 2 1,566 Aug-13-2022, 08:27 PM
Last Post: rob101
  ValueError: Found input variables with inconsistent numbers of samples saoko 0 2,561 Jun-16-2022, 06:59 PM
Last Post: saoko
  function accepts infinite parameters and returns a graph with those values edencthompson 0 924 Jun-10-2022, 03:42 PM
Last Post: edencthompson
  Loop Dict with inconsistent Keys Personne 1 1,675 Feb-05-2022, 03:19 AM
Last Post: Larz60+
  Inconsistent counting / timing with threading rantwhy 1 1,819 Nov-24-2021, 04:04 AM
Last Post: deanhystad
  Inconsistent behaviour in output - web scraping Steve 6 2,708 Sep-20-2021, 01:54 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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