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 PM, Albert-Jan Roskamwrote: > > I think that it would be a great enhancement if os.realpath would return the > UNC path if > given a mapped drive in Windows, if needed as extended path (prefixed with > "\\?\UNC\"). > That's something I use all the time, unlike symlinks, in Windows. pathlib can do this for you, or call os.path._getfinalpathname. I recently helped someone that wanted the reverse, to map the resolved UNC path back to a logical drive: https://bugs.python.org/issue32442 > And I would also welcome a convenience function in the os.path module that > does > expanduser, expandvars, normpath, realpath, and maybe more. pathlib implements expanduser, but it's still lame on Windows for a user other than the current user. It assumes all user profiles are in the same directory instead of directly getting the user's profile path. Anyway, expanduser is of limited use. We can't assume in general that a user's special folders (e.g. Desktop, Documents) are in the default location relative to the profile directory. Almost all of them are relocatable. There are shell APIs to look up the current locations, such as SHGetKnownFolderPath. This can be called with ctypes [1]. For users other than the current user, it requires logging on and impersonating the user, which requires administrator access. [1]: https://stackoverflow.com/a/33181421/205580 You can log a user on without a password by calling LsaLogonUser to request an MSV1 S4U (service for user) logon. The access token will only be identification level, unless the script is running as a SYSTEM service. But identification level is enough to query the location of a user's known folders. I don't recommended calling LsaLogonUser via ctypes if you have the option to write an extension module in C/C++, but I did manage to get it working with ctypes [2]. For example: >>> from security_lsa import logon_msv1_s4u >>> from knownfolders import FOLDERID, get_known_folder_path >>> logon_info = logon_msv1_s4u('Administrator') >>> get_known_folder_path(FOLDERID.Desktop, logon_info.Token) 'C:\\Users\\Administrator\\Desktop' [2]: https://stackoverflow.com/a/4322/205580 Also, please don't use expanduser to enable applications to spam the profile directory with configuration files and directories. Use the local and roaming application data directories. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] delete strings from specificed words
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 much. WE would need some idea of the input and output data (both current and desired) > [PATCH] perf tools: Fix copyfile_offset update of output offset > > We need to increase output offset in each iteration, > not decrease it as we currently do. > It sounds like you are building some kind of pretty printer. Maybe you could use Pythons pretty-print module as a design template? Or maybe even use some of it directly. It just depends on your data formats etc. > In fact, this is a patch from lkml,my goal is to design a kernel podcast > for myself to focus on what happened in kernel. Sorry, I've no idea what lkml is nor what kernel you are talking about. Can you show us what you are receiving, what you are currently producing and what you are trying to produce? Some actual code might be an idea too. And the python version and OS. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] delete strings from specificed words
Hi, I am learning python to reslove issue,which make happy:) But, i am facing an interesting question.I have no idea to deal with it. The text i will working as follow: ```text [PATCH] perf tools: Fix copyfile_offset update of output offset We need to increase output offset in each iteration, not decrease it as we currently do. I guess we were lucky to finish in most cases in first iteration, so the bug never showed. However it shows a lot when working with big (~4GB) size data. Link: http://lkml.kernel.org/n/tip-f4az7t2nxjbjz5tqrv83z64e@xx Signed-off-by: Jiri Olsa--- tools/perf/util/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index a789f952b3e9..443892dabedb 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -210,7 +210,7 @@ static int copyfile_offset(int ifd, loff_t off_in, int ofd, loff_t off_out, u64 size -= ret; off_in += ret; - off_out -= ret; + off_out += ret; } munmap(ptr, off_in + size); -- 2.13.6 ``` In fact, this is a patch from lkml,my goal is to design a kernel podcast for myself to focus on what happened in kernel. I have crawled the text with python and want to remove strings from *diff --git*, because reading the git commit above, i have a shape in head. I have tried split(), replace(), but i have no idea to deal with it. I will appericate if you have any idea. Thanks! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?
From: Tutoron behalf of Steven D'Aprano Sent: Tuesday, January 9, 2018 8:47 AM To: tutor@python.org Subject: Re: [Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter? > The Python 3.5 source code for os.path.realpath under Windows looks like > this: > ># realpath is a no-op on systems without islink support > realpath = abspath Déjà-vu [1], but I think that it would be a great enhancement if os.realpath would return the UNC path if given a mapped drive in Windows, if needed as extended path (prefixed with "\\?\UNC\"). That's something I use all the time, unlike symlinks, in Windows. And I would also welcome a convenience function in the os.path module that does expanduser, expandvars, normpath, realpath, and maybe more. I haven't used pathlib yet. Will os.path development some day be frozen so pathlib becomes the standard? It seems to be nicer. [1] http://python.6.x6.nabble.com/Tutor-getUncPath-mappedDrive-td4652304.html ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?
On Mon, Jan 08, 2018 at 05:08:49PM -0600, boB Stepp wrote: > Hi Steve, > > On Mon, Jan 8, 2018 at 12:47 AM, Steven D'Apranowrote: > > > As I actually explained in my previous email, the one which has > > disappeared into the aether, ... > > Do you still have the email you sent? I would like to read it if you > don't mind sending it to me. Mystery solved. I've been sending to the wrong email address... Fixed now, and re-sent to the list. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor