导航:首页 > 编程语言 > python获取当前方法名

python获取当前方法名

发布时间:2023-08-04 20:15:43

python怎样获取当前打开的文件的文件名

import os.path

f1 = open(m,'r') #打开文件

filename=os.path.basename(f1.name) #用f1.name得到文件路径,os.path.basename得到文件名

Ⅱ python获取指定目录下所有文件名列表的方法


本文实例讲述了python获取指定目录下所有文件名列表的方法。分享给大家供嫌返厅大家参考。具体实现方法如下:世拦
这里python代码实现获取文件名列表的功能,可以指定文件中包含的字符,方便提取特定类型的文件名列表:
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
#~ #------------------------------------------------------------------
#~ mole:wlab
#~ Filename:wgetfilelist.py
#~ Function :
#~ def IsSubString(SubStrList,Str)
#~ def GetFileList(FindPath,FlagStr=[]):
#~ 功能:读取芹隐指定目录下特定类型的文件名列表
#~ Data: 2013-08-08,星期四
#~ Author:吴徐平
#~ Email:[email protected]
#~ #------------------------------------------------------------------
#~ #------------------------------------------------------------------
def IsSubString(SubStrList,Str):
#判断字符串Str是否包含序列SubStrList中的每一个子字符串
#SubStrList=[F,EMS,txt]
#Str=F06925EMS91.txt
#IsSubString(SubStrList,Str)#return True (or False)
flag=True
for substr in SubStrList:
if not(substr in Str):
flag=False
return flag
#~ #----------------------------------------------------------------------
def GetFileList(FindPath,FlagStr=[]):
#获取目录中指定的文件名
#FlagStr=[F,EMS,txt] #要求文件名称中包含这些字符
#FileList=GetFileList(FindPath,FlagStr) #
import os
FileList=[]
FileNames=os.listdir(FindPath)
if (len(FileNames)0):
for fn in FileNames:
if (len(FlagStr)0):
#返回指定类型的文件名
if (IsSubString(FlagStr,fn)):
fullfilename=os.path.join(FindPath,fn)
FileList.append(fullfilename)
else:
#默认直接返回所有文件名
fullfilename=os.path.join(FindPath,fn)
FileList.append(fullfilename)
#对文件名排序
if (len(FileList)0):
FileList.sort()
return FileList
可以使用pip在线安装wlab
?
1
pip install wlab
还是给个图吧:
希望本文所述对大家的Python程序设计有所帮助。

Ⅲ 如何用python获取某一文件下所有函数名

import test
help(test)

Ⅳ python能不能动态获取运行的文件名

不清楚你的问题是什么?是指在程序当中获取本程序的文件名称吗?可以使用sys.argv来传递这个参数。

例如,建立一个Python代码文件,起名为self_known.py。内含以下内容:

importsys
printsys.argv[0]

运行这个文件:

pythonself_known.py

可以发现运行结果就是文件名称:

self_known.py


在运行Python代码时,不仅可以送入“文件名称”一个参数,还可以送入更多参数:

pythonself_known.pyarg1arg2arg3

此时,在代码文件中可以这样得到这些参数:

printsys.argv[0]
printsys.argv[1]
printsys.argv[2]
printsys.argv[3]

Ⅳ python如何获取函数的参数名

我这里用的是IDLE(我自己也觉得有点低端),Python3(2应该也可以)
>>> help()

Welcome to Python 3.7's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.7/tutorial/.

Enter the name of any mole, keyword, or topic to get help on writing
Python programs and using Python moles. To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available moles, keywords, symbols, or topics, type
"moles", "keywords", "指型旁symbols", or "topics". Each mole also comes
with a one-line summary of what it does; to list the moles whose name
or summary contain a given string such as "spam", type "moles spam".

help> sum
Help on built-in function sum in mole builtins:

sum(iterable, start=0, /)
Return the sum of a 'start' value (default: 0) plus an iterable of numbers

When the iterable is empty, return the start value.
This function is intended specifically for use with numeric values and may
reject non-numeric types.
解释一下:先在Shell输入help(),它就会问你你要哪个租辩函数的说明。然后你输入对应函数(比如sum),就可以看到这一行:sum(iterable, start=0, /),也就是说你要先输入iterable参数,start可以选择输入(有默认值)。

或唯橡者还有一种方法:用的时候直接输入函数加上左括号 比如sum( 然后你就可以看到下面有一个框,然后按照说明写就好了。如果不小心不见了,就可以把左括号去掉再重新输入,就可以再看到这个框啦!

Ⅵ python如何获取不含路径的当前文件夹的名称(不含子目录)

import os
print(os.getcwd())
print(os.getcwd().split('\')[-1])

阅读全文

与python获取当前方法名相关的资料

热点内容
python爬虫框架推荐 浏览:518
matlab遗传算法适应度函数 浏览:129
制作linux系统镜像 浏览:154
域名解析服务器ip地址不能正常 浏览:845
程序员十万个为什么 浏览:535
维信卡卡贷app怎么下载不了 浏览:919
qdim命令使用 浏览:873
截图R命令 浏览:654
基于单片机的智能台灯设计 浏览:685
多余app是怎么兑换皮肤的 浏览:552
sql数据库查询表命令 浏览:551
简单音乐网站源码 浏览:644
运动健康app华为手表怎么连接 浏览:748
肌肉塑造全书pdf下载 浏览:796
安卓简约拼图用什么软件好 浏览:289
fx1n加密程序 浏览:844
淘客阿里云服务器 浏览:476
100压缩打造 浏览:422
安卓手机怎么和苹果平板传文件 浏览:973
开始选项卡中的页眉和页脚命令选项 浏览:424