Regarding the parsing of await expression.

2016-11-06 Thread Shiyao Ma
Hi, In the pep, https://www.python.org/dev/peps/pep-0492/#examples-of-await-expressions It is said, await await coro() is SyntaxError, instead, we should use await (await coro()) Why? because of await is not left-associative? also, for await -coro() , it should be written as, await (-coro

The order of iterable de-referencing in assignment?

2016-08-24 Thread Shiyao Ma
Hi, Given a = [1, 2] a.extend(a) makes a = [1,2, 1,2] One might guess a.extend(a) would turn into an infinite loop. It turns out here Python first gets all the items of `a' and then append them to `a', so the infinite loop is avoided. My question is, is there any doc on the behavior of thing

Why monkey patching on module object doesn't work ?

2016-08-17 Thread Shiyao Ma
Hi, I am using Python2. For the following snippet, http://ideone.com/i36pKO I'd suppose the dummy_func would be invoked, but seems not. Indeed, heapq.heapify does invoke cmp_lt per here: https://hg.python.org/cpython/file/2.7/Lib/heapq.py#l136 So why this way of monkey patching failed? Reg

How to simulate C style integer division?

2016-01-21 Thread Shiyao Ma
Hi, I wanna simulate C style integer division in Python3. So far what I've got is: # a, b = 3, 4 import math result = float(a) / b if result > 0: result = math.floor(result) else: result = math.ceil(result) I found it's too laborious. Any quick way? -- 吾輩は猫である。ホームーページはhttps://introo.me

Re: Where is the c source code of the import mechanism that ignores invalid directory?

2015-07-21 Thread Shiyao Ma
Yep. I followed from bltmodule.c(the import function) and got to the import.c file, and finally got lost. Regards. On Tue, Jul 21, 2015 at 12:16 PM, Mark Lawrence wrote: > On 21/07/2015 16:35, Shiyao Ma wrote: > >> Hi, >> >> It looks to me that the import system of Py

Where is the c source code of the import mechanism that ignores invalid directory?

2015-07-21 Thread Shiyao Ma
Hi, It looks to me that the import system of Python will ignore invalid directories and cache the result in memory. For example, the following code: paste here: https://bpaste.net/show/b144deb42620 #!/usr/bin/env python3 import sysimport osimport shutil sys.path.append("./test")shutil.rmtree("./

Re: Why PyINCREF on _PyFalseStruct and _PyTrueStruct?

2015-04-08 Thread Shiyao Ma
On Wed, Apr 8, 2015 at 11:24 AM, Ian Kelly wrote: > The ref count is incremented because the caller will decrement it when > it's done with the reference. That makes sense. To be generic, the caller won't check what the returned result is. It just takes it as a normal PyObject. Traditionally, fo

Why PyINCREF on _PyFalseStruct and _PyTrueStruct?

2015-04-08 Thread Shiyao Ma
Hi. While reading the rich_compare of PyLongObject, I noticed this line: https://hg.python.org/cpython/file/a49737bd6086/Objects/longobject.c#l2785 It increments the ob_ref of the builtin True/False object. Initializing the ob_ref of True/False to one so that they won't be garbage collected if

Weird behavior on __dict__ attr

2015-02-09 Thread Shiyao Ma
instantiate an instance of Node n = Node() # I checked, there is no __dict__ on 'n' # but the following succeeds. n.foobar = 3 My understanding is the foobar is stored in n.__dict__, but seemingly n has no __dict__. So where does the foobar go? TIA. -- Shiyao Ma http://introo.me

Re: problem with for and if

2015-01-05 Thread Shiyao Ma
On Jan 05 at 22:38 +0800, Shiyao Ma wrote: > More preferably, you should repetitively use "str.find" > > Or just use `max(0,len(zmienna.split(szukana))-1)` Forgot there was a `str.count`, ;). -- Shiyao Ma http://introo.me -- https://mail.python.org/mailman/listinfo/python-list

Re: problem with for and if

2015-01-05 Thread Shiyao Ma
else: continue return count More preferably, you should repetitively use "str.find" Or just use `max(0,len(zmienna.split(szukana))-1)` -- Shiyao Ma http://introo.me -- https://mail.python.org/mailman/listinfo/python-list

Re: Nested loops is strangely slow, totally at a loss.

2014-12-10 Thread Shiyao Ma
Thanks guys. I was only aware of a limited iterables which themselves are iterators, e.g., the generator. Seems like its really a pitfall. Any glossary, list on the iterables that *might* exhaust themselves? Regards. -- https://mail.python.org/mailman/listinfo/python-list

Re: Nested loops is strangely slow, totally at a loss.

2014-12-09 Thread Shiyao Ma
One thing to note, the logic of using "in" is not of concern here. This is a *contrived* example, the problem is the slowness of the first iteration. -- https://mail.python.org/mailman/listinfo/python-list

Nested loops is strangely slow, totally at a loss.

2014-12-09 Thread Shiyao Ma
oop with ', 9.5367431640625e-07) ('B, finish a loop with ', 9.5367431640625e-07) ... """ We can see that the first iteration of B ends rather slow, 8.7 seconds here. Why? I am curious about the internals, what's happening under the hood that makes this happen? Thanks in advance! -- Shiyao Ma http://introo.me -- https://mail.python.org/mailman/listinfo/python-list

Re: Python re.search simple question

2014-12-07 Thread Shiyao Ma
.. else: > ... print "BYE" > ... so see here: https://bpaste.net/show/d2f1cf66a492 . It prints "HI" /me always wishes code is sent without others doing some extra formatting before testing. Hope that helps. -- Shiyao Ma http://introo.me -- https://mail.python.org/mailman/listinfo/python-list

Re: Setting default_factory of defaultdict to key

2014-12-07 Thread Shiyao Ma
n, based on what information a thread is formed? -- Shiyao Ma http://introo.me -- https://mail.python.org/mailman/listinfo/python-list

Re: Tuple of lists concatenation - function vs comprehension

2014-12-07 Thread Shiyao Ma
within function: > > >>> def myfunc(): > x = ([1, 2], [3, 4], [5, 6]) > L = [] > [L.extend(i) for i in x] > print(L) > > >>>myfunc() > [1, 2, 3, 4, 5, 6] This is also so true, as you are print the var 'L'. > > The q

Re: Can you use self in __str__

2014-11-28 Thread Shiyao Ma
2014-11-29 11:36 GMT+08:00 Chris Angelico : > You can use id() on any object. You are guaranteed to get back an > integer which is both stable and unique among all ids of objects that > exist at the same time as the one you called it on. For as long as the > object continues to exist, that number *

Re: Can you use self in __str__

2014-11-28 Thread Shiyao Ma
2014-11-28 13:00 GMT+08:00 Chris Angelico : > On Fri, Nov 28, 2014 at 2:04 PM, Shiyao Ma wrote: >> What if it's in the local namespace of a function or method? IDK, try >> to get that thing first. > Sure enough. I will even avoid using "id" as it's dependent

Re: Can you use self in __str__

2014-11-27 Thread Shiyao Ma
2014-11-28 9:26 GMT+08:00 Seymore4Head : > def __str__(self): > s = "Hand contains " > for x in self.hand: > s = s + str(x) + " " > return s > > This is part of a Hand class. I need a hand for the dealer and a hand > for the player. > dealer=Hand() > player=

Understanding co_lnotab

2014-09-26 Thread Shiyao Ma
When reading the notes on co_lnotab I totally got lost at this line:https://hg.python.org/cpython/file/fd0c02c3df31/Objects/lnotab_notes.txt#l31 It says,"In case #b, there's no way to know from looking at the table later how many were written." No way to know "what" is written? And why no way

What's the function location that reads the cached .pyc file from disk.

2014-09-15 Thread Shiyao Ma
Hi. what's the location of the function that reads the .pyc file ? I bet it should lie in somewhere in https://hg.python.org/cpython/file/322ee2f2e922/Lib/importlib But what's the actual location? Btw, why I need it? I want to know the structure of a .pyc file. Of course the function that read

Re: PyWart(2.7.8) IDLE is more buggy than "Joe's apartment"!

2014-07-21 Thread Shiyao Ma
No intent to pollute this thread. But really interested in the invalid@invalid.invalid mailing address. And,,, obviously, I cannot send to invalid@invalid.invalid, so How does you(he) make this? 2014-07-21 22:27 GMT+08:00 Grant Edwards : > I was always taught that it's a "bug" is when a program

Python3+Vim dev environment

2014-07-17 Thread Shiyao Ma
Hi. Anyone with working experience on setting up Python3 dev with vim? functionalities needed: code completion and jump to defintion YCM suffices but only with py2. Any vim (plugin) for py3? Or do you have any experience both running YCM and jedi-vim(for py3) ? How's that going? Regards --

How do you use `help` when write your code

2014-07-06 Thread Shiyao Ma
Hi Pythonistas I often heard people mention use help(ob) as a way of documentation look up. Personally I seldom/never do that. My normal workflow is use ipython, obj? or obj?? for quick look up or use docs.python.org for a detailed read. Do you use `help`? How does it integrate into your workflo

Re: how can i get the source code of goagent.exe?

2014-07-02 Thread Shiyao Ma
Ask on the goagent googlecode? exe is fow win, dig out more on the linux version. I bet it should be delivered with py source in that version. Regards. 2014-07-03 10:20 GMT+08:00 liuerfire Wang : > Hi 水静流深 > the source code is on https://github.com/goagent/goagent > > Hi Terry, > GoAgent, a to

Re: First time I looked at Python was(...)

2014-06-10 Thread Shiyao Ma
I wonder if it's opensourced. I am kinda interested in its implementation. On the whole, the performance is rather good. 2014-06-10 22:39 GMT+08:00 Mark H Harris : > On 6/9/14 3:54 PM, Carlos Anselmo Dias wrote: > >> Hi ... >> >> I'm finishing my messages with this ... >> >> The first time I loo

Re: try/except/finally

2014-06-09 Thread Shiyao Ma
It would be great if someone could discuss it from the viewpoint of bytecode. e.g., how the stack is popped, etc. 2014-06-09 17:40 GMT+08:00 Marko Rauhamaa : > Philip Shaw : > > > OTOH, it could just be that Guido didn't think of banning [return from > > finally] when exceptions were first added

Re: None in string => TypeError?

2014-06-09 Thread Shiyao Ma
2014-06-09 23:34 GMT+08:00 Roy Smith : > We noticed recently that: > > >>> None in 'foo' > > raises (at least in Python 2.7) > > TypeError: 'in ' requires string as left operand, not NoneType > > This is surprising. The description of the 'in' operatator is, 'True if > an item of s is equal to x,

Re: Bug? ( () == [] ) != ( ().__eq__([]) )

2013-08-07 Thread Shiyao Ma
Sorry. I don't quite get it. As you said, it first tries, leftOperand.__eq__(rightOperand) then if it returns NotImplemented, it goes to invoke rightOperand.__eq__(leftOperand). But for any reason, [] == () returns false, why? On Mon, Aug 5, 2013 at 7:06 AM, Chris Angelico wrote: > On Sun, Aug

Re: At a loss on python scoping.

2013-03-26 Thread Shiyao Ma
After read Dave's answer, I think I confused LEGB with attribute lookup. So, a.r has nothing to do with LEGB. On Tue, Mar 26, 2013 at 7:03 PM, Shiyao Ma wrote: > Thx, really a nice and detailed explanation. > > > On Tue, Mar 26, 2013 at 6:07 PM, Dave Angel wrote: > >&

Re: At a loss on python scoping.

2013-03-26 Thread Shiyao Ma
Thx, really a nice and detailed explanation. On Tue, Mar 26, 2013 at 6:07 PM, Dave Angel wrote: > On 03/26/2013 02:17 AM, Shiyao Ma wrote: > >> Hi, >> suppose I have a file like this: >> class A: >> r = 5 >> def func(self, s): >> sel

Re: python3 string format

2013-03-26 Thread Shiyao Ma
urn a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces ('{' and '}'). """ pass I am curious how you find the corresponding c source code. On Tue, Mar 26, 2013 at 2:16 PM, Ian Kell

Re: At a loss on python scoping.

2013-03-26 Thread Shiyao Ma
ote: > On Tue, Mar 26, 2013 at 5:17 PM, Shiyao Ma wrote: > > class A: > > r = 5 > > def func(self, s): > > self.s = s > > a = A() > > print(a.r)# this should print 5, but where does py store the name of > r > > What do you mean by

Re: At a loss on python scoping.

2013-03-25 Thread Shiyao Ma
PS, I now python's scoping rule is lexical rule (aka static rule). How does LEGB apply to class? On Tue, Mar 26, 2013 at 2:17 PM, Shiyao Ma wrote: > Hi, > suppose I have a file like this: > class A: > r = 5 > def func(self, s): > self.s = s > a =

At a loss on python scoping.

2013-03-25 Thread Shiyao Ma
Hi, suppose I have a file like this: class A: r = 5 def func(self, s): self.s = s a = A() print(a.r)# this should print 5, but where does py store the name of r a.func(3) print(a.s)# this should print 3, also where does py store this name. what's the underlying difference b

python3 string format

2013-03-25 Thread Shiyao Ma
HI. one thing confuses me. It is said in the pep3101 that "{}".format (x) will invoke the method x.__format__ However, I looked at the src of python3 and found: in class str(object), the format simply contains a pass statement in class int(object), things is the same. So, what's the mechanism that

Re: How to quickly set up a multithreaded server that can handle http file post.

2013-03-11 Thread Shiyao Ma
Yes, sounds good. I should give it a try. On Tue, Mar 12, 2013 at 1:02 AM, Xavier L. wrote: > On 13-03-11 10:42 AM, Shiyao Ma wrote: > >> Today I come across a problem. >> Basically, my need is that I want to launch a http server that can not >> only support get but also

How to quickly set up a multithreaded server that can handle http file post.

2013-03-11 Thread Shiyao Ma
Today I come across a problem. Basically, my need is that I want to launch a http server that can not only support get but also support post (including post file). My first idea is to use -m http.sever. However, it only supports get. Later I find some one extended basehttpserver and made it suppor