标签: overwrite

用JavaScript覆盖数组

如何覆盖(或取消设置然后设置)数组?似乎"array = new_array"不起作用.

javascript arrays overwrite unset

3
推荐指数
1
解决办法
2万
查看次数

如何覆盖Python当前正在读取的文件

我不太确定说出这个的最佳方式,但我想做的是读取pdf文件,进行各种修改,并将修改后的pdf保存在原始文件上.截至目前,我能够将修改后的pdf保存到单独的文件中,但我希望替换原始文件,而不是创建新文件.

这是我目前的代码:

from pyPdf import PdfFileWriter, PdfFileReader

output = PdfFileWriter()
input = PdfFileReader(file('input.pdf', 'rb'))
blank = PdfFileReader(file('C:\\BLANK.pdf', 'rb'))

# Copy the input pdf to the output.
for page in range(int(input.getNumPages())):
    output.addPage(input.getPage(page))

# Add a blank page if needed.
if (input.getNumPages() % 2 != 0):
    output.addPage(blank.getPage(0))

# Write the output to pdf.
outputStream = file('input.pdf', 'wb')
output.write(outputStream)
outputStream.close()
Run Code Online (Sandbox Code Playgroud)

如果我更改outputStream为不同的文件名,它工作正常,我只是不能保存输入文件,因为它仍在使用.我试过.close()了流,但它也给了我错误.

我觉得这有一个相当简单的解决方案,我没有找到任何运气.

谢谢!

python pdf input overwrite

3
推荐指数
1
解决办法
1576
查看次数

如何在VB.NET中覆盖文本

我曾经教过如何使用下面的代码附加文本文件,但是每次按下按钮1时我如何覆盖文件(没有人教过我)?

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim ALPHAVAL As String = "C:\ALPHAVAL.txt"

    If System.IO.File.Exists(ALPHAVAL) = True Then
        Dim objWriter As New System.IO.StreamWriter(ALPHAVAL, True)
        objWriter.WriteLine(TextBox1.Text)
        objWriter.Close()
    End If
Run Code Online (Sandbox Code Playgroud)

结束课程

vb.net overwrite text-files

3
推荐指数
1
解决办法
3万
查看次数

在python中覆盖{}

我想创建一个dict int,你可以这样访问:

>>> my_dict["property'] = 3
>>> my_dict.property
3
Run Code Online (Sandbox Code Playgroud)

所以我做了这个:

class DictAsMember(dict):
    def __getattr__(self, name):
        return self[name]
Run Code Online (Sandbox Code Playgroud)

这工作正常,但如果你有嵌套dicts它不起作用,例如:

my_dict = DictAsMember()
my_dict["property"] = {'sub': 1}
Run Code Online (Sandbox Code Playgroud)

我可以访问my_dict.property,但逻辑上我不能做my_dict.property.sub因为属性是一个默认的dict,所以我想要做的就是覆盖默认的dict,所以你可以使用{}.

这可能吗?

python dictionary overwrite

3
推荐指数
1
解决办法
1409
查看次数

覆盖 zip 文件中的条目

我遇到了麻烦,我得到了这个代码:

DirectoryInfo di = new DirectoryInfo(dir);
FileInfo[] rgFiles = di.GetFiles();
DirectoryInfo[] d = di.GetDirectories();
if(rgFiles != null && d != null) {
foreach (FileInfo fi in rgFiles)
{
    foreach (DirectoryInfo dii in d)
    {
        using (ZipFile zip = ZipFile.Read(locateZipFile()))
        {

            zip.AddFile(fi.FullName, "");

            zip.AddDirectory(dii.FullName,dii.Name);
            toolStripStatusLabel1.Text = "Inserting " + fi.Name;
            toolStripStatusLabel1.Text = "Inserting " + dii.Name + " and all of it's contents";

            MessageBox.Show("Inserted the file " + fi.Name);
            MessageBox.Show("Inserted the folder " + dii.Name + " and all contents in …
Run Code Online (Sandbox Code Playgroud)

c# overwrite dotnetzip

3
推荐指数
1
解决办法
6163
查看次数

为什么perl对象实例会相互覆盖

我编写了一些Perl代码,它构成了基础代码中固有的两个类.我想它会打印出这样的东西

Mik: Meow! Meow!
Sat: Woof! Woof!
Run Code Online (Sandbox Code Playgroud)

但它实际上是这样打印的:

Sat: Woof! Woof!
Sat: Woof! Woof!
Run Code Online (Sandbox Code Playgroud)

,

package Animal;
sub new {

    my $obj = shift;
    my $name = shift;
    our %pkg = ( 'name' => $name );
    bless \%pkg, $obj;
    return \%pkg;
}

package Cat;
@ISA = ("Animal");

sub new {
    my $obj = shift;
    my $name = shift;
    my $self =  $obj->SUPER::new($name);
    return $self;
}

sub get_name {
    my $obj = shift;
    return $obj->{'name'};
}


sub talk {
    my $obj …
Run Code Online (Sandbox Code Playgroud)

oop perl class object overwrite

3
推荐指数
1
解决办法
235
查看次数

Python:覆盖两个变量

在我使用python期间,我遇到了一个阻塞问题.我有一些SomeFunction应该做一些简单的计算(并且还要对它进行排序 - 我删除那段代码以使其更清晰)在给定的整数向量上并返回新的.主要问题是,每个内部循环的结果必须成为下一个的输入,但变量k和X似乎在内存中具有相同的地址.

功能如下:

def SomeFunction(k, N):
    X = range(N);
    for i in range(N):
        for j in range(3):
            X[i] = k[i]*2;
        print "X:";
        print X;
        print "k -> :";
        print k
        k = X;
        print "============================";
    return k;
Run Code Online (Sandbox Code Playgroud)

它产生输出:

    X:
    [0, 1, 2, 3, 4, 5, 6, 7]
    k -> :
    [0, 1, 2, 3, 4, 5, 6, 7]
    ============================

    X:
    [0, 8, 2, 3, 4, 5, 6, 7]
    k -> :
    [0, 8, 2, 3, 4, 5, 6, 7] …

python sorting variables overwrite

3
推荐指数
1
解决办法
149
查看次数

JavaScript - 用户安全覆盖变量

我在JavaScript中有一个变量:

var userIp = '192.168.0.1';
Run Code Online (Sandbox Code Playgroud)

但是,用户可以打开浏览器控制台并覆盖它:

userIp = '123.45.127.21';
Run Code Online (Sandbox Code Playgroud)

我怎么能锁定这个变量,用户无法改变它的值?可能吗?

javascript variables overwrite

3
推荐指数
1
解决办法
45
查看次数

使用Ruby替换文件中的特定行

我有一个文本文件(a.txt),如下所示.

open
close
open
open
close
open
Run Code Online (Sandbox Code Playgroud)

我需要找到一种用"关闭"替换第3行的方法.我做了一些搜索,大多数方法都涉及搜索线而不是替换它.不能真的在这里做,因为我不想把所有"开放"变为"关闭".

基本上(对于这种情况)我正在寻找IO.readlines("./ a.txt")[2]的写版本.

ruby overwrite line

3
推荐指数
1
解决办法
2721
查看次数

如何在 python 中覆盖 __mul__ 函数

我用 python 写了一个这样的类

class Vector(object):
def __init__(self, coordinates):
    try:
        if not coordinates:
            raise ValueError
        self.coordinates = tuple(coordinates)
        self.dimension = len(coordinates)

    except ValueError:
        raise ValueError('The coordinates must be nonempty')

    except TypeError:
        raise TypeError('The coordinates must be an iterable')

def __add__(self,v):
    v1 = np.array(self.coordinates)
    v2 = np.array(v.coordinates)
    result = v1 + v2
    return result.tolist()

def __sub__(self, other):
    v1 = np.array(self.coordinates)
    v2 = np.array(other.coordinates)
    result = v1 - v2
    return result.tolist()

def __mul__(self, other):
    return other * np.array(self.coordinates)

def multiply(self,other):
    v = Decimal(str(other)) …
Run Code Online (Sandbox Code Playgroud)

python overwrite operation

3
推荐指数
1
解决办法
1750
查看次数