我希望能够使用正则表达式替换文件中的字符串.但我的功能是找不到匹配.所以我嘲笑了一个测试来复制正在发生的事情.
我已经定义了要替换的字符串,如下所示:
string = 'buf = O_strdup("ONE=001&TYPE=PUZZLE&PREFIX=EXPRESS&");'
我想用其他东西替换"TYPE = PUZZLE&PREFIX = EXPRESS&"部分.NB.该字符串并不总是在原始文件中包含完全"PUZZLE"和"PREFIX",但它将具有该格式).
所以首先我尝试测试我得到了正确的匹配.
obj = re.search(r'TYPE=([\^&]*)\&PREFIX=([\^&]*)\&', string)
if obj:
print obj.group()
else:
print "No match!!"
Run Code Online (Sandbox Code Playgroud)
思考([\^&]*)将匹配任何不是符号的字符数.但我总是得到"不匹配!!".
然而,
obj = re.search(r'TYPE=([\^&]*)', string)
给我回复"TYPE ="
为什么我的第一个不工作?
我希望我的程序创建一个位于命令参数路径的文件,即program /home/user/directory/that/doesnt/exist/file.如果该目录不存在,fopen将无法打开该文件,因此程序必须创建目录.我是否必须编写自己的循环来检测每个斜杠和mkdir每个目录,或者是否有自动执行此操作的函数?
public int Fibonacci(int x)
{
int prev = -1;
int next = 1;
for (int i = 0; i < x; i++)
{
int sum = prev + next;
prev = next;
next = sum;
Console.WriteLine(sum);
}
return sum; // plz teel me how can i return whole list ??
}
Run Code Online (Sandbox Code Playgroud)
如何返回上述系列的整个输出?即如果x = 3然后0 1 1 2那么我该如何归还呢?
我试图了解标志的n字符串格式中的选项值究竟是什么type.
PEP 3101说(在可用的整数类型部分):
'n' - Number. This is the same as 'd', except that it uses the
current locale setting to insert the appropriate
number separator characters.
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码:
print "This is a large number with formatting applied: {0:n}".format(1384309238430)
Run Code Online (Sandbox Code Playgroud)
我得到输出:
This is a large number with formatting applied: 1384309238430
Run Code Online (Sandbox Code Playgroud)
也就是说,不存在数字分隔符.如何找到我的区域设置?如何获取数字分隔符(我认为通过数字分隔符,它指的是诸如千位分隔符逗号之类的东西).
当它为null时,我想将总值替换为0
这是查询:
SELECT DISTINCT(location), (
SELECT Count(a.location) as total
FROM table_fo a
LEFT JOIN table_info b ON a.TRADEID = b.TRADEID AND a.asofdate = b.asofdate
WHERE (b.TERMSTATUS <> 'TRAN' OR b.TERMSTATUS is NULL) AND b.asofdate = '20110105' AND a.location = pfo.location
GROUP BY a.LOCATION
) AS total
FROM table_fo pfo
WHERE asofdate = '20110105';
Run Code Online (Sandbox Code Playgroud) 什么是在数据库中存储诸如"7年4个月"(例如,多年经验)之类的东西的最佳方式.浮动?
我在python上并不是特别新,但我只是觉得这个程序可能没有正常工作的原因.我已经写了一个类似的,从中得到了,这仍然可以正常工作.它是一个程序,用于绘制一组ping响应的平均时间,以查看当天是否存在任何模式.来源如下
from Tkinter import *
import matplotlib
import time
import os, sys, threading, Queue
matplotlib.use('TkAgg')
from numpy import arange, array, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import Tkinter
import sys
class App(object):
def __init__(self):
self.q = Queue.Queue()
self.q2 = Queue.Queue()
self.avvals=[]
self.addlist=['bbc.co.uk', 'google.co.uk', 'nhgs.co.uk', 'bing.co.uk', 'msn.com']
self.addlistlen = len(self.addlist)
self.root = Tkinter.Tk()
self.root.wm_title("Connection Speed")
self.frame = Tkinter.Frame(self.root)
self.frame.pack(side='top', expand=1, fill='both',)
self.frame2 = Tkinter.Frame(self.frame)
self.frame2.pack(side='bottom', expand=1, fill='both',)
self.f = Figure(figsize=(5,4), dpi=100)
self.a = self.f.add_subplot(111)
self.gframe = Tkinter.Frame(self.frame) …Run Code Online (Sandbox Code Playgroud) 我需要一个匹配 0 到 99.999 之间数字的正则表达式(99,999 也有效)。
有效示例:
1,1
99.9
12.876
1,777
Run Code Online (Sandbox Code Playgroud)
无效示例:
9837,83
-12,24
11.1112
Run Code Online (Sandbox Code Playgroud) 以下是在C上使用cbc和pkcs7填充(和密码)加密的aes256的代码(Windows和C++(使用libcrypto ++的Ubuntu).加密结果不一样.为什么?
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;
public static class AESEncryption
{
public static string Encrypt(byte[] PlainTextBytes, byte[] KeyBytes, string InitialVector)
{
try
{
byte[] InitialVectorBytes = Encoding.UTF8.GetBytes(InitialVector);
RijndaelManaged SymmetricKey = new RijndaelManaged();
SymmetricKey.Mode = CipherMode.CBC;
// SymmetricKey.Padding = PaddingMode.PKCS7;
ICryptoTransform Encryptor = SymmetricKey.CreateEncryptor(KeyBytes, InitialVectorBytes);
MemoryStream MemStream = new MemoryStream();
CryptoStream CryptoStream = new CryptoStream(MemStream, Encryptor, CryptoStreamMode.Write);
CryptoStream.Write(PlainTextBytes, 0, PlainTextBytes.Length);
CryptoStream.FlushFinalBlock();
byte[] CipherTextBytes = MemStream.ToArray();
MemStream.Close();
CryptoStream.Close();
//return ByteToHexConversion(CipherTextBytes);
return Convert.ToBase64String(CipherTextBytes);
} …Run Code Online (Sandbox Code Playgroud)