« first day (3152 days earlier)      last day (1806 days later) » 

2:26 AM
@Arne Oh yeah... that's even better
Well, then why not:
a = 3
:P
 
3:20 AM
>>> (a:=[]) += [1, 2, 3]
  File "<stdin>", line 1
SyntaxError: cannot assign to named expression
>>> (a:=[]).__iadd__([1, 2, 3])
[1, 2, 3]
Lord have mercy
can't wait for all the HNQs on walrus ops be like "doh wat dis do" get hundreds of upvotes
 
@cs95 Eeek caaan't run it yet, only when i upgrade python...
 
WOW, i didn't know that it was published a month ago...
 
3:47 AM
how exciting how exciting
@cs95 For some reason, that page asks me to turn on javascript
 
you don't need to
 
but it looks ugly. :(
 
>>> ''.join(map(chr,(114,98)*2))
'rbrb'
>>>
 
 
wish I could help ya
 
4:01 AM
why do computers hate me?
 
 
1 hour later…
5:13 AM
@Dair HEY!!! same with me, it looks like that as well for me:
cbg
 
5:28 AM
cs95, +1 for your bounty question.
And here you go 10
 
rbrb
 
6:11 AM
@Dair probably something to do with your hairstyle
 
import random
random.seed(1215198)
''.join(map(chr, [random.randint(0, 127) for _ in range(3)]))
 
6:52 AM
                    permissions[1].(constant.ROLES_KEY).append(constant.ADMIN_KEY)
How can I do something like that? In order to access to a property in a variable through a constant?
 
: stackoverflow.com/questions/56422197/… Not clear what is being asked/Too broad
 
7:39 AM
@QuicoLlinaresLlorens getattr(persmissions[1], constant.ROLES_KEY)
 
;)
Why if I do this I get a None object?
appended = permissions[1][constant.ROLES_KEY].append(constant.ADMIN_KEY)
 
25
Q: Appending turns my list to NoneType

user460847In Python Shell, I entered: aList = ['a', 'b', 'c', 'd'] for i in aList: print(i) and got a b c d but when I tried: aList = ['a', 'b', 'c', 'd'] aList = aList.append('e') for i in aList: print(i) and got Traceback (most recent call last): File "<py...

 
7:54 AM
If I do this:
permissions = constant.GREEN_PERMISSION
permissions[1].get(constant.ROLES_KEY).append(constant.ADMIN_KEY)
I am modifying the original GREEN_PERMISSION, no?
how can I avoid it?
 
HI bro
 
@chiragsoni hey
 
Either copy it or use +. new_list = original_list + [new_element]
 
@chiragsoni ... so?
 
I am able to left join all the three models Product, Photo, and ProductLikeDislike via

`p = Product.objects.all().prefetch_related('photo__set','productlikedislike__set').values('name','photo__file','productlikedislike__status')`

Through this I am getting correct left join I printed and checked like this:

`SELECT "olx_product"."name", "olx_photo"."file",
"olx_productlikedislike"."status" FROM "olx_product" LEFT OUTER JOIN "olx_photo"
ON ("olx_product"."id" = "olx_photo"."reference_id_id") LEFT OUTER JOIN
 
7:59 AM
I can't answer this regardless, but you should probably mention which ORM you are using
 
Django ORM
 
@chiragsoni lose the all(). and add .filter(productlikedislike__ product_liked_by=USER)
 
I am trying this:
permissions = constant.GREEN_PERMISSION.copy()
permissions[1].get(constant.ROLES_KEY).append(constant.ADMIN_KEY)
print(constant.GREEN_PERMISSION)
 
let me try
 
@QuicoLlinaresLlorens terrible. use: permissions = copy.deepcopy(constant.GREEN_PERMISSION)
 
if you're only appending, there's no need to deepcopy... shallow copy will do just fine
 
its called "constant" -- something tells me this is going to give OP bad side effects
@Aran-Fey i stand by my suggestion
 
HI bro I did this but it is not adding any condition I checked again by printing: print(p.query)
 
@JavierBuzzi depending on how said constants are used, deep copy may have unwanted side-effects as well
mostly breaking identity, which is something commonly checked for constants
the ideal solution is that constants are constants, i.e. immutable/persistent/frozen
 
normally, when you have a dict of lists in a place called constants, and you want to mess with them for a single purpose, you'd do a deepcopy, that way youre absolutely sure that you wont be modifying the original object at all. otherwise why do the copy() in the first place if that was your intent
@chiragsoni can you please show me the data your using. look at my last comment about pasting the equivalent lines of your model.
 
8:17 AM
@JavierBuzzi because you know that you are only modifying the top-level and do not need arbitrary depth of copying
 
if the intent is never to modify the constants, then the constants should not allow modification
 
i would define as the combination of dict+list as the constant
not just the dict
at the end of the day we're splitting hairs.
 
which depends solely on the use-case
 
i absolutely agree with you there. the case youre describing ive never dealt with. seems bizarre. specially since your "dict" constant will still be attached to your list which you would have modified. again... odd.
 
8:21 AM
I didn't get which data you need? Do you need data of tables?
 
the idea of having a "dict constant" in the first place is terrible
 
amen brother!
 
Or asking for the Django query?
 
neither. django objects
i want your equivalent of lines 160-175 : gist.github.com/kingbuzzman/…
how are you testing your code @chiragsoni ?
 
by the way can you tell me that can I use filter() inside values() like this: values(...,filter() )
 
8:23 AM
that you cannot.
you can do something like annotate(somename=F(..complex stuff...)).values('somename', ...)
depending on your use case, i really suggest you dont do that.
but ultimately depends on the amount of data your sending down the wire, if its < 100 a couple of ms here and there dont matter. if youre talking > 10k maybe start thinking about it
 
Hi everyone
 
test case I not yet wrote
in my views.py file I am directly writing the Django query like: Product.objects...... to fetch the result
 
@chiragsoni no time like the present.
 
means
 
means: do the test now :P not later, now :P
 
8:37 AM
from the test you suggested it looks like creating the data for tables but in my case already data is there in tables so using query we are trying to fetch the data the only problem I am facing is to pass the and condition with the ON statement for that there can be a simplest way
If not then I will go with your suggestion i. e. annotate(somename=F(..complex stuff...)).values('somename', ...)
I hope we add the and condition along with ON statement by doing the little change in p=Product.objects.all().prefetch_related('photo__set','productlikedislike__set').values('name','photo__file','productlikedislike__status')
i.e. we can add
 
@chiragsoni ok lets try a different approach. based on the data i gave you, what do you expect to get back? all 3 products?
 
9:00 AM
I want to get p1 and p3 because these are liked by user2
 
is that not what it gives you now?
 
I didn't get ?
One more thing Javier someone suggested me that do handle complex query write the stored procedure and call the procedure in Django views. So what is your opinion on this. Even with stored procedure I can handle some required security stuff also there itselft in the procedure.
because when we use Django api for querying purpose sucurity stuff will be handled by Django but in case we are writing custom sql query then we need to look for those stuff so if I go with the stored procedure I can handle security also .
 
that is a horrible advice.
 
why ?
 
9:15 AM
the point of django is to help you develop faster. storedprocedures are something that you do when A. you need to squeeze every once of juice out of your db and should NOT be the first thing you do. B. they're a pain in the ass to handle
 
(They're also what you do if your company policy is to have a layer of stored procedures)
 
django orm was made for the 99% of all the queries you write to be simpler on the eye. AND your needs fall into the 99%
 
Of course Django is to help develop faster. So what if complexity increase day by day then also we should stick with Django ORM.
 
you should always try to stick with the ORM, until you cant...
 
Ok good suggestion
 
9:20 AM
@chiragsoni back to:
> is that not what it gives you now?

look at the test i wrote for you. this is what it gives you RIGHT now!
 
And also to resolve my problem I guess I no need to go with stored procedure ORM can do that but only thing is I need to do some R&D
 
https://gist.github.com/kingbuzzman/05ed095d8f48c3904e217e56235af54a#file-otc-py-L192

look at 192 and 194
 
I tried your query that you answered the only thing is that is inner joining productlikedislike table but we need to join that plus need to add one AND condition so to achieve the left join I came up with the simplest solutiion that is by wiriing this query:p=Product.objects.all().prefetch_related('photo__set','productlikedislike__set').values('name','photo__file','productlikedislike__status')
 
forget the query. look at the result. is that not what youre looking for?
 
9:26 AM
ok what about it is it incorrect.
do you want something that is NOT product 1 and 3?
 
No I want product 1 and 3 only bcz this are liked by user2
Ok so what you are trying to say that with your query product 1 and 3 are getting right?
 
9:53 AM
@chiragsoni yup. BECAUSE theyre liked by the user
look at the tests. it couldnt be clearer
 
10:04 AM
@chiragsoni .. any questions?
 
Thanks for chat bro please let me think more If I have any question I will surely ask you. Thanks again for your time
 
cool. let me know
 
10:31 AM
Is json field is only for postgress in django?
 
sorry?
 
Django model only supports JsonField() for postgress?
I know mysql also supports json data type but there are docs regarding mysql json data type.
I am taking about django model here.
 
Any Oauth2 experts here?
So I'm not sure what grant type to use... I'm have a server running on a device, and now I'm implementing a RestAPI in the device. The consumer of the API will probably be a program some where, but we still want the user to login with a password to receive a Token.
 
10:52 AM
@chiragsoni did you have 3 parallel discussions of your question from yesterday, one on the Q&A and 2 in two chatrooms? If yes, that's exactly why we ask not to discuss fresh questions here. Cc. @JavierBuzzi
 
I'm leaning towards the Resource Owner Password Credentials Grant but I'm not sure on this...
 
Yes I am true but to elaborate discussion with two different people I am doing this
 
Doesn't matter, please do it elsewhere
 
@Markus Are there even any other options?
 
How do you mean? there are 4 different Grants. but if there are any other option for me, since I want to use password? I don't know
 
10:57 AM
I am the 5th Grant. Bruce Willis is searching for me.
 
I heard his tongue is what activates it...
 
:)
So I'll go with you then...
So it's very confusing since I'm both Auth server, and I guess client
 
Ok, so, I'm not an expert, but let's take this from the top:
*) You have a server that implements a REST API and OAuth2. It also manages the user accounts.
*) You have an app that relies on this REST API
If that's correct, I don't see how you could authenticate a user without sending the password to the server.
 
2* I don't have the app that relies in the REST, that is someone elses
but basically yes
So I'm trying to get through the spec right now, and I haven't gotten to the specific Grants yet, so I don't really know how they work, more than that I have looked a bit more on the Password grant
 
Ah, ok. Then I guess I can see two ways to go about it:
1) You implement the password grant and the 3rd party app uses the password to authenticate
2) On your server, you implement a nice user interface where the user can log in and authorize the 3rd-party app to access their account. (Going through the usual redirect -> authentication code -> access token routine)
3) both
 
11:06 AM
@chiragsoni also, you have the privilege to create chatrooms, no need to hijack other rooms. You should create a room for your issue and lure helpers there to have one coherent discussion to minimize people wasting their time.
 
ok.
I think that I'll at least start with 1
 
Ok but I don't have that much reputation
 
So have I understood it correctly that I in that case only will have one client? even though I might have several users?
 
AFAIK the "client" is the 3rd-party app, so... yeah
Because when a developer registers their app on their server, you grant them a client_id and (possibly) a client_secret
 
mm but in this case I'm the 3-rd-party as well? the resource owner have the password, and will receive the Access Token when providing his/her pass
 
11:13 AM
Doesn't your server handle the user accounts? Why would your server need an access token?
 
@chiragsoni you have 263, you need 100
 
@AndrasDeak my apologies, didnt know i could create rooms.
 
the server will send the user the access token, so that the user doesn't have to send the pwd in each request
 
@JavierBuzzi it's OK, it's primarily chirag's responsibility for bringing the noise here :P
 
i feel responsible, since i suggested this today. :( again, my apologies
 
11:15 AM
it's okay, no worries :)
 
or does that sound idiotic? and if so, why?
 
yeah, you create and store the access token, but you don't receive it. You're not 3rd-party, you're 1st-party
or 2nd
idk how numbers work
now I've got to google what "2nd-person view" is
 
hehe so I think that usually the API could be the 3-rd party, but in this case, since I host it my self, well then it's... 2nd party?
 
it's definitely < 3, let's not sweat the details
 
look at that means
@JavierBuzzi look at that means
Do you want to initiate chat
 
11:35 AM
I don't mind if you post a link here to the room for interested parties to continue discussing your question there. Just make sure to post your question in the other chatroom for full context, that's one of the things you forgot to do here.
 
Are discussions related to tensorflow allowed here?
 
Discussions about most things are allowed
But not technical questions about most things
E.g. "what's the best way to do mocking in C#" isn't appropriate
 
what about "what's the best way to mock C#"?
 
However "Mocking objects in C# is so horrific compared to Python's mocking libraries" is of course welcome
I mock C# using Python
 
@Aran-Fey calling it Java?
 
11:50 AM
brutal :D
 
12:17 PM
What really happen when a machine learns something, is that on machine level? or software level?. Is that a right question to ask?
 
just software.
"learning" is basically just finding the best possible value for a bunch of variables
 
well, I've heard of applying machine learning to physical systems, encoding information into interactions and whatnot, but in terms of machine learning software it's software
 
then apparently the level in which the tweakings can be done to alter what machine has learned must be higher than the level on which the tests are taken.
@AndrasDeak Well, what about the former approach? Can I take any physical system?
 
of course not
you need to find a system which is complex enough to be able to work as a useful black box and be able to imprint information into it in a training phase
 
If you hit any physical system hard enough with a hammer, it'll learn that you hate it and stop working (:
 
12:26 PM
@Aran-Fey What would be use of that learning? How I know that that physical system have learnt that fact[ Please do not say, By just looking at the point which I've hammered]
 
he was joking
 
@AndrasDeak Is that thing real?
I wonder how jokes emerge.
 
Pretty theoretical, but plausible. I heard at least on talk on the subject a few years ago, but I don't remember many details and I couldn't google anything too informative in 5 minutes so I gave up
I mean, it's easy to implement classification like OCR into a magnetic system, but that's still just software. It's hard to implement the same thing on an actual same magnetic system in an experiment
 
What you've said, I can think that it can be implemented in two type either like 'Scanning-copying', or like brain.
 
okay
 
12:30 PM
Isn't the machine learning software learns in physical system, as softwares can't exist by themselves?
 
sorry, I have no idea what you're asking
 
13 mins ago, by Ajay Mishra
What really happen when a machine learns something, is that on machine level? or software level?. Is that a right question to ask?
 
I think he's asking "isn't it accurate to say that all machine learning systems operate at the software level and the hardware level, because software can't run without hardware?"
 
Probably yeah, the RAM where the software lives is actually a solid-state device where information is stored as charges, and when you save a model to the disk it becomes the same thing or magnetic patterns.
Technically a computer is exactly a physical system that acts like a black box.
 
But how the fact like that the machine have learned $80 % $ can be stored?
 
12:35 PM
it's kind of misleading to call the current fad "machine learning", it's more like statistical inferences from big data
proper learning involves autonomous reformulation of goals
 
I just thought AI is misleading term, but what you said makes sense.
 
@AjayMishra if that's an attempt at latex markdown: we don't have mathjax here
 
@tripleee I guess, Agents in DQN formulate goals, isn't that Machine learning? Btw how one can know that Reformulation of goals have tookplace.
@AndrasDeak I thought I've a bug.
 
@AjayMishra when your system stabs you in the face you'll know
 
it's a kind of "turtles all the way down" question - if a machine exhibits behavior which is indistinguishable from conscious thought then maybe we are just not flexible enough in what we call consciousness ... but we still understand on some level what deep learning does, even if the details are obscured
 
12:40 PM
@AndrasDeak How can by laptop stab me if I have not connected the tools by which one can stab?
 
I don't think we're going to be able to answer "but what does it really mean to learn something?" since that particular conundrum has gone unsolved for all of human history
 
as in, we can reason about convolutional netwoks based on how they are implemented, and rather safely conclude that they are not articulating novel goals because they really can't
 
@AjayMishra If it's connected to the Internet, then it's connected to the tool that it can use to construct any other tool
 
Hi everyone, I see there are so AI experts :) Good, I need some info about TensorRT. Has anyone every used it?
 
I don't see any AI experts
but don't let that discourage you :P
 
12:43 PM
nope
 
@Kevin If I have learned that process I can apply those in problems which are diverse (Not like Searle's chinese room argument which are fixed)
I feel sorry to discuss these things here, but chat room of AI SE are just plain dead.
 
@AjayMishra Is there a chatroom dedicated to AI?
 
You may as well say "if I can construct the Philosopher's Stone, then I can use it to open a moderately successful family restaurant franchise"
 
@Mez13 Yeah, but they don't discuss implementation details (I asked that yesterday) chat.stackexchange.com/rooms/43371/the-singularity chat.stackexchange.com/rooms/94194/neural-networks
 
In other words, it's aiming rather low to say "once I discover the secret of replicating conscious thought, I'll use it to be a better programmer"
 
12:50 PM
@AjayMishra Thanks anyway :)
 
Better goals: collect ten nobel prizes and retire on a tropical island; build a fully general friendly AI and use it to become god-emperor of the solar system
 
@Kevin On wiki, Philosopher stone means a substance which can convert base metals into gold, if you meant that, then that's just the exaggeration of generality, and you certainly missed what the system has learnt. If I know how to write 'A', that in no way meant I can fly Aeroplane.
If the AI is friendly, how can it help me to kill people and to become emperor? I guess that was a joke.
 
it just depends on your definition of friendly
just like it depends on your definition of learning, intelligence, and a whole other box of things that commonly get handwaved
 
If you're the one designing it, you get to decide who it's friendly to. "You and only you" being a prime candidate
 
I object to the assumption that becoming god-emperor necessarily involves killing people
 
12:58 PM
Although if it's compassionate towards all living things, that doesn't necessarily disqualify it from making you god-emperor of the solar system. A sufficiently intelligent agent could probably accomplish that with zero bloodshed.
Oops, beaten.
 
Kevin, I've never said about the goals of mine, Have you started that branch of thought by my definition of "learning"?
 
If you're thinking "how would it do that, exactly?", I don't know. I'm not sufficiently intelligent.
 
@AjayMishra you aren't making a very coherent argument of anything so it's not surprising if others go on along various tangents
 
Please ping whom you are referring.
 
@Kevin just have to do the killing with higher resolution than the "living versus not-living" decision
 
1:00 PM
@AndrasDeak I know that, it's hard to think of them, I guess you know that too.But that shouldn't stop one from thinking about them.
 
conclusion: friendliness is a sampling bias
 
1:17 PM
Hmm, what encoding should I use if I want to ensure that some_bytes.decode(encoding).encode(encoding) == some_bytes for any bytes object?
I think "ansi" works but the docs say it's Windows-only
 
use surrogateescapes
sec...
1
A: Opening a file with universal newlines in binary mode in python 3

MisterMiyagiTLDR: Use ASCII with surrogate escapes on Python3: def text_open(*args, **kwargs): return open(*args, encoding='ascii', errors='surrogateescape', **kwargs) The recommended approach if you know only a partial encoding (e.g. ASCII \r and \n) is to use surrogate escapes for unknown code poi...

 
i got a quick question if i'am returning x with the render_template
return render_template("index.html",x = x )
can i call it any time using javascript for ex:
var y = x;
?
 
To part the kimono a little more, I'm trying to convert a bytes to string so I can send it to json.dumps. Just in case there's some idiomatic solution for that particular use-case
stackoverflow.com/questions/40059654/… boils down to "just call .decode()" and that definitely does not work for me
 
@Kevin latin1
 
e.g.
>>> import json
>>> x = b"\xff"
>>> json.dumps(x.decode())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
>>> json.dumps(x.decode("utf-8"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
 
1:25 PM
Mar 12 at 8:05, by PM 2Ring
@Aran-Fey Sort of. Due to how Latin1 maps to Unicode, you can just decode your bytes with the Latin1 codec.
 
I thought you were joking
 
@Aran-Fey Hmm, could work. x = bytes(range(256)); x == x.decode("latin1").encode("latin1") evaluates to True for me so it passes my sniff test
 
what about b'\xc5\x91'?
oh, it gets cut up and converted back fine?
essentially mojibake undone anyway?
 
Yeah, every individual byte is converted to a character. For some strange reason, unicode has a character equivalent for every single one of the 256 possible bytes.
>>> '\x91'
'\x91'
>>> unicodedata.name('\x91')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: no such name
God knows why those characters exist ¯\_(ツ)_/¯
 
Hmm. I said that latin1 encoding is more efficient than b64encoding and then ascii encoding but looking at my json output I see a lot of six character \u escapes so maybe that's not actually true
 
1:36 PM
You can make it a bit lot shorter with ensure_ascii=False:
>>> json.dumps('\x91')
'"\\u0091"'
>>> json.dumps('\x91', ensure_ascii=False)
'"\x91"'
 
Let's see... latin1 1803 characters, b64-and-ascii 403. Eurgh
latin1 with ensure_ascii: 1303
 
Wha? How can that be longer than b64? Every byte is a single character, whereas b64 needs 4 characters to encode 3 bytes
Am I trippin'?
 
Looking at my output json file, even with ensure_ascii I see lots of \u0000s
 
Huh, apparently json still uses unicode-escapes to represent characters up to \u001f
 
Incidentally I think I broke Notepad++ while I was testing this... Instead of saving, ctrl-s now inserts a "DC3" glyph
Ah ha. superuser.com/questions/211084/… says this happens if you try to save while a message box is open.
Hunting through my task bar, I see that a message box appeared at some point, popping up behind all my other windows.
"bad allocation". Informative.
 
1:46 PM
clearly it's scolding a dog named "allocation"
 
Hmm, stackoverflow.com/a/27527728/953482 claims that latin-1 can fail to decode, so it's no better than utf-8 for decoding arbitrary bytes. But then why did my x = bytes(range(256)); x == x.decode("latin1").encode("latin1") test succeed?
 
fail to decode something that wasn't latin1-encoded perhaps?
ah nevermind, you're starting from an arbitrary bytes
 
Pretty sure they're wrong... it can fail to encode something >255, though
 
monday morning cabbage
 
In theory, there could be a specific 2 (or more) byte sequence that causes latin1 decoding to crash, but I'm pretty sure it's a single-byte encoding, so...
 
2:00 PM
Maybe what they're trying to say is, "According to en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout, there are 65 ordinal values that map to an 'undefined' character in latin1. If Python converts these ordinal values without complaint, that can only be considered an implementation detail, and should not be relied upon"
At the same time they may also be saying "even supposing that you can encode arbitrary bytes to string with latin1, you still can't decode arbitrary strings with it. You'll get ordinal not in range if you try"
e.g. "\N{SNAKE}".encode("latin1") will crash with ordinal not in range
Luckily I don't care that I can't decode arbitrary strings.
 
confusing usage of "encode" and "decode" intensifies
 
en,de = de,en # fixed
also works for translation
 
Uh oh. Did I get them backwards. I always do this.
 
technically you can't get it wrong because converting from one representation to another is always "encoding"
 
2:11 PM
I have long upheld that "encode" and "decode" are awfully opinionated verbs about a process that's basically symmetrical
 
cabbage
Has anyone used the 'Winutils' package ?
 
"this method converts data from one type to another" describes both encode and decode
 
@Kevin I don't agree. Text is abstract, bytes is concrete code for the abstract concept.
the letter ő doesn't symbolize anything other than the sound ő
strings are inherently more fundamental than bytes (which is to say, I don't agree it's symmetrical)
Furthermore, even if it was symmetrical, I'd argue that "left" and "right" are also just due to community consensus :P Also a lot of people get them wrong, and it easily gets confusing when you're talking to actors on a set.
 
it would help if the str and bytes signatures were not overloaded for non-typisth stuff
 
I propose we refer to encoding and decoding as "byteify" and "textify" from now on
 
2:16 PM
so that you would just do str(something, encoding='latin1')
 
I find it confusing as well - certainly have to slow my thinking down and remember what is considered encoding and what's considered decoding
 
@Aran-Fey I'd be okay with that
 
is that byteify or bytify?
 
byteify
@MisterMiyagi no no no no
 
the former looks a little more like an actual word and less like 5 typos
 
2:17 PM
What about to_b() and not_to_b()?
 
there are way too many problems already arising from "I have a thing, I have to convert it to a string; let me call str() on it!"
 
@AndrasDeak something::latin1 instead?
@AndrasDeak well, yes, because str is both a type and some pseudo-operator
I'd prefer having just the former
 
@AndrasDeak that's annoying, because calling str() on a thing seems a pretty sensible approach
 
@AndrasDeak I partially agree. Strings and bytes have differing levels of abstractness as you describe, but I feel that it's less-than-ideal design to make the programmer think about this relation while they're coding.
Or, hmm, maybe that's too strong of an assertion, because clearly you have to at some level understand when to use string vs bytes, or else your program is going to fail in all sorts of fun ways, usually when the user enters unicode data
 
It's annoying when base64 encoding in python gives you bytes instead of a string
 
2:21 PM
@Kevin I believe that your notion is the same reason why we had python 2 the way it was. You have to think about it.
 
@MisterMiyagi how is it not just a type?
or are you saying that because __str__ exists?
 
I'm a making a module that will take info (eg age, vaccination dates) and calculate probability of immunity to an illness/risk of infection when exposed.
What makes sense to the room to call the file with the legal/diclosure "this is not medical advice etc" file: LEGAL.md, DISCLAIMER.md or something else?
 
I'm trying to reverse-engineer my mental model to so I can articulate my problem. I (almost) never use bytes when I should be using strings, and vice versa. So I don't have any trouble conceptualizing the distinction between the types. So why can't I remember which one to use .encode on?
 
7 mins ago, by Aran-Fey
I propose we refer to encoding and decoding as "byteify" and "textify" from now on
 
2:24 PM
PEPb8
 
@AndrasDeak because str is one of those catch-all operators that work on everything
like bool
 
@toonarmycaptain disclaimers seem to normally go in the licence file
 
byteify and textify are perhaps a little too cute, but I do endorse the general idea of putting the type names in the method names.
 
@RobertGrant Oh, that makes sense. I did not think of that. yam, now I have to pick a license lol.
 
calling str on something usually does not mean "convert it to a unicode type" but "provide a nice repr for the puny human"
 
2:29 PM
Feb 8 at 13:06, by Arne
It wouldn't break compatibility, since it's a new keyword. I guess what I'm trying to say is that the current str function is more alike to to_string, which is kinda useful because that's what you want most of the times anyways.
 
isn't that what repr does as well?
conceptually speaking
 
Soo.... Anyone know how to change a Flask request header?
 
i think repr is also supposed to produce different strings for objects that aren't equal
and str does not assert anything like that
so in particular for complex objects they'll be different
 
well, there are some recommendations for __str__ and __repr__ but no real contract
 
consenting adults, right?
 
2:33 PM
no problem with that
my problem is that the str function is exactly what you want unless you actually want a str
 
ideally __repr__ returns enough information to reconstruct the object
 
which, let's be honest here, rarely is the case
'<object object at 0x10c11d950>'
 
str() is still a type, it just accepts all sorts of inputs to instantiate from. The way it does is probably wonky, but it's still a type, and str(bytes) could have been a sane decode with an encoding provided. It's just too late
@MisterMiyagi object(), done :P
 
Maybe the language devs were reluctant to make str(some_bytes) automatically decode via latin1 because they didn't want to show favoritism towards a particular encoding
(Nevermind that 99.9% of other encodings are completely unsuitable for the task since they choke on one ordinal or another)
 
in the old days str(bytes) was semantically a no-op...
too much baggage here
oh, you mean on 3.0
 
2:42 PM
@AndrasDeak bows head in awe
bytes was str, literally
good old days
 
Or, hmm. How does str(some_bytes) work now?
 
'b"asdf"' I think
>>> str(b'asdf')
"b'asdf'"
 
"b'Hello World'"
 
Yes, but how does it know that asdf maps to asdf?
 
it's the repr of the bytes...
 
2:44 PM
In other words, is it already using an encoding? And if so, which one?
 
"b'Hello World\\x99'"
 
>>> str("ő".encode('utf8'))
"b'\\xc5\\x91'"

>>> str("ő".encode('latin2'))
"b'\\xf5'"
 
that's the backslashreplace error handling, I think
 
@Kevin the "which one" is done by b'asdf', right? Which should be...ascii?
>>> b'ó'
  File "<ipython-input-13-46be4a03b3a2>", line 1
    b'ó'
        ^
SyntaxError: bytes can only contain ASCII literal characters.
 
To rephrase as a puzzle: write a function stringify(some_bytes), which does the same thing that str(some_bytes) does. You are allowed to use decode, but not str.
It's not just return 'b"' + some_bytes.decode("utf-8", "backslashreplace") + '"' since that mangles "\x00" through "/" on my machine
 
2:49 PM
Ah, I get what you mean
 
def stringify(byts):
    if b'"' in bytes:
        return 'b'' + byts.decode(encoding='ascii', errors='backslashreplace') + '''
    return 'b"' + byts.decode(encoding='ascii', errors='backslashreplace') + '"'
@Kevin b"\x00".decode("utf-8", "backslashreplace") gives '\x00' for me
 
Both windows?
 
MacOS
 
I'm on windows.
 
to the thunder dome, then
 
2:55 PM
That's a starrin'
 
Something weird is going on here. How the heck is "0" (actual zero, not NUL) getting replaced with a unicode box
I suspect a control character such as "\r" is mucking things up
That would also explain the line break
 

« first day (3152 days earlier)      last day (1806 days later) »