导航:首页 > 编程语言 > 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获取当前方法名相关的资料

热点内容
吧杂志解压密码 浏览:835
风险普查app如何绘图 浏览:559
钢制防火卷帘加密喷头 浏览:379
安卓手机文件怎么转到旧苹果手机 浏览:601
2015肖秀荣pdf 浏览:396
如何给手机的卡包加密 浏览:441
安卓微信如何更换铃声 浏览:599
程序员谈判场在哪里 浏览:413
山东有线服务器中断云主机 浏览:472
java截取文件名 浏览:463
jquery教程pdf 浏览:164
三略pdf 浏览:584
spiflash单片机 浏览:11
阿里云的域名怎么解析到国外服务器 浏览:299
app客户端开发用什么服务器 浏览:293
台湾人能备案云服务器吗云空间 浏览:468
程序员小哥哥都喜欢动漫 浏览:374
如何用免费亚马逊云搭建服务器 浏览:665
php评论功能实现代码 浏览:526
犀牛中移动物件命令 浏览:788