我有一个字符串
a=">NKMFFALGLLGDGVIGALDTVVSSMGAVGASGLS"
Run Code Online (Sandbox Code Playgroud)
我想打印一个
">
NKMFFALGLLGDGVIGALDTVVSSMGAVGASGLS"
Run Code Online (Sandbox Code Playgroud)
我做了,a=a.replace(">","> \n")
但它不起作用.我哪里错了?
我目前正在阅读Bjarne Stroustrup撰写的"The C++ Programming Language:Special Edition"和第133页,其中说明如下:
对于用户定义的类型,将变量的定义推迟到合适的初始化程序可用之后,也可以获得更好的性能.例如:
Run Code Online (Sandbox Code Playgroud)string s; /* .... */ s = "The best is the enemy of the good.";
很容易慢得多
Run Code Online (Sandbox Code Playgroud)string s = "Voltaire";
我知道状态很容易,这意味着它不一定是这样,但是我们只是说它确实发生了.
为什么这会带来潜在的性能提升?
难道只有这样与用户定义类型(甚至STL型)或者是这也与案件int
,float
等等?
所以,我正在开始使用python的半完全背景的C++.在python中,你创建一个像这样的列表/数组:
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Run Code Online (Sandbox Code Playgroud)
然后,要打印列表,包括方括号,您所做的只是:
print x
Run Code Online (Sandbox Code Playgroud)
那会显示出来:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Run Code Online (Sandbox Code Playgroud)
我怎样才能在c ++中做同样的事情,以优雅/干净的方式打印括号和元素?注意我不想只是数组的元素,我想要整个数组,如下所示:
{1, 2, 3, 4, 5, 6, 7, 8, 9}
Run Code Online (Sandbox Code Playgroud)
当我使用此代码尝试打印数组时,会发生以下情况:
输入:
#include <iostream>
using namespace std;
int main()
{
int anArray[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
cout << anArray << endl;
}
Run Code Online (Sandbox Code Playgroud)
输出是内存中存储数组的位置(我想是这样,如果我错了,请纠正我):
0x28fedc
Run Code Online (Sandbox Code Playgroud)
作为旁注,我不知道如何创建一个包含许多不同数据类型的数组,例如整数,字符串等,所以如果有人可以启发我,那就太好了!感谢您回答我那些非常明显/无趣的问题!
嗨我有一个模型,里面有2到多个字段.一个是标准m2m字段,它不使用任何通过表,而另一个更复杂,并有一个通过表.我正在使用Django forms.modelform来显示和保存表单.我必须保存表单的代码是
if form.is_valid():
f = form.save(commit=False)
f.modified_by = request.user
f.save()
form.save_m2m()
Run Code Online (Sandbox Code Playgroud)
当我尝试保存表单时,我收到以下错误:
无法在指定中间模型的ManyToManyField上设置值.
我知道当我执行form.save_m2m()时会发生这种情况,因为直通表.我要做的就是告诉Django忽略带有直通表的m2m字段,但仍然保存没有直通表的m2m字段.然后,我可以继续手动保存直通表字段的数据.
谢谢
使用Python 3.1.2我在发送二进制附件文件(jpeg,pdf等)时遇到问题 - MIMEText附件工作正常.有问题的代码如下......
for file in self.attachments:
part = MIMEBase('application', "octet-stream")
part.set_payload(open(file,"rb").read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % file)
msg.attach(part) # msg is an instance of MIMEMultipart()
server = smtplib.SMTP(host, port)
server.login(username, password)
server.sendmail(from_addr, all_recipients, msg.as_string())
Run Code Online (Sandbox Code Playgroud)
但是,在调用堆栈中向下(参见下面的回溯),看起来好像msg.as_string()已经收到一个附件,它创建了'bytes'类型的有效负载而不是字符串.
有谁知道可能导致问题的原因是什么?任何帮助,将不胜感激.
艾伦
builtins.TypeError: string payload expected: <class 'bytes'>
File "c:\Dev\CommonPY\Scripts\email_send.py", line 147, in send
server.sendmail(self.from_addr, all_recipients, msg.as_string())
File "c:\Program Files\Python31\Lib\email\message.py", line 136, in as_string
g.flatten(self, unixfrom=unixfrom)
File "c:\Program Files\Python31\Lib\email\generator.py", line 76, in flatten
self._write(msg)
File "c:\Program Files\Python31\Lib\email\generator.py", line 101, in _write
self._dispatch(msg)
File …
Run Code Online (Sandbox Code Playgroud) 看看下面的链接:
http://msdn.microsoft.com/en-us/library/ms190215.aspx
根据上述链接,NEWID()
将包含网卡的标识号,但如果机器没有网卡,会发生什么?
这NEWID()
还会产生一个数字吗?
您好以下代码是一个wordfeud程序.它允许您搜索与前缀,后缀和一些字母匹配的单词列表.我的问题是,我不想使用底部的列表,而是使用包含单词的外部文本文件并将其加载到列表中.我该怎么做呢?
count :: String -> String -> Int
count _[] = 0
count [] _ = 0
count (x:xs) square
|x `elem` square = 1 + count xs (delete x square)
|otherwise = count xs square
check :: String -> String -> String -> String -> Bool
check prefix suffix word square
| (length strippedWord) == (count strippedWord square) = True
| otherwise = False
where
strippedWord = drop (length prefix) (take ((length word ) - (length suffix)) word)
wordfeud …
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现与 multidigimon.exe 相同的功能,即将输入数字化仪映射到给定的显示器,我想知道是否有我可以访问的 API,或者 multidigimon.exe 是否支持我可以调用它的任何参数自动化映射过程。
到目前为止,我发现 multidigimon.exe 写入了以下注册表项
密钥:20-\\?\hid#&col06#1&4784345&d&0005#{4d1e55b2-f16f-11cf-88cb-001111000030}
值:\\?\DISPLAY#Default_Monitor#5&5e64b29&0&UID268435456#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
到
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Wisp\Pen\Digimon
如何让python运行sudo openvpn --cd/etc/openvpn --config client.ovpn
我现在正在尝试以下方面但没有成功
vpnfile2 = '/etc/init.d/openvpn'
cfgFile = 'client.ovpn'
os.system('sudo \"" + vpnFile2 + "\" --cd \"" + vpnpath + "\" --config \"" + cfgFile + "\"')
Run Code Online (Sandbox Code Playgroud) 我需要一个函数来返回一个字符串.我使用以下代码来声明函数:
const char* serv_con(char app_data[50])
{
char send_data[1024],recv_data[1024];
//i am avoiding code segments irrelevant to the issue.
return recv_data;
}
Run Code Online (Sandbox Code Playgroud)
然后像这样调用main中的函数:
int main()
{
char ser_data[50], app_data[50];
ser_data[0] = '\0';
app_data[0] = '\0';
//avoiding code segments irrelevant to the issue.
app_data = serv_con(ser_data); //function call
}
Run Code Online (Sandbox Code Playgroud)
编译时会出错:
connect.c:109: error: incompatible types when assigning to type ‘char[50]’ from type ‘const char *’
Run Code Online (Sandbox Code Playgroud)
然后我用std :: string 替换了声明中的const char.声明现在如下:
std::string serv_con(char app_data[50])
{
char send_data[1024],recv_data[1024];
//avoiding code segments irrelevant to the …
Run Code Online (Sandbox Code Playgroud) c++ ×3
python ×3
attachment ×1
binary ×1
c ×1
definitions ×1
django ×1
email ×1
forms ×1
function ×1
guid ×1
haskell ×1
m2m ×1
many-to-many ×1
performance ×1
return-type ×1
smtp ×1
sql-server ×1
windows-7 ×1