Re: help on "from deen import *" vs. "import deen"

2016-11-20 Thread jfong
Tristan B. Kildaire at 2016/11/20 8:23:37PM wrote: > From deen import * imports all the things in deen but accessable with no > `deen.` These "accessible" objects become read-only even if it's mutable. For immutable objects, you can't even create a new one in the deen's namespace. > import

Re: help on "from deen import *" vs. "import deen"

2016-11-20 Thread Bev in TX
Thanks to ChrisA and Ned for that clarification. Bev in TX -- https://mail.python.org/mailman/listinfo/python-list

Re: help on "from deen import *" vs. "import deen"

2016-11-20 Thread Ned Batchelder
On Sunday, November 20, 2016 at 6:47:35 AM UTC-5, Bev in TX wrote: > From the Python 3.5.2 docs: > > 6.15. Evaluation order > Python evaluates expressions from left to right. Notice that while > evaluating an assignment, the right-hand side is evaluated before the > left-hand side. > > Thus,

Re: help on "from deen import *" vs. "import deen"

2016-11-20 Thread Chris Angelico
On Sun, Nov 20, 2016 at 10:47 PM, Bev in TX wrote: > From the Python 3.5.2 docs: > > 6.15. Evaluation order > Python evaluates expressions from left to right. Notice that while > evaluating an assignment, the right-hand side is evaluated before the > left-hand side. > >

Re: help on "from deen import *" vs. "import deen"

2016-11-20 Thread Tristan B. Kildaire
On Tue, 15 Nov 2016 22:16:07 +, Erik wrote: > On 15/11/16 14:43, Michael Torrie wrote: >> As you've been told several times, if you "import deen" then you can >> place a new object into the deen namespace using something like: >> >> deen.foo=bar >> >> Importing everything from an imported

Re: help on "from deen import *" vs. "import deen"

2016-11-20 Thread Bev in TX
From the Python 3.5.2 docs: 6.15. Evaluation order Python evaluates expressions from left to right. Notice that while evaluating an assignment, the right-hand side is evaluated before the left-hand side. Thus, spam = eggs = cheese = obj is equivalent to: spam = (eggs = (cheese = obj))

Re: help on "from deen import *" vs. "import deen"

2016-11-19 Thread Michael Torrie
On 11/19/2016 08:46 AM, Steve D'Aprano wrote: > I think you're being harsh on J Fong. And for what it is worth, I think that > I (slightly) agree with him: in my experience, many people have difficulty > understanding object model at first, especially if they've come from a > background of named

Re: help on "from deen import *" vs. "import deen"

2016-11-19 Thread Steve D'Aprano
On Fri, 18 Nov 2016 03:14 pm, Michael Torrie wrote: > On 11/17/2016 08:41 PM, jf...@ms4.hinet.net wrote: >> The fact that most novices will stumble on Python variable many times >> until it becomes his "second nature" proves it's different from the >> human language:-) > > The fact is that most

Re: help on "from deen import *" vs. "import deen"

2016-11-19 Thread jfong
Chris Angelico at 2016/11/19 2:58:41PM wrote: > On Sat, Nov 19, 2016 at 3:34 PM, Steve D'Aprano > wrote: > > What happens if you do this? > > > > spam = eggs = cheese = obj > > > > Is that different from: > > > > spam = obj > > eggs = obj > > cheese = obj > > > > > >

Re: help on "from deen import *" vs. "import deen"

2016-11-18 Thread Chris Angelico
On Sat, Nov 19, 2016 at 3:34 PM, Steve D'Aprano wrote: > What happens if you do this? > > spam = eggs = cheese = obj > > Is that different from: > > spam = obj > eggs = obj > cheese = obj > > > or from this? > > spam = obj > eggs = spam > cheese = eggs > ... > These

Re: help on "from deen import *" vs. "import deen"

2016-11-18 Thread Steve D'Aprano
On Sat, 19 Nov 2016 05:50 am, Dennis Lee Bieber wrote: > Python's name binding is very easy to state in English: Assignment in > Python attaches the name (on the left hand side of the statement) to the > object (that is the result of the right hand side). What do you mean "attach"? What's a

Re: help on "from deen import *" vs. "import deen"

2016-11-17 Thread Michael Torrie
On 11/17/2016 08:41 PM, jf...@ms4.hinet.net wrote: > The fact that most novices will stumble on Python variable many times > until it becomes his "second nature" proves it's different from the > human language:-) The fact is that most novices don't stumble when dealing with Python variables. The

Re: help on "from deen import *" vs. "import deen"

2016-11-17 Thread jfong
Michael Torrie at 2016/11/18 11:03:12AM wrote: > >> Python's variables are different from other languages, but in an > >> understandable way. > > > > Unfortunately it's also different from human language. > > How so? I don't find this to be true at all. The fact that most novices will stumble

Re: help on "from deen import *" vs. "import deen"

2016-11-17 Thread Michael Torrie
On 11/17/2016 07:23 PM, jf...@ms4.hinet.net wrote: >> Python's variables are different from other languages, but in an >> understandable way. > > Unfortunately it's also different from human language. How so? I don't find this to be true at all. --

Re: help on "from deen import *" vs. "import deen"

2016-11-17 Thread jfong
Michael Torrie at 2016/11/17 11:38:32PM wrote: > Like I said, whether the names you use are appropriate is completely up > to you. But this statement seems to imply you're still not getting it > and still thinking of variables as boxes like they are in other > languages, rather than labels that

Re: help on "from deen import *" vs. "import deen"

2016-11-17 Thread Nathan Ernst
I would also toss in there: never name a script test.py. Causes nothing but trouble, at least in python2. On Nov 17, 2016 8:01 PM, wrote: > Steven D'Aprano at 2016/11/17 4:04:04PM wrote: > > The most important thing you should learn from this thread is: > > > > - avoid

Re: help on "from deen import *" vs. "import deen"

2016-11-17 Thread jfong
Steven D'Aprano at 2016/11/17 4:04:04PM wrote: > The most important thing you should learn from this thread is: > > - avoid using "from module import *" as it is usually more trouble > than it is worth. > > > It is confusing and leads to more problems than it solves. If Python was > being

Re: help on "from deen import *" vs. "import deen"

2016-11-17 Thread Michael Torrie
On 11/16/2016 07:01 PM, jf...@ms4.hinet.net wrote: > Michael Torrie at 2016/11/16 11:15:11AM wrote: >> ... The globals object is a dictionary and is itself mutable. But >> when we assign a new object to a particular dictionary key, it >> tosses out the old reference and makes the key now refer to

Re: help on "from deen import *" vs. "import deen"

2016-11-17 Thread Steven D'Aprano
On Thursday 17 November 2016 17:48, jf...@ms4.hinet.net wrote: > Steven D'Aprano at 2016/11/17 12:06:19PM wrote: >> You understand how this works? > > Yes, thank you for your detail explanation. > >> import russia as _tmp >> president = _tmp.president >> del _tmp > > This one I can

Re: help on "from deen import *" vs. "import deen"

2016-11-16 Thread jfong
Steven D'Aprano at 2016/11/17 12:06:19PM wrote: > You understand how this works? Yes, thank you for your detail explanation. > import russia as _tmp > president = _tmp.president > del _tmp This one I can understand. But the previous one >>_tmp = int('5') >>for name in dir(_tmp): >>

Re: help on "from deen import *" vs. "import deen"

2016-11-16 Thread Steven D'Aprano
On Thursday 17 November 2016 12:54, jf...@ms4.hinet.net wrote: > Steve D'Aprano at 2016/11/16 8:33:23AM wrote: >> `import foo` imports the module foo, that is all. (To be pedantic: it is >> *nominally* a module. By design, it could be any object at all.) >> >> `from foo import *` imports all the

Re: help on "from deen import *" vs. "import deen"

2016-11-16 Thread Chris Angelico
On Thu, Nov 17, 2016 at 1:01 PM, wrote: > Michael Torrie at 2016/11/16 11:15:11AM wrote: >> ... The globals object is a dictionary and is itself >> mutable. But when we assign a new object to a particular dictionary >> key, it tosses out the old reference and makes the key

Re: help on "from deen import *" vs. "import deen"

2016-11-16 Thread jfong
Michael Torrie at 2016/11/16 11:15:11AM wrote: > ... The globals object is a dictionary and is itself > mutable. But when we assign a new object to a particular dictionary > key, it tosses out the old reference and makes the key now refer to the > new object. It does not do anything to the old

Re: help on "from deen import *" vs. "import deen"

2016-11-16 Thread jfong
Steve D'Aprano at 2016/11/16 8:33:23AM wrote: > `import foo` imports the module foo, that is all. (To be pedantic: it is > *nominally* a module. By design, it could be any object at all.) > > `from foo import *` imports all the visible public attributes of foo. > > They do completely different

Re: help on "from deen import *" vs. "import deen"

2016-11-15 Thread Michael Torrie
On 11/15/2016 07:39 PM, jf...@ms4.hinet.net wrote: > Michael Torrie at 2016/11/15 10:43:58PM wrote: >> Seems like you're still not understanding Python variables. > > I do, just not get used to it yet:-) No you don't yet. See below. > Why? the name "tblm" is already exist and is a mutable one,

Re: help on "from deen import *" vs. "import deen"

2016-11-15 Thread jfong
Michael Torrie at 2016/11/15 10:43:58PM wrote: > Seems like you're still not understanding Python variables. I do, just not get used to it yet:-) > However once > you assign to these names in your current module you are breaking this > link to the deen module and assigning a new object to

Re: help on "from deen import *" vs. "import deen"

2016-11-15 Thread Steve D'Aprano
On Wed, 16 Nov 2016 09:16 am, Erik wrote: > On 15/11/16 14:43, Michael Torrie wrote: >> As you've been told several times, if you "import deen" then you can >> place a new object into the deen namespace using something like: >> >> deen.foo=bar >> >> Importing everything from an imported module

Re: help on "from deen import *" vs. "import deen"

2016-11-15 Thread Erik
On 15/11/16 14:43, Michael Torrie wrote: As you've been told several times, if you "import deen" then you can place a new object into the deen namespace using something like: deen.foo=bar Importing everything from an imported module into the current module's namespace is not the best idea

Re: help on "from deen import *" vs. "import deen"

2016-11-15 Thread Michael Torrie
On 11/14/2016 11:32 PM, jf...@ms4.hinet.net wrote: > But obviously it's not. The compiled code of function gpa is still > reference to a hidden deen.tblm 'global' object which I can't access > anymore. A bad news:-( Seems like you're still not understanding Python variables. After importing all

Re: help on "from deen import *" vs. "import deen"

2016-11-14 Thread jfong
MRAB at 2016/11/15 11:31:41AM wrote: > When you say "from deen import *" you're copying names and their > references from the module's namespace to your local namespace: > > [module deen] [locally] > > tblm > [0, 0, 0] <-

Re: help on "from deen import *" vs. "import deen"

2016-11-14 Thread MRAB
On 2016-11-15 01:36, jf...@ms4.hinet.net wrote: Ned Batchelder at 2016/11/15 6:33:54AM wrote: > But I get a wrong answer this way: > >>> from deen import * > >>> tblm = tbli > >>> gpa(0x7d) > 125 # it's 0x7d, the tblm[2] is 0 > > Why? why! why:-( Here you are assigning a value to your own

Re: help on "from deen import *" vs. "import deen"

2016-11-14 Thread jfong
Ned Batchelder at 2016/11/15 6:33:54AM wrote: > > But I get a wrong answer this way: > > >>> from deen import * > > >>> tblm = tbli > > >>> gpa(0x7d) > > 125 # it's 0x7d, the tblm[2] is 0 > > > > Why? why! why:-( > > Here you are assigning a value to your own tblm, not deen.tblm, > so gpa does

Re: help on "from deen import *" vs. "import deen"

2016-11-14 Thread Ned Batchelder
On Sunday, November 13, 2016 at 9:39:12 PM UTC-5, jf...@ms4.hinet.net wrote: > Running the following codes (deen.py) under Win32 python 3.4.4 terminal: > > tbli = [0x66, 0x27, 0xD0] > tblm = [0 for x in range(3)] > def gpa(data): > td = data ^ tblm[2] > return td The function gpa

help on "from deen import *" vs. "import deen"

2016-11-13 Thread jfong
Running the following codes (deen.py) under Win32 python 3.4.4 terminal: tbli = [0x66, 0x27, 0xD0] tblm = [0 for x in range(3)] def gpa(data): td = data ^ tblm[2] return td I can get a correct answer this way: >>> import deen >>> deen.tblm = deen.tbli >>> deen.gpa(0x7d) 173 # 0xad (=