将 int 转换为 ASCII 并返回 Python

2023-04-14Python开发问题
1

本文介绍了将 int 转换为 ASCII 并返回 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在为我的网站制作 URL 缩短器,我目前的计划(我愿意接受建议)是使用节点 ID 来生成缩短的 URL.因此,理论上,节点 26 可能是 short.com/z,节点 1 可能是 short.com/a,节点 52 可能是 short.com/Z,节点 104 可能是 short.com/ZZ.当用户访问该 URL 时,我需要反转该过程(显然).

I'm working on making a URL shortener for my site, and my current plan (I'm open to suggestions) is to use a node ID to generate the shortened URL. So, in theory, node 26 might be short.com/z, node 1 might be short.com/a, node 52 might be short.com/Z, and node 104 might be short.com/ZZ. When a user goes to that URL, I need to reverse the process (obviously).

我能想到一些笨拙的方法来解决这个问题,但我猜还有更好的方法.有什么建议吗?

I can think of some kludgy ways to go about this, but I'm guessing there are better ones. Any suggestions?

推荐答案

ASCII 转 int:

ASCII to int:

ord('a')

给出97

然后返回一个字符串:

  • 在 Python2 中:str(unichr(97))
  • 在 Python3 中:chr(97)

给出'a'

这篇关于将 int 转换为 ASCII 并返回 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

pandas 有从特定日期开始的按月分组的方式吗?
Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)...
2024-08-22 Python开发问题
10

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10