谁能帮忙把python转换为c成c++

懂python语言的麻烦翻译一下成C++ 谢谢了_百度知道
懂python语言的麻烦翻译一下成C++ 谢谢了
sglobal hl2dsendnewpacket
for i3hl2 in hl2dsendnewpacket.sendto(i3hl2,(adrcs.sleep(0,portcs))
提问者采纳
10,(adrcs,可以在很多地方修改给hl2dsendnewpacket个范围;}因为程序太局部;10;i3hl2++){s.85),那么for(i3hl2=5.sleep(0,如5&lt.sendto(i3hl2;time,portcs))global hl2dsendnewpacket是定义一个全局变量hl2i3hl2&=hl2dsendnewpacket&lt
那是向指定地址和端口发送数据的
加我抠,详细的代码发给你帮我看看。解决了有追加
不用了,不太会,你找别人吧
好吧 那我HI给你怎样。。如果不行那也没办法了。主要是我想弄明白这个的发送机制是个什么玩意
提问者评价
其他类似问题
为您推荐:
python的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Windows 10 is hereAnd you can download it for free.*PreviousNextPlay
This package contains the compiler and set of system headers necessary for producing binary wheels for Python 2.7 packages.
9.0.0.30729VCForPython27.msi9/29/201483.8 MB
This package contains the compiler and set of system headers necessary for producing binary wheels for Python packages. A binary wheel of a Python package can then be installed on any Windows system without requiring access to a C compiler.
The typical error message you will receive if you need this compiler package is Unable to find vcvarsall.bat
This message appears because the Python package being installed contains the source code for a native extension module (.pyd), but does not have a pre-built copy of the module. The Python packages highlighted at
have already been updated by their developers to include pre-built binaries, but many are still only available as source code.
This compiler package is entirely unsupported and represents a snapshot of the last version that is fully compatible with Python 2.7. For the latest security and bug fixes, please use the latest version of
for any development work that does not directly interface with Python 2.7.
Supported Operating System
Windows 7, Windows 8, Windows 8.1
Microsoft Visual C++ 2008 SP1 Redistributable Package (, )
Windows 8 and later require the Microsoft .NET Framework 3.5. See
for installation instructions.
Disk Space Requirements
Installation requires 380 megabytes (MB) of hard disk space.
Python Packages
6.0 or later is required for Python to automatically detect this compiler package.
is recommended for producing pre-built binary packages.
Installing and Uninstalling
The compiler package will default to installing just for the current user and does not require administrative privileges. To install for all users of a machine, execute msiexec /i &path to MSI& ALLUSERS=1 from an elevated Command Prompt.
To remove or repair the compiler package, locate the entry in Programs and Features and select Remove or Repair.
Using with Python distribution tools
Python package developers should download and use this compiler to produce binary wheels for their Python packages to upload to PyPI. Installing the wheel package, updating to setuptools 6.0 or later, and adding setup.py bdist_wheel upload to your build process will produce the correct files (remember to do this for both 32-bit and 64-bit versions).
If a Python package you are installing does not have a wheel, you can install this compiler package on your own machine. Once the compiler is installed and you have updated to setuptools 6.0 or later, you can use pip install to build and install the Python package. If you are managing multiple machines and need to install the Python package on all of them, you should install the wheel package and use pip wheel to produce a wheel that can be installed on machines without requiring this package.
Follow Microsoft
Microsoft Store
Company Site feedbackWhat category would you like to give web site feedback on?Choose a categorySite Navigation (finding what you want)Site ContentLanguage QualitySite DesignOtherRate your level of satisfaction with this web page today:Very SatisfiedSomewhat SatisfiedSomewhat DissatisfiedVery DissatisfiedComments:Submit将下面的python类改写成c++类_百度知道
将下面的python类改写成c++类
print &tstop only if %s&#39. see effective()
def __init__(self.append(self)
if (file.file.ignore, disabling and
(self:%d&#39:
disp = disp + &#39.next = Breakpoint, line) in self.cond = cond
self.line)
if self, line]; % (out.cond, &#39!
self.append(self)
else.enabled = 1
def disable(self):
self.funcname = funcname
# Needed if funcname is not Nkeep &#39.temporary.
The latter points to a
list of such instances since there may be more than one
breakpoint per line, temporary=0;out.bpbynumber[self,)
if self.;tignore next %d hits'Breakpoint class
Implements t&quot.line)
self.file:
disp = &#39,yes
&#39, &#39:
print &gt:
self.bplist[index], and conditionals.file = file
# This better be in canonical form, cond=None, funcname=None);
print &tbreakpoint already hit %d time%s&#39.hits);&#92.func_first_executable_line = None
self.enabled.ignore = 0
if out is None.ignore)
if (self: ss = &#39.enabled = 0
def bpprint( 1).bplist[&quot.cond.hits, except for marking an
# effective break .enabled = 1
self.stdoutno
disp = &#39:
self, disp.next + 1
# Build the two lists
self.bplist.number] = None
# No longer in list
&quot.remove(self)&quot, line] = [self]def deleteMe(self).hits &gt.number = Breakpoint,lin&#92.
if self: ss = &#39.bplist[index]
def enable(self):
index = (&&#39., ignore counts, &#39:
out =&#92:
disp = disp + &#39.hits = 0
# XXX Keeping state in the class is a mistake -- this means
# you cannot have more than one active Bdb instance,&gt.
The former points to a
single instance of class Breakpoint,
else.&gt. % (self.
Breakpoints are indexed by number through bpbynumber and by&quot.
self.line = line
self, out=None).bplist[index];out.next
B % (self:l combo
del self, lineno) tuple
bpbynumber = [None] # Each entry is None or an instance of Bpt
# index 0 is unused.bplist[file.;%-4dbreakpoint
%s at %s;del
&#39.temporary = temporary
# No more bp for this f.
# Next bp to be assigned
bplist = {}
# indexed by (file谢谢大家了class Breakpoint, (&#39
提问者采纳
对于c不是很了解了,研究过python调用C的接口,你可以看下python的C扩展,看看对你是否有帮助
嗯嗯,python的c api我看过了。但是这个类里bplist是由元组索引的 这太蛋疼了 不会写。而且这个静态变量 由于考python的变量类型定义 我不知道该怎么写。。。
提问者评价
其他类似问题
为您推荐:
python的相关知识
其他1条回答
其实我也不懂
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁把下面三句C++语句改为Python语句。_百度知道
把下面三句C++语句改为Python语句。
GLfloat sun_light_position[] = {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat sun_light_ambient[]
= {0.0f, 0.0f, 0.0f, 1.0f};
GLfloat sun_light_diffuse[]
= {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat sun_light_specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_POS俯珐碘貉鄢股碉瘫冬凯ITION, sun_light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT,
sun_light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE,
sun_light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, sun_light_specular);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
我有更好的答案
# coding=gb2312def Decrypt(s):
newlen=len(s)
lpTargetData=[0]*int(newlen/2)
lpSourceData =s.encode(encoding=&gb2312&)
newlen=int(newl俯珐碘貉鄢股碉瘫冬凯en/2)
for i in range(0,newlen):
lpTargetData[i]=bytes(((lpSourceData[i*2]-ord('A'))*16)+(lpSourceData[i*2]|1-ord('A')))
result=''.join(bytes.decode(lpTargetData[i],&gb2312&))
return &decode error&
return resultprint(Decrypt('hello'))
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁简易的python脚本:c代码转c++,有需要的朋友可以参考下。最近需要将一些c的代码封装成类的方式,方便调用,手工改太麻烦,于是想到了Python+正则表达式,方便又快捷。正则表达式的用法网上非常详细,我就不再细说。百度百科的说明就不错:/view/94238.htm我只简要说下脚本内容 ,这是转换常见内容的脚本,基本c转换c++都用得上的。有具体要求的,需要转换特定语句的,可以以这个为基础改,代码奉上:import redef convertFuncDef(lines , lineNo):
line = lines[lineNo]
paras = {}
while not re.match('^/s*{/s*$' , line):mp = re.match('^/s*(double/s*/**|float/s*/**|char/s*/**|long/s*/**|int/s*/**)/s*([^;]+);/s*$' , line)args = mp.group(2).split(',')for arg in args:if len(arg.strip())==0 : continuetmp = arg.strip()if '[' in tmp : tmp = arg[:arg.find('[')].strip()
# get rid of [x], for example 'window[13]'paras[tmp] = '%s %s'%(mp.group(1).strip(), arg.strip())lineNo+=1line = lines[lineNo]
return lineNo, parasdef detectPattern(lines):
# h =(double **)malloc(sizeof(double *)*n7);
malloc2 = re.compile(r'^/s*(/w+)/s*=/s*/(/s*(double|float|int)/s*/*/*/)/s*malloc/s*/(/s*sizeof/s*/(/s*(double|float|int)/s*/*/s*/)/s*/*/s*(/w+)/s*/)/s*;/s*$')
# for(i=0; i&n7; ++i)
h[i]=(double *)malloc(sizeof(double)*n8);
malloc1 = re.compile(r'^/s*for/(([^/)]*)/)/s*(/w+/[/w+/])/s*=/s*/(/s*(double|float|int)/s+/*/)/s*malloc/s*/(/s*sizeof/s*/(/s*(double|float|int)/s*/)/s*/*/s*(/w+)/s*/)/s*;/s*$')
# free((char *)a);
free2 = re.compile(r'^/s*free/s*/(/s*/(/s*(/s*double/s*/*|/s*float/s*/*|/s*int/s*/*|/s*char/s*/*)/s*/)/s*(/w+)/s*/)/s*;/s*$')
# for(i=0; i&n7; ++i) free((char *)a[i]);
free1 = re.compile(r'^/s*for/(([^/)]*)/)/s*free/s*/(/s*/((/s*double/s*/*|/s*float/s*/*|/s*int/s*/*|/s*char/s*/*)/)/s*([^/)]+)/)/s*;/s*$')
# void dral(x9, y9, k9, p0, w)
funcDef = re.compile(r'^/s*(void/s*/**|bool/s*/**|float/s*/**|double/s*/**|int/s*/**|long/s*/**)/s*(/w+)/s*/(/s*([^/)]*)/)/s*$')
# double **v0;
= re.compile(r'^/s*(bool/s*/*+|float/s*/*+|double/s*/*+|int/s*/*+|long/s*/*+)/s*(/w+)/s*;/s*$')
while lineNo & len(lines):curline = lines[lineNo].rstrip()lineNo += 1
if varDef.match( curline):
# double **v0;mp = varDef.match( curline)text = mp.group(1)[:mp.group(1).index('*')]count = mp.group(1).count('*')for i in range(count):
text = 'vector&%s&'%textprint lineNo , '--- ' , '%s %s;'%(text, mp.group(2))elif malloc2.match( curline):
# h =(double **)malloc(sizeof(double *)*n7);print lineNo , '--- ' , malloc2.sub(r'/1.resize(/4);' , curline) elif malloc1.match( curline):
# for(i=0; i&n7; ++i)
h[i]=(double *)malloc(sizeof(double)*n8);print lineNo , '--- ' , malloc1.sub(r'for(/1)
/3.resize(/5);' , curline)elif free2.match( curline):
# free((char *)a);print lineNo , '--- ' , free2.sub(r'/2.clear();', curline)elif free1.match( curline):
# for(i=0; i&n7; ++i) free((char *)a[i]);print lineNo , '--- ' , free1.sub(r'for(/1) /3.clear();', curline)elif funcDef.match( curline):
# void dral(x9, y9, k9, p0, w)mp = funcDef.match(curline)args = mp.group(3).split(',')lN , paras = convertFuncDef(lines , lineNo)tmpArgs = []for arg in args:
if len(arg.strip())==0: continue
assert paras[arg.strip()]
tmpArgs.append(paras[arg.strip()])text = '%s %s( %s )'%(mp.group(1) , mp.group(2) , ','.join(tmpArgs))print lineNo , '---3333--- ' , textif lN-lineNo&0: print '/n'.join(['----']*(lN-lineNo))lineNo = lNelse:print curline f = open('abc.c' , 'rb')lines = f.readlines()f.close()detectPattern(lines)重点说明下里面的正则表达式吧,及作用吧。正则表达式中每使用一对圆括号,就代表这后的替换中可以使用'/n'来取出这个匹配(pattern),n代表第几个匹配。另外,‘/s*'用于处理可能存在的空格,嫌麻烦可以把'/s*'删除掉再看。有了这些就很简单了。malloc和free都是一维加二维的,只介绍二维的情况。先看malloc的:
# h =(double **)malloc(sizeof(double *)*n7);
malloc2 = re.compile(r'^/s*(/w+)/s*=/s*/(/s*(double|float|int)/s*/*/*/)/s*malloc/s*/(/s*sizeof/s*/(/s*(double|float|int)/s*/*/s*/)/s*/*/s*(/w+)/s*/)/s*;/s*$')
# (/w+)匹配 h
# (double|float|int)
匹配 double 、 float
、 int之一
匹配 n7再看free的
# for(i=0; i&n7; ++i) free((char *)a[i]);
free1 = re.compile(r'^/s*for/(([^/)]*)/)/s*free/s*/(/s*/((/s*double/s*/*|/s*float/s*/*|/s*int/s*/*|/s*char/s*/*)/)/s*([^/)]+)/)/s*;/s*$')
# ([^/)]*)
匹配 for(...)省略号内容,从for之后的'('开始,以for的')'结束
# (/s*double/s*/*|/s*float/s*/*|/s*int/s*/*|/s*char/s*/*)/)
匹配 数据类型,数据类型可能是double、float、int、char,也可能是它的们指针类型
匹配 a[i],匹配代表&不是)的字符&变量定义
# double **v0; 指针类型不安全,且长度不易管理
= re.compile(r'^/s*(bool/s*/*+|float/s*/*+|double/s*/*+|int/s*/*+|long/s*/*+)/s*(/w+)/s*;/s*$')
# (bool/s*/*+|float/s*/*+|double/s*/*+|int/s*/*+|long/s*/*+) 匹配bool、float、double、int、long类型之一或是它们的指针类型
匹配 v0函数转换老式的c语言中,允许类似于的定义
void dral(x9, y9, k9, p0, w)
double w[12];
double x9, y9;
long p0, k9;现在要把它转换成void
exti( long ** ss,long n7,long n8,long m7 )首先,函数头处理
# void dral(x9, y9, k9, p0, w)
funcDef = re.compile(r'^/s*(void/s*/**|bool/s*/**|float/s*/**|double/s*/**|int/s*/**|long/s*/**)/s*(/w+)/s*/(/s*([^/)]*)/)/s*$')
# 函数返回类型
和前面相似,不再细说
# ([^/)]*)
匹配 dral(...)省略号内容,也就是参数,这个参数顺序是调用函数时使用的,要保存下来。函数参数处理
mp = re.match('^/s*(double/s*/**|float/s*/**|char/s*/**|long/s*/**|int/s*/**)/s*([^;]+);/s*$' , line)
# 参数类型匹配和之前一样
匹配 ;之前的所有参数,以','分割,之后制作一个字典,以'参数名:参数定义'为键值对。例如,'x9:long x9',再以之前参数顺序组合,就
得得参数列表}

我要回帖

更多关于 python 编码转换 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信