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
```x = 5 def f(x2=None): if x2: return x2 * 5 return x * 5```
2019-06-06T12:36:36.366400
Romaine
pythondev_help_Romaine_2019-06-06T12:36:36.366400
1,559,824,596.3664
27,221
pythondev
help
it would be wise to do some validation on `x2` but thats the basic premise
2019-06-06T12:37:03.366900
Romaine
pythondev_help_Romaine_2019-06-06T12:37:03.366900
1,559,824,623.3669
27,222
pythondev
help
but you could also let Exception do its job in this case... it really depends
2019-06-06T12:37:59.368300
Romaine
pythondev_help_Romaine_2019-06-06T12:37:59.368300
1,559,824,679.3683
27,223
pythondev
help
yup, makes sense. in my case i need that outside variable to be accessed by all functions so I think it would be better to not pass it as argument to avoid it all
2019-06-06T12:38:04.368400
Raguel
pythondev_help_Raguel_2019-06-06T12:38:04.368400
1,559,824,684.3684
27,224
pythondev
help
yeah, or exception
2019-06-06T12:38:13.368800
Raguel
pythondev_help_Raguel_2019-06-06T12:38:13.368800
1,559,824,693.3688
27,225
pythondev
help
when you start working in that territory, I recommend using Classes
2019-06-06T12:38:27.369100
Romaine
pythondev_help_Romaine_2019-06-06T12:38:27.369100
1,559,824,707.3691
27,226
pythondev
help
```class F: x = 5 def f(self, x=None): if x: return x * 5 return self.x * 5 f = F() f.x = 44 f.f()```
2019-06-06T12:41:34.369600
Romaine
pythondev_help_Romaine_2019-06-06T12:41:34.369600
1,559,824,894.3696
27,227
pythondev
help
on it now -- have been avoiding classes for no reason lol. thanks <@Romaine> :taco:
2019-06-06T12:43:03.370400
Raguel
pythondev_help_Raguel_2019-06-06T12:43:03.370400
1,559,824,983.3704
27,228
pythondev
help
np! once you go classes, you never go back
2019-06-06T12:44:02.370700
Romaine
pythondev_help_Romaine_2019-06-06T12:44:02.370700
1,559,825,042.3707
27,229
pythondev
help
^
2019-06-06T12:48:09.372000
Holly
pythondev_help_Holly_2019-06-06T12:48:09.372000
1,559,825,289.372
27,230
pythondev
help
I'll write a script for something, and as soon as I see another use for it I convert it into a class
2019-06-06T12:48:27.372400
Holly
pythondev_help_Holly_2019-06-06T12:48:27.372400
1,559,825,307.3724
27,231
pythondev
help
its the best way to have multiple versions of your script isolated from each other in the same python instance!
2019-06-06T12:49:15.373100
Romaine
pythondev_help_Romaine_2019-06-06T12:49:15.373100
1,559,825,355.3731
27,232
pythondev
help
functions provide a little bit of isolation, but its not their purpose
2019-06-06T12:49:57.373600
Romaine
pythondev_help_Romaine_2019-06-06T12:49:57.373600
1,559,825,397.3736
27,233
pythondev
help
classes organize and isolate your code to its specific needs
2019-06-06T12:50:15.374300
Romaine
pythondev_help_Romaine_2019-06-06T12:50:15.374300
1,559,825,415.3743
27,234
pythondev
help
with that same example class: you can do: ```a = F() b = F() a.x = 25 b.x = 125 a.f() b.f()```
2019-06-06T12:51:16.375900
Romaine
pythondev_help_Romaine_2019-06-06T12:51:16.375900
1,559,825,476.3759
27,235
pythondev
help
I think I have a mental block when it comes to classes -- I am like that function is getting work done, and though class could do better, I end up choosing former.
2019-06-06T12:51:23.376100
Raguel
pythondev_help_Raguel_2019-06-06T12:51:23.376100
1,559,825,483.3761
27,236
pythondev
help
and they have different trackable outcomes
2019-06-06T12:51:41.376900
Romaine
pythondev_help_Romaine_2019-06-06T12:51:41.376900
1,559,825,501.3769
27,237
pythondev
help
true, now that you have mentioned it and when I am reading my code again, it totally makes sense to put into classes
2019-06-06T12:51:50.377100
Raguel
pythondev_help_Raguel_2019-06-06T12:51:50.377100
1,559,825,510.3771
27,238
pythondev
help
<@Raguel> one change for that logic - `if x:` should be `if x is not None:` `0` evaluates as false
2019-06-06T12:54:40.378100
Clemmie
pythondev_help_Clemmie_2019-06-06T12:54:40.378100
1,559,825,680.3781
27,239
pythondev
help
also you may or may not care about making sure that x is a numeric. `'a'*5, []*5` is all valid python
2019-06-06T12:55:36.379000
Clemmie
pythondev_help_Clemmie_2019-06-06T12:55:36.379000
1,559,825,736.379
27,240
pythondev
help
Thank you
2019-06-06T13:30:46.379100
Porsche
pythondev_help_Porsche_2019-06-06T13:30:46.379100
1,559,827,846.3791
27,241
pythondev
help
Can anyone recommend a task queue framework/library
2019-06-06T13:43:06.379500
Pura
pythondev_help_Pura_2019-06-06T13:43:06.379500
1,559,828,586.3795
27,242
pythondev
help
celery, redis-queue
2019-06-06T13:44:34.379700
Hiroko
pythondev_help_Hiroko_2019-06-06T13:44:34.379700
1,559,828,674.3797
27,243
pythondev
help
i have come across these 2, do you have a preference?
2019-06-06T13:46:40.379800
Pura
pythondev_help_Pura_2019-06-06T13:46:40.379800
1,559,828,800.3798
27,244
pythondev
help
celery has a steeper learning curve, but is better documented and more fully featured
2019-06-06T13:48:37.380000
Clemmie
pythondev_help_Clemmie_2019-06-06T13:48:37.380000
1,559,828,917.38
27,245
pythondev
help
one time I used rq because I didn't want the "weight" of celery (and I was experienced with celery). Ultimately switched because getting rq to do what I needed ended up needing several more packages, and figuring out the missing documentation bits
2019-06-06T13:49:54.380200
Clemmie
pythondev_help_Clemmie_2019-06-06T13:49:54.380200
1,559,828,994.3802
27,246
pythondev
help
I was doing like this to see user details ``` def get(self, request, user_uuid): print(user_uuid) try: user = User.objects.get(id=user_uuid) return render(request, 'user_detail.html' except return HttpResponse('user not found') ``` url is like `url(_(r'^dashboard-user/(?P&lt;user_uuid&gt;[\w-]*)/?$')......`
2019-06-06T13:59:09.382600
Hassie
pythondev_help_Hassie_2019-06-06T13:59:09.382600
1,559,829,549.3826
27,247
pythondev
help
but I always got back validation error `["'1356f6bf-2b5e-4f31-90f4-3cfd75575972' value must be an integer."]`
2019-06-06T13:59:38.383300
Hassie
pythondev_help_Hassie_2019-06-06T13:59:38.383300
1,559,829,578.3833
27,248
pythondev
help
I have no idea. pleas help me
2019-06-06T13:59:49.383600
Hassie
pythondev_help_Hassie_2019-06-06T13:59:49.383600
1,559,829,589.3836
27,249
pythondev
help
you almost certainly want `pk=` not `id=`
2019-06-06T14:00:09.384100
Clemmie
pythondev_help_Clemmie_2019-06-06T14:00:09.384100
1,559,829,609.3841
27,250
pythondev
help
you might also want to use a `get_or_404` instead of a `try/except`
2019-06-06T14:00:37.384800
Clemmie
pythondev_help_Clemmie_2019-06-06T14:00:37.384800
1,559,829,637.3848
27,251
pythondev
help
also, if that is your code and you didn’t retype it, you are missing a `)` at the end of the first return and `:` after except (though the except should be `except User.DoesNotExist:`)
2019-06-06T14:02:00.386500
Clemmie
pythondev_help_Clemmie_2019-06-06T14:02:00.386500
1,559,829,720.3865
27,252
pythondev
help
except is `except User.DoesNotExist`
2019-06-06T14:02:00.386600
Hassie
pythondev_help_Hassie_2019-06-06T14:02:00.386600
1,559,829,720.3866
27,253
pythondev
help
I retyped to ask, that's why I missed.
2019-06-06T14:02:53.387500
Hassie
pythondev_help_Hassie_2019-06-06T14:02:53.387500
1,559,829,773.3875
27,254
pythondev
help
Thanks i was initially thinking of apache-airflow but this does not seem to be a good fit for a task queue... Its more a work scheduler right?
2019-06-06T14:03:01.387800
Pura
pythondev_help_Pura_2019-06-06T14:03:01.387800
1,559,829,781.3878
27,255
pythondev
help
but it's not working with `pk` too
2019-06-06T14:03:10.388100
Hassie
pythondev_help_Hassie_2019-06-06T14:03:10.388100
1,559,829,790.3881
27,256
pythondev
help
I am trying to build some etl pipeline which can be ran from an api endpoint.
2019-06-06T14:03:39.388500
Pura
pythondev_help_Pura_2019-06-06T14:03:39.388500
1,559,829,819.3885
27,257
pythondev
help
are your user id/pks numbers or uuids?
2019-06-06T14:03:39.388700
Clemmie
pythondev_help_Clemmie_2019-06-06T14:03:39.388700
1,559,829,819.3887
27,258
pythondev
help
pk is uuid
2019-06-06T14:03:56.389000
Hassie
pythondev_help_Hassie_2019-06-06T14:03:56.389000
1,559,829,836.389
27,259
pythondev
help
for some reason your validator is expecting an integer
2019-06-06T14:04:30.389400
Clemmie
pythondev_help_Clemmie_2019-06-06T14:04:30.389400
1,559,829,870.3894
27,260
pythondev
help
is this django or rest-framework?
2019-06-06T14:05:32.390000
Hiroko
pythondev_help_Hiroko_2019-06-06T14:05:32.390000
1,559,829,932.39
27,261
pythondev
help
django
2019-06-06T14:05:43.390200
Hassie
pythondev_help_Hassie_2019-06-06T14:05:43.390200
1,559,829,943.3902
27,262
pythondev
help
are you doing form validation?
2019-06-06T14:05:57.390400
Hiroko
pythondev_help_Hiroko_2019-06-06T14:05:57.390400
1,559,829,957.3904
27,263
pythondev
help
eg, is this a modelform?
2019-06-06T14:06:06.390600
Hiroko
pythondev_help_Hiroko_2019-06-06T14:06:06.390600
1,559,829,966.3906
27,264
pythondev
help
Yes, a form
2019-06-06T14:06:18.391000
Hassie
pythondev_help_Hassie_2019-06-06T14:06:18.391000
1,559,829,978.391
27,265
pythondev
help
I have the following usecase. Someone makes a request to an endpoint passing in a user_name. It should then begin doing the following work. One after the other. 1st stage fetches data from various sources which takes a long time. 2nd stage then fetches some other data based on the data received in the first fetch. 3rd stage then analyses the data. is celery a good usecase for this <@Clemmie> <@Hiroko>
2019-06-06T14:10:15.391100
Pura
pythondev_help_Pura_2019-06-06T14:10:15.391100
1,559,830,215.3911
27,266
pythondev
help
good catch on `if x is not None:` `0` <@Clemmie> :smile:
2019-06-06T14:12:20.391800
Romaine
pythondev_help_Romaine_2019-06-06T14:12:20.391800
1,559,830,340.3918
27,267
pythondev
help
yup
2019-06-06T14:14:05.392100
Clemmie
pythondev_help_Clemmie_2019-06-06T14:14:05.392100
1,559,830,445.3921
27,268
pythondev
help
Hey I'm trying to translate my Powershell knowledge to Python and I've moved into functions now. I'm using PyAD and I've created a get_aduser() function but I want to be able to assign the result to a value to perform actions on and I'm not sure how to do that. ```from pyad import aduser import pyad def get_aduser(search): user = aduser.ADUser.from_cn(search) print(user) return```
2019-06-06T14:15:39.393700
Emelda
pythondev_help_Emelda_2019-06-06T14:15:39.393700
1,559,830,539.3937
27,269
pythondev
help
<@Emelda> ok so, powershell has some weird return semantics that you'll have to "unlearn" in other languages
2019-06-06T14:17:34.394300
Carlo
pythondev_help_Carlo_2019-06-06T14:17:34.394300
1,559,830,654.3943
27,270
pythondev
help
<https://stackoverflow.com/a/10288256>
2019-06-06T14:18:02.394700
Carlo
pythondev_help_Carlo_2019-06-06T14:18:02.394700
1,559,830,682.3947
27,271
pythondev
help
How do you handle in celery running of a 2nd stage only when a 1st stage is complete. This is where i thought an airflow pipeline dag would be useful.
2019-06-06T14:18:11.395300
Pura
pythondev_help_Pura_2019-06-06T14:18:11.395300
1,559,830,691.3953
27,272
pythondev
help
basically right now, your function is not returning anything
2019-06-06T14:18:13.395500
Carlo
pythondev_help_Carlo_2019-06-06T14:18:13.395500
1,559,830,693.3955
27,273
pythondev
help
the end of the first stage triggers the start ogf the second
2019-06-06T14:18:40.396000
Clemmie
pythondev_help_Clemmie_2019-06-06T14:18:40.396000
1,559,830,720.396
27,274
pythondev
help
`return user` is how you'd return the user in your function
2019-06-06T14:18:57.396700
Carlo
pythondev_help_Carlo_2019-06-06T14:18:57.396700
1,559,830,737.3967
27,275
pythondev
help
ahh
2019-06-06T14:19:03.396900
Emelda
pythondev_help_Emelda_2019-06-06T14:19:03.396900
1,559,830,743.3969
27,276
pythondev
help
So you can't assign a function result before you call it like `$v = get-aduser np12487`
2019-06-06T14:19:35.397600
Emelda
pythondev_help_Emelda_2019-06-06T14:19:35.397600
1,559,830,775.3976
27,277
pythondev
help
then doing stuff to `$v`
2019-06-06T14:19:45.397800
Emelda
pythondev_help_Emelda_2019-06-06T14:19:45.397800
1,559,830,785.3978
27,278
pythondev
help
hmm not sure I follow your question
2019-06-06T14:20:26.398000
Carlo
pythondev_help_Carlo_2019-06-06T14:20:26.398000
1,559,830,826.398
27,279
pythondev
help
well, you can do `user = add_user(some_search_term)`
2019-06-06T14:20:53.398500
Hiroko
pythondev_help_Hiroko_2019-06-06T14:20:53.398500
1,559,830,853.3985
27,280
pythondev
help
right, that makes sense
2019-06-06T14:20:54.398600
Pura
pythondev_help_Pura_2019-06-06T14:20:54.398600
1,559,830,854.3986
27,281
pythondev
help
bu tthen user is null if I do that
2019-06-06T14:21:03.399000
Emelda
pythondev_help_Emelda_2019-06-06T14:21:03.399000
1,559,830,863.399
27,282
pythondev
help
not if you return the user
2019-06-06T14:21:11.399200
Hiroko
pythondev_help_Hiroko_2019-06-06T14:21:11.399200
1,559,830,871.3992
27,283
pythondev
help
you need to explicitly return anything from a method if you want the thing used outside it
2019-06-06T14:21:29.399700
Hiroko
pythondev_help_Hiroko_2019-06-06T14:21:29.399700
1,559,830,889.3997
27,284
pythondev
help
ahhhh
2019-06-06T14:21:39.399900
Emelda
pythondev_help_Emelda_2019-06-06T14:21:39.399900
1,559,830,899.3999
27,285
pythondev
help
Intersting
2019-06-06T14:21:43.400200
Emelda
pythondev_help_Emelda_2019-06-06T14:21:43.400200
1,559,830,903.4002
27,286
pythondev
help
explicit is better than implicit
2019-06-06T14:21:48.400300
Hiroko
pythondev_help_Hiroko_2019-06-06T14:21:48.400300
1,559,830,908.4003
27,287
pythondev
help
one of the core tenets of the language
2019-06-06T14:22:03.400600
Hiroko
pythondev_help_Hiroko_2019-06-06T14:22:03.400600
1,559,830,923.4006
27,288
pythondev
help
you could even have a pipeline passed to the steps as a list, where the list ins the function objects to be calles, and each step would pop the top off the list to call the next one, and pass the pipeline list on
2019-06-06T14:22:05.400700
Clemmie
pythondev_help_Clemmie_2019-06-06T14:22:05.400700
1,559,830,925.4007
27,289
pythondev
help
that allows for dynamic pipelines
2019-06-06T14:22:19.400900
Clemmie
pythondev_help_Clemmie_2019-06-06T14:22:19.400900
1,559,830,939.4009
27,290
pythondev
help
can I assign the output to any other value aside from it's return?
2019-06-06T14:22:58.401500
Emelda
pythondev_help_Emelda_2019-06-06T14:22:58.401500
1,559,830,978.4015
27,291
pythondev
help
or does it have to match the return variable?
2019-06-06T14:23:08.401800
Emelda
pythondev_help_Emelda_2019-06-06T14:23:08.401800
1,559,830,988.4018
27,292
pythondev
help
or am I thinking about it all wrong
2019-06-06T14:23:14.402100
Emelda
pythondev_help_Emelda_2019-06-06T14:23:14.402100
1,559,830,994.4021
27,293
pythondev
help
what do you mean?
2019-06-06T14:23:15.402200
Hiroko
pythondev_help_Hiroko_2019-06-06T14:23:15.402200
1,559,830,995.4022
27,294
pythondev
help
My powershell brain thinks about everything as an object
2019-06-06T14:23:29.402600
Emelda
pythondev_help_Emelda_2019-06-06T14:23:29.402600
1,559,831,009.4026
27,295
pythondev
help
python is similar
2019-06-06T14:23:40.402800
Hiroko
pythondev_help_Hiroko_2019-06-06T14:23:40.402800
1,559,831,020.4028
27,296
pythondev
help
I've been able to use some of the same stuff in python like using `[0]` on a string to get the first letter
2019-06-06T14:24:18.403500
Emelda
pythondev_help_Emelda_2019-06-06T14:24:18.403500
1,559,831,058.4035
27,297
pythondev
help
like it's an array
2019-06-06T14:24:22.403700
Emelda
pythondev_help_Emelda_2019-06-06T14:24:22.403700
1,559,831,062.4037
27,298
pythondev
help
because it is
2019-06-06T14:24:28.403900
Clemmie
pythondev_help_Clemmie_2019-06-06T14:24:28.403900
1,559,831,068.4039
27,299
pythondev
help
well, a list
2019-06-06T14:24:35.404100
Clemmie
pythondev_help_Clemmie_2019-06-06T14:24:35.404100
1,559,831,075.4041
27,300
pythondev
help
so a string is a list of chars
2019-06-06T14:24:45.404500
Emelda
pythondev_help_Emelda_2019-06-06T14:24:45.404500
1,559,831,085.4045
27,301
pythondev
help
the dynamic typing + everything is an object in python allows for some nifty stuff
2019-06-06T14:24:55.404800
Clemmie
pythondev_help_Clemmie_2019-06-06T14:24:55.404800
1,559,831,095.4048
27,302
pythondev
help
not exactly, no
2019-06-06T14:25:02.405000
Clemmie
pythondev_help_Clemmie_2019-06-06T14:25:02.405000
1,559,831,102.405
27,303
pythondev
help
string implements `__iter__`
2019-06-06T14:25:11.405300
Clemmie
pythondev_help_Clemmie_2019-06-06T14:25:11.405300
1,559,831,111.4053
27,304
pythondev
help
so it can be iterated on
2019-06-06T14:25:16.405500
Clemmie
pythondev_help_Clemmie_2019-06-06T14:25:16.405500
1,559,831,116.4055
27,305
pythondev
help
and `__getitem__`
2019-06-06T14:26:06.405800
Hiroko
pythondev_help_Hiroko_2019-06-06T14:26:06.405800
1,559,831,166.4058
27,306
pythondev
help
<https://docs.python.org/3/reference/datamodel.html#object.__getitem__>
2019-06-06T14:26:06.406000
Hiroko
pythondev_help_Hiroko_2019-06-06T14:26:06.406000
1,559,831,166.406
27,307
pythondev
help
&gt;&gt;&gt;Called to implement evaluation of self[key]. For sequence types, the accepted keys should be integers and slice objects
2019-06-06T14:26:20.406300
Hiroko
pythondev_help_Hiroko_2019-06-06T14:26:20.406300
1,559,831,180.4063
27,308
pythondev
help
what are the __values__ in python compared to powershell?
2019-06-06T14:26:56.406900
Emelda
pythondev_help_Emelda_2019-06-06T14:26:56.406900
1,559,831,216.4069
27,309
pythondev
help
Ye maybe. What tool would you use for this pipeline?
2019-06-06T14:26:57.407000
Pura
pythondev_help_Pura_2019-06-06T14:26:57.407000
1,559,831,217.407
27,310
pythondev
help
I see those alot
2019-06-06T14:27:06.407300
Emelda
pythondev_help_Emelda_2019-06-06T14:27:06.407300
1,559,831,226.4073
27,311
pythondev
help
I haven’t built one, so I don’t know
2019-06-06T14:27:21.407500
Clemmie
pythondev_help_Clemmie_2019-06-06T14:27:21.407500
1,559,831,241.4075
27,312
pythondev
help
for a simple pass I would build my own
2019-06-06T14:27:30.407900
Clemmie
pythondev_help_Clemmie_2019-06-06T14:27:30.407900
1,559,831,250.4079
27,313
pythondev
help
i think we deffinatly need to make it dynamic, some stages need to be skipped
2019-06-06T14:27:33.408100
Pura
pythondev_help_Pura_2019-06-06T14:27:33.408100
1,559,831,253.4081
27,314
pythondev
help
they are called dunder methods - they are special
2019-06-06T14:27:49.408500
Clemmie
pythondev_help_Clemmie_2019-06-06T14:27:49.408500
1,559,831,269.4085
27,315
pythondev
help
dunder mifflins?
2019-06-06T14:28:20.409400
Emelda
pythondev_help_Emelda_2019-06-06T14:28:20.409400
1,559,831,300.4094
27,316
pythondev
help
for instance, I can call `len(&lt;thing&gt;)` on any thing that is of a class that implements `__len__`
2019-06-06T14:28:22.409500
Clemmie
pythondev_help_Clemmie_2019-06-06T14:28:22.409500
1,559,831,302.4095
27,317
pythondev
help
XD
2019-06-06T14:28:24.409800
Emelda
pythondev_help_Emelda_2019-06-06T14:28:24.409800
1,559,831,304.4098
27,318
pythondev
help
“d”ouble “under”
2019-06-06T14:28:39.410100
Clemmie
pythondev_help_Clemmie_2019-06-06T14:28:39.410100
1,559,831,319.4101
27,319
pythondev
help
i see
2019-06-06T14:28:44.410300
Emelda
pythondev_help_Emelda_2019-06-06T14:28:44.410300
1,559,831,324.4103
27,320