V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ghhccghk
V2EX  ›  Python

我想问一下 Python 下 str 转 int 格式怎么转

  •  
  •   ghhccghk ·
    ghhccghk · 140 天前 via Android · 1971 次点击
    这是一个创建于 140 天前的主题,其中的信息可能已经有所发展或是发生改变。

    原因是在搞字体字号设置的时,输入字体大小后,跳转到一个函数更改全局变量,然后再跳转到另一个函数读取变量应用,不知道什么原因报错,代码明天上午贴。

    我在搞一个自用的歌词显示器,因为 linux 下 yes playmusic 没有桌面歌词,打算自己搞一个,写代码稍微用了 ai 辅助。

    8 条回复    2023-12-15 09:25:44 +08:00
    NoOneNoBody
        1
    NoOneNoBody  
       140 天前   ❤️ 1
    内置函数 int(string, base=10),base 为进制,默认十进制,所以可以直接写 int(string)

    我好奇你都会改 python 程序,还用 ai 了,为何连这个内置函数都不知道,所以我现在完全搞不清上述是否就是你需要的答案
    param
        2
    param  
       140 天前 via Android   ❤️ 1
    你的 ai 连这个都不会吗
    ghhccghk
        3
    ghhccghk  
    OP
       139 天前
    @NoOneNoBody
    Traceback (most recent call last):
    File "/home/ghhc/lyc/my_window.py", line 118, in change_font
    a = int(s)
    TypeError: 'int' object is not callable
    主要是碰到这个情况都不知道啊
    leon1s97
        4
    leon1s97  
       139 天前
    @ghhccghk int 被覆盖了?上面的代码有用到 int 当作变量名吗
    ghhccghk
        5
    ghhccghk  
    OP
       139 天前
    ghhccghk
        6
    ghhccghk  
    OP
       139 天前
    @leon1s97 #####默认字体变量
    font = str ###字体
    bold = bool = True ####粗细
    underline = bool = 0 #####下划线
    pointSize = int = 20 ###字号

    这个算是吗
    dayeye2006199
        7
    dayeye2006199  
       139 天前 via Android
    @ghhccghk 你这不是把 20 赋值给 int 了么。你冒号打成等号了
    ghhccghk
        8
    ghhccghk  
    OP
       139 天前
    @dayeye2006199 这样啊,我边学边写不知道啊抱歉
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   869 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:01 · PVG 07:01 · LAX 16:01 · JFK 19:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.