易截截图软件、单文件、免安装、纯绿色、仅160KB

[提问]Python 如何忽略 whitespace 读入

像 C 的 scanf() 那样
比如读入 1 2 3 a b c
每次读入一个
下面这个应该是你想要的吧:

Python code:

>>> k = raw_input()
0 0123 ds dsl sd
>>> k
'0 0123 ds dsl sd'
>>> k.split(' ')
['0', '0123', 'ds', 'dsl', 'sd']
>>>




LS的回答不错

不知道python有没有现成的函数可以调用

总算发现了解决方法
使用 ctypes 库

from ctypes import *
libc = CDLL('libc.so.6')
a = c_int()
b = c_double()
c = c_char()
s = create_string_buffer(100)
libc.scanf('%c%d%lf%s', byref(c), byref(a), byref(b), byref(s))
print c.value, a.value, b.value, s.value


43842050 Python,c/c++群,有志想学Python,C和C++的朋友请加入群。


相关问答:

请问python和pyodc有什么区别

麻烦高手解答一下 谢谢了 我是新手 一些概念都不太清楚。。。
pyodbc is a Python module that allows you to use ODBC to connect to almost any database from Windows, Linux, OS/X, and more.

pyodbc是 ......

关于用Python处理大量数据的问题

我现在要处理数百万条数据,处理过程是通过比较数据里是否有指定的字符串,再插入到另外的表中,请问用Python如何高效完成?先谢谢各位了。

建议:别直接跟数据库比较。太耗费IO。
把你需要比较的字段从数据 ......

看看这段Python代码问题出在哪

照着书上写的,执行时报错(Python2.6)
import wx
class InsertFrame(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,'F ......

第一次用Python写程序,使用find函数遇到一个问题

//下面的代码运行正常

tomstrs=re.findall(......)
mtxx=''
for tomstr in tomstrs:
  tomstr=tomstr.strip()
  if  tomstr:
      mtxx += tomstr ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号