小编Par*_*aH2的帖子

如何从脚本中提取PDF文档的标题以进行重命名?

我的计算机里有成千上万的PDF文件,这些文件的名称来自a0001.pdfa3621.pdf,每个文件的内部都有一个标题; 例如,"碳酸铝" a0001.pdf,"硝酸铝" a0002.pdf等,我想提取重命名我的文件.

我用这个程序重命名一个文件:

path=r"C:\Users\YANN\Desktop\..."

old='string 1'
new='string 2'

def rename(path,old,new):
    for f in os.listdir(path):
        os.rename(os.path.join(path, f), os.path.join(path, f.replace(old, new)))

rename(path,old,new)
Run Code Online (Sandbox Code Playgroud)

我想知道是否有解决方案提取嵌入在PDF文件中的标题来重命名文件?

python pdf file python-3.x

15
推荐指数
2
解决办法
7918
查看次数

如何在Python 3.4中获得字母表中的字符位置?

我需要知道文本中第n个字符的字母位置,我读了这个问题答案,但它不适用于我的Python 3.4


我的节目

# -*- coding: utf-8 -*-
"""
Created on Fri Apr 22 12:24:15 2016

@author: Asus
"""

import string

message='bonjour'
string.lowercase.index('message[2]')
Run Code Online (Sandbox Code Playgroud)

它不适用于ascii_lowercase而不是小写.


错误消息

runfile('C:/Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts/ESSAI.py',wdir ='C:/ Users/Asus/Desktop/Perso /WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts')Traceback(最近一次调用最后一次):

文件"",第1行,在runfile中('C:/Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts/ESSAI.py',wdir ='C: /Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts')

文件"C:\ Users\Asus\Desktop\Perso\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",第685行,in runfile execfile(文件名,命名空间)

文件"C:\ Users\Asus\Desktop\Perso\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",第85行, execfile exec(compile(open(filename,'rb').read(),filename,'e​​xec'),namespace

在string.lowercase.index('message 2 ')中输入文件"C:/Users/Asus/Desktop/Perso/WinPython-64bit-3.4.3.4/python-3.4.3.amd64/Scripts/ESSAI.py",第11行)

AttributeError:'module'对象没有属性'lowercase'

alphabet python-3.x

5
推荐指数
1
解决办法
3262
查看次数

是否可以在Python中创建具有未知属性的类?

我正在学习Python,我刚学完该课程的基础知识.这是我学习的第一个OOP语言,所以目前并非一切都非常清晰.无论如何.


我想知道在Python(3.6)中是否可以创建一个我们不知道几个对象的属性的类(或许可能只有2或3个).

例如,假设您想要通过其属性定义分子,以便您可以在其他程序中使用它们来建模或预测事物.您可以涉及的基本属性(例如)Temperature,MolecularWeightMolarVolume.但是,您也可以使用20个不同的参数轻松定义分子.但是,其中一些可能不存在于每个分子中,或者您现在可能不需要使用它们.(即软件的第一版,......).


问题:

我想知道Python 3.x中是否存在以下语法,以便该类能够精确地创建分子具有的参数数量.我认为定义数千个分子不存在的变量需要花费大量的内存空间......

class Molecule:

    def __init__(self, Temperature, MolecularWeight, MolarVolume, *properties):
        self.Temperature = Temperature
        self.MolecularWeight = MolecularWeight
        self.MolarVolume = MolarVolume
        self.*properties = *properties
Run Code Online (Sandbox Code Playgroud)

我的目标是使用文件.txt来记录我的分子的属性(我有数千个),它们的属性按照定义的顺序排序,这样当使用类时,如果对于分子甲醇我们有10个参数与第一个如前所述,然后该类将按顺序创建具有十个属性的分子"甲醇".


否则,如果它不存在,我应该默认创建一个包含我所有参数的类,并根据情况考虑其中一些没用吗?或者使用更好的东西存在?

先感谢您

python parameters class python-3.x

5
推荐指数
1
解决办法
248
查看次数

如何将Flexbox放入另一个?

我正在学习HTML5/CSS3一周,现在我正在研究flexbox.我只是有一个问题,我想用它们制作一个块"块",其中包含两个垂直方向的盒子和另一个块"block2",其中包含两个水平方框.

因此,我希望bblock中的block和block2以水平方式彼此相邻,并且块的两个部分在垂直方向上,而block2的两个部分以水平方式.

但它不起作用.

我该怎么办 ?先感谢您 !

.bblock {
  border: 2px solid #444;
  display: flex;
}
.block {
  border: 2px solid #444;
  max-width: 542px;
  /*margin: 0 auto;*/
}
.section:nth-child(1) background-color:orange;
 width:500px;
 max-height:250px;
 border:1px solid black;
 text-align:justify;
 padding-top:0px;
 padding-right:20px;
 padding-left:20px;
 padding-bottom:0px;
 border-radius:10px;

}
.section:nth-child(2) {
  background-color: yellow;
  width: 500px;
  max-height: 170px;
  border: 1px solid black;
  text-align: justify;
  padding-top: 0px;
  padding-right: 20px;
  padding-left: 20px;
  padding-bottom: 0px;
  border-radius: 10px;
}
.block2 {
  border: 2px solid #444;
  max-width: 542px;
  margin-bottom: 10px;
  /*margin: 0 auto;*/
} …
Run Code Online (Sandbox Code Playgroud)

html css html5 css3 flexbox

2
推荐指数
1
解决办法
49
查看次数

标签 统计

python-3.x ×3

python ×2

alphabet ×1

class ×1

css ×1

css3 ×1

file ×1

flexbox ×1

html ×1

html5 ×1

parameters ×1

pdf ×1