How to get desktop path in python Đầy đủ Chi tiết

Thủ Thuật Hướng dẫn How to get desktop path in python Đầy đủ Mới Nhất

Bạn đang tìm kiếm từ khóa How to get desktop path in python Đầy đủ được Cập Nhật vào lúc : 2022-02-17 08:13:00 . Với phương châm chia sẻ Kinh Nghiệm Hướng dẫn trong nội dung bài viết một cách Chi Tiết 2022. Nếu sau khi Read nội dung bài viết vẫn ko hiểu thì hoàn toàn có thể lại phản hồi ở cuối bài để Ad lý giải và hướng dẫn lại nha.

Mẹo Hướng dẫn How to get desktop path in python Mới Nhất

Bạn đang tìm kiếm từ khóa How to get desktop path in python được Update vào lúc : 2022-02-17 08:13:06 . Với phương châm chia sẻ Bí quyết về trong nội dung nội dung bài viết một cách Chi Tiết 2022. Nếu sau khi tìm hiểu thêm tài liệu vẫn ko hiểu thì hoàn toàn hoàn toàn có thể lại Comment ở cuối bài để Ad lý giải và hướng dẫn lại nha.

trang chủ
python
Summary of five methods for Python to obtain windows desktop path

    2022-07-18 08:36:07
    OfStack

Here introduced 5 python to get window desktop path method, get this path is of what use? 1 is to output the documents generated by the program to the desktop for easy viewing and editing.

The first two methods are to obtain the absolute path of the current windows desktop through the registry, and the first one is recommended for comparison, because there is no need to install additional extensions, and others can be understood

1. Use the built-in winreg (recommended)

import _winreg

def get_desktop():

key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,r’SoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders’)

return _winreg.QueryValueEx(key, “Desktop”)[0]

2. win32 extension (third party library required)

import win32api,win32con

def get_desktop():

key =win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,r’SoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders’,0,win32con.KEY_READ)

return win32api.RegQueryValueEx(key,’Desktop’)[0]

3. win32 extensions are also required

from win32com.shell import shell, shellcon

def GetDesktopPath():

ilist =shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_DESKTOP)

return shell.SHGetPathFromIDList(ilist)

4. path module of os library built into python

This method may fail after the user changes the desktop path.

import os

def GetDesktopPath():

return os.path.join(os.path.expanduser(“~”), ‘Desktop’)

5. Use the socket module (not recommended)

Of course, this method, Is to get the host name of the current pc, 1 Under normal circumstances, the windows system will set a computer name the beginning of the first time, this computer name will appear in the user directory under the C disk, for example, my computer name is’ jayzhen ‘, then there will be a directory path: C: Users jayzhen, this time my desktop path is: C: Users jayzhen Desktop (the problem is that if you modify the computer name later, this method will not take effect), the code performance is very similar to the fourth

import socket, os

def GetDesktopPath()

hostname = socket.gethostname() #socket.getfqdn(socket.gethostname())

basepath = os.path.join(“C:Users”,hostname )

return os.path.join(basepath, ‘Desktop’)

Reply

5

0

Chia sẻ

Share Link Tải How to get desktop path in python miễn phí

Bạn vừa tìm hiểu thêm Post Với Một số hướng dẫn một cách rõ ràng hơn về Clip How to get desktop path in python tiên tiến và phát triển và tăng trưởng nhất Chia SẻLink Download How to get desktop path in python Free.

Hỏi đáp vướng mắc về How to get desktop path in python

Nếu sau khi đọc nội dung nội dung bài viết How to get desktop path in python vẫn chưa hiểu thì hoàn toàn hoàn toàn có thể lại Comments ở cuối bài để Mình lý giải và hướng dẫn lại nha

#desktop #path #python

Clip How to get desktop path in python Đầy đủ ?

Bạn vừa Read Post Với Một số hướng dẫn một cách rõ ràng hơn về Clip How to get desktop path in python Đầy đủ tiên tiến và phát triển nhất

Share Link Download How to get desktop path in python Đầy đủ miễn phí

You đang tìm một số trong những Chia Sẻ Link Cập nhật How to get desktop path in python Đầy đủ miễn phí.

Thảo Luận vướng mắc về How to get desktop path in python Đầy đủ

Nếu sau khi đọc nội dung bài viết How to get desktop path in python Đầy đủ vẫn chưa hiểu thì hoàn toàn có thể lại Comments ở cuối bài để Tác giả lý giải và hướng dẫn lại nha
#desktop #path #python #Đầy #đủ

Phone Number

Share
Published by
Phone Number

Recent Posts

Tra Cứu MST KHƯƠNG VĂN THUẤN Mã Số Thuế của Công TY DN

Tra Cứu Mã Số Thuế MST KHƯƠNG VĂN THUẤN Của Ai, Công Ty Doanh Nghiệp…

2 years ago

[Hỏi – Đáp] Cuộc gọi từ Số điện thoại 0983996665 hoặc 098 3996665 là của ai là của ai ?

Các bạn cho mình hỏi với tự nhiên trong ĐT mình gần đây có Sim…

2 years ago

Nhận định về cái đẹp trong cuộc sống Chi tiết Chi tiết

Thủ Thuật về Nhận định về nét trẻ trung trong môi trường tự nhiên vạn…

2 years ago

Hướng Dẫn dooshku là gì – Nghĩa của từ dooshku -Thủ Thuật Mới 2022

Thủ Thuật về dooshku là gì - Nghĩa của từ dooshku -Thủ Thuật Mới 2022…

2 years ago

Tìm 4 số hạng liên tiếp của một cấp số cộng có tổng bằng 20 và tích bằng 384 2022 Mới nhất

Kinh Nghiệm Hướng dẫn Tìm 4 số hạng liên tục của một cấp số cộng…

2 years ago

Mẹo Em hãy cho biết nếu đèn huỳnh quang không có lớp bột huỳnh quang thì đèn có sáng không vì sao Mới nhất

Mẹo Hướng dẫn Em hãy cho biết thêm thêm nếu đèn huỳnh quang không còn…

2 years ago