专栏导读
-
🌸 欢迎来到Python办公自动化专栏—Python处理办公问题,解放您的双手
-
-
-
-
📕 此外还有python基础专栏:请点击——>Python基础学习专栏求订阅
-
文章作者技术和水平有限,如果文中出现错误,希望大家能指正🙏
-
❤️ 欢迎各位佬关注! ❤️
背景
-
在日常的办公中,我们经常需要利用python去读写Excel类型的文件,有时候我们需要将每个数字代表的列的字母表现出来,那么我们可以利用Python实现,而且今天的代码可以根据自己的需求去任意的改变你想规定的长度
-
如,或者更长
a = {1: 'A', 2: 'B',
3: 'C', 4: 'D',
5: 'E', 6: 'F',
7: 'G', 8: 'H',
9: 'I',10: 'J'}
代码
-
for i in range(1, 50):,这里的50可根据自己的实际情况去修改
dictionary = {}
for i in range(1, 50):
dictionary[i] = chr(i + 64) if i <= 26 else f'{chr((i - 1) // 26 + 64)}{chr((i - 1) % 26 + 65)}'
print(dictionary)
json版+读取+完整版
'''
@作者 :一晌小贪欢
'''
import json
dictionary = {}
for i in range(1, 50):
dictionary[i] = chr(i + 64) if i <= 26 else f'{chr((i - 1) // 26 + 64)}{chr((i - 1) % 26 + 65)}'
print(dictionary)
with open("./data.json", "w", encoding="utf-8") as f_w:
f_w.write(json.dumps(dictionary, ensure_ascii=False))
with open("./data.json","r",encoding="utf-8")as f:
res = json.load(f)
print(res['1'])
print(res['2'])
print(res['3'])
print()
![在这里插入图片描述](https://img-blog.csdnimg.cn/62af76a491f1447796da570a41965d6d.png)
总结
-
希望对初学者有帮助
-
致力于办公自动化的小小程序员一枚
-
希望能得到大家的【一个免费关注】!感谢
-
求个 🤞 关注 🤞
-
-
求个 ❤️ 喜欢 ❤️
-
-
求个 👍 收藏 👍
-