09 2012 档案

【python】YY一下python里的 True 和 False
摘要:习惯了C++等其他语言的人都会习惯性的认为,在python里,True和False应当也是关键字才对,但是接下来问题就来了:首先,既然是关键字,为什么这两个关键字不像其他关键字一样全部小写呢?其次,既然是关键字,为什么写python脚本的时候,在python3.0之前的版本里这两个单词并没有像其他关键字一样标为特殊颜色?再次,由此我们开始怀疑,这两个单词真的是关键字么?让我们来做个实验,假设有如下代码:True = Falseprint(True)在python2.6里执行输出如下结果:而在python3.1里执行输出如下结果:这时我们不禁要惊呼,怎么回事?!实际上原因是这样的:在python 阅读全文

posted @ 2012-09-26 11:32 jeJee 阅读(1036) 评论(0) 推荐(0)

【Lua】为什么 Lua 里没有 continue
摘要:对于Lua里没有continue的问题相信很多用lua的人都遇到过,官方也有作出了解释。在Lua中,repeat until 有点类似于C++的do while,但在机制上有一点区别,在Lua的until的条件表达式中,表达式中的变量可以是repeat until代码块内声明的局部变量,但在C++中,while的条件表达式中的变量不允许出现do while内部声明的临时变量,必须是do while外部声明的变量。基于这个原因,我们假设Lua支持了continue,考虑以下代码:local a = 1 -- outerrepeat if f() then continue ... 阅读全文

posted @ 2012-09-22 13:20 jeJee 阅读(32826) 评论(1) 推荐(1)

【C/C++】关于C++的名字查找与继承
摘要:为了将问题简化,首先来看一段代码:#include <tchar.h>#include "stdio.h"class A{public: void func() { printf("A::func\n"); }};class B : public A{public: void func(int n) // 注意这里func与A的func同名,但参数不同 { printf("B::func\n"); }};int _tmain(int argc, _TCHAR* argv[]){ B b; b.func(); ... 阅读全文

posted @ 2012-09-20 11:56 jeJee 阅读(386) 评论(0) 推荐(0)

【C/C++】关于编译错误 "error C2146: syntax error : missing ';' before identifier 'xxx'"
摘要:今天帮同学解决了一个问题,之前其实也遇到过,现在总结一下。问题大概是这样的,假设有如下代码:#include <tchar.h>DWORD g_count = 0;int _tmain(int argc, _TCHAR* argv[]){ return 0;}使用VS编译会报如下错误:1>f:\testproj\consoletest_vs2005\test\test.cpp(3) : error C2146: syntax error : missing ';' before identifier 'g_count'1>f:\testp 阅读全文

posted @ 2012-09-19 14:53 jeJee 阅读(14301) 评论(0) 推荐(0)

【python】只对文件open,不close的后果
摘要:这个问题的主要目的是研究当程序中没有显示close掉已经open的文件,那么这个文件会在什么时候被close掉?已经知道在C++中,打开的文件句柄没有被close掉的话,那这个句柄只会在程序退出时才会被释放掉,那么在python是否也是这样的呢?接下来做个实验:1.有如下代码:import osclass OpenFileTest: def openfile(self, filePath): handle = open(filePath, 'wb') passif __name__ == "__main__": t = OpenFileTest(... 阅读全文

posted @ 2012-09-19 12:01 jeJee 阅读(9571) 评论(0) 推荐(0)

【Linux】CollabnetSVN安装
摘要:使用 rz 命令上将svn安装包到Linux系统;假设安装包的路径为RPM_PATH,使用命令 "Rpm –ivh RPM_PATH" 来安装;使用 "whereis svn" 来获取 svn 的路径;如:"/opt/CollabNet_Subversion/bin/svn";在PATH环境变量中添加svn的路径("/opt/CollabNet_Subversion/bin",注意不要最后面的svn);添加环境变量的方法为:vi /etc/profile在文件最后一行添加:exportPATH=/opt/Colla 阅读全文

posted @ 2012-09-10 10:56 jeJee 阅读(245) 评论(0) 推荐(0)

【C/C++】设置磁盘剩余空间
摘要:const DWORD g_sysReserveBytes = 5 * 1024;const tstring g_diskEmulatorFileName = _T("DiskEmulatorFile_1C14D9BC-3056-4fdf-9BE5-CEFC9C7EF074");tstring GetDiskName(const char* disk){ tstring __disk; if (NULL == disk) { tstring curDir; GetMainModuleDir(curDir); assert(curDir... 阅读全文

posted @ 2012-09-07 15:51 jeJee 阅读(585) 评论(0) 推荐(0)

【C/C++】一种同步目录的实现——No“删除整个目录再拷贝”
摘要:// 算法是:// 遍历 dstDir,将所有 srcDir 中不存在的文件删除;// 遍历 srcDir,若与 dstDir 目录中对应文件的修改日期不一致则替换该文件;// 忽略 excludeFile 文件里指示的目录和文件。struct IgnoreName{ bool isDir; tchar fileName[MAX_PATH];};bool GetIgnoreNames(const char* excludeFile, std::vector<IgnoreName>& ignoreNames){ bool result = true; igno... 阅读全文

posted @ 2012-09-07 15:28 jeJee 阅读(574) 评论(0) 推荐(0)

【python】计算文件md5值
摘要:import md5import sysdef sumfile(fobj): m = md5.new() while True: d = fobj.read(8096) if not d: break m.update(d) return m.hexdigest()def md5sum(fname): if fname == '-': ret = sumfile(sys.stdin) else: try: f = file(fname, '... 阅读全文

posted @ 2012-09-07 15:10 jeJee 阅读(300) 评论(0) 推荐(0)

【python】递归复制文件或者文件夹到指定目录
摘要:def CopyFileOrDir(src, targetDir): print src, targetDir baseName = os.path.basename(src) print baseName targetFileOrDirName = os.path.join(targetDir, baseName) print targetFileOrDirName if os.path.isfile(src): open(targetFileOrDirName, "wb").write(open(src, "rb").read()) ... 阅读全文

posted @ 2012-09-07 15:08 jeJee 阅读(433) 评论(0) 推荐(0)

【python】获取系统当前登录的用户名
摘要:import win32apiprint win32api.GetUserName() 阅读全文

posted @ 2012-09-07 15:04 jeJee 阅读(1259) 评论(0) 推荐(0)

【C/C++】生成64位随机数
摘要:google到的,直接上代码:mt64.hView Code /* A C-program for MT19937-64 (2004/9/29 version). Coded by Takuji Nishimura and Makoto Matsumoto. This is a 64-bit version of Mersenne Twister pseudorandom number generator. Before using, initialize the state by using init_genrand64(seed) or init_by_arr... 阅读全文

posted @ 2012-09-07 15:02 jeJee 阅读(1880) 评论(0) 推荐(0)

【C/C++】字符串编码转换【Windows版】
摘要:StrConv.hView Code #pragma once#include <string> #ifdef _UNICODE#ifndef tchar#define tchar wchar_t#endif#ifndef tstring#define tstring std::wstring#endif#else#ifndef tchar#define tchar char#endif#ifndef tstring#define tstring std::string#endif#endif // _UNICODE//////////////////////////////... 阅读全文

posted @ 2012-09-07 14:52 jeJee 阅读(635) 评论(0) 推荐(0)

查询域名对应IP地址
摘要:命令:nslookup详细说明:http://baike.baidu.com/view/441751.htm 阅读全文

posted @ 2012-09-07 14:41 jeJee 阅读(248) 评论(0) 推荐(0)

导航