摘要: 用python进行OO编程时, 经常会用到类的构造函数来初始化一些变量。 class FileData: def __init__(self, data, name, type): self.bits = base64.encodestring(data) self.name = name self.type = type其中self类似c++或者c#的this指针。 阅读全文
posted @ 2013-07-18 16:32 muzizongheng 阅读(979) 评论(0) 推荐(0) 编辑
摘要: 我们有时写的python模块需要自己测试, 简单方法就是定义main函数, 然后测试自己的模块接口。 def main(): test_yourCode() if __name__ == "__main__": main() 阅读全文
posted @ 2013-07-18 16:31 muzizongheng 阅读(1920) 评论(0) 推荐(0) 编辑
摘要: 我们经常会用python来进行抓包,模拟登陆等等, 势必要构造http请求包。 http的request通常有4个方法get,post,put,delete,分别对应于查询,更新,添加,删除。我们经常用到的也就get,post。1.用python构造get#build request for accessed url homeReq = urllib.request.Request( url... 阅读全文
posted @ 2013-07-18 16:30 muzizongheng 阅读(2309) 评论(0) 推荐(0) 编辑
摘要: python3中构造http的Request需要用到urllib.request.有时会用到cookie。比如在访问网站首页得到cookie,通过下面代码添加cookie: #install cookie cj = cookiejar.CookieJar(); opener = urllib.request.build_opener(urllib.request.HTTPCookieProce... 阅读全文
posted @ 2013-07-18 16:29 muzizongheng 阅读(3176) 评论(0) 推荐(0) 编辑
摘要: http的数据需要2种编码解码。 1. url中的特殊字符转换, 比如”,‘, :,//等python3中通过urllib.parse.quote(..)和urllib.parse.unquote(..)来编码解码。如:import urllib.parse url = "http://blog.csdn.net/muzizongheng" en = urllib.parse.quote(url... 阅读全文
posted @ 2013-07-18 15:20 muzizongheng 阅读(544) 评论(0) 推荐(0) 编辑
摘要: python中字符串“True” 和 “False"转为bool类型时, 不能通过bool(xx)强转。 注意是因为在python中,除了''、""、0、()、[]、{}、None为False, 其他转换都为True。 也就是说字符串如果不为空,则永远转换为True。好吧, 只能通过这样了:data = "True"isTrue = data == str(True) 阅读全文
posted @ 2013-07-18 15:19 muzizongheng 阅读(3644) 评论(0) 推荐(0) 编辑
摘要: python中在module定义的变量可以认为是全局变量, 而对于全局变量的赋值有个地方需要注意。 test.py--------------------------------------------------import sysusername = "muzizongheng"password = "xxxx"def Login(u, p): username = u password... 阅读全文
posted @ 2013-07-18 15:18 muzizongheng 阅读(325) 评论(0) 推荐(0) 编辑
摘要: snoop是开发wpf应用程序的利器。用它可以观察WPF的可视树,监听事件,更改元素属性等。 下面我介绍下snoop一些用法。1.获取指定应用程序的UI 打开snoop,选择“Drag and Drop this crosshairs over wpf window inorder to snoop it” 按钮, 拖动它到你要观察的wpf窗体上。 你会发现 十字准线 会标出窗体的名字及进程号。... 阅读全文
posted @ 2013-07-16 10:58 muzizongheng 阅读(532) 评论(0) 推荐(0) 编辑
摘要: 开发wpf时我们经常遇到一个xaml文件在设计时显示解析错误(比如在:VS或者Blend)而编译正常运行正常。 原因是:xaml的在Debug版本下必须为anyCPU。解决办法:1.打开工程文件xxx.csproj,2.找到含有 Debug的PropertyGroup节点3.将此PropertyGroup节点中的改为anyCPU。示例: Debug anyCPU 阅读全文
posted @ 2013-07-15 14:28 muzizongheng 阅读(414) 评论(0) 推荐(0) 编辑
摘要: 最近CM(Configuration Management) 的同事在自定义开发TFS的过程中遇到一个问题。 领导要求快速开发一个工具, 可以自动连接TFS,然后自动Check out一些word文件, 然后程序修改后自动check in。(比如签名)这个实现的话,需要3个方面:1.根据现有TFS界面抽出可以使用的UI, 然后找到对应dll2.利用C#的反射, 获取到对应字段或者属性, 进行更改... 阅读全文
posted @ 2013-07-10 16:20 muzizongheng 阅读(211) 评论(0) 推荐(0) 编辑
摘要: 最近在写一个关于如何上传文件到skydrive的demo, 用REST上传失败。 安装Telerik的Fiddler后, 可以监听http或者https通信, 然后可以在软件中看到返回的json数据或者其他详细信息。 阅读全文
posted @ 2013-07-10 16:18 muzizongheng 阅读(203) 评论(0) 推荐(0) 编辑
摘要: #coding:utf-8 import sys sys.path.append("lib") import thrift.protocol.TBinaryProtocol as TBinaryProtocol import thrift.transport.THttpClient as THttpClient import evernote.edam.userstore.UserStore as... 阅读全文
posted @ 2013-07-05 13:58 muzizongheng 阅读(399) 评论(0) 推荐(0) 编辑
摘要: Sublime Text2是个强大的编辑器, 有好多插件供我们使用, 其中有个插件SublimeEvernote, 可以把代码发送到Evernote里。 但是没找见使用说明, 今天看了下Sublime_Evernote.py源码, 配置如下:/* Sublime evernote default settings */ { "authToken": "your dev authToken", ... 阅读全文
posted @ 2013-07-05 13:50 muzizongheng 阅读(791) 评论(0) 推荐(0) 编辑
摘要: 我们编译python代码时, 经常出现各种因为tab和空格的问题, 例如:IndentationError: unindent does not match any outer indentation level有个简便的办法:用python的IDLE打开python 代码, 选中所有代码, 点击菜单项Format/Untabify Region 阅读全文
posted @ 2013-07-05 09:31 muzizongheng 阅读(593) 评论(0) 推荐(0) 编辑
摘要: Python的list,dictionary可以写入file, 也可以从file中读取。 关于list:1)写入文件 self.existedBlog.write("your item data" + "\n")2)读取 self.existedBlog = open("existedBlog", "r+") self.existedBlog.seek(0) currentBlog... 阅读全文
posted @ 2013-07-05 09:30 muzizongheng 阅读(329) 评论(0) 推荐(0) 编辑
摘要: import module与from module import funtion区别:import module导入模块后你需要使用module.function()来调用一个函数from module import function导入一个function后你可以直接使用它请在你经常要使用这个function或者你确认你的代码中不会与导入的function冲突时使用from module imp... 阅读全文
posted @ 2013-07-05 09:29 muzizongheng 阅读(279) 评论(0) 推荐(0) 编辑
摘要: 尽量使用using语句块和finally (实现IDisposable) 尽量使用单个大程序集而不是多个小程序集 (使用NGen.exe)使用sealed关键字权衡虚函数使用弱引用 阅读全文
posted @ 2013-07-05 09:28 muzizongheng 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 1.下载ODB library:ODB Compiler,Common Runtime Library,Database Runtime Library。 http://www.codesynthesis.com/products/odb/download.xhtml(注意:ODB Compiler为odb-x.x.x-i686-windows, Database Runtime Librari... 阅读全文
posted @ 2013-07-05 09:27 muzizongheng 阅读(890) 评论(0) 推荐(0) 编辑
摘要: 今天同事问在一个WCF server的解决方案里调试时如何禁止Server自动启动。 经过调查发现, VS的工具WcfSvcHost会在调试时自动扫描工程里的WCF server, 然后启动起来。如果需要禁止其工作, 解决方法:在工程文件(csproj)里的节点中删除{3D9AD99F-2412-4246-B90B-4EAA41C64699} 阅读全文
posted @ 2013-07-05 09:07 muzizongheng 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 今天在用python3的getattr时遇到一个问题, 就是老提示传入参数和函数前面不一致, 代码为: class Test: def __init__(self, name): self.name = name def execute(self, methodname, *args): print(args) print(self.name) print(getattr(self.... 阅读全文
posted @ 2013-07-05 09:06 muzizongheng 阅读(1197) 评论(0) 推荐(0) 编辑
摘要: 进行在用python的list结构时, 发现一个问题: methods =['blogger.deletePost', 'blogger.getUsersBlogs', 'metaWeblog.editPost', 'metaWeblog.getCategories', 'metaWeblog.getPost', 'metaWeblog.getRecentPosts', 'metaWeblog.... 阅读全文
posted @ 2013-07-05 09:05 muzizongheng 阅读(1273) 评论(0) 推荐(0) 编辑
摘要: w代表清空后写入 r代表打开后追查+代表可以写b代表二进制写入 阅读全文
posted @ 2013-07-05 09:04 muzizongheng 阅读(344) 评论(0) 推荐(0) 编辑
摘要: 今天在把Evenote的笔记内容写为文件时出错: f.write(content) UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 135: illegal multibyte sequence经过调查,发现应该在打开文件时设置编码格式。解决办法: f = open(n.guid, "w... 阅读全文
posted @ 2013-07-05 09:03 muzizongheng 阅读(807) 评论(0) 推荐(0) 编辑
摘要: 今天编译Python时, 输出窗口信息出现: [Decode error - output not utf-8] [Decode error - output not utf-8]发现是print不支持中文字符的输出, 需要修改python的build的setting, 打开Python.sublime-build,修改为:{ "cmd": ["C:/Python33/python.exe",... 阅读全文
posted @ 2013-07-05 09:02 muzizongheng 阅读(11246) 评论(1) 推荐(1) 编辑
摘要: 今天在调试Evernote SDK时, 遇到PythonPath的问题。 查了很多资料,有说用系统环境变量添加PythonPath, 有说在注册表中的PythonPath添加新Default字段, 但是对于我来说都没有效果, 很奇怪。 最后还是在代码里显式添加sys.path才好用: import sys import hashlib import binascii import time if... 阅读全文
posted @ 2013-07-05 09:01 muzizongheng 阅读(740) 评论(0) 推荐(0) 编辑
摘要: 1.下载开发版:http://www.sublimetext.com/dev2.安装Package control: (1)按键ctrl+~ (2)在命令行中输入:import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if no... 阅读全文
posted @ 2013-07-05 09:00 muzizongheng 阅读(369) 评论(0) 推荐(0) 编辑
摘要: 在做WPFMVVM中经常会遇到一些Model、ViewModel的属性添加添加私有字段和更改通知方法来支持Binding。比如把:public class Test{ public string TestData1{get; set;} public string TestData2{get;set;}}变为:public class Test : INotifyPropertyChanged{ ... 阅读全文
posted @ 2013-07-05 08:59 muzizongheng 阅读(751) 评论(0) 推荐(0) 编辑
摘要: 因为以前一直在用TSVN, 对其界面操作比较熟悉。 因此,决定不用Git Gui而是用TortoiseGit来访问GitHub。 安装TortoiseGit成功后,1.运行PuTTY Key Generator2.如果GitHub上已经有SSH key,本地也有对应的私钥请在菜单项Conversions/Import key, 导入现有私钥文件,导入后:3.如果没有现成的私钥公钥, 请点击Gen... 阅读全文
posted @ 2013-07-04 09:49 muzizongheng 阅读(427) 评论(0) 推荐(0) 编辑
摘要: 我们在用WPF时, 经常会对系统控件的默认高亮等等颜色进行更改。 以前通常是用controlTemplate来实现。 今天发现一个更合理或者简单的方法:用系统默认颜色的key, 比如 SystemColors.HighlightBrushKey 此资源可以动态引用和改变。而SystemColors.HighlightBrush只能用于静态资源。 example: http://msdn.... 阅读全文
posted @ 2013-07-04 09:48 muzizongheng 阅读(1574) 评论(0) 推荐(0) 编辑
摘要: TreeView控件可以通过HierarchicalDataTemplate 和DataTemplate来自定义。1)HierarchicalDataTemplate用来支持HeaderedItemsControl,其中DataType指定当前的数据类型, 只有符合这个类型才使用HierarchicalDataTemplate;ItemsSource用来指定ItemsHost;内部的自定义实现(T... 阅读全文
posted @ 2013-07-04 09:48 muzizongheng 阅读(287) 评论(0) 推荐(0) 编辑
摘要: DataGrid支持截断时, 需要分2部分, DataGridColumnHeader和DataGridCell。 1)创建上述2部分的ControlTemplate 。2)把其中的ContentPresenter改为TextBlock3)使用TextTrimming属性xaml code like this: 阅读全文
posted @ 2013-07-04 09:47 muzizongheng 阅读(478) 评论(0) 推荐(0) 编辑
摘要: 添加: TextTrimming="CharacterEllipsis"到TextBlock中, 即可让TextBlock 支持截断字符显示为。。。 阅读全文
posted @ 2013-07-04 09:46 muzizongheng 阅读(322) 评论(0) 推荐(0) 编辑
摘要: 今天帮忙同事调试一个自定义Panel的问题, 很奇怪, 利用Binding可以通过ItemSource来添加控件,但是在Listbox的xaml里添加几个ListboxItem却报异常: VisualTree of ItemsPanelTemplate must be a single element.原因有2:1)ListBox的ItemPanelTemplate使用自定义Panel时, 需要... 阅读全文
posted @ 2013-07-04 09:45 muzizongheng 阅读(269) 评论(0) 推荐(0) 编辑
摘要: c#中有Expression,即表达式。 通过Expression可以动态构造代码,并编译执行。比如:1.创建参数表达式:ParameterExpression numParam = Expression.Parameter(typeof(int), "num");、创建常量表达式:ConstantExpression five = Expression.Constant(5, typeof(i... 阅读全文
posted @ 2013-07-04 09:44 muzizongheng 阅读(1021) 评论(0) 推荐(0) 编辑
摘要: 前段时间做了一个worklist的项目,有部分是利用xml配置DICOM的tag,然后根据xml把DICOM的Dataset转为实体类,或者把实体类转为Dataset。 当中主要应用了反射来调用Dataset的put方法, 但是发现性能很慢, 一个解析映射花了几百毫秒。解决办法:利用dynamic来替换反射:dynamic temp = new ExampleClass();temp.someM... 阅读全文
posted @ 2013-07-04 09:43 muzizongheng 阅读(343) 评论(0) 推荐(0) 编辑
摘要: 最近做项目时,用到了xml的序列化与反序列化, 发现最好用xsd来验证xml, 因为反序列化xml不校验xsd。 方法:xmlData变量为xml字符串MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xmlData)); ms.Position = 0; ... 阅读全文
posted @ 2013-07-04 09:29 muzizongheng 阅读(543) 评论(0) 推荐(0) 编辑
摘要: https://github.com/OSEHRA/mdo C# http://sourceforge.net/p/nhapi/code/HEAD/tree/NHapi20/ C# 阅读全文
posted @ 2013-07-04 09:28 muzizongheng 阅读(2315) 评论(0) 推荐(0) 编辑
摘要: 1. 代码中使用配置文件: log4net.Config.DOMConfigurator.Configure(new FileInfo("log4netConfig.xml")); 2.配置文件样例: --> --> ... 阅读全文
posted @ 2013-07-04 09:28 muzizongheng 阅读(272) 评论(0) 推荐(0) 编辑
摘要: 利用xs:unique关键字。在xs:element里添加unique节点,任意命名,然后用xs:selector来选择需要唯一的域, xs:field 里指定特定的字段。 例如:定义所有Item里的Key为唯一, 阅读全文
posted @ 2013-07-04 09:27 muzizongheng 阅读(373) 评论(0) 推荐(0) 编辑
摘要: EF中设计数据库表结构时,在Designer UI中无法调整添加好的字段顺序。 方法:1.在Solution Explorer中右击XXX.edmx文件, 选择“Open With”, 用XML Editor打开。2.在edmx:ConceptualModels (即:CSDL content)节点内,找到对应Table及Property, 调整Property节点顺序。 阅读全文
posted @ 2013-07-04 09:27 muzizongheng 阅读(356) 评论(0) 推荐(0) 编辑
如果我们时时忙着展现自己的知识, 将何从忆起成长所需的无知?