最近在做一部分Pyhton代码转c#代码的工作,以下案例亲自都测试过,现整理出来希望对有帮助的同学提供参考:

Python | C#

*:first-child{margin-top:0 !important}body>*:last-child{margin-bottom:0 !important}p,blockquote,ul,ol,dl,table,pre{margin:15px 0}h1,h2,h3,h4,h5,h6{margin:20px 0 10px;padding:0;font-weight:bold;-webkit-font-smoothing:antialiased}h1 tt,h1 code,h2 tt,h2 code,h3 tt,h3 code,h4 tt,h4 code,h5 tt,h5 code,h6 tt,h6 code{font-size:inherit}h1{font-size:28px;color:#000}h2{font-size:24px;border-bottom:1px solid #ccc;color:#000}h3{font-size:18px}h4{font-size:16px}h5{font-size:14px}h6{color:#777;font-size:14px}body>h2:first-child,body>h1:first-child,body>h1:first-child+h2,body>h3:first-child,body>h4:first-child,body>h5:first-child,body>h6:first-child{margin-top:0;padding-top:0}a:first-child h1,a:first-child h2,a:first-child h3,a:first-child h4,a:first-child h5,a:first-child h6{margin-top:0;padding-top:0}h1+p,h2+p,h3+p,h4+p,h5+p,h6+p{margin-top:10px}a{color:#4183c4;text-decoration:none}a:hover{text-decoration:underline}ul,ol{padding-left:30px}ul li>:first-child,ol li>:first-child,ul li ul:first-of-type,ol li ol:first-of-type,ul li ol:first-of-type,ol li ul:first-of-type{margin-top:0}ul ul,ul ol,ol ol,ol ul{margin-bottom:0}dl{padding:0}dl dt{font-size:14px;font-weight:bold;font-style:italic;padding:0;margin:15px 0 5px}dl dt:first-child{padding:0}dl dt>:first-child{margin-top:0}dl dt>:last-child{margin-bottom:0}dl dd{margin:0 0 15px;padding:0 15px}dl dd>:first-child{margin-top:0}dl dd>:last-child{margin-bottom:0}pre,code,tt{font-size:12px;font-family:Consolas,"Liberation Mono",Courier,monospace}code,tt{margin:0;padding:0;white-space:nowrap;border:1px solid #eaeaea;background-color:#f8f8f8;border-radius:3px}pre>code{margin:0;padding:0;white-space:pre;border:0;background:transparent}pre{background-color:#f8f8f8;border:1px solid #ccc;font-size:13px;line-height:19px;overflow:auto;padding:6px 10px;border-radius:3px}pre code,pre tt{background-color:transparent;border:0}blockquote{border-left:4px solid #DDD;padding:0 15px;color:#777}blockquote>:first-child{margin-top:0}blockquote>:last-child{margin-bottom:0}hr{clear:both;margin:15px 0;height:0;overflow:hidden;border:0;background:transparent;border-bottom:4px solid #ddd;padding:0}table th{font-weight:bold}table th,table td{border:1px solid #ccc;padding:6px 13px}table tr{border-top:1px solid #ccc;background-color:#fff}table tr:nth-child(2n){background-color:#f8f8f8}img{max-width:100%}
-->

Python C#
datetime.datetime.strftime(datetime.datetime.now(), '%Y%m%d%H%M%S') DateTime.Now.ToString("yyyyMMddHHmmss")
random.choice('123456789') random.Next(1, 9).ToString()
struct.pack('>I', int(time.time())) TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
byte[] timeSpanBytes = BitConverter.GetBytes(Convert.ToUInt32(ts));
if (BitConverter.IsLittleEndian)
{
Array.Reverse(timeSpanBytes);
}
binascii.hexlify(ab) BitConverter.ToString(timeSpanBytes)
random.randint(0, 100000000)) Random random = new Random(DateTime.Now.Millisecond);
random.Next(0, 100000000)
myhmac = hmac.new("d6fc3a4a06adbde89223bvefedc24fecde188aaa9161",digestmod=hashlib.sha1)
myhmac.update(binascii.unhexlify('57b47f0a1b8a35a00300fbe94bcf'))
encode=base64.b64encode(myhmac.digest())
string hexData = "57b47f0a1b8a35a00300fbe94bcf";
if(hexvalue.Length % 2 != 0)
{
hexvalue = "0" + hexvalue;
}
int len = hexvalue.Length / 2;
byte[] bytes = new byte[len];
for (int i = 0; i < len; i++)
{
string byteString = hexvalue.Substring(2 * i, 2);
bytes[i] = Convert.ToByte(byteString, 16);
}

string str = "d6fc3a4a06adbde89223bvefedc24fecde188aaa9161";
ASCIIEncoding encoder = new ASCIIEncoding();
Byte[] code = encoder.GetBytes(str);
HMACSHA1 hmSha1 = new HMACSHA1(code);
Byte[] hmBytes = hmSha1.ComputeHash(bytes);
string encode = Convert.ToBase64String(hmBytes);

bytes=binascii.unhexlify(hexvalue) if (hexvalue.Length % 2 != 0)
{
hexvalue = "0" + hexvalue;
}
int len = hexvalue.Length / 2;
byte[] bytes = new byte[len];
for (int i = 0; i < len; i++)
{
string byteString = hexvalue.Substring(2 * i, 2);
bytes[i] = Convert.ToByte(byteString, 16);
}
return bytes;
var hmac=hashlib.md5('F%s%s' % (time_str, device_no)).hexdigest() var md5 = new MD5CryptoServiceProvider();
byte[] m =md5.ComputeHash(Encoding.UTF8.GetBytes($"F{timeSpan}{deviceNO}"));
var hmac = BitConverter.ToString(m).Replace("-", "").ToLower();
buf_size = 0x1000
raw_memory = bytearray(buf_size)
ctypes_raw_type = (ctypes.c_char * buf_size)
ctypes_raw_memory=ctypes_raw_type.from_buffer(raw_memory)
encLen = Objdll.encode(byref(ctypes_raw_memory),buf_size,inputCode,len(inputCode))#Objdll.encode为c++调用#
return raw_memory[:encLen]
IntPtr data = Marshal.StringToHGlobalAnsi(inputCode);
byte[] aaab = new byte[4096]; int aa = encode(aaab, 4096, data, inputCode.Length);byte[] byteNew = new byte[aa];
for (int i = 0; i < aa; i++)
{
byteNew[i] = aaab[i];
}
return byteNew;
szPara = create_string_buffer('/0'*buf_size)
decLen = Objdll.decode(byref(szPara), buf_size,decodeInput,len(decodeInput))
#Objdll.encode为c++调用#
return szPara.value[:decLen]
byte[] outsting = new byte[0x1000];
int encLen = decode(outsting, outsting.Length, inputCode, inputCode.Length);
String ret = Encoding.UTF8.GetString(outsting, 0, encLen);
return ret;
json.loads(test) JsonConvert.DeserializeObject(test)

Python代码转c#部分参考样例的更多相关文章

  1. 异步nodejs代码的同步样子写法样例

    异步nodejs代码的同步样子写法样例 js的异步嵌套太深代码将不好看.尤其在用node的时候这种情况会大量出现. 这里用node连接redis,做一个用户注册的简单例子来说明.例如用redis做存储 ...

  2. Python Socket 编程——聊天室演示样例程序

    上一篇 我们学习了简单的 Python TCP Socket 编程,通过分别写服务端和client的代码了解主要的 Python Socket 编程模型.本文再通过一个样例来加强一下对 Socket ...

  3. D3的参考样例

    官网进去就可以看到很多样例了.但是最喜欢的是mbostock的http://bl.ocks.org 然后其它的也有一些: 看上去很酷--http://www.visualcinnamon.com/po ...

  4. python模块 - re模块使用演示样例

    http://blog.csdn.net/pipisorry/article/details/46619179 re模块匹配规则见:http://blog.csdn.net/pipisorry/art ...

  5. 吴裕雄 python 神经网络——TensorFlow 图像预处理完整样例

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...

  6. C++ Primer中文本查询演示样例Query的实现

    近期在看C++ Primer复习C++的语法,看到书中15.9章中的文本查询演示样例时,认为设计得非常不错,于是便动手照着实现了一个,改动了非常久最终执行成功了,从中也学习到了非常多的语法.以下把实现 ...

  7. [Python] SQLBuilder 演示样例代码

    用Python写一个SQLBuilder.Java版能够从 http://www.java2s.com/Code/Java/Database-SQL-JDBC/SQLBuilder.htm 看到. 附 ...

  8. Python Web框架Tornado的异步处理代码演示样例

    1. What is Tornado Tornado是一个轻量级但高性能的Python web框架,与还有一个流行的Python web框架Django相比.tornado不提供操作数据库的ORM接口 ...

  9. Python 100个样例代码【爆肝整理 建议收藏】

    本教程包括 62 个基础样例,12 个核心样例,26 个习惯用法.如果觉得还不错,欢迎转发.留言. 一. Python 基础 62 例 1 十转二 将十进制转换为二进制: >>> b ...

随机推荐

  1. zookeeper.Net

    原文转至:http://www.cnblogs.com/shanyou/p/3221990.html 之前整理过一篇文章<zookeeper 分布式锁服务>,本文介绍的 Zookeeper ...

  2. LeetCode题解之Binary Tree Paths

    1.题目描述 2.分析 使用递归. 3.代码 vector<string> ans; vector<string> binaryTreePaths(TreeNode* root ...

  3. Centos7下安装与卸载docker应用容器引擎

    Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到任何流行的 Li ...

  4. ORA-12538;ORA-12154;使用PL/SQL dve无法连接远程服务器上的oracle数据库,同时本机上也安装了一个oracle数据库

    问题描述:本人使用PL/SQL dve连接远程服务器上的oracle数据库,一直是没有问题的.我想提高下自己在数据库方面的能力就在自己的笔记本上安装了一个oracle数据库实例,安装并配置好之后,使用 ...

  5. Beta冲刺! Day4 - 砍柴

    Beta冲刺! Day4 - 砍柴 今日已完成 晨瑶:追进度 昭锡:改主页UI(还在 永盛:完成大部分接口和接口文档,上线代码 立强:文章去广告,适配手机屏幕.第三方编辑器整合到记录模块. 炜鸿:完成 ...

  6. [Eclipse+PyDev]ImportError: DLL load failed:找不到指定的模块 解决方案

    1. 环境 Eclipse 4.4.2 Python 3.5 Window 8.1 2. 问题 在代码中import numpy时,提示 " ImportError: DLL load fa ...

  7. 西安80投影坐标系转WGS84地理坐标系如何求七参数

    需求:西安80投影坐标系(平面坐标)转为WGS84地理坐标系(球面坐标) 这其中涉及的问题主要有以下两点: 1.一个是投影坐标系,一个是地理坐标系,而七参数指的是两个地理坐标系之间的转换,因此需要把投 ...

  8. python 在windows下的 虚拟环境

    解决 python 环境问题 windows 下安装 pip install virtualenv virtualenv的基本使用 1.1 创建虚拟环境 virtualenv venv 为环境指定Py ...

  9. sysctl命令

    sysctl命令作用: 被用于在内核运行时动态地修改内核的运行参数,可用的内核参数在目录/proc/sys中,它包含一些TCP/ip堆栈和虚拟内存系统的高级选项,用sysctl可以读取设置超过五百个系 ...

  10. UVA1451 Average

    嘟嘟嘟 看到比值,就想到01分数规划,令\(ans = \frac{\sum a_i}{\sum l_i}\),其中\(l\)表示长度,所以\(l_i\)都是\(1\). 然后变一下型,得到\(\su ...