之前发过一篇关于定位csv中的特殊字符的,主要是用到了python的自带的函数,近期又遇到了一些新的问题,比如isdigit()的缺点在于不能判断浮点型,以及小数中有多个小数点的情况.发现还是正则表达式更灵活一些. import pandas as pd import numpy as np import csv import re def is_chinese(uchar): if u'\u4e00' <= uchar <= u'\u9fff': return True else: retu…
ref:https://www.cnblogs.com/jiangxinnju/p/5137760.html?utm_source=tuicool&utm_medium=referral 如何在大量jar包中搜索特定字符 -------------------------------------------------- 如果在jar包只搜索文件名呢?例如搜索一个类文件在哪个jar包里面 find foo/ -name "*.jar" | xargs grep Hello.cl…
分析 在Python中,字符串是不可变的.所以无法直接删除字符串之间的特定字符. 所以想对字符串中字符进行操作的时候,需要将字符串转变为列表,列表是可变的,这样就可以实现对字符串中特定字符的操作. 1.删除特定字符 特定字符的删除,思路跟插入字符类似. 可以分为两类,删除特定位置的字符 或者 删除指定字符. 1.1.删除特定位置的字符 使用.pop()方法.输入参数,即为要删除的索引. string = '公众号:土堆碎念' list_str = list(string) list_str.po…
欢迎关注我的社交账号: 博客园地址: http://www.cnblogs.com/jiangxinnju/p/4781259.html GitHub地址: https://github.com/jiangxincode 知乎地址: https://www.zhihu.com/people/jiangxinnju 邮箱: jiangxinnju@163.com 工作中定位某些问题时需要在jar包中搜索某些特定的字符.如果jar包数量比较少可以直接使用JD-GUI等反编译软件导出源码,但是如果ja…
例1: 字符串: '湖南省长沙市岳麓区麓山南路麓山门' 提取:湖南,长沙 在不用正则表达式的情况下: address = '湖南省长沙市岳麓区麓山南路麓山门' address1 = address.split('省') # 用“省”字划分字符串,返回一个列表 address2 = address1[1].split('市') # 用“市”字划分address1列表的第二个元素,返回一个列表 print(address1) # 输出 ['湖南', '长沙市岳麓区麓山南路麓山门'] print(ad…
需要从sftp上下载一些图片文件,文件名存放在一个csv文件中.代码如下: # -*- coding:utf-8 -*- import paramiko import csv import os def sft_download_all(host,port,username,password): sf = paramiko.Transport((host,port)) sf.connect(username = username,password = password) sftp = param…
# -*- coding:utf8 -*- import string from collections import namedtuple def str_count(s): '''找出字符串中的中英文.空格.数字.标点符号个数''' count_en = count_dg = count_sp = count_zh = count_pu = 0 s_len = len(s) for c in s: # 英文 if c in string.ascii_letters: count_en +=…
CSV文件结构如下,其中字段A为唯一 代码如下,Python27 with open(file_obj+'TEST.CSV','r') as f: #转为字典 Reader=csv.DictReader(f) #转为列表,列表中多维字典 csvlist1 = list(Reader) #将A当做为索引 csvlist2 = [row['A'] for row in csvlist1] #根据A的值找到下标值 n = csvlist2.index(A VALUE) #根据下标值获取对应的字典 cs…
package com.xfzx.test.POI.main; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import jav…
# -*- coding: utf-8 -*- import math import re import csv import repr def ean_checksum(eancode): """returns the checksum of an ean string of length 13, returns -1 if the string has the wrong length""" if len(eancode) != 13: re…