python正则表达式从路径中取文件名出来不加后缀(txt)
正则表达式[^\\/:*?"<>|\r\n]+$ ---->取文件名包括后缀
e.g. >>>D:\PyCharm 2018.2.4\pythonWork\venv\Scripts\python.txt
->python.txt
正则表达式(.+?)\.txt ---->取上次结果去掉后缀
e.g. >>>python.txt
->python 部分代码应用截取>>>
def send():
sendfile = tk.Tk()
sendfile.withdraw() file_path = filedialog.askopenfilename()
print(file_path) newName = re.findall(r'[^\\/:*?"<>|\r\n]+$',file_path)
newName = re.findall(r'(.+?)\.txt',newName[0]) os.system('python markup.py < %s > d:/%s.html '%(file_path,newName[0]))
取路径中最后一个‘/’前的所有内容包括最后一个‘/’
newNamepath = re.findall(r'(.+/).+?\.',file_path)
print(newNamepath[0]) # 打印文件的路径
e.g.>>>D:/PyCharm 2018.2.4/pythonWork/item1/test_input.txt
-->D:/PyCharm 2018.2.4/pythonWork/item1/
python正则表达式从路径中取文件名出来不加后缀(txt)的更多相关文章
- 【php】 php获取文件路径中的文件名和文件后缀方法
获取文件名 $file = realpath(__DIR__.'/images/common/../addBtn.png'); 方法一 $file = realpath(__DIR__.'/image ...
- Java获取路径中的文件名(正则表达式)
Java获取路径中的文件名(正则表达式) 目标 在这个路径中我想得到model2 /E:/2017-02-21--SoftWare/github/test/Java/poiDemo_word2exce ...
- python和C语言从路径中获取文件名
1.Python import os file_name = os.path.basename(filepath)#带后缀的文件名(不含路径) file_name_NoExtension = os.p ...
- Python正则表达式使用过程中的小细节
今天用Python写了个简单的爬虫程序,抓取虎扑篮球(nba.hupu.com)的首页内容,代码如下: #coding:gb2312 import urllib2, re webpage = urll ...
- 一个简易的Python爬虫,将爬取到的数据写入txt文档中
代码如下: import requests import re import os #url url = "http://wiki.akbfun48.com/index.php?title= ...
- 论 Python Opencv 中文路径及中文文件名图像文件读取的两种方式
python 2中对于中文字符的处理可谓是诟病已久,虽然python 3 使用统一编码解决了中文字符串的问题,但在使用opencv中imread函数读取中文路径图像文件时仍会报错. 1) 借助nump ...
- R语言:提取路径中的文件名字符串(basename函数)
假设存在路径C:/coverage/Homo_sapiens.sort.add_exon1_coverage.txt,欲提取Homo_sapiens.sort.add_exon1_coverage.t ...
- Spring MVC-从零开始-@RequestMapping结合@PathVariable (从URL路径中取值,作用于函数参数)
1.可以直接在RequestMapping中value元素中使用{key}描述属性键 2.也可以在{key}中使用正则限定key的取值范围,从而限定url的变化范围 package com.jt; i ...
- 3种Java从文件路径中获取文件名的方法
package test; import java.io.File; public class FileName { /** * @param args */ public static void m ...
随机推荐
- 设计模式之第12章-享元模式(Java实现)
设计模式之第12章-享元模式(Java实现) “怎么回事,竟然出现了OutOfMemory的错误.鱼哥,来帮我看看啊.”“有跟踪错误原因么?是内存泄露么?”“不是内存泄露啊,具体原因不知道啊.对了,有 ...
- 【Surrounded Regions】cpp
题目: Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is capt ...
- UNIX 系统中 wc 程序的主要部分
以下代码为 UNIX 系统中 wc 程序的骨干部分 #include <stdio.h> #define IN 1 #define OUT 0 int main(int argc, cha ...
- IOS开发学习笔记033-UIScrollView
1.滚动显示图片 如果图片过大,则需要滚动显示,这是需要用到类UIScrollView,可是实现控件的水平和垂直滚动. 可用三步实现:1 设置UIScrollView,2 设置UIImageView, ...
- 区分Activity的四种加载模式【转载】
此文为转载,文章来源:http://marshal.easymorse.com/archives/2950 文章作者: Marshal's Blog 参考文章:http://blog.csdn.n ...
- Spring整合hibernate -SessionFactory
本文目录 1 本文采用 hibernate4 整合 Spring3.1 2 把Spring获取datasource通过class="org.springframework.orm.hibe ...
- android实现前置后置摄像头相互切换
首先自定义一个继承自SurfaceView并且实现了SurfaceHolder.Callback接口的组件: public class CameraView extends SurfaceView i ...
- springboot集成pagehelper插件
1.在pom.xml中引入依赖 <dependency> <groupId>com.github.pagehelper</groupId> <artifact ...
- 【转】behave行为树学习使用第一天
最近在学习使用行为树做AI,决定把学到的贡献出来,抛砖引玉,希望可以认识到更多大牛 -- 首先我们了解下什么是行为树和为什么要使用行为树. 在我们项目中如果需要做一个AI敌人,比如做一个手游 某民 ...
- Vue2.0 - 自定义指令 vue-directive
Vue.directive('指令',function(el,binding,vnode){ el.style='color:'+binding.value;}); el : 指令所绑定的元素,可以用 ...