workspace
stringclasses 1
value | channel
stringclasses 1
value | sentences
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
| sentence_id
stringlengths 44
53
| timestamp
float64 1.5B
1.56B
| __index_level_0__
int64 0
106k
|
---|---|---|---|---|---|---|---|
pythondev | help | I don't know spark well, but as far as I know you connect spark to a database and run the data transformations off there. What loads that database doesn't matter (PHP, Python, Raw SQL, etc) | 2017-08-16T11:37:49.000186 | Beula | pythondev_help_Beula_2017-08-16T11:37:49.000186 | 1,502,883,469.000186 | 89,803 |
pythondev | help | I think you are correct. thanks <@Beula> | 2017-08-16T11:45:10.000263 | Assunta | pythondev_help_Assunta_2017-08-16T11:45:10.000263 | 1,502,883,910.000263 | 89,804 |
pythondev | help | Awesome post! Thx for sharing the link. | 2017-08-16T15:38:54.000434 | Deedee | pythondev_help_Deedee_2017-08-16T15:38:54.000434 | 1,502,897,934.000434 | 89,805 |
pythondev | help | Hello, can I get some help with tensorflow? I'm doing image recognition, and I've seen in different examples that I have to use `tf.gfile.FastGFile(image_path, 'rb').read()` as my image data. But I was wondering if there's a way to use an image in memory instead | 2017-08-16T20:38:03.000006 | Prudence | pythondev_help_Prudence_2017-08-16T20:38:03.000006 | 1,502,915,883.000006 | 89,806 |
pythondev | help | I want to use an image in a post request (I'm using Bottle framework) | 2017-08-16T20:38:55.000145 | Prudence | pythondev_help_Prudence_2017-08-16T20:38:55.000145 | 1,502,915,935.000145 | 89,807 |
pythondev | help | check whether that tensorflow method takes in a file like object | 2017-08-16T20:47:37.000187 | Meg | pythondev_help_Meg_2017-08-16T20:47:37.000187 | 1,502,916,457.000187 | 89,808 |
pythondev | help | if so, you can create a temp file, read the image into memory and pass it in | 2017-08-16T20:47:57.000236 | Meg | pythondev_help_Meg_2017-08-16T20:47:57.000236 | 1,502,916,477.000236 | 89,809 |
pythondev | help | It takes the path of an image. Should I write the file to the disk and then pass that path to the FastGFile class? | 2017-08-16T20:51:37.000072 | Prudence | pythondev_help_Prudence_2017-08-16T20:51:37.000072 | 1,502,916,697.000072 | 89,810 |
pythondev | help | I find it weird it can’t take in a temp file | 2017-08-16T20:56:41.000160 | Meg | pythondev_help_Meg_2017-08-16T20:56:41.000160 | 1,502,917,001.00016 | 89,811 |
pythondev | help | I'm not sure of what FastGFile does. Perhaps it just reads a file as I would normally do with python, and adds extra features. I'll try to read it as normal, and pass that as the image data, skipping the FastGFile object | 2017-08-16T21:02:33.000033 | Prudence | pythondev_help_Prudence_2017-08-16T21:02:33.000033 | 1,502,917,353.000033 | 89,812 |
pythondev | help | hi guys, in which case we should consider using multi processes rather than threads? I think if we have 4 core, we can create 4 processes with might better than 4 threads using one process right? I’m writing script to migrate data from db postgres to other db (elasticsearch) | 2017-08-16T23:18:22.000041 | Hermina | pythondev_help_Hermina_2017-08-16T23:18:22.000041 | 1,502,925,502.000041 | 89,813 |
pythondev | help | is what you have currently going super slow? | 2017-08-16T23:22:58.000163 | Johana | pythondev_help_Johana_2017-08-16T23:22:58.000163 | 1,502,925,778.000163 | 89,814 |
pythondev | help | i’m running threads, and few like its quite slow, trying to update it to make it faster | 2017-08-16T23:23:20.000064 | Hermina | pythondev_help_Hermina_2017-08-16T23:23:20.000064 | 1,502,925,800.000064 | 89,815 |
pythondev | help | In python we have the gil, which only lets a single thread run at a time. Given that, the only way threads help you in python is io bound things (waiting on network requests). Processes help for cpu bound work, but sharing data is expensive as it makes entire copies to share (since memory space isn't shared in python). | 2017-08-16T23:24:04.000144 | Beula | pythondev_help_Beula_2017-08-16T23:24:04.000144 | 1,502,925,844.000144 | 89,816 |
pythondev | help | i’ve never filled elastic search with tons of data but i have done so with postgres. typically in these situations you gotta be careful about your database sessions and want to use a connection pool. | 2017-08-16T23:24:20.000074 | Johana | pythondev_help_Johana_2017-08-16T23:24:20.000074 | 1,502,925,860.000074 | 89,817 |
pythondev | help | Agreed, I'm not sure how much perf you can really squeze out of a database migration (but since it should be 1 time, that's probably ok | 2017-08-16T23:25:46.000060 | Beula | pythondev_help_Beula_2017-08-16T23:25:46.000060 | 1,502,925,946.00006 | 89,818 |
pythondev | help | yea… i agree there sometimes its ok to ensure all the data goes in properly. | 2017-08-16T23:26:35.000073 | Johana | pythondev_help_Johana_2017-08-16T23:26:35.000073 | 1,502,925,995.000073 | 89,819 |
pythondev | help | i know i’ve done well over 10,000 transactions a second with postgresql. i’m not sure about elastic search. | 2017-08-16T23:27:49.000128 | Johana | pythondev_help_Johana_2017-08-16T23:27:49.000128 | 1,502,926,069.000128 | 89,820 |
pythondev | help | umm, I do it quite simple by using django orm model. So technically I just assign my_models[0,100] to thread1, my_models[101,200] to thread2…..
So each thread, I think it have it self connection pool. (every time I run 5 threads, I see 5 connection to db is open).
Sorry I still not clear what you are suggesting :disappointed: | 2017-08-16T23:33:36.000118 | Hermina | pythondev_help_Hermina_2017-08-16T23:33:36.000118 | 1,502,926,416.000118 | 89,821 |
pythondev | help | if I spawn 4 processes, will it use 4 core in cpu? Or I’m lacking of OS knowledge… | 2017-08-16T23:35:53.000062 | Hermina | pythondev_help_Hermina_2017-08-16T23:35:53.000062 | 1,502,926,553.000062 | 89,822 |
pythondev | help | yea you might be ok. try it and see what happens. | 2017-08-16T23:36:45.000059 | Johana | pythondev_help_Johana_2017-08-16T23:36:45.000059 | 1,502,926,605.000059 | 89,823 |
pythondev | help | when i need to do a bunch of database work i just use a work queue. | 2017-08-16T23:37:04.000035 | Johana | pythondev_help_Johana_2017-08-16T23:37:04.000035 | 1,502,926,624.000035 | 89,824 |
pythondev | help | hmm, ok i’ll try it :slightly_smiling_face: | 2017-08-16T23:37:42.000017 | Hermina | pythondev_help_Hermina_2017-08-16T23:37:42.000017 | 1,502,926,662.000017 | 89,825 |
pythondev | help | let us know how it works out. | 2017-08-16T23:37:51.000109 | Johana | pythondev_help_Johana_2017-08-16T23:37:51.000109 | 1,502,926,671.000109 | 89,826 |
pythondev | help | :ok_hand: | 2017-08-16T23:38:11.000010 | Hermina | pythondev_help_Hermina_2017-08-16T23:38:11.000010 | 1,502,926,691.00001 | 89,827 |
pythondev | help | i haven’t done any database loads using multiprocessing so it will be nice to know if i ever need to ping you for help :wink:. | 2017-08-16T23:38:48.000131 | Johana | pythondev_help_Johana_2017-08-16T23:38:48.000131 | 1,502,926,728.000131 | 89,828 |
pythondev | help | how can i generate a chart using table in html with matplotlib by using django? | 2017-08-17T04:54:31.000045 | Georgetta | pythondev_help_Georgetta_2017-08-17T04:54:31.000045 | 1,502,945,671.000045 | 89,829 |
pythondev | help | If we want to build a dictionary like this:
```
d = {
"hello": world,
f(),
}
```
Is there a function `f` that would allow for this?
I very often find myself repeating this pattern:
```
d = { "some_preknown_key": "some_preknown_value", }
if cond1:
d[cond1_key] = cond1_value
if cond2:
d[cond2_key] = cond2_value
do_something_with_dict(d)
```
but I'd like to do be able to write it something like
```
d = cond_build_dict({
"some_preknown_key": some_preknown_value",
when(cond1, cond1_key, cond1_value),
when(cond2, cond2_key, cond2_value),
})
```
which would return a regular dict, with the `cond1_key` and `cond2_key` keys only
present if the first argument of their respective `when` function call is `True`. | 2017-08-17T05:14:25.000026 | Lanita | pythondev_help_Lanita_2017-08-17T05:14:25.000026 | 1,502,946,865.000026 | 89,830 |
pythondev | help | when could return the equivalent of `cond1_key : cond1_value` if the first argument is True, else puts some key: value token of some kind that will be filtered out by cond_build_dict (which is a function that takes a dict and remove all keys containing this token) | 2017-08-17T05:16:01.000258 | Lanita | pythondev_help_Lanita_2017-08-17T05:16:01.000258 | 1,502,946,961.000258 | 89,831 |
pythondev | help | > Is there a function `f` that would allow for this?
Kinda. | 2017-08-17T05:18:27.000337 | Suellen | pythondev_help_Suellen_2017-08-17T05:18:27.000337 | 1,502,947,107.000337 | 89,832 |
pythondev | help | ```
>>> def conditional_data():
... if random.randint(0, 1) == 1:
... return {'condition_is_met': '1234'}
... return {}
...
>>> d = {'hello': 'world', **conditional_data()}
>>> d
{'hello': 'world'}
>>> d = {'hello': 'world', **conditional_data()}
>>> d
{'hello': 'world'}
>>> d = {'hello': 'world', **conditional_data()}
>>> d
{'hello': 'world', 'condition_is_met': '1234'}
``` | 2017-08-17T05:18:34.000194 | Suellen | pythondev_help_Suellen_2017-08-17T05:18:34.000194 | 1,502,947,114.000194 | 89,833 |
pythondev | help | so your original example can be written like this:
```
d = {
"hello": world,
**f(),
}
``` | 2017-08-17T05:19:01.000023 | Suellen | pythondev_help_Suellen_2017-08-17T05:19:01.000023 | 1,502,947,141.000023 | 89,834 |
pythondev | help | <@Suellen> yup, that's how I've been doing before | 2017-08-17T05:19:16.000030 | Lanita | pythondev_help_Lanita_2017-08-17T05:19:16.000030 | 1,502,947,156.00003 | 89,835 |
pythondev | help | but I'd like to have everything be in one place, to make it visually easier to parse | 2017-08-17T05:19:26.000077 | Lanita | pythondev_help_Lanita_2017-08-17T05:19:26.000077 | 1,502,947,166.000077 | 89,836 |
pythondev | help | since it looks and feels more declerative | 2017-08-17T05:19:43.000262 | Lanita | pythondev_help_Lanita_2017-08-17T05:19:43.000262 | 1,502,947,183.000262 | 89,837 |
pythondev | help | one built-in option that works if you're okay with keeping the key is simply doing
```
d = {
"some_key": some_value if cond else None
}
``` | 2017-08-17T05:20:33.000431 | Lanita | pythondev_help_Lanita_2017-08-17T05:20:33.000431 | 1,502,947,233.000431 | 89,838 |
pythondev | help | well.. it's easy to cross into "ugly code" territory | 2017-08-17T05:21:06.000041 | Suellen | pythondev_help_Suellen_2017-08-17T05:21:06.000041 | 1,502,947,266.000041 | 89,839 |
pythondev | help | yeah | 2017-08-17T05:21:14.000205 | Lanita | pythondev_help_Lanita_2017-08-17T05:21:14.000205 | 1,502,947,274.000205 | 89,840 |
pythondev | help | what I just wrote wasn't ugly though, but it can quickly get ugly | 2017-08-17T05:21:24.000056 | Lanita | pythondev_help_Lanita_2017-08-17T05:21:24.000056 | 1,502,947,284.000056 | 89,841 |
pythondev | help | Personally I like the explicit `if` statements. If the dict really does have a variety of different permutations I like that to be explicit in the code | 2017-08-17T05:21:38.000242 | Gabriele | pythondev_help_Gabriele_2017-08-17T05:21:38.000242 | 1,502,947,298.000242 | 89,842 |
pythondev | help | short, declarative code in one place is typically easier to read than slowly mutating an object to get to where we want to be | 2017-08-17T05:22:22.000060 | Lanita | pythondev_help_Lanita_2017-08-17T05:22:22.000060 | 1,502,947,342.00006 | 89,843 |
pythondev | help | ```
>>> d = {'hello': 'world'}
>>> condition = True
>>> d.update({'abc': 'def'} if condition else {})
>>> d
{'abc': 'def', 'hello': 'world'}
```
More real-life example:
```
>>> d = {'hello': 'world'}
>>> d.update(**user_data() if store_user else {})
>>> d.update(**group_data() if store_group else {})
```
This way the key isn't added to the dictionary if the condition is false | 2017-08-17T05:22:31.000274 | Suellen | pythondev_help_Suellen_2017-08-17T05:22:31.000274 | 1,502,947,351.000274 | 89,844 |
pythondev | help | but I feel like it's already a bit ugly | 2017-08-17T05:22:37.000189 | Suellen | pythondev_help_Suellen_2017-08-17T05:22:37.000189 | 1,502,947,357.000189 | 89,845 |
pythondev | help | you could do a loop on your condition/value | 2017-08-17T05:23:22.000190 | Ciera | pythondev_help_Ciera_2017-08-17T05:23:22.000190 | 1,502,947,402.00019 | 89,846 |
pythondev | help | the upside is - you can cycle through multiple additional_dictionaries and conditions | 2017-08-17T05:23:26.000010 | Suellen | pythondev_help_Suellen_2017-08-17T05:23:26.000010 | 1,502,947,406.00001 | 89,847 |
pythondev | help | <@Ciera> :slightly_smiling_face: | 2017-08-17T05:23:34.000055 | Suellen | pythondev_help_Suellen_2017-08-17T05:23:34.000055 | 1,502,947,414.000055 | 89,848 |
pythondev | help | I like declarative code, but sometimes it obscures the outcome. | 2017-08-17T05:23:38.000145 | Gabriele | pythondev_help_Gabriele_2017-08-17T05:23:38.000145 | 1,502,947,418.000145 | 89,849 |
pythondev | help | ```
for condi, key, value in ((True, 'a', 'b'), (False, 'c', 'd')):
if condi:
dict[key] = value
``` | 2017-08-17T05:23:45.000439 | Ciera | pythondev_help_Ciera_2017-08-17T05:23:45.000439 | 1,502,947,425.000439 | 89,850 |
pythondev | help | There's a reason we prefer Python over Prolog, after all. | 2017-08-17T05:23:48.000102 | Gabriele | pythondev_help_Gabriele_2017-08-17T05:23:48.000102 | 1,502,947,428.000102 | 89,851 |
pythondev | help | ```
def dict_builder(default={}, *when):
for w in when:
if callable(w):
if w[0](): default[w[1]] = w[2]
elif w[0]: default[w[1]] = w[2]
return default
``` | 2017-08-17T05:25:20.000168 | Carri | pythondev_help_Carri_2017-08-17T05:25:20.000168 | 1,502,947,520.000168 | 89,852 |
pythondev | help | oowie oof ouch | 2017-08-17T05:26:13.000264 | Suellen | pythondev_help_Suellen_2017-08-17T05:26:13.000264 | 1,502,947,573.000264 | 89,853 |
pythondev | help | it's hacky imo, but ¯\_(ツ)_/¯ | 2017-08-17T05:26:40.000095 | Carri | pythondev_help_Carri_2017-08-17T05:26:40.000095 | 1,502,947,600.000095 | 89,854 |
pythondev | help | can be a nice `util` | 2017-08-17T05:32:22.000017 | Ciera | pythondev_help_Ciera_2017-08-17T05:32:22.000017 | 1,502,947,942.000017 | 89,855 |
pythondev | help | I would just not do the `if` `elif` inline imo | 2017-08-17T05:32:36.000322 | Ciera | pythondev_help_Ciera_2017-08-17T05:32:36.000322 | 1,502,947,956.000322 | 89,856 |
pythondev | help | ```
from typing import Tuple, Dict, Optional
def when(predicate, d) -> Optional[Dict]:
return d if predicate else None
def cond_build_dict(d, *when_dicts) -> Dict:
"""
Conditionally build dict
"""
for when_dict in when_dicts:
if when_dict is not None:
d.update(**when_dict)
return d
should_add_surname = True
d = cond_build_dict({
"name": "John"
},
when(should_add_surname, {
"surname": "Doe",
"surname_backwards": "Doe"[::-1],
}),
)
print(d)
# Output:
# {'surname': 'Doe', 'surname_backwards': 'eoD', 'name': 'John'}
```
Any ideas on how to better name things/improve on this? | 2017-08-17T05:42:18.000225 | Lanita | pythondev_help_Lanita_2017-08-17T05:42:18.000225 | 1,502,948,538.000225 | 89,857 |
pythondev | help | <@Lanita> fyi you can delete a message but clicking on the `...` :slightly_smiling_face: | 2017-08-17T05:42:56.000289 | Ciera | pythondev_help_Ciera_2017-08-17T05:42:56.000289 | 1,502,948,576.000289 | 89,858 |
pythondev | help | What message? :wink: | 2017-08-17T05:44:06.000147 | Lanita | pythondev_help_Lanita_2017-08-17T05:44:06.000147 | 1,502,948,646.000147 | 89,859 |
pythondev | help | One addition could be to add support for recursive when's, so that you can build an entire tree from it | 2017-08-17T05:47:31.000266 | Lanita | pythondev_help_Lanita_2017-08-17T05:47:31.000266 | 1,502,948,851.000266 | 89,860 |
pythondev | help | hm, but that would require another cond_build_dict and that'd be ugly | 2017-08-17T05:48:10.000408 | Lanita | pythondev_help_Lanita_2017-08-17T05:48:10.000408 | 1,502,948,890.000408 | 89,861 |
pythondev | help | some way of supporting this:
```
d = cond_build_dict({
"name": "John"
},
when(should_add_surname, {
"surname": "Doe",
when(backward_please, {
"surname_backwards": "Doe"[::-1],
}),
},
)
``` | 2017-08-17T05:50:11.000202 | Lanita | pythondev_help_Lanita_2017-08-17T05:50:11.000202 | 1,502,949,011.000202 | 89,862 |
pythondev | help | that's already getting ugly though | 2017-08-17T05:50:37.000060 | Lanita | pythondev_help_Lanita_2017-08-17T05:50:37.000060 | 1,502,949,037.00006 | 89,863 |
pythondev | help | I think a better API would be
```
d = build_dict({'b':'a'}, key=(condition_or_callable, value)
``` | 2017-08-17T05:50:39.000388 | Ciera | pythondev_help_Ciera_2017-08-17T05:50:39.000388 | 1,502,949,039.000388 | 89,864 |
pythondev | help | so key is a `Tuple[Any, Any]`? | 2017-08-17T05:52:43.000061 | Lanita | pythondev_help_Lanita_2017-08-17T05:52:43.000061 | 1,502,949,163.000061 | 89,865 |
pythondev | help | yeah | 2017-08-17T05:52:54.000074 | Ciera | pythondev_help_Ciera_2017-08-17T05:52:54.000074 | 1,502,949,174.000074 | 89,866 |
pythondev | help | or just an iterable of `[Any, Any]` | 2017-08-17T05:53:27.000171 | Ciera | pythondev_help_Ciera_2017-08-17T05:53:27.000171 | 1,502,949,207.000171 | 89,867 |
pythondev | help | that way it's obvious what key you are trying to fill | 2017-08-17T05:53:55.000033 | Ciera | pythondev_help_Ciera_2017-08-17T05:53:55.000033 | 1,502,949,235.000033 | 89,868 |
pythondev | help | ya. something like
```
def cond_build_dict2(d, *when_tuples) -> Dict:
for condition_or_callable, when_dict in when_tuples:
if callable(condition_or_callable):
condition = condition_or_callable()
else:
condition = condition_or_callable
if condition:
d.update(**when_dict)
return d
def should_add_surname():
return True
d = cond_build_dict2({
"name": "John",
},
(should_add_surname, {
"surname": "Doe",
"surname_backwards": "Doe"[::-1],
}),
)
``` | 2017-08-17T05:58:01.000227 | Lanita | pythondev_help_Lanita_2017-08-17T05:58:01.000227 | 1,502,949,481.000227 | 89,869 |
pythondev | help | What would be the resulting dict? I don't get it | 2017-08-17T05:58:03.000232 | Collette | pythondev_help_Collette_2017-08-17T05:58:03.000232 | 1,502,949,483.000232 | 89,870 |
pythondev | help | malinoff, no extra dict options would leave the default dict, e.g `cond_build_dict(d) == d` | 2017-08-17T05:58:40.000014 | Lanita | pythondev_help_Lanita_2017-08-17T05:58:40.000014 | 1,502,949,520.000014 | 89,871 |
pythondev | help | <@Ciera> while that it shorter, it's less clear what's happening I think | 2017-08-17T05:59:26.000169 | Lanita | pythondev_help_Lanita_2017-08-17T05:59:26.000169 | 1,502,949,566.000169 | 89,872 |
pythondev | help | Also, what's exactly wrong with ```
d = {'name': 'John'}
if should_add_surname:
d['surname'] = 'Doe'
if backwards_please:
d['surname_backwards'] = 'Doe'[::-1]
```
How it's longer than ```
def should_add_surname():
return True
d = cond_build_dict2({
"name": "John",
},
(should_add_surname, {
"surname": "Doe",
"surname_backwards": "Doe"[::-1],
}),
)
``` ? | 2017-08-17T06:00:29.000088 | Collette | pythondev_help_Collette_2017-08-17T06:00:29.000088 | 1,502,949,629.000088 | 89,873 |
pythondev | help | those two aren't equivalent | 2017-08-17T06:03:04.000402 | Lanita | pythondev_help_Lanita_2017-08-17T06:03:04.000402 | 1,502,949,784.000402 | 89,874 |
pythondev | help | (hm, need to get to lunch... gone for an hour) | 2017-08-17T06:03:25.000071 | Lanita | pythondev_help_Lanita_2017-08-17T06:03:25.000071 | 1,502,949,805.000071 | 89,875 |
pythondev | help | I don't really agree with that but each is own | 2017-08-17T06:10:09.000109 | Ciera | pythondev_help_Ciera_2017-08-17T06:10:09.000109 | 1,502,950,209.000109 | 89,876 |
pythondev | help | if you name the function with an adequate name it should be obvious what it is doing and hide how it's doing it | 2017-08-17T06:10:41.000308 | Ciera | pythondev_help_Ciera_2017-08-17T06:10:41.000308 | 1,502,950,241.000308 | 89,877 |
pythondev | help | <@Lanita> how so? What's the difference? | 2017-08-17T06:11:08.000055 | Collette | pythondev_help_Collette_2017-08-17T06:11:08.000055 | 1,502,950,268.000055 | 89,878 |
pythondev | help | > and hide how it's doing it
Aha! So I can use "{...} if cond else {}" after all! | 2017-08-17T06:12:23.000151 | Suellen | pythondev_help_Suellen_2017-08-17T06:12:23.000151 | 1,502,950,343.000151 | 89,879 |
pythondev | help | Just gonna hide it... | 2017-08-17T06:12:28.000150 | Suellen | pythondev_help_Suellen_2017-08-17T06:12:28.000150 | 1,502,950,348.00015 | 89,880 |
pythondev | help | Nuts | 2017-08-17T06:12:47.000270 | Collette | pythondev_help_Collette_2017-08-17T06:12:47.000270 | 1,502,950,367.00027 | 89,881 |
pythondev | help | :chestnut: what about them? | 2017-08-17T06:14:33.000389 | Suellen | pythondev_help_Suellen_2017-08-17T06:14:33.000389 | 1,502,950,473.000389 | 89,882 |
pythondev | help | Well that's what he want. I don't really see the use case but ¯\_(ツ)_/¯ | 2017-08-17T06:16:05.000265 | Ciera | pythondev_help_Ciera_2017-08-17T06:16:05.000265 | 1,502,950,565.000265 | 89,883 |
pythondev | help | Hm, getting this to not hard to use is really hard... Right now I'm at this point:
```
def get_query_kwargs1():
d = {
"documents": ids_string,
}
if source_file:
d["source_file"] = "true"
if collection_name:
d["collection_name"] = collection_name
return d
# Versus:
def get_query_kwargs2():
return cond_build_dict(
{"documents": ids_string},
source_file,
{"source_file": "true"},
collection_name,
{"collection_name": collection_name},
)
``` | 2017-08-17T08:07:40.000305 | Lanita | pythondev_help_Lanita_2017-08-17T08:07:40.000305 | 1,502,957,260.000305 | 89,884 |
pythondev | help | oh my | 2017-08-17T08:09:54.000157 | Suellen | pythondev_help_Suellen_2017-08-17T08:09:54.000157 | 1,502,957,394.000157 | 89,885 |
pythondev | help | I should just give up and become a lisper :disappointed: | 2017-08-17T08:10:08.000430 | Lanita | pythondev_help_Lanita_2017-08-17T08:10:08.000430 | 1,502,957,408.00043 | 89,886 |
pythondev | help | I need to `import this` intravenously | 2017-08-17T08:10:18.000002 | Suellen | pythondev_help_Suellen_2017-08-17T08:10:18.000002 | 1,502,957,418.000002 | 89,887 |
pythondev | help | ```
def get_query_kwargs3():
return cond_build_dict({
"documents": ids_string,
"source_file": only_if(source_file, "true"),
"collection_name": only_if(collection_name, collection_name),
})
```
Shorter, and more explicit. | 2017-08-17T08:11:16.000227 | Lanita | pythondev_help_Lanita_2017-08-17T08:11:16.000227 | 1,502,957,476.000227 | 89,888 |
pythondev | help | and looks a bit like doing `some_dict.get("value", default)` | 2017-08-17T08:11:37.000207 | Lanita | pythondev_help_Lanita_2017-08-17T08:11:37.000207 | 1,502,957,497.000207 | 89,889 |
pythondev | help | <@Lanita> `get_query_kwargs3` is still just one line shorter than `get_query_kwargs1`, what's the point? | 2017-08-17T08:12:38.000168 | Collette | pythondev_help_Collette_2017-08-17T08:12:38.000168 | 1,502,957,558.000168 | 89,890 |
pythondev | help | it's not all about the number of lines | 2017-08-17T08:12:50.000268 | Lanita | pythondev_help_Lanita_2017-08-17T08:12:50.000268 | 1,502,957,570.000268 | 89,891 |
pythondev | help | it's about general readability (both of the entire thing and in diffs) and the ease of changing something | 2017-08-17T08:13:52.000338 | Lanita | pythondev_help_Lanita_2017-08-17T08:13:52.000338 | 1,502,957,632.000338 | 89,892 |
pythondev | help | I am not convinced. I think `get_query_kwargs1` is simple enough to write and to maintain, and `get_query_kwargs3` isn't much better to deserve a tested and battle-proven implementation of `cond_build_dict` and `only_if` functions. | 2017-08-17T08:20:57.000060 | Collette | pythondev_help_Collette_2017-08-17T08:20:57.000060 | 1,502,958,057.00006 | 89,893 |
pythondev | help | I'd say even if solution#2 is 2x better than solution#1, it's better to take solution#1 and start using it or working on something else, than trying to achieve perfection | 2017-08-17T08:23:31.000190 | Suellen | pythondev_help_Suellen_2017-08-17T08:23:31.000190 | 1,502,958,211.00019 | 89,894 |
pythondev | help | ```
d = {}
if collection_name:
d["collection_name"] = collection_name
```
is not the same as
```
"collection_name": only_if(collection_name, collection_name),
```
in 2nd case you will still create item in dict no matter what bool value of collection_name. And secondly `only_if` does pretty much look like `stm1 if cond else stm2`, don’t you think so? | 2017-08-17T08:26:32.000140 | Liberty | pythondev_help_Liberty_2017-08-17T08:26:32.000140 | 1,502,958,392.00014 | 89,895 |
pythondev | help | <@Liberty>
> in 2nd case you will still create item in dict no matter what bool value of collection_name
No, the idea was `only_if` to return a sentinel object if the condition is false, so the corresponding key won't be created within `cond_build_dict` | 2017-08-17T08:27:58.000060 | Collette | pythondev_help_Collette_2017-08-17T08:27:58.000060 | 1,502,958,478.00006 | 89,896 |
pythondev | help | oh, yeah, see now, I got to conversation too late and did not notice `cond_build_dict` | 2017-08-17T08:28:49.000058 | Liberty | pythondev_help_Liberty_2017-08-17T08:28:49.000058 | 1,502,958,529.000058 | 89,897 |
pythondev | help | sorry, then in this case I would agree with <@Suellen> | 2017-08-17T08:29:26.000254 | Liberty | pythondev_help_Liberty_2017-08-17T08:29:26.000254 | 1,502,958,566.000254 | 89,898 |
pythondev | help | <@Liberty> привет земляк :blush: | 2017-08-17T08:31:22.000308 | Ebonie | pythondev_help_Ebonie_2017-08-17T08:31:22.000308 | 1,502,958,682.000308 | 89,899 |
pythondev | help | I'm trying it out with actual code, and I've figured that...
1. it's shorter, but not that much shorter. It does reduce duplication though
2. it makes it easier to group things by key "theme", but makes it harder to see what things will always be there and what things wont | 2017-08-17T08:32:11.000131 | Lanita | pythondev_help_Lanita_2017-08-17T08:32:11.000131 | 1,502,958,731.000131 | 89,900 |
pythondev | help | but only if there are lot of conditions and they are made somewhere else programmatically, then it would make some pretty cool “magic”. But if you only got few of them and they hardcoded there then you should use 1 option, as it’s easier to understand and read. | 2017-08-17T08:32:41.000171 | Liberty | pythondev_help_Liberty_2017-08-17T08:32:41.000171 | 1,502,958,761.000171 | 89,901 |
pythondev | help | I think that you're missing out on the way you actually read code, and what you want from it | 2017-08-17T08:33:47.000193 | Lanita | pythondev_help_Lanita_2017-08-17T08:33:47.000193 | 1,502,958,827.000193 | 89,902 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.