推荐学习书目
› 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 · Dec 14, 2023 via Android · 3887 views
    This topic created in 1060 days ago, the information mentioned may be changed or developed.

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

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

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

    我好奇你都会改 python 程序,还用 ai 了,为何连这个内置函数都不知道,所以我现在完全搞不清上述是否就是你需要的答案
    param
    param
    Dec 15, 2023 via Android❤️1
    2
    你的 ai 连这个都不会吗
    ghhccghk
    ghhccghk
    OP
    Dec 15, 2023
    3
    @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
    leon1s97
    Dec 15, 2023
    4
    @ghhccghk int 被覆盖了?上面的代码有用到 int 当作变量名吗
    ghhccghk
    ghhccghk
    OP
    Dec 15, 2023
    5
    ghhccghk
    ghhccghk
    OP
    Dec 15, 2023
    6
    @leon1s97 #####默认字体变量
    font = str ###字体
    bold = bool = True ####粗细
    underline = bool = 0 #####下划线
    pointSize = int = 20 ###字号

    这个算是吗
    dayeye2006199
    dayeye2006199
    Dec 15, 2023 via Android
    7
    @ghhccghk 你这不是把 20 赋值给 int 了么。你冒号打成等号了
    ghhccghk
    ghhccghk
    OP
    Dec 15, 2023
    8
    @dayeye2006199 这样啊,我边学边写不知道啊抱歉
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   849 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 17:09 · PVG 01:09 · LAX 09:09 · JFK 12:09
    ♥ Do have faith in what you're doing.