这与我之前提出的问题类似.但我决定让它变得更复杂一些.
我正在创建一个程序,可以读取文本文件并将文本文件的特定部分复制到另一个文本文件中.但是,我也希望生成错误消息.
例如,我的文本文件如下所示:
* VERSION_1_1234
#* VERSION_2_1234
* VERSION_3_1234
#* VERSION_2_4321
Run Code Online (Sandbox Code Playgroud)
到目前为止,我的程序通过"VERSION_2"行查看并将该行复制到另一个文本文件中.
但现在,我希望它搜索"VERSION_3",如果它找到"VERSION_2"和"VERSION_3",它将产生错误.
这是我到目前为止所拥有的:
with open('versions.txt', 'r') as verFile:
for line in verFile:
# if pound sign, skip line
if line.startswith('#'):
continue
# if version_3 there, copy
if 'VERSION_3_' in line:
with open('newfile.txt', 'w') as wFile:
wFile.write(line.rpartition('* ')[-1])
# if version_2 there, copy
if 'VERSION_2_' in line:
with open('newfile.txt', 'w') as wFile:
wFile.write(line.rpartition('* ')[-1])
# if both versions there, produce error
if ('VERSION_3_' and 'VERSION_2_') in line:
print ('There's an …Run Code Online (Sandbox Code Playgroud) 我目前正在编写一个小型绘图应用程序,用户可以在Panel上绘图.我正在使用选择工具,并希望能够选择面板的某个区域,然后将此选定区域直接粘贴到我刚刚在Panel右侧的PictureBox中.
我的问题是我的代码目前无法正常工作,当我尝试从面板粘贴我正在创建的Bitmap时,我在PictureBox中获得了一个大的红色X而不是实际的图像.我知道图像正在正确地复制到Bitmap,因为我尝试在它周围放一些代码将它作为jpeg保存到磁盘,然后查看图像,它显示正常.
这是我的代码:
private void tbCopy_Click(object sender, EventArgs e)
{
int width = selectList[0].getEnd().X - selectList[0].getInitial().X;
int height = selectList[0].getEnd().Y - selectList[0].getInitial().Y;
using (Bitmap bmp = new Bitmap(width, height))
{
pnlDraw.DrawToBitmap(bmp, new System.Drawing.Rectangle(
selectList[0].getInitial().X,
selectList[0].getInitial().Y,
width, height));
pbPasteBox.Image = bmp;
}
}
Run Code Online (Sandbox Code Playgroud)
宽度和高度只是我要复制的区域的尺寸,而selectList是一个包含一个对象的List,其中包含我要复制的区域的坐标.
任何帮助将不胜感激.
我从C++开始,我对指针有一些疑问,而且它是副本.
我打算写一个例子:
class Abc{
Qwe q;
}
Abc* a = new Abc();
Abc* b = new Abc();
b->q = a->q; //??
Run Code Online (Sandbox Code Playgroud)
这项任务会发生什么?是'a'将'q'的副本给'b'?
问题是我想对两个指针都有不同的'q',我不知道如何复制它.就像在例子中?
谢谢
我正在阅读NSPasteboard,然后想找到....
我试图找到正确的通知方法,该方法监听数据到剪贴板的复制事件.
此外,我试图找到复制到剪贴板的数据的文件路径.哪个是粘贴板对象.
如果我从浏览器中的页面复制文本,我试图找出如何获取文本从中复制的页面的URL地址.
有任何想法吗?
我试图将一个数组的内容复制到另一个数组而不指向相同的内存,但我不能.
我的代码:
class cPrueba {
private float fvalor;
public float getFvalor() {
return fvalor;
}
public void setFvalor(float fvalor) {
this.fvalor = fvalor;
}
}
List<cPrueba> tListaPrueba = new ArrayList<cPrueba>();
List<cPrueba> tListaPrueba2 = new ArrayList<cPrueba>();
cPrueba tPrueba = new cPrueba();
tPrueba.setFvalor(50);
tListaPrueba.add(tPrueba);
tListaPrueba2.addAll(tListaPrueba);
tListaPrueba2.get(0).setFvalor(100);
System.out.println(tListaPrueba.get(0).getFvalor());
Run Code Online (Sandbox Code Playgroud)
结果是"100.0"....
仍然指向同一个对象...任何简短的复制方式?(不适用于(..){})
编辑:
class cPrueba implements Cloneable {
private float fvalor;
public float getFvalor() {
return fvalor;
}
public void setFvalor(float fvalor) {
this.fvalor = fvalor;
}
public cPrueba clone() {
return this.clone();
}
} …Run Code Online (Sandbox Code Playgroud) 似乎他们唯一的价值就是存储属性.即便如此,这些都无法改变,或者所有实例都会反映出这些变化!
如果我在这里上课:
# Vertex
class Vertex:
label = str()
ID = int()
outEdges = list()
inEdges = list()
Run Code Online (Sandbox Code Playgroud)
创建一个新的顶点对象:
v = Vertex()
Run Code Online (Sandbox Code Playgroud)
并添加到v的outedges:
v.outEdges.append(1)
Run Code Online (Sandbox Code Playgroud)
然后Vertex.outEdges不再是一个空列表,但也包含1.
那我应该如何使用python类?有了复制模块吗?一点也不?
我有一个简单的div与单个图像.我想将同一个img元素复制到另一个div.
$('.copy').click(function() {
imageElement = $(this).siblings('img.source')[0];
item = $('<div class="item">' + imageElement + '</div>');
});
Run Code Online (Sandbox Code Playgroud)
我明白了:
[object HTMLImageElement]
Run Code Online (Sandbox Code Playgroud)
而不是实际的图像标签渲染.有任何想法吗?
好的,所以这可能有一个简单的解决方案,但经过一些搜索和测试后,我仍然困惑.. :(
这是我编写的代码片段:
int main(int argc, char *argv[]){
int test;
test = copyTheFile("test.txt", "testdir");
if(test == 1)
printf("something went wrong");
if(test == 0)
printf("copydone");
return 0;
}
int copyTheFile(char *sourcePath, char *destinationPath){
FILE *fin = fopen(sourcePath, "r");
FILE *fout = fopen(destinationPath, "w");
if(fin != NULL && fout != NULL){
char buffer[10000];//change to real size using stat()
size_t read, write;
while((read = fread(buffer, 1, sizeof(buffer), fin)) > 0){
write = fwrite(buffer, 1, read, fout);
if(write != read)
return 1;
}//end of …Run Code Online (Sandbox Code Playgroud) 我试图将我的类路径中的文件复制到另一个临时位置.
这是它的代码:
InputStream inputStream = this.getClass().getClassLoader()
.getResourceAsStream(readmeFile);
Path path = Paths.get(tempFilesOutputPath + File.separator + readmeFile);
try {
Files.copy(inputStream, path, StandardCopyOption.REPLACE_EXISTING);
inputStream.close();
} catch (IOException e) {
throw e;
}
Run Code Online (Sandbox Code Playgroud)
readMeFile有2个页面,tempFilesOutputPath文件夹中的复制文件也有两个页面,但没有任何内容.
如果我犯了一些错误或者必须以不同的方式完成,请告诉我.
干杯,Madhu
如果我用C或C++编写程序,在Windows/CMD提示符中将非文本文件(.mp3,.avi等)从一个位置复制到另一个位置,我是否真的依赖Windows API来完成所有工作为了我?复制文本文件是一回事,我可以打开它并按字符或逐字符串复制字符.有人可以给我一个简短的纲要(如果你有参考链接,甚至更好.我只是问,因为我找不到任何合理的解释它.)关于非文本文件复制程序如何工作?
谢谢大家!