Python 的字符串问题 [英] String problems with Python

查看:39
本文介绍了Python 的字符串问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个 Python 菜鸟,所以我可能在这里遗漏了一些东西,但我对如何在我的程序中处理字符串有疑问.当我显示它时,只显示第一个字符.

I am a Python noob so I may be missing something here, but I have a problem with how a string is handled inside my program. When I display it, only the first character is displayed.

# some code
MessageBox = ctypes.windll.user32.MessageBoxA
# some other code
testString = self.statusBar1.GetStatusText(0)
# displays "azertyu"
MessageBox(None, "azertyu", 'COUCOU', 0)
# displays 'M'
MessageBox(None, testString, 'COUCOU3', 0)
# displays 'a'
MessageBox(None, testString[1:], 'COUCOU3', 0) #
#displays 'c'
MessageBox(None, testString[2:], 'COUCOU3', 0)

完整的字符串是 'Machine'(它实际上比那个更长).为什么 Python 会认为任何字符都是结束字符并且一次只显示一个字符?我是否在这里遗漏了一些 Python 基础知识?

The full string is 'Machine' (it's actually longer than that). How comes Python considers any character is the ending one and displays only one character at once ? Am I missing some Python basics here ?

附注.GetStatusText 参考位于 http://www.wxpython.org/docs/api/wx.StatusBar-class.html#GetStatusText.我用一个很长的字符串测试了 GetStatusText,它似乎没有剪切文本.

PS. GetStatusText reference is available at http://www.wxpython.org/docs/api/wx.StatusBar-class.html#GetStatusText. I have tested GetStatusText with a very long string and it doesn't seem to cut texts.

推荐答案

如果您使用的是 wxPython,为什么要尝试显示带有 ctypes 的消息框?wxPython 包有自己的消息对话框.请参阅以下链接:

If you are using wxPython, why are you trying to show a message box with ctypes? The wxPython package has its own message dialogs. See the following links:

wxPython 演示包(可从 wxPython 网站下载)包含 MessageDialog 和 GenericMessageDialog 的示例.

The wxPython demo package (downloadable from the wxPython website) has examples of MessageDialog and GenericMessageDialog.

这篇关于Python 的字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆