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

热点内容
云引擎云服务器 浏览:903
解压视频声控吃冰意大利 浏览:401
涡旋压缩机动涡盘 浏览:875
手机邮件发文件夹 浏览:446
魔兽世界怀旧服tbc萨满宏命令 浏览:546
linuxsvn手册 浏览:264
程序员图鉴 浏览:537
东营程序员 浏览:714
发票上传参数没置服务器地址 浏览:43
程序员网上接单能挣多少钱 浏览:179
稀有传奇手游源码 浏览:551
u盘里的cd驱动加密是什么 浏览:419
遗传算法编码长度 浏览:978
pe装服务器需要注意什么 浏览:324
foreach计数php 浏览:529
php自连接 浏览:300
程序员被喷了怎么办 浏览:713
android消息数 浏览:265
为什么在服务器里输不了指令 浏览:33
程序员那么可爱前女友剧情介绍 浏览:106