Chinaunix首页 | 论坛 | 博客
  • 博客访问: 818134
  • 博文数量: 756
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 4980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:40
文章分类

全部博文(756)

文章存档

2011年(1)

2008年(755)

我的朋友

分类:

2008-10-13 16:14:23

偶想学Python,苦于找不到名师,嘿嘿,只好自己瞎琢磨了。立下死规矩,每天至少写一个小代码出来。估计一个月就能把语法特性和常用库函数用法搞熟了,嘿嘿。:p

今天就先写个整理收藏夹的。由于一边写这个代码一边指导小MM做blog(要不停的抓图),所以……  如果有不爽之处请多多包涵(欢迎Python大牛指点)——偶是初学者嘛!~~

## Generate Favorit Web Links
# File   : makefav.py
# Author : Spark Song
# Date   : 2005-08-23

from win32api import RegQueryValue,RegQueryValueEx,RegOpenKey, RegCloseKey, GetProfileVal
from win32con import HKEY_CURRENT_USER
import os

html_str = ''

def trealUrlShortCut(File):
    if File.find('url') == -1:
        return
    val = GetProfileVal('InternetShortcut', 'url', 'about:blank', File)
    if val == 'about:blank':
        val = GetProfileVal('DEFAULT', 'BASEURL', 'about:blank', File)
    globals()['html_str'] = globals()['html_str'] + '
  • ' + "" + getFileNameWithoutExt(getFolderName(File)) \
    + "
    " def getFavoritesFolder(): name = 'Favorites' hkey = HKEY_CURRENT_USER subkey = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' hkey = RegOpenKey(hkey, subkey) obj, type = RegQueryValueEx(hkey, name) return obj def getFolderName(Path): path, tail = os.path.split(Path) return tail def getFileNameWithoutExt(File): Filename, Ext = os.path.splitext(File) return Filename def allFileDir(path): for file in os.listdir(path): file_or_dir = os.path.join(path,file) if os.path.isdir(file_or_dir) and not os.path.islink(file_or_dir): globals()['html_str'] = globals()['html_str'] + '
      ' + getFolderName(file_or_dir) allFileDir(file_or_dir) #it's a directory reucursive call to function again else: trealUrlShortCut(file_or_dir) globals()['html_str'] = globals()['html_str'] + '
    ' allFileDir(getFavoritesFolder()) f = open("out.html", "w") f.write('\n') f.write( html_str) f.close()
    #:~~
  • 注:运行该代码需要安装,其中包含了ActiveState Corp.整合的Python和Python for Windows Extensions。本程序在Windows XP Professional下通过。

    为了吸引观众,推广Python,抓个图放在下面,嘿嘿。(下图是上面这段程序在偶机器上的运行效果,老少皆易,一点即得,价格公道,童叟无欺)


    --------------------next---------------------

    阅读(420) | 评论(0) | 转发(0) |
    给主人留下些什么吧!~~