Python for win
Python操作Excel方法:
(1)在sourceforge.net上有一个扩展模块叫pyXLWriter,可以方便的写Excel文件。
(2)下载win32com包装上,这个包可以调用windows的com及API函数等这类的功能。Python利用win32com操作Excel。
例子:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from win32com.client import Dispatch
import win32com.client
class easyExcel:
"""A utility to make it easier to get at Excel. Remembering
to save the data is your problem, as is error handling.
Operates on one workbook at a time."""
def __init__(self, filename=None):
self.xlApp = win32com.client.Dispatch('Excel.Application')
if filename:
self.filename = filename
self.xlBook = self.xlApp.Workbooks.Open(filename)
else:
self.xlBook = self.xlApp.Workbooks.Add()
self.filename = ''
def save(self, newfilename=None):
if newfilename:
self.filename = newfilename
相关文档:
凑24是经典的益智游戏,多玩可以使脑筋灵活一点,但是当遇到无解的时候,就会很伤脑筋,为此,写个程序来代为计算。
运行结果,去除了重复的一些表达式:
entry: 1
entry: 4
entry: 5
entry: 6
(4/(1-(5/6))) = 24
(6/((5/4)-1)) = 24
Press any key to exit...
entry: 3
entry: 3
entry: 8
entry: 8
(8/(3-(8 ......
今天学习了一下Python的操作符重载,总结了几点比较神奇的东东:
------------------------------------------------------------------------------------------------------------
关于iter:
Technically, iteration contexts work by calling the iter built-in function to try to
find an _ _iter_ _ method, whi ......
看着网上抓取网页数据的文章直瞪眼
后来想到用字符串分割来提取相应部分的内容
程序简单,但数行数和下标费了很长时间
我知道这肯定不是最好的办法- -!!
但我实现了,哈哈
# -*- coding: cp936 -*-
from urllib import *
import re
def stockSearch():
baseurl="http://www.google.cn/financ ......
如果python调用外部程序,需要直接抓去命令行的输出,有什么好的办法呢?
这里我们需要用到 os.popen 这个管道,然后用 read、readline或者readlines来读取命令行输出
#需要执行的命令
strCommand = 'xxxxxxxxxxxxxxxxx'
#用popen来执行命令行
oStdout = os.popen(strCommand)
#假设输出的内容只有一行
strStdout = ......