Re: Observations on the List - "Be More Kind"

2018-10-09 Thread jfong
Chris Angelico at 2018.10.10 UTC+8 AM 10:31:33 wrote: > On Wed, Oct 10, 2018 at 1:21 PM wrote: > > I switched from comp.lang.python to mailing list a few months ago for those > > spam threads there. Now it seems a bad decision because 1) replied mail can > > be lost or duplicated or even

Re: Observations on the List - "Be More Kind"

2018-10-09 Thread jfong
Richard Damon at 2018.10.9 UTC+8 PM 8:40:29 wrote: > Moderators are generally appointed by those who do 'pay the bill' for > the mailing list they are moderators for, and serve at their pleasure. > Mailing List are generally 'private property', though often made open to > the public for general

Re: Observations on the List - "Be More Kind"

2018-10-09 Thread jfong
I am wondering the role of the moderator. Does he own the server or pay the bill? Where he get the power to suspending people? Is he a police or judge? Can he shoot someone just because he has any reason? What will happen if his power was limited? Will the forum be end in disorder? No, I

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread jfong
Chris Angelico於 2018年4月12日星期四 UTC+8下午4時05分29秒寫道: > On Thu, Apr 12, 2018 at 4:20 PM, wrote: > > Chris Angelico於 2018年4月12日星期四 UTC+8下午1時31分35秒寫道: > >> On Thu, Apr 12, 2018 at 2:16 PM, wrote: > >> > This C function returns a buffer which I declared it as

Re: How to write partial of a buffer which was returned from a C function to a file?

2018-04-12 Thread jfong
Chris Angelico於 2018年4月12日星期四 UTC+8下午1時31分35秒寫道: > On Thu, Apr 12, 2018 at 2:16 PM, wrote: > > This C function returns a buffer which I declared it as a ctypes.c_char_p. > > The buffer has size 0x1 bytes long and the valid data may vary from a > > few bytes to the

How to write partial of a buffer which was returned from a C function to a file?

2018-04-11 Thread jfong
This C function returns a buffer which I declared it as a ctypes.c_char_p. The buffer has size 0x1 bytes long and the valid data may vary from a few bytes to the whole size. In every call I know how much the valid data size is, but I suppose I can't use slice to get it because there may be

Is pdb suitable for debugging asyncio module?

2018-04-04 Thread jfong
I have a module below and run it under pdb, the result seems not easy to xplain. (Note: the sleep periods are in reverse order) --- # asyncio_as_completed.py import asyncio @asyncio.coroutine def phase(i): print('in phase {}'.format(i)) yield from asyncio.sleep(0.5 - (0.1 *

Re: In asyncio, does the event_loop still running after run_until_complete returned?

2018-04-03 Thread jfong
Ian於 2018年4月3日星期二 UTC+8下午1時38分57秒寫道: > On Mon, Apr 2, 2018 at 9:01 PM, wrote: > > def run_forever(self): > """Run until stop() is called.""" >try: > events._set_running_loop(self) > while True: > self._run_once() >

Re: In asyncio, does the event_loop still running after run_until_complete returned?

2018-04-02 Thread jfong
Ian於 2018年4月2日星期一 UTC+8下午9時37分08秒寫道: > On Mon, Apr 2, 2018 at 5:32 AM, wrote: > > I am new to the asyncio subject, just trying to figure out how to use it. > > Below is the script I use for testing: > > - > > # asyncio_cancel_task2.py > > > >

In asyncio, does the event_loop still running after run_until_complete returned?

2018-04-02 Thread jfong
I am new to the asyncio subject, just trying to figure out how to use it. Below is the script I use for testing: - # asyncio_cancel_task2.py import asyncio @asyncio.coroutine def task_func(): print('in task_func, sleeping') try: yield from

Re: {:2X} didn't output what I expected

2018-03-19 Thread jfong
Chris Angelico於 2018年3月20日星期二 UTC+8上午8時06分05秒寫道: > On Tue, Mar 20, 2018 at 10:46 AM, wrote: > > D:\Temp>py > > Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 > > bit (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more

{:2X} didn't output what I expected

2018-03-19 Thread jfong
D:\Temp>py Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> '{:02X}'.format(256) '100' >>> What I expected is '00'. Am I wrong? Best Regards, Jach Fong --

Re: File opening modes (r, w, a ...)

2018-02-22 Thread jfong
Lew Pitcher於 2018年2月23日星期五 UTC+8上午9時43分19秒寫道: > jf...@ms4.hinet.net wrote: > > > ast於 2018年2月22日星期四 UTC+8下午8時33分00秒寫道: > >> Hello > >> > >> I share a very valuable table I found on > >> StackOverflow about file opening modes > >> > >> If like me you always forget the details of > >> file

Re: File opening modes (r, w, a ...)

2018-02-22 Thread jfong
ast於 2018年2月22日星期四 UTC+8下午8時33分00秒寫道: > Hello > > I share a very valuable table I found on > StackOverflow about file opening modes > > If like me you always forget the details of > file opening mode, the following table provides > a good summary > >| r r+ w w+ a

Re: How to exec a string which has an embedded '\n'? (Posting On Python-List Prohibited)

2017-12-31 Thread jfong
Lawrence D’Oliveiro於 2018年1月1日星期一 UTC+8上午7時56分02秒寫道: > On Sunday, December 31, 2017 at 11:04:19 PM UTC+13, jf...@ms4.hinet.net wrote: > > > > This answer makes me think about '\' more thoughtful:-) > > Python generating HTML containing JavaScript which generates HTML: > > out.write \ >

Re: How to exec a string which has an embedded '\n'?

2017-12-31 Thread jfong
Random832於 2017年12月31日星期日 UTC+8下午1時25分50秒寫道: > On Sat, Dec 30, 2017, at 23:57, jf...@ms4.hinet.net wrote: > > I have a multiline string, something like '''...\nf.write('\n')\n...''' > > when pass to exec(), I got > > SyntaxError: EOL while scanning string literal > > > > How to get rid of it? >

How to exec a string which has an embedded '\n'?

2017-12-30 Thread jfong
I have a multiline string, something like '''...\nf.write('\n')\n...''' when pass to exec(), I got SyntaxError: EOL while scanning string literal How to get rid of it? Best Regards, Jach Fong -- https://mail.python.org/mailman/listinfo/python-list

Re: How to modify this from Python 2.x to v3.4?

2017-11-12 Thread jfong
Thomas Jollans於 2017年11月12日星期日 UTC+8下午5時17分38秒寫道: > By all means, port ctypesgen to Python 3 (and publish your port) if you > want to, I am not the right person because I have never use Python2 before:-) > but you might want to consider whether it's easier to port your > code from

Re: How to modify this from Python 2.x to v3.4?

2017-11-12 Thread jfong
Rick Johnson於 2017年11月12日星期日 UTC+8上午11時07分20秒寫道: > `print` was changed from a statement to a function, so it's > just a matter of converting it to a function call. If you > read the docs for the new print function, it should be > relatively easy to translate. I don't understand why you're > having

Re: How to modify this from Python 2.x to v3.4?

2017-11-11 Thread jfong
Ned Batchelder於 2017年11月11日星期六 UTC+8下午8時49分27秒寫道: > This looks like fairly advanced code.  It will be difficult to port to > Python 3 *without* understanding some of the old history.  There seem to > be forks on GitHub, including one with a pull request about Python 3 > made in the last few

How to modify this from Python 2.x to v3.4?

2017-11-11 Thread jfong
I learned python start from using v3.4 and never has any v2.x experience. There is a Pypi project "ctypesgen" I like to use, but it seems is for v2.x. (un)Fortunately I found one of its branch on github which announced is for Python3, but strangely it still use some v2.x words, for example,

Re: How to debug an unfired tkinter event?

2017-10-21 Thread jfong
Terry Reedy at 2017-10-20 UTC+8 AM 7:37:59 wrote: > On 10/19/2017 5:07 AM, jf...@ms4.hinet.net wrote: > > > I got some info below each time when I squeeze the table: > > . > > .5006 > > .5006.50712528 > > .5006.50712496 > > .5006.50712464 > > .5006.50712144 > >

Re: How to debug an unfired tkinter event?

2017-10-19 Thread jfong
Terry Reedy於 2017年10月20日星期五 UTC+8上午7時37分59秒寫道: > On 10/19/2017 5:07 AM, jf...@ms4.hinet.net wrote: > > > I got some info below each time when I squeeze the table: > > . > > .5006 > > .5006.50712528 > > .5006.50712496 > > .5006.50712464 > > .5006.50712144 > >

Re: How to debug an unfired tkinter event?

2017-10-19 Thread jfong
Peter Otten於 2017年10月20日星期五 UTC+8上午4時37分10秒寫道: > jf...@ms4.hinet.net wrote: > > > Peter Otten於 2017年10月19日星期四 UTC+8下午6時04分39秒寫道: > >> jf...@ms4.hinet.net wrote: > >> > >> > Peter Otten at 2017-10-19 UTC+8 PM 3:24:30 wrote: > >> >> It's not clear to me what you mean with this. Did you place the

Re: How to debug an unfired tkinter event?

2017-10-19 Thread jfong
Peter Otten於 2017年10月19日星期四 UTC+8下午6時04分39秒寫道: > jf...@ms4.hinet.net wrote: > > > Peter Otten at 2017-10-19 UTC+8 PM 3:24:30 wrote: > >> It's not clear to me what you mean with this. Did you place the table > >> from the recipe elsewhere inside a window that you created or did you > >> make

Re: How to debug an unfired tkinter event?

2017-10-19 Thread jfong
Peter Otten at 2017-10-19 UTC+8 PM 3:24:30 wrote: > It's not clear to me what you mean with this. Did you place the table from > the recipe elsewhere inside a window that you created or did you make > changes in the recipe's code? Thank you, Peter. I am using Python 3.4.4 under WinXP. When

How to debug an unfired tkinter event?

2017-10-18 Thread jfong
In last few days, I tried to experiment with the scrolling table implemented in canvas, started from this example: http://code.activestate.com/recipes/580793-tkinter-table-with-scrollbars/. Everything works fine until I moved the scrolling_area instance (which the canvas is in) from column=0

Re: Ask for help about a tkinter problem

2017-08-20 Thread jfong
Peter Otten at 2017/8/20 UTC+8 PM 5:52:24 wrote: > jf...@ms4.hinet.net wrote: > > > I am running a tkinter tutor downloaded from web, > > https://github.com/daleathan/widget-tour-py3. there are two files > > involved: > > > > > > #file button.py > > > > from tkinter import

Ask for help about a tkinter problem

2017-08-20 Thread jfong
I am running a tkinter tutor downloaded from web, https://github.com/daleathan/widget-tour-py3. there are two files involved: #file button.py from tkinter import * from tkinter.ttk import * import infrastructure ... class ButtonsDemoWindow( infrastructure.DemoWindow ):

Re: Call a class A method from a class B instance? Do I miss something?

2017-08-18 Thread jfong
Rick Johnson at 2017/8/18 UTC+8 AM 11:43:06 wrote: > jf...@ms4.hinet.net wrote: > > I study some codes of a tutorial about tkinter > > > > [snip code] > > > > My question is that the object which was left by > > callit(self.demoenter_callback, tag) is a callit instance, > > and the method it calls

Re: Call a class A method from a class B instance? Do I miss something?

2017-08-18 Thread jfong
Ian於 2017年8月18日星期五 UTC+8上午10時41分44秒寫道: > On Thu, Aug 17, 2017 at 6:03 PM, wrote: > > I study some codes of a tutorial about tkinter > > (https://github.com/daleathan/widget-tour-py3) and can't figure out how it > > works. > > > > Below is the codes from its two major

Call a class A method from a class B instance? Do I miss something?

2017-08-17 Thread jfong
I study some codes of a tutorial about tkinter (https://github.com/daleathan/widget-tour-py3) and can't figure out how it works. Below is the codes from its two major files: # file infrastructure.py ... ... class callit: def __init__(self, function, *args ):

Re: Strang thing in tkinter, and pdb too?

2017-06-12 Thread jfong
Terry Reedy於 2017/06/12 UTC+8 12:04:18PM wrote: > Right. I got this with IDLE tests before using ttk. Good luck tracing > this to its origin. A little progress. If I remove temp.destroy() at line 34 then that message is gone. hmm...trying to find another way of doing it:-) --Jach Fong --

Strang thing in tkinter, and pdb too?

2017-06-11 Thread jfong
I had donwload wdiget-tour-py3.tar.gz examples from this site: http://www.hullsvle.ch/moodle/mod/resource/view.php?id=6697 and run one of its scripts canvasruler.py, I get stange result. First, when I run it in the cmd box, although I get a message in the box, but everything else is fine. The GUI

Re: What is the difference between x[:]=y and x=y[:]?

2017-04-12 Thread jfong
Peter Otten at 2017/4/12 UTC+8 PM 8:13:53 wrote: > I should add that you can write > > lr = [[1], [0]] > lx = [] > for i in range(len(lr)): > > ... lx = lr[i][:] > > ... lx.append(0) > > ... lr[i].append(1) > > ... lr.append(lx) > > ... > lr > >[[1, 1], [0, 1],

Re: What is the difference between x[:]=y and x=y[:]?

2017-04-12 Thread jfong
Peter Otten at 2017/4/12 UTC+8 PM 4:41:36 wrote: > jf...@ms4.hinet.net wrote: > > Assuming both x and y are lists > > x[:] = y > > replaces the items in x with the items in y while > > > x = y[:] > > makes a copy of y and binds that to the name x. In both cases x and y remain > different

What is the difference between x[:]=y and x=y[:]?

2017-04-12 Thread jfong
I have a list of list and like to expand each "list element" by appending a 1 and a 0 to it. For example, from "lr = [[1], [0]]" expand to "lr = [[1,1], [0,1], [1,0], [0,0]]". The following won't work: Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on

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: How to append a modified list into a list?

2016-11-19 Thread jfong
Peter Otten at 2016/11/19 5:40:34PM wrote: > And now for something completely different ;) > > What if you only record the changes to the list? For a long list that would > save space at the expense of calculation time. For example: Excellent! Although not 100% fit into my application, I must

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: How to append a modified list into a list?

2016-11-18 Thread jfong
Oh, I don't know slice well enough:-( So, slice tbl[:] will create a new object (a copy of tbl) which can be passed as a function argument m.append(tbl[:]) or bind to a new name w=tbl[:] or re-bind to itself w[:]=tbl Thanks you, Ian and Steve. Steve D'Aprano at 2016/11/19 11:01:26AM wrote: >

How to append a modified list into a list?

2016-11-18 Thread jfong
I have a working list 'tbl' and recording list 'm'. I want to append 'tbl' into 'm' each time when the 'tbl' was modified. I will record the change by append it through the function 'apl'. For example: >>>tbl=[0,0] >>>m=[] >>>tbl[0]=1 >>>apl(tbl) >>>m [[1,0]] >>>tbl[1]=2 >>>apl(tbl) >>>m

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 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 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-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 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 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-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 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

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 (=

Re: Is it possible Python can distinguish capital letter and small letter in the path of Windows?

2016-10-11 Thread jfong
wxjm...@gmail.com at 2016/10/11 9:40:21PM wrote: > If you are about to modify your registry, do not > forget to switch your Windows in a *utf-8 mode*. Have no idea how to "switch" Windows in a "utf-8 mode"? What will happens if not? Can you give a simple example? Thanks ahead. --Jach --

Re: Is it possible Python can distinguish capital letter and small letter in the path of Windows?

2016-10-11 Thread jfong
Hi, eryk, thanks for your solution. I had try to find the document of the _winapi module, but can't find any in my installed Python directory. Can you give me a link to look for? > This alone doesn't make the Windows API case sensitive, but it does > enable individual CreateFile calls to be

Is it possible Python can distinguish capital letter and small letter in the path of Windows?

2016-10-11 Thread jfong
I have two files in the Q:\lib directory: Q:\lib>dir 2007/03/11 AM 08:025,260 lib_MARK.so 2007/03/11 AM 08:024,584 lib_mark.so Under Python 3.4.4 I got: >>> f = open('lib_MARK.so', 'br') >>> data = f.read() >>> f.close() >>> len(data) 4584 I know Windows won't, but can Python

Re: How to make a foreign function run as fast as possible in Windows?

2016-10-01 Thread jfong
Chris Angelico at 2016/10/1 11:25:03AM wrote: > What's it doing? Not every task can saturate the CPU - sometimes they > need the disk or network more. > This function has no I/O or similar activity, just pure data processing, and it takes less than 200 bytes of data area to work with. My CPU is

Re: How to make a foreign function run as fast as possible in Windows?

2016-09-30 Thread jfong
Paul Moore at 2016/9/30 7:07:35PM wrote: > OK. So if your Python code only calls the function once, the problem needs to > be fixed in the external code (the assembly routine). But if you can split up > the task at the Python level to make multiple calls to the function, each to > do a part of

Re: How to make a foreign function run as fast as possible in Windows?

2016-09-28 Thread jfong
Paul Moore at 2016/9/28 11:31:50PM wrote: > Taking a step back from the more detailed answers, would I be right to assume > that you want to call this external function multiple times from Python, and > each call could take days to run? Or is it that you have lots of calls to > make and each

Re: How to make a foreign function run as fast as possible in Windows?

2016-09-28 Thread jfong
eryk sun at 2016/9/28 1:05:32PM wrote: > In Unix, Python's os module may have sched_setaffinity() to set the > CPU affinity for all threads in a given process. > > In Windows, you can use ctypes to call SetProcessAffinityMask, > SetThreadAffinityMask, or SetThreadIdealProcessor (a hint for the >

Re: How to make a foreign function run as fast as possible in Windows?

2016-09-27 Thread jfong
eryk sun at 2016/9/27 11:44:49AM wrote: > The threads of a process do not share a single core. The OS schedules > threads to distribute the load across all cores hmmm... your answer overthrow all my knowledge about Python threads completely:-( I actually had ever considered using

How to make a foreign function run as fast as possible in Windows?

2016-09-26 Thread jfong
This function is in a DLL. It's small but may run for days before complete. I want it takes 100% core usage. Threading seems not a good idea for it shares the core with others. Will the multiprocessing module do it? Any suggestion? Thanks ahead. --Jach --

Re: Iteration, while loop, and for loop

2016-06-30 Thread jfong
Steven D'Aprano at 2016/6/30 7:59:40AM wrote: > py> mi = list('bananas') > py> for char in mi: > ... if char == 'a': > ... mi.extend(' yum') > ... print(char, end='') > ... else: # oh no, the feared for...else! > ... # needed to prevent the prompt overwriting the output >

Re: "for/while ... break(by any means) ... else" make sense?

2016-06-29 Thread jfong
Steven D'Aprano at 2016/6/29 UTC+8 10:43:52AM wrote: > The "else" in for...else has nothing to do with any "if" inside the for > block. Yes, the "else" has nothing to do with "break" syntactically in Python language, but semantically in English it cause confusion. When I said "insane", I just

"for/while ... break(by any means) ... else" make sense?

2016-06-28 Thread jfong
Anyone who wrote the code below must be insane:-) for x in range(3): print(x) else: print('I am done') But here it seems perfectly OK: for x in range(3): print(x) if x == 1: break else: print('I am done') To me, the "else" was bonded

Re: Guys, can you please share me some sites where we can practice python programs for beginners and Intermediate.

2016-06-21 Thread jfong
Pushpanth Gundepalli at 2016/6/21 7:03:28PM wrote: > Guys, can you please share me some sites where we can practice python > programs for beginners and Intermediate. Is this you want? http://pythontutor.com/ --Jach -- https://mail.python.org/mailman/listinfo/python-list

Re: How to memory dump an object?

2016-05-21 Thread jfong
Make a quick experiment under version 3.4.4 through this simple "tool" Chris had provided, now I know how the unicode string was stored in memory:-) >>> s1 = '\x80abc' >>> s1 '\x80abc' >>> len(s1) 4 >>> sys.getsizeof(s1) 41 >>> s1ptr = ctypes.cast(id(s1), ctypes.POINTER(ctypes.c_uint8)) >>>

Re: How to memory dump an object?

2016-05-20 Thread jfong
Sorry, forget to mention that I am working on version 3.4 Following the steps given in Chris's reply, I get the result from bytes string: >>> b1 = b'\x80abc' >>> ctypes.cast(id(b1), ctypes.c_voidp) c_void_p(35495992) >>> sys.getsizeof(b1) 21 >>> b1ptr = ctypes.cast(id(b1),

How to memory dump an object?

2016-05-20 Thread jfong
Is there any tools which can do the memory dump of an object so I can view their content or implementation? For example, >>> s1 = '\x80abc' >>> b1 = b'\x80abc' What are exactly stored in memory for each of them? Is their content really the same? This kind of tool should be helpful "for me" to

Re: You gotta love a 2-line python solution

2016-05-02 Thread jfong
Stephen Hansen at 2016/5/3 11:49:22AM wrote: > On Mon, May 2, 2016, at 08:27 PM, jf...@ms4.hinet.net wrote: > > But when I try to get this forum page, it does get a html file but can't > > be viewed normally. > > What does that mean? > > -- > Stephen Hansen > m e @ i x o k a i . i o The page

Re: You gotta love a 2-line python solution

2016-05-02 Thread jfong
DFS at 2016/5/3 9:12:24AM wrote: > try > > from urllib.request import urlretrieve > > http://stackoverflow.com/questions/21171718/urllib-urlretrieve-file-python-3-3 > > > I'm running python 2.7.11 (32-bit) Alright, it works...someway. I try to get a zip file. It works, the file can be

Re: You gotta love a 2-line python solution

2016-05-02 Thread jfong
DFS at 2016/5/2 UTC+8 11:39:33AM wrote: > To save a webpage to a file: > - > 1. import urllib > 2. urllib.urlretrieve("http://econpy.pythonanywhere.com > /ex/001.html","D:\file.html") > - > > That's it! Why my system

Re: Dictionary is really not easy to handle

2016-04-28 Thread jfong
I was overwhelmed that three gurus inspire me in three different ways in their own flavour:-) That's really appreciated! Now I understand why it's so, thanks to all of you. To Peter: > With that information, can you predict what > for k, v in {(1, 2): "three"}: print(k, v) > will print?

Dictionary is really not easy to handle

2016-04-28 Thread jfong
I have a dictionary like this: >>> dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'} The following code works: >>> for k in dct: print(k, dct[k]) ... 1 D 2 B 3 B 4 E 5 A and this one too: >>> for k,v in dct.items(): print(k,v) ... 1 D 2 B 3 B 4 E 5 A But...this one? >>> for k,v in dct:

Re: how to create a dictionary from csv file?

2016-04-26 Thread jfong
Just curious:-) why everyone here open the csv file without using newline='' as suggested in Python 3.4.4 document section 14.1? -- https://mail.python.org/mailman/listinfo/python-list

What is the common technique used to cross-reference in module's method?

2016-03-19 Thread jfong
There are two modules (say model.py and piece.py) which has methods need to refer to each other module's methods. I saw in a book using the way below, by assigning one (the Model) object to an attribute of the other (the Piece) bject. - ##model.py import piece ... class Model(dict):

Re: Any comment on using ctypesgen package?

2016-03-06 Thread jfong
Mark Lawrence at 2016/3/5 UTC+8 8:01:06PM wrote: > > HTH http://python3porting.com/problems.html OK, now I understand what "from .cparset import *" means, but it didn't help on solving this import error:-( Thanks for the link, although it seems not help on this problem either:-) --Jach --

Re: Any comment on using ctypesgen package?

2016-03-05 Thread jfong
Chris Angelico at 2016/3/5 UTC+8 1:50:05PM wrote: > Your conclusion may well be correct. However, the exact issue you're > looking at here might be easily enough fixed; it looks like it's > trying to sort things by length, so you can simply use "key=len" (and > maybe "reverse=True"). After Chris

Re: Any comment on using ctypesgen package?

2016-03-04 Thread jfong
Peter Otten 2016/3/4 UTC+8 8:36:02PM worte: > """ > The 2to3 route is not likely to apply since ctypesgen actually writes Python > code and the 2to3 utility will probably miss a good portion of that logic. > """ > > But as someone else seems to have done the work already > >

Any comment on using ctypesgen package?

2016-03-04 Thread jfong
I try to test this package but with no luck. This module was written for Python 2.x but mine is 3.4 so I use the 2To3 to "upgrade" it first (it seems OK). Then I run "python setup.py install" and get the following error: ... ... File

Re: How to know if an object is still be referenced?

2016-03-02 Thread jfong
sohca...@gmail.com at 2016/3/3 UTC+8 7:38:45AM wrote: > "label" might be a local variable, but it's constructor includes a reference > to the frame in which it is going. The frame object will create a reference > to the newly-created Label object. At that point, there will be two >

Re: How to know if an object is still be referenced?

2016-03-02 Thread jfong
Terry Reedy at 2016/3/2 UTC+8 3:04:10PM wrote: > On 3/1/2016 9:35 PM, jf...@ms4.hinet.net wrote: > > Recently I was puzzled by a tkinter problem. The codes below (from a book) > > can display the picture correctly. > > > > gifdir = "../gifs/" > > from tkinter import * > > win =

How to know if an object is still be referenced?

2016-03-01 Thread jfong
Recently I was puzzled by a tkinter problem. The codes below (from a book) can display the picture correctly. gifdir = "../gifs/" from tkinter import * win = Tk() photo = PhotoImage(file=gifdir + "ora-pp.gif") Button(win, image=photo).pack() win.mainloop() And the codes

Re: Will file be closed automatically in a "for ... in open..." statement?

2016-02-17 Thread jfong
The "for ... open ..." is definitely not a good design pattern. It opens a file at "for" block but leaves it closed somewhere in the sky. > The garbage collector will: > - reclaim the memory used by the object; > - close the file. I suppose (IMO) that the primitive idea of garbage collection

Re: Will file be closed automatically in a "for ... in open..." statement?

2016-02-16 Thread jfong
Thanks for these detailed explanation. Both statements will close file automatically sooner or later and, when considering the exceptions, "with" is better. Hope my understanding is right. But, just curious, how do you know the "for" will do it? I can't find any document about it from every

Will file be closed automatically in a "for ... in open..." statement?

2016-02-16 Thread jfong
I know with open('foo.txt') as f: ...do something... will close the file automatically when the "with" block ends. I also saw codes in a book: for line in open('foo.txt'): ...do something... but it didn't mention if the file will be closed automatically or not when

Re: How this C function was called through ctypes this way?

2016-02-04 Thread jfong
eryk sun at 2016/2/4 UTC+8 7:35:17PM wrote: > > _mod = ctypes.cdll.LoadLibrary(_path) > > Calling ctypes.CDLL directly is preferable since it allows passing > parameters such as "mode" and "use_errno". > > IMO, the ctypes.cdll and ctypes.windll loaders should be avoided in > general, especially

How this C function was called through ctypes this way?

2016-02-04 Thread jfong
Here is an example from "Python Cookbook, Third Edition(by David Beazley and Brian K. Jones)" Chapter 15.1. "Accessing C Code Using ctypes" --- import ctypes ... # Try to locate the .so file in the same directory as this file ... _mod = ctypes.cdll.LoadLibrary(_path) ... ... #

Re: Which Python editor has this feature?

2016-01-13 Thread jfong
Terry Reedy at 2016/1/13 UTC+8 5:15:20PM wrote: > This was a Windows specific problem that was fixed (for me) in all three > recent (last November/December) bugfix releases. If you have a problem > with *current* IDLE, I would like to know. I download/install the latest version 3.4.4 and it

Re: Which Python editor has this feature?

2016-01-12 Thread jfong
Terry Reedy at 2016/1/12 UTC+8 3:56:03PM wrote: > Revamping IDLE to 1. use ttk widgets and 2. become a modern single > window app with multiple panes, including a tabbed editor pane, is a > goal for 2016. That will be great, I'm looking forward to it. By the way, when I was playing around with

Re: Which Python editor has this feature?

2016-01-12 Thread jfong
wxjm...@gmail.com at 2016/1/月12 4:29:08PM wrote: > IDLE ? > I need less than 10 seconds to make it crash. Unwittingly or intentionally? > The interesting aspect is not only to show that it crashes, > the very interesting point is to explain why it is crashing. Can you tell us (in a separate

Re: Which Python editor has this feature?

2016-01-11 Thread jfong
Chris Angelico at 2016/1/11 UTC+8 10:59:47AM wrote: > On Mon, Jan 11, 2016 at 12:59 PM, wrote: > > It lets you jump between the current cursor position and the line the upper > > level indentation start, something like the bracket matching in C editor. > > Because of

Re: Which Python editor has this feature?

2016-01-11 Thread jfong
Tim Chase at 2016/1/11 UTC+8 11:16:27AM wrote: > On 2016-01-10 17:59, jf...@ms4.hinet.net wrote: > > It lets you jump between the current cursor position and the line > > the upper level indentation start, something like the bracket > > matching in C editor. Because of Python use indentation as

Re: Which Python editor has this feature?

2016-01-11 Thread jfong
Terry Reedy at 2016/1/12 UTC+8 5:22:35AM wrote: > IDLE has an optional 'code context' feature that shows header lines that > have scrolled up off the top of the screen. This would let you see > which class you are in, Thanks, Terry. It's just what I am looking for:-) By the way, do you know

Re: Which Python editor has this feature?

2016-01-11 Thread jfong
Gordon Levi at 2016/1/11 UTC+8 4:41:20PM wrote: > Jetbrains Pycharm has "go to start of block" and "go to end of block" > commands . Thanks, Gordon. But this seems only jump between the current code block's start and end, not to the code one level above:-(

Which Python editor has this feature?

2016-01-10 Thread jfong
It lets you jump between the current cursor position and the line the upper level indentation start, something like the bracket matching in C editor. Because of Python use indentation as its code block mark, It might be helpful if we can jump between different level of it:-) --Jach Fong --

Is there a way importing a string object?

2016-01-04 Thread jfong
For example, name = "test" # test.py is a module's file import name Regards, Jach -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there a way importing a string object?

2016-01-04 Thread jfong
jf...@ms4.hinet.net at 2016/1/5 UTC+8 8:49:56AM wrote: Thanks, Ian and Ben. This forum is really a good place for learning Python. I am glad I had join in. To Ben, > (Please make the body of your message complete. The "Subject" field > should be a summary of your message's subject, and may not

Re: A newbie quesiton: local variable in a nested funciton

2015-12-27 Thread jfong
Chris Angelico at 2015/12/27 UTC+8 2:32:32PM wrote: > On Sun, Dec 27, 2015 at 3:11 PM, wrote: > > Last night I noticed that Python does not resolve name in "def" during > > import, as C does in the compile/link stage, it was deferred until it was > > referenced (i.e.

Re: A newbie quesiton: local variable in a nested funciton

2015-12-26 Thread jfong
Chris Angelico at 2015/12/26 UTC+8 11:44:21AM wrote: > Pike is semantically very similar to Python, but it uses C-like > variable scoping. Here's an equivalent, which might help with > comprehension: > > function outerf() > { > int counter = 55; > void innerf() > { >

Re: A newbie quesiton: local variable in a nested funciton

2015-12-26 Thread jfong
Ben Finney at 2015/12/26 UTC+8 11:42:08AM wrote: > The Python FAQ answers this, even using an example the same as yours > . > Thank you, Ben. It's amazing that you seem to know

<    1   2   3   >