随笔分类 - python
摘要:转自:http://www.cnblogs.com/jonathanlife/archive/2013/02/04/2892366.html
阅读全文
摘要:Methods of File ObjectsThe rest of the examples in this section will assume that a file object calledfhas already been created.To read a file’s contents, callf.read(size), which reads some quantity of data and returns it as a string or bytes object.sizeis an optional numeric argument. Whensizeis omi
阅读全文
摘要:>>> tel = {'jack': 4098, 'sape': 4139}>>> tel['guido'] = 4127>>> tel{'sape': 4139, 'guido': 4127, 'jack': 4098}>>> tel['jack']4098>>> del tel['sape']>>> tel['irv'] = 4127>
阅读全文
摘要:Set包含不重复元素,用{}或者set()创建,有于或非等运算符>>> basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}>>> print(basket) # show that duplicates have been removed{'orange', 'banana', 'pear', 'apple'}>&g
阅读全文
摘要:定义函数>>> def fib(n): # write Fibonacci series up to n... """Print a Fibonacci series up to n."""... a, b = 0, 1... while a < n:... print(a, end=' ')... a, b = b, a+b... print()...>>> # Now call the function we just defined:... fib(2000)0 1 1
阅读全文
摘要:if>>> x = int(input("Please enter an integer: "))Please enter an integer: 42>>> if x < 0:... x = 0... print('Negative changed to zero')... elif x == 0:... print('Zero')... elif x == 1:... print('Single')... else:... print('More')...Moref
阅读全文
摘要:动态数组,可以存储不同数据类型>>> a = ['spam', 'eggs', 100, 1234]>>> a['spam', 'eggs', 100, 1234]和string一样,支持索引,+,*>>> a[0]'spam'>>> a[3]1234>>> a[-2]100>>> a[1:-1]['eggs', 100]>>> a[:2] + ['bacon'
阅读全文
摘要:多行文本以\结尾,换行还是要用\nhello = "This is a rather long string containing\n\several lines of text just as you would do in C.\n\ Note that whitespace at the beginning of the line is\ significant."print(hello)多行原格式文本用"""或者'''围绕。里面的换行就是换行print("""\Usage: thin
阅读全文
摘要:python默认的除法运算时浮点运算如:1/3 0.33333333333如果想要整除结果,要用//如:1//3 0
阅读全文
摘要:import sitesite.getusersitepackages()上面代码可以得到import的导入包文件夹,只要把自己的py文件放到这个文件夹里,那么每个.py文件执行的时候都会导入
阅读全文
摘要:cdecl格式的调用要用 p = ctypes.cdll.LoadLibrary('a.dll') 或者 p = ctypes.CDll('a.dll')stdcall用 p = ctypes.windll.LoadLibrary('a.dll') 或者 p = ctypes.WinDll('a.dll')一般c++用的是__cdecl,windows里大都用的是__stdcall(API), win32中的CALLBACK是__stdcall
阅读全文
摘要:导入ctypes以后cdll.msvcrt为标准c的函数库,可以调用标准C里的函数,如from ctypes import *libc = cdll.msvcrtprint(libc.printf)print(libc.time(None))print(libc.sin(2))windll代表windows的一些常用dll,如from ctypes import *libc = cdll.msvcrtprint(hex(windll.kernel32.GetModuleHandleA(None)))
阅读全文
摘要:转自:http://blog.csdn.net/lf8289/article/details/2322550在python中调用dll文件中的接口比较简单,实例代码如下:如我们有一个test.dll文件,内部定义如下:extern"C"{int__stdcalltest(void*p,intlen){returnlen;}}在python中我们可以用以下两种方式载入1.importctypesdll=ctypes.windll.LoadLibrary('test.dll')2.importctypesdll=ctypes.WinDll('test.d
阅读全文

浙公网安备 33010602011771号