Re: [Tutor] When is and isn't "__file__" set?

2018-01-10 Thread Steven D'Aprano
On Wed, Jan 10, 2018 at 08:02:24PM -0600, boB Stepp wrote: > I am still puzzling over things from the thread, "Why does > os.path.realpath('test_main.py') give different results for unittest > than for testing statement in interpreter?" The basic question I am > trying to answer is how to

[Tutor] When is and isn't "__file__" set?

2018-01-10 Thread boB Stepp
I am actually interested in the answer to this question for Python versions 2.4, 2.6 and 3.x. At https://docs.python.org/3/reference/import.html?highlight=__file__#__file__ it says: __file__ is optional. If set, this attribute’s value must be a string. The import system may opt to leave

Re: [Tutor] delete strings from specificed words

2018-01-10 Thread Cameron Simpson
On 09Jan2018 22:20, YU Bo wrote: The text i will working as follow: ```text [...] diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index a789f952b3e9..443892dabedb 100644 [...] +++ b/tools/perf/util/util.c [...] ``` In fact, this is a patch from lkml,my

Re: [Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?

2018-01-10 Thread Alan Gauld via Tutor
On 10/01/18 20:20, eryk sun wrote: > ... And working with COM via ctypes is also complex, which is why > comtypes exists. Or easier still Pythonwin (aka PyWin32). I far prefer pythonwin over ctypes for any kind of COM work. -- Alan G Author of the Learn to Program web site

Re: [Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?

2018-01-10 Thread eryk sun
On Wed, Jan 10, 2018 at 12:59 PM, Albert-Jan Roskam wrote: > > I tried: from os.path import _getfullpathname _getfullpathname(r"H:") > 'h:\\path\\to\\folder' import os os.getcwd() > 'h:\\path\\to\\folder' > > I expected h:\ to be \\server\share\foo.

Re: [Tutor] question about metaclasses

2018-01-10 Thread Peter Otten
Albert-Jan Roskam wrote: > Why does following the line (in #3) > # 3- > class Meta(type): > def __new__(cls, name, bases, attrs): > for attr, obj in attrs.items(): > if attr.startswith('_'): > continue >

Re: [Tutor] question about metaclasses

2018-01-10 Thread Zachary Ware
On Wed, Jan 10, 2018 at 10:08 AM, Albert-Jan Roskam wrote: > Hi, > > > In another thread on this list I was reminded of types.SimpleNamespace. This > is nice, but I wanted to create a bag class with constants that are > read-only. My main question is about example #3

Re: [Tutor] question about metaclasses

2018-01-10 Thread Steven D'Aprano
On Wed, Jan 10, 2018 at 04:08:04PM +, Albert-Jan Roskam wrote: > In another thread on this list I was reminded of > types.SimpleNamespace. This is nice, but I wanted to create a bag > class with constants that are read-only. If you expect to specify the names of the constants ahead of

[Tutor] question about metaclasses

2018-01-10 Thread Albert-Jan Roskam
Hi, In another thread on this list I was reminded of types.SimpleNamespace. This is nice, but I wanted to create a bag class with constants that are read-only. My main question is about example #3 below (example #2 just illustrates my thought process). Is this a use case to a metaclass? Or

Re: [Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?

2018-01-10 Thread Albert-Jan Roskam
From: eryk sun Sent: Wednesday, January 10, 2018 3:56 AM To: tutor@python.org Cc: Albert-Jan Roskam Subject: Re: [Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?   On Tue, Jan 9, 2018 at 2:48

Re: [Tutor] delete strings from specificed words

2018-01-10 Thread YU Bo
Hi, On Wed, Jan 10, 2018 at 10:37:09AM +0100, Peter Otten wrote: YU Bo wrote: index 45a63e0..3b9b238 100644 ... ``` I want to delete string from *diff --git* to end, because too many code is here Use str.split() or str.partition() and only keep the first part: text = """The registers rax,

Re: [Tutor] delete strings from specificed words

2018-01-10 Thread Peter Otten
YU Bo wrote: > ```text > The registers rax, rcx and rdx are touched when controlling IBRS > so they need to be saved when they can't be clobbered. > > diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h > index 45a63e0..3b9b238 100644 > ... > ``` > I want to delete string from *diff

Re: [Tutor] delete strings from specificed words

2018-01-10 Thread YU Bo
Hi, First, thank you very much for your reply. On Tue, Jan 09, 2018 at 10:25:11PM +, Alan Gauld via Tutor wrote: On 09/01/18 14:20, YU Bo wrote: But, i am facing an interesting question.I have no idea to deal with it. I don;t think you have given us enough context to be able to help