python 读取txt中数字的方法

本文介绍了Python读取txt文件中数字的多种方法,包括读取特定行、转换数据类型、提取并转换为整型,以及如何处理矩阵数据。讲解了.read(), .readline(), .readlines()等函数的用法,并提到了按位读取和以逗号为间隔符的读取策略。" 44245647,4899725,Java实现文本相似度计算,"['计算文本相似度', 'LCS', '最长公共子序列', 'Java算法', '文本处理']
摘要由CSDN通过智能技术生成
#encoding=utf-8
import cv2
import json
import numpy as np
import torch
from skimage import measure

from skimage import morphology
import torchvision
import torchvision.transforms as transforms
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
import torch.optim as optim  
import matplotlib.pyplot as plt
from PIL import Image

import warnings
from collections import namedtuple
from torch.utils.model_zoo import load_url as load_state_dict_from_url
import re


def Readinfor():
	with open('lucky.txt') as a:
		head= a.readlines(1)
		print("head = ", head)
		str2 = str(head)
		#print("abc = ", str2.split(','))
		
		strimgh = str2.split(',')[1]
		#print("strimgh = ", strimgh)
		strhimg = re.sub("\D", "", strimgh)
		
		strimgw = str2.split(',')[0]
		#print("strimgw = ", strimgw)
		strwimg = re.sub("\D", ""
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值