Posts: 85
Threads: 12
Joined: May 2018
I am wondering if my conversion on this dictionary was done correctly. Take a look at the way this was written in py2:
1 2 3 4 5 6 7 8 |
def new_item( self ,raw_string):
the_type = raw_string.split( "," )[ 0 ]
if self .constructors.has_key(the_type):
return self .constructors[the_type](raw_string)
else :
return None
|
I want to say with the changes from py2 to py3 that the new method should be:
1 2 3 4 5 6 7 8 |
def new_item( self ,raw_string):
the_type = raw_string.split( "," )[ 0 ]
if the_type in self .constructors:
return the_type in self .constructors[raw_string]
else :
return None
|
If it helps the initialization for constructors is:
1 |
self .constructors = { "None" : None }
|
The problem for me is that I am not sure what was meant by the py2 return statement:
1 |
return self .constructors[the_type](raw_string)
|
Posts: 566
Threads: 10
Joined: Apr 2017
Obviously, self.constructors dictionary has functions as its values
1 |
self .constructors[the_type](raw_string)
|
retrieves function corresponding to the_type (unfortunate name, data_type , maybe?) and calls it with an argument raw_string . Looks like you are breaking the functionality by assuming that Python2 code did something wrong.
Migration from 2 to 3 is mostly about interfaces returning generator-like objects instead of lists and some streamlining of APIs - I mostly remember reduction in dict methods. I would recommend to do conversion by proper tools. 2to3 used to work rather well
Test everything in a Python shell (iPython, Azure Notebook, etc.) - Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.
Posts: 85
Threads: 12
Joined: May 2018
Jun-06-2018, 05:40 PM
(This post was last modified: Jun-06-2018, 05:40 PM by Vysero.)
(Jun-06-2018, 04:34 PM)volcano63 Wrote: Obviously, self.constructors dictionary has functions as its values
1 |
self .constructors[the_type](raw_string)
|
retrieves function corresponding to the_type (unfortunate name, data_type , maybe?) and calls it with an argument raw_string . Looks like you are breaking the functionality by assuming that Python2 code did something wrong.
Migration from 2 to 3 is mostly about interfaces returning generator-like objects instead of lists and some streamlining of APIs - I mostly remember reduction in dict methods. I would recommend to do conversion by proper tools. 2to3 used to work rather well
So I actually do not need to convert that is what your saying? It should work in py3 the way it was written in py2?
Posts: 566
Threads: 10
Joined: Apr 2017
(Jun-06-2018, 05:40 PM)Vysero Wrote: So I actually do not need to convert that is what your saying? It should work in py3 the way it was written in py2? That's exactly what I said
Test everything in a Python shell (iPython, Azure Notebook, etc.) - Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.
Posts: 85
Threads: 12
Joined: May 2018
(Jun-06-2018, 07:04 PM)volcano63 Wrote: (Jun-06-2018, 05:40 PM)Vysero Wrote: So I actually do not need to convert that is what your saying? It should work in py3 the way it was written in py2? That's exactly what I said
Actually, exactly what you said was: "Looks like you are breaking the functionality by assuming that Python2 code did something wrong.", you then went on to say: "Migration from 2 to 3 is mostly about interfaces returning generator-like objects instead of lists and some streamlining of APIs - I mostly remember reduction in dict methods. I would recommend to do conversion by proper tools. 2to3 used to work rather well" which can easily mislead someone into thinking that the code is broken and that I should be using a tool to fix it rather than trying to fix it manually. So I did use a tool to fix it (as suggested) and that portion of the code was not changed which is the only way I was able to come to the conclusion that what you actually were saying was that there was nothing wrong with the code.
Please read the following very, very thoroughly believe me you need the advice:
https://markmanson.net/how-to-give-advice
Posts: 566
Threads: 10
Joined: Apr 2017
Jun-06-2018, 07:40 PM
(This post was last modified: Jun-06-2018, 07:40 PM by volcano63.)
You need an advice in manners and a lesson in gratitude - but I will just add you to ignore list, second in 10 minutes.What a night
Getting an accusation of being Quote:extremely rude
from an ungrateful pompous ass feels me with pride
Test everything in a Python shell (iPython, Azure Notebook, etc.) - Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.
Posts: 8,167
Threads: 160
Joined: Sep 2016
Jun-06-2018, 07:49 PM
(This post was last modified: Jun-06-2018, 07:49 PM by buran.)
(Jun-06-2018, 07:14 PM)Vysero Wrote: that portion of the code was not changed which is the only way I was able to come to the conclusion that what you actually were saying was that there was nothing wrong with the code. The sole fact that you *think* it needs to be translated to py3 suggest you shoudn't do it manually as you don't know what you are doing. And that is also confirmed by how you translated it...
Posts: 85
Threads: 12
Joined: May 2018
(Jun-06-2018, 07:49 PM)buran Wrote: (Jun-06-2018, 07:14 PM)Vysero Wrote: that portion of the code was not changed which is the only way I was able to come to the conclusion that what you actually were saying was that there was nothing wrong with the code. The sole fact that you *think* it needs to be translated to py3 suggest you shoudn't do it manually as you don't know what you are doing. And that is also confirmed by how you translated it...
Your not fit to be a moderator. This is going up the chain.
Posts: 7,324
Threads: 123
Joined: Sep 2016
Jun-06-2018, 08:33 PM
(This post was last modified: Jun-06-2018, 08:33 PM by snippsat.)
(Jun-06-2018, 08:06 PM)Vysero Wrote: Your not fit to be a moderator. This is going up the chain. We stop here,Thread closed.
Star a new thread if you have problem with suggestions,and we try to keep it polite here.
|