Questions tagged [setdefault]

49 questions
0
votes
1 answer

How to add a default timestamp with time 09.00 o'clock in postgresql?

I am trying to add a default timetable into my query with a chosen time, 09.00 o'clock. The type of the column was 'date', I changed it to 'timestamp', my assignment sais so. I don't know what to do now. I am very new to this and trying to…
Bosbes
  • 17
  • 4
0
votes
1 answer

Python, dict. Changes also appear on the main object even though saved only on a different object?

Changes also appear on the main object even though saved only on a different object? A dict: transportation = {"car":"ford", "coche":"fiat"} The changes: x = transportation.setdefault("carro", "BMW") Output of the object where changes were…
0
votes
1 answer

adding values to defaultdict set breaking on 128

Something always breaks once my address reaches value 128, and it stops putting the new value at the end of the nested dict. And instead starts ordering it from the beginning again. Why is it doing this? result.setdefault(fan_definitions_name,…
Andrew Clark
  • 850
  • 7
  • 13
0
votes
0 answers

setdefault() not inserting key with default for nested dictionary in python

The dictionary structure is: storage = {} storage['first'] = {} storage['middle'] = {} storage['last'] = {} The first insertion made to this dictionary is: me = 'Magnus Lie Hetland' storage['first']['Magnus'] = [me] …
Brijesh Joshi
  • 19
  • 1
  • 10
0
votes
2 answers

dict.setdefault() is used when value already exists

I'm trying to add new keys to the existing dictionary, setting as default value, the value of the previous key. def check_data(end, start, profile): print(profile) for day in range((end-start).days+1): …
Artur
  • 21
  • 1
  • 6
0
votes
1 answer

SET_DEFAULT for ForeignKey column itself

I'm create this table in Django models: class customer(models.Model): name = models.CharField(max_length=100) inviter = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_DEFAULT) inviter is ForeignKey of self Now I…
0
votes
1 answer

setdefault() in nested dictionary?

trying to store the values in a nested dictionary in a shelve file with setdefult(). Is there any easy way to do this? The following code seems to make the values immutable, for example, the last line is unable to change the 'price' value to 25.…
WastedHat
  • 15
  • 1
  • 6
0
votes
4 answers

MySQL SET DEFAULT returns error: query is empty

I have an existing MySQL (version 5.6.12) table called 'users' and am trying to set the column defaults via php (version 5.4.12), for example: $query = "ALTER TABLE users ALTER username SET DEFAULT NULL"; $result = mysqli_query($query); However…
Stefan
  • 3,850
  • 2
  • 26
  • 39
0
votes
1 answer

Matlab: set default values for GUI edit text and use them in push button callback

I'm trying to initialize a GUI (built with GUIDE) with default values and then, if the user does not change the defaults, use these values in a function triggered by a push button callback. To do this, inside the _CreateFcn, I first store the…
Andrea
  • 335
  • 3
  • 11
0
votes
0 answers

Python-dict setdefault - about using it only for setting

I see the discussion here setdefault vs. get and here when using setdefault (vs. defaultdict). My question is more about coding style. It's agreed that we shouldn't use setdefault for simple dict setting: d = {} d[k] = v but not: d.setdefault(k,…
alikyos
  • 86
  • 1
  • 7
0
votes
1 answer

Locale setDefault() Risk in Java

I got one application that can switch language between English and Germany. When in Germany language i want the currency display will auto convert into German format. Therefore in my program i have to do checking for the locale then convert the…
yukiko
  • 103
  • 1
  • 10
0
votes
1 answer

symfony setDefault not saving values

I'm defining a form in the actions, and passing it to the template. It's failing to set the default values when saving. Can you tell me what I'm doing wrong? In modules\question\actions: public function executeNew(sfWebRequest $request) { …
Martin Fall
  • 121
  • 7
0
votes
1 answer

Mysql set default to null if multiple rows dont match

I have a table called invoices. to help make this question simple we will say that there are 4 columns in the invoice. id (PK auto int) booking_id (int) is_business_invoice (1 or 0 or NULL) amount …
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117
0
votes
3 answers

An alternative to pythons "setdefault" augmented assignment

I want a dictionary that shows boolean counts. I.e. how often name/position combination meets criteria. E.g.: Key - Value1 - Value2 John12 Yes:300 No:25 John13 Yes:400 No:29 Linda13 Yes:300 No:60 ... I tried this: if str(f[1]) + str(f[7]) in…
AWE
  • 4,045
  • 9
  • 33
  • 42
-1
votes
1 answer

How do dict2.setdefault() work ? How it influence my if else statement?

dict2 = {'Name': 'sandeep', 'Age': 15, 'Class': '11th', 'school': 'GSBV'} print(dict2) if 'collage' in dict2.keys(): print(dict2['collage']) else: print('no key found in dict') print(dict2.setdefault('collage', 'this key do not exist in dict')) if…