针对是否可以使用Python访问GetLongPathName和Win32API?这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展centos7.2getpidbyprocessnamewi
针对是否可以使用Python访问GetLongPathName和Win32 API?这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展centos7.2 get pid by process name with python3.6、Cpp调用Python3,使用matplotlib画(二维)图----1.配置(Clion,mingW64, python, matplotlib)、Django -Python Copyfile 使用 win32api 权限被拒绝、IronPython的任何替代品,Python for .NET用于从python访问CLR?等相关知识,希望可以帮助到你。
本文目录一览:- 是否可以使用Python访问GetLongPathName()Win32 API?(python怎么访问)
- centos7.2 get pid by process name with python3.6
- Cpp调用Python3,使用matplotlib画(二维)图----1.配置(Clion,mingW64, python, matplotlib)
- Django -Python Copyfile 使用 win32api 权限被拒绝
- IronPython的任何替代品,Python for .NET用于从python访问CLR?
是否可以使用Python访问GetLongPathName()Win32 API?(python怎么访问)
我需要将8.3约定中的路径转换为完整路径。在Perl中,可以使用如何从Perl的8.3
DOS路径获取完整的Win32路径中Win32::GetLongPathName()
指出的方式使用。但是,我需要在Python中执行此操作。
centos7.2 get pid by process name with python3.6
centos7.2 get pid by process name with python3.6
#-*- encoding:UTF-8 -*-
import os
import sys
import string
import psutil
import re
def get_pid(name):
process_list = psutil.pids()
pid = 0
for i in range(0,len(process_list)):
p = psutil.Process(process_list[i])
if len(p.cmdline())>=2:
process_info = str(p.cmdline()[1])
result = process_info.find(name)
if result != -1:
pid = process_list[i]
break
print(pid)
return pid
def main(argv):
name = argv[1]
#print(name)
get_pid(name)
if __name__ == "__main__":
main(sys.argv)
关于:psutil 5.2.2使用说明参见:
https://pypi.python.org/pypi/psutil/5.2.2
Example usages
cpu
>>> import psutil >>> psutil.cpu_times() scputimes(user=3961.46, nice169.729, system2150.659, idle16900.540, iowait629.59, irq0.0, softirq19.42, stealguest=0,112)">0.0) >>> >>> for x in range(3): ... psutil.cpu_percent(interval1) ... 4.0 5.9 3.8 1, percpu=True) ... [4.0, 6.9,112)">3.7,112)">9.2] [7.0,112)">8.5,112)">2.4,112)">2.1] [1.2,112)">9.0,112)">9.9,112)">7.2] .cpu_times_percent(intervalFalse) ... scputimes(user1.5,112)">0.5,112)">96.5, guest_nice0.0) scputimes(user1.0,112)">99.0,112)">2.0,112)">98.0,102)">.cpu_count() 4 .cpu_count(logicalFalse) 2 .cpu_stats() scpustats(ctx_switches20455687, interrupts6598984, soft_interrupts2134212, syscalls0) .cpu_freq() scpufreq(current931.42925, min800.0,32)">max3500.0) >>>
.virtual_memory() svmem(total10367352832, available6472179712, percent37.6, used8186245120, free2181107712, active4748992512, inactive2758115328, buffers790724608, cached3500347392, shared787554304) .swap_memory() sswap(total2097147904,112)">296128512,112)">1801019392,112)">14.1, sin304193536, sout677842944) >>>
.disk_partitions() [sdiskpart(device='/dev/sda1', mountpoint'/', fstype'ext4', opts'rw,nosuid'), sdiskpart(device'/dev/sda2',160)">'/home',160)">'ext,opts='rw')] .disk_usage('/') sdiskusage(total21378641920,112)">4809781248,112)">15482871808,112)">22.5) .disk_io_counters(perdiskFalse) sdiskio(read_count719566, write_count1082197, read_bytes18626220032, write_bytes24081764352, read_time5023392, write_time63199568, read_merged_count619166, write_merged_count812396, busy_time4523412) >>>
.net_io_counters(pernicTrue) {'eth0': netio(bytes_sent485291293, bytes_recv6004858642, packets_sent3251564, packets_recv4787798, errinerrout dropin dropout0), 'lo': netio(bytes_sent2838627,112)">30567,112)">0)} .net_connections() [pconn(fd115, family=<AddressFamily.AF_INET: 2>,32)">type=<SocketType.SOCK_STREAM: 1 laddr=('10.0.0.1', 48776), raddr'93.186.135.91',112)">80), status'ESTABLISHED', pid1254), pconn(fd117,112)">43761),160)">'72.14.234.100',160)">'CLOSING',112)">2987),102)">=-60759),160)">'72.14.234.104',32)">None),112)">51314),160)">'72.14.234.83',112)">443),160)">'SYN_SENT',32)">None) ...] .net_if_addrs() {'lo': [snic(family address'127.0.0.1', netmask'255.0.0.0', broadcast ptp snic(family.AF_INET6: 10'::1',160)">'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',32)">None,102)">.AF_LINK: 17'00:00:00:00:00:00',32)">None)],160)">'wlan0': [snic(family'192.168.1.3',160)">'255.255.255.0',160)">'192.168.1.255', snic(family'fe80::c685:8ff:fe45:641%wlan0',160)">'ffff:ffff:ffff:ffff::',160)">'c4:85:08:45:06:41',160)">'ff:ff:ff:ff:ff:ff',32)">None)]} .net_if_stats() {'eth0': snicstats(isupTrue, duplex=<NicDuplex.NIC_DUPLEX_FULL: speed100, mtu1500),160)">'lo': snicstats(isup.NIC_DUPLEX_UNKNowN: 065536)} >>>
.sensors_temperatures() {'acpitz': [shwtemp(label'', current47.0, high103.0, critical103.0)],160)">'asus': [shwtemp(label'coretemp': [shwtemp(label'Physical id 0',112)">52.0,112)">100.0,112)">100.0), shwtemp(label'Core 0',112)">45.0,160)">'Core 1',160)">'Core 2',160)">'Core 3',112)">100.0)]} .sensors_fans() {'asus': [sfan(label'cpu_fan',112)">3200)]} .sensors_battery() sbattery(percent93, secsleft16628, power_plugged>>>
.users() [user(name'giampaolo', terminal'pts/2', host'localhost', started1340737536.0), user(name'pts/3',112)">1340737792.0)] .boot_time() 1365519115.0 >>>
.pids() [2,112)">3,112)">4,112)">5,112)">6,112)">7,112)">46,112)">48,112)">50,112)">51,112)">178,112)">182,112)">222,112)">223,112)">224,112)">268,112)">1215,112)">1216,112)">1220,112)">1221,112)">1243,112)">1244, 1301,112)">1601,112)">2237,112)">2355,112)">2637,112)">2774,112)">3932,112)">4176,112)">4177,112)">4185,112)">4187,112)">4189,112)">4225,112)">4243,112)">4245,112)">4263,112)">4282,112)">4306,112)">4311,112)">4312,112)">4313,112)">4314,112)">4337,112)">4339,112)">4357,112)">4358,112)">4363,112)">4383,112)">4395,112)">4408,112)">4433,112)">4443,112)">4445,112)">4446,112)">5167,112)">5234,112)">5235,112)">5252,112)">5318,112)">5424,112)">5644,112)">6987,112)">7054,112)">7055,112)">7071] >>> p = psutil.Process(7055) >>> p.name() 'python' .exe() '/usr/bin/python' .cwd() '/home/giampaolo' .cmdline() ['/usr/bin/python', 'main.py'] .pid 7055 .ppid() 7054 .parent() <psutil.Process(pidname'bash') at 140008329539408> .children() [8031,160)">'python') at 14020832451977 8044,112)">19229444921932>] .status() 'running' .username() 'giampaolo' .create_time() 1267551141.5019531 .terminal() '/dev/pts/0' .uids() puids(real1000, effective saved1000) .gids() pgids(real.cpu_times() pcputimes(user1.02,112)">0.31, children_user0.32, children_system0.1) 1.0) 12.1 .cpu_affinity() [3] .cpu_affinity([1]) # set .cpu_num() 1 .memory_info() pmem(RSS10915840, vms67608576,112)">3313664, text2310144, lib data7262208, dirty.memory_full_info() # "real" USS memory usage (Linux,OSX,Win only) pfullmem(RSS10199040,112)">52133888,112)">3887104,112)">2867200,112)">5967872, uss6545408, pss6872064, swap.memory_percent() 0.7823 .memory_maps() [pmmap_grouped(path'/lib/x8664-linux-gnu/libutil-2.15.so', RSS32768, size2125824, shared_clean shared_dirty private_clean20480, private_dirty12288, referenced anonymous pmmap_grouped(path'/lib/x8664-linux-gnu/libc-2.15.so',112)">3821568,112)">3842048,112)">3575808,160)">'/lib/x8664-linux-gnu/libcrypto.so.0.1',112)">34124,112)">2134016,112)">15360,112)">24576,112)">8192,160)">'[heap]', RSS139264,160)">'[stack]',112)">2465792,112)">2494464,112)">2277376,102)">.io_counters() pio(read_count478001,112)">59371,112)">700416,112)">69632, read_chars456232, write_chars517543) .open_files() [popenfile(path'/home/giampaolo/svn/psutil/setup.py', fd position mode'r', flags32768), popenfile(path'/var/log/monitd',112)">235542,160)">'a',112)">33793)] .connections() [pconn(fd'ESTABLISHED'),160)">'CLOSING'),112)">119,112)">123,160)">'SYN_SENT')] .num_threads() .num_fds() 8 .threads() [pthread(id user_time22.5, system_time9.2891), pthread(0.0),112)">5236,112)">5237,112)">0.0707,112)">1.1)] .num_ctx_switches() pctxsw(voluntary78, involuntary19) .nice() 0 .nice(10) .ionice(psutil.IOPRIO_CLASS_IDLE) # IO priority (Win and Linux only) .ionice() pionice(ioclass=<IOPriority.IOPRIO_CLASS_IDLE: 3 value.rlimit(psutil.RLIMIT_NOFILE, (5)) # set resource limits (Linux only) .RLIMIT_NOFILE) (5) .environ() {'LC_PAPER': 'it_IT.UTF-8',160)">'SHELL': '/bin/bash',160)">'GREP_OPTIONS': '--color=auto', 'XDG_CONfig_Dirs': '/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg',160)">'COLORTERM': 'gnome-terminal',102)">...} .as_dict() {'status': 'running',160)">'num_ctx_switches': pctxsw(voluntary63,112)">1),160)">'pid': 5457, .is_running() True .suspend() .resume() .terminate() .wait(timeout3) .test() USER PID %cpu %MEM VSZ RSS TTY START TIME COMMAND root 1 0.0 0.0 24584 2240 Jun17 00:00 init root 2 0.0 0 0 Jun17 00 kthreadd root 3 05 ksoftirqd/... giampaolo 31475 20760 3024 /dev/pts0 Jun19 00 python2.4 giampaolo 31721 2.2 773060 181896 04 10:30 chrome root 31763 0 05 00 kworker0:>>>
for p in psutil.process_iter(): ... print(p) ... psutil'init') psutil'kthreadd') psutil'ksoftirqd/0') ... def on_terminate(proc): print("process {} terminated".format(proc)) >>> # waits for multiple processes to terminate >>> gone, alive .wait_procs(procs_list, timeoutcallback=on_terminate) >>>
>>> list(psutil.win_service_iter()) [<WindowsService(name'AeLookupSvc', display_name'Application Experience') at 38850096'ALG',160)">'Application Layer Gateway Service') at 38850128'APNMCP',160)">'Ask Update Service') at 38850160'AppIDSvc',160)">'Application Identity') at 38850192>>> s .win_service_get('alg') >>> s'binpath': 'C:\\WindowsSystem32alg.exe',160)">'description': 'Provides support for 3rd party protocol plug-ins for Internet Connection Sharing',160)">'display_name': 'Application Layer Gateway Service',160)">'name': 'alg',160)">'pid': 'start_type': 'manual',160)">'stopped',160)">'username': 'NT AUTHORITYLocalService'}
Cpp调用Python3,使用matplotlib画(二维)图----1.配置(Clion,mingW64, python, matplotlib)
To my knowledge so far, Cpp画图是真滴捉急, 那就调用python帮帮忙吧。
百度了好久,试了好几次,终于走完了配置的过程。我要记录一下。
1.0 配置:(操作系统)64位Win7, (Cpp的IDE是)Clion。
1.1 安装Clion
官网下载就可以了,地址 https://www.jetbrains.com/clion/
1.2 安装,配置mingW64
1.2.1:Clion需要我们安装Toolchain,我用的是mingW64(因为我用的是64位系统),附上百度网盘地址。
地址:https://pan.baidu.com/s/14FkN0Ul9cvcRxCOcylmoxw,密码:qu5l
1.2.2:然后我一股脑把路径全部添加到环境变量path了
(
D:\ProgramFile\mingw64;
D:\ProgramFile\mingw64\bin;
D:\ProgramFile\mingw64\lib;
D:\ProgramFile\mingw64\include
)
1.2.3:让Clion找到mingw64
如果其中的Make, C Complier,C++ Complier没找到,就手动帮Clion添加。
!!!注意mingw的版本(指的是64位还是32位),一定要和pyhton的匹配。否则会出现如下错误:
载入Python.h:没问题 ; 读取其中函数:unreferenced...
1.3 安装python
1.3.1 安装python3.7
我的安装目录是 D:\ProgramFile\Python37 ,没有用Anaconda,事实上(可能是由于环境变量path中争抢调用关系的问题),我把原来装好的anaconda卸载了。
安装的版本是官网下载的。
同时,添加了 D:\ProgramFile\Python37到环境变量path。
1.3.2 用pip安装matplotlib
a. python3.7中的pip是自带的
b. 将python安装目录下的scripts添加到环境变量bin
c. (可选)查看python是否安装成功:在cmd界面,输入:python --version
d. (可选)查看pip是否安装成功:在cmd界面,输入:pip --version
e. (可选)升级pip:在cmd界面,输入:python -m pip install -U pip setuptools
f. 用pip安装matplotlib:在cmd界面,输入:python -m pip install matplotlib
1.4 Clion联结Cpp和python
1.4.1:CMakeLists.txt的配置:
用clion新建cpp的project,在CMakeLists.txt中添加以下两句话
# 添加python.h头文件路径
include_directories(D:/ProgramFile/Python37/include)
# 添加python动态链接库文件
link_libraries(D:/ProgramFile/Python37/libs/python37.lib)
如下图:
1.4.2:main.cpp的配置
我直接上图吧,如果这个cpp可以运行,那么说明配置成功了。
Django -Python Copyfile 使用 win32api 权限被拒绝
如何解决Django -Python Copyfile 使用 win32api 权限被拒绝?
我希望在服务器上实现一个副本,我在我的网络服务器的客户端 HTML 上单击一个按钮,服务器实现了服务器内特定文件从固定目的地到服务器内另一个目的地的副本本身。服务器是基于 Windows 的,所以我使用了 win32api copyFile 方法,但它显示了访问被拒绝的错误。我该如何解决这个问题?我已尝试为驱动器设置权限。似乎 Django 为此需要管理权限,但不确定。欢迎使用其他解决方案。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
IronPython的任何替代品,Python for .NET用于从python访问CLR?
解决方法
(我对.NET com interop还不太了解,所以希望其他人可以提供进一步的解释.)
关于是否可以使用Python访问GetLongPathName和Win32 API?的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于centos7.2 get pid by process name with python3.6、Cpp调用Python3,使用matplotlib画(二维)图----1.配置(Clion,mingW64, python, matplotlib)、Django -Python Copyfile 使用 win32api 权限被拒绝、IronPython的任何替代品,Python for .NET用于从python访问CLR?等相关知识的信息别忘了在本站进行查找喔。
本文标签: