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

热点内容
文件夹0项什么意思 浏览:602
空调冷媒压缩机启动 浏览:911
流氓文件夹怎么强制删除 浏览:783
嵌入式基础命令 浏览:526
当程序员必学的编程语言 浏览:906
pro文件夹有什么用 浏览:357
我的世界服务器有人开挂如何踢出 浏览:482
程序员有天赋 浏览:640
编程计算并输出半径 浏览:709
日期排序java 浏览:953
程序员的中介模式 浏览:881
python中求两个字符串重复部分 浏览:495
如何查看收件发件服务器 浏览:110
linux配置android环境变量 浏览:132
android文字测量 浏览:883
压力大金钱怎么解压 浏览:641
生男算法 浏览:771
php读取当前目录 浏览:440
说一个可以连接的服务器地址 浏览:508
操盘手1pdf 浏览:536