Python代码转c#部分参考样例
最近在做一部分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"; |
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#部分参考样例的更多相关文章
- 异步nodejs代码的同步样子写法样例
异步nodejs代码的同步样子写法样例 js的异步嵌套太深代码将不好看.尤其在用node的时候这种情况会大量出现. 这里用node连接redis,做一个用户注册的简单例子来说明.例如用redis做存储 ...
- Python Socket 编程——聊天室演示样例程序
上一篇 我们学习了简单的 Python TCP Socket 编程,通过分别写服务端和client的代码了解主要的 Python Socket 编程模型.本文再通过一个样例来加强一下对 Socket ...
- D3的参考样例
官网进去就可以看到很多样例了.但是最喜欢的是mbostock的http://bl.ocks.org 然后其它的也有一些: 看上去很酷--http://www.visualcinnamon.com/po ...
- python模块 - re模块使用演示样例
http://blog.csdn.net/pipisorry/article/details/46619179 re模块匹配规则见:http://blog.csdn.net/pipisorry/art ...
- 吴裕雄 python 神经网络——TensorFlow 图像预处理完整样例
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...
- C++ Primer中文本查询演示样例Query的实现
近期在看C++ Primer复习C++的语法,看到书中15.9章中的文本查询演示样例时,认为设计得非常不错,于是便动手照着实现了一个,改动了非常久最终执行成功了,从中也学习到了非常多的语法.以下把实现 ...
- [Python] SQLBuilder 演示样例代码
用Python写一个SQLBuilder.Java版能够从 http://www.java2s.com/Code/Java/Database-SQL-JDBC/SQLBuilder.htm 看到. 附 ...
- Python Web框架Tornado的异步处理代码演示样例
1. What is Tornado Tornado是一个轻量级但高性能的Python web框架,与还有一个流行的Python web框架Django相比.tornado不提供操作数据库的ORM接口 ...
- Python 100个样例代码【爆肝整理 建议收藏】
本教程包括 62 个基础样例,12 个核心样例,26 个习惯用法.如果觉得还不错,欢迎转发.留言. 一. Python 基础 62 例 1 十转二 将十进制转换为二进制: >>> b ...
随机推荐
- 如何猜出 Y combinator
先约定几个记号: 定义用一个冒号加等号表示":=", 表达式全等用两个等号表示"==", 归约意义上的相等用一个等号表示"="," ...
- sysbench对MySQL的压测,使用sysbench压测磁盘io
QPS - query per secondTPS - transaction per second 不是特别关注,每个业务场景中事务标准是不一样的 Ⅰ.sysbench测试框架 Ⅱ.常用测试脚本 [ ...
- pandas的resample重采样
Pandas中的resample,重新采样,是对原样本重新处理的一个方法,是一个对常规时间序列数据重新采样和频率转换的便捷的方法. 降采样:高频数据到低频数据 升采样:低频数据到高频数据 主要函数:r ...
- 【hexo】03config文件配置详解
YAML 是专门用来写配置文件的语言,非常简洁和强大,我们的配置文件就是这种格式.需要了解的只有: # 我是文配置件的注释 重要提示,例如:"theme: landspace"中冒 ...
- Centos7系统特性之systemd
1.centos系列的系统启动流程(内核级别的启动流程): POST(加电自检)---> Boot Sequence(BIOS)---> Boot loader (MBR)---> ...
- oracle使用with as提高查询效率
经常在开发过程中会用到视图或组合查询的情况,但由于涉及表数据经常达到千万级别的笛卡尔积,而且一段查询时会反复调用,但结果输出往往不需要那么多,可以使用with将过滤或处理后的结果先缓存到临时表(此处原 ...
- django 中的 ajax
(Asynchronous Javascript And XML ) 特点: 异步 页面局部刷新 传递的数据量小 ajax 请求返回数据 重定向 location.href='/index/' 发请求 ...
- Unity手游之路手游代码更新策略探讨
版权声明: https://blog.csdn.net/janeky/article/details/25923151 这几个月公司项目非常忙.加上家里事情也多,所以blog更新一直搁置了. 近期在项 ...
- go标准库的学习-net/http
参考:https://studygolang.com/pkgdoc 概念解释: request:用户请求的信息,用来解析用户的请求信息,包括post.get.cookie.url等信息 respons ...
- AWS 为 Elasticsearch 推出开源发行版
WS 近日宣布为 Elasticsearch 推出开源发行版 Open Distro for Elasticsearch. Elasticsearch 是一个分布式.面向文档的搜索和分析引擎,它支持结 ...