Integers being added to Dictionary with single quotes and as as float
Hi I'm getting some very strange behaviour which i can't really understand when adding a value to a dictionary
this is the code i'm using (it's part of a larger piece of code of-course but i think this is enough to isolate the issue
player = {
'first_name': str(row['first_name']),
'last_name': str(row['last_name']),
"email": email,
"phone_number": str(row["contacts_phone"]),
"country": str(row['country']),
"custom_fields": {}
}
for obj in sg_custom_fields:
if obj['name'] == 'deposit_count':
player['custom_fields'][obj['id']] = int(row['deposit_count'])
print(type(player['custom_fields']['e45_N']))
print(int(row['deposit_count']))
print(player)
and this is the output theres more inbetween the printing of the player obviously but nothing that would effect this.
<class 'int'>
0
{'first_name': '', 'last_name': '', 'email': '', 'phone_number': '', 'country': '', 'custom_fields': {'e45_N': '0.0', }}
Really can't figure out why it is in quotations or has a decimal place.
As an extra bit of confusion the same things is not true if i just run it in the interpreter
Python 3.9.11 (main, Mar 29 2022, 19:08:29)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> data = {'something':0}
>>> data['new_data'] = 0
>>> print(data)
{'something': 0, 'new_data': 0}
>>>
If anyone can help make sense of this i would be grateful
Thanks
How many English words
do you know?
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
how many words do you know
Powered by Examplum