小编Pyt*_*zer的帖子

openpyxl中的水平文本对齐方式

我尝试将文本对齐方式更改为2个合并销售的中心,我发现了一些对我的案例不起作用的答案

currentCell = ws.cell('A1')
currentCell.style.alignment.horizontal = 'center' #TypeError: cannot set horizontal attribute
#or
currentCell.style.alignment.vertical = Alignment.HORIZONTAL_CENTER #AttributeError: type object 'Alignment' has no attribute 'HORIZONTAL_CENTER'
Run Code Online (Sandbox Code Playgroud)

两者都没有用,还有其他办法吗?

python xlsx openpyxl

13
推荐指数
3
解决办法
3万
查看次数

将十六进制数据写入文件

我正在尝试将从ascii文件中获取的十六进制数据写入新创建的二进制文件

ascii文件示例:

98 af b7 93 bb 03 bf 8e ae 16 bf 2e 52 43 8b df
4f 4e 5a e4 26 3f ca f7 b1 ab 93 4f 20 bf 0a bf
82 2c dd c5 38 70 17 a0 00 fd 3b fe 3d 53 fc 3b
28 c1 ff 9e a9 28 29 c1 94 d4 54 d4 d4 ff 7b 40
Run Code Online (Sandbox Code Playgroud)

我的代码

hexList = []
with open('hexFile.txt', 'r') as hexData:
    line=hexData.readline()
    while line != '': …
Run Code Online (Sandbox Code Playgroud)

python string binary hex file

13
推荐指数
1
解决办法
4万
查看次数

在python中订购了os.listdir()

如何按顺序将文件添加到列表中

在我的目录中,我有以下文件: slide1.xml, slide2.xml, slide3.xml ... slide13.xml

os.listdir(path) 不按订单返回列表

我试过这种方式

files_list = [x for x in sorted(os.listdir(path+"/slides/")) if os.path.isfile(path+"/slides/"+x)]
Run Code Online (Sandbox Code Playgroud)

输出: ['slide1.xml', 'slide10.xml', 'slide11.xml', 'slide12.xml', 'slide13.xml', 'slide2.xml', 'slide3.xml', 'slide3_COPY.xml', 'slide4.xml', 'slide5.xml', 'slide6.xml', 'slide7.xml', 'slide8.xml', 'slide9.xml']

python file

7
推荐指数
1
解决办法
1万
查看次数

从python中的2个列表中删除不匹配的项目

如果list2中不存在,我需要从list1中删除所有不匹配的项目

 List1 = ['dog', 'cat', 'bird']
 List2 = ['dog']

 for x in List2:
      for y in List1:
           if x!=y:
                List1.remove(x)
Run Code Online (Sandbox Code Playgroud)

从list1中删除一个项后,此循环停滞.这个操作的正确代码是什么

python list

3
推荐指数
1
解决办法
94
查看次数

迭代Python中的字符串

我想制作一个逐个输入字符串的脚本

def autotype(info):
    count = len(info) #Countign number of letters of the string
    splitlist = list(info) 
    i = int(count) #getting an error on this line! it accept i=int(0) but my loop doesnt work because of this
    while i>0:
        sys.stdout.write(splitlist[i])
        time.sleep(0.2)
        i -= 1

info = str("hello world")
autotype(info)
Run Code Online (Sandbox Code Playgroud)

错误是:列表索引超出范围我该如何解决?

python

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

从python中的列表项中删除模式

我的清单有15个项目,所有这些项目最后都包含"_new"这个词.所以我想创建一个文件夹,其中包含没有'_new'的项目名称.怎么做?

python list

0
推荐指数
1
解决办法
2675
查看次数

标签 统计

python ×6

file ×2

list ×2

binary ×1

hex ×1

openpyxl ×1

string ×1

xlsx ×1