in-place

How can I convert tabs to spaces in every file of a directory?

我的未来我决定 提交于 2019-11-27 04:08:33
问题 How can I convert tabs to spaces in every file of a directory (possibly recursively)? Also, is there a way of setting the number of spaces per tab? 回答1: Warning: This will break your repo. This will corrupt binary files , including those under svn , .git ! Read the comments before using! find . -type f -exec sed -i.orig 's/\t/ /g' {} + The original file is saved as [filename].orig . Downsides: Will replace tabs everywhere in a file. Will take a long time if you happen to have a 5GB SQL dump

Python Math - TypeError: 'NoneType' object is not subscriptable

青春壹個敷衍的年華 提交于 2019-11-27 01:27:22
问题 I'm making a small program for math (no particular reason, just kind of wanted to) and I ran into the error "TypeError: 'NoneType' object is not subscriptable. I have never before seen this error, so I have no idea what it means. import math print("The format you should consider:") print str("value 1a")+str(" + ")+str("value 2")+str(" = ")+str("value 3a ")+str("value 4")+str("\n") print("Do not include the letters in the input, it automatically adds them") v1 = input("Value 1: ") v2 = input(

Jq to replace text directly on file (like sed -i)

梦想与她 提交于 2019-11-26 20:54:23
I have a json file that needs to be updated on a certain condition. Sample json { "Actions" : [ { "value" : "1", "properties" : { "name" : "abc", "age" : "2", "other ": "test1" } }, { "value" : "2", "properties" : { "name" : "def", "age" : "3", "other" : "test2" } } ] } I am writing a script that makes use of Jq to match a value and update, as shown below cat sample.json | jq '.Actions[] | select (.properties.age == "3") .properties.other = "no-test"' Output (printed to terminal) { "value": "1", "properties": { "name": "abc", "age": "2", "other ": "test1" } } { "value": "2", "properties": {

Numpy modify array in place?

喜欢而已 提交于 2019-11-26 20:29:29
I have the following code which is attempting to normalize the values of an m x n array (It will be used as input to a neural network, where m is the number of training examples and n is the number of features). However, when I inspect the array in the interpreter after the script runs, I see that the values are not normalized; that is, they still have the original values. I guess this is because the assignment to the array variable inside the function is only seen within the function. How can I do this normalization in place? Or do I have to return a new array from the normalize function?

What is an in-place constructor in C++? [duplicate]

半腔热情 提交于 2019-11-26 18:18:16
问题 Possible Duplicate: C++'s “placement new” What is an in-place constructor in C++? e.g. Datatype *x = new(y) Datatype(); 回答1: This is called the placement new operator. It allows you to supply the memory the data will be allocated in without having the new operator allocate it. For example: Foo * f = new Foo(); The above will allocate memory for you. void * fm = malloc(sizeof(Foo)); Foo *f = new (fm) Foo(); The above will use the memory allocated by the call to malloc . new will not allocate

Replace entire HTML document in-place

拟墨画扇 提交于 2019-11-26 17:16:06
问题 I'm trying to avoid using a data URI because I do not want the generated document to be stored in the browser's history. Is it possible to replace the entire HTML document in-place? I tried jQuery("html").html("<html>....</html>") , but the style information does not survive. 回答1: You probably want to do this: jQuery("body").html("new content"); ...where "new content" would ideally only include the markup that would normally appear within the body element and not the rest. That will replace

In-place edits with sed on OS X

孤街醉人 提交于 2019-11-26 14:58:49
I'd like edit a file with sed on OS X. I'm using the following command: sed 's/oldword/newword/' file.txt The output is sent to the terminal. file.txt is not modified. The changes are saved to file2.txt with this command: sed 's/oldword/newword/' file1.txt > file2.txt However I don't want another file. I just want to edit file1.txt . How can I do this? I've tried the -i flag. This results in the following error: sed: 1: "file1.txt": invalid command code f whittle You can use the -i flag correctly by providing it with a suffix to add to the backed-up file. Extending your example: sed -i.bu 's

Python Pandas - Understanding inplace=True

回眸只為那壹抹淺笑 提交于 2019-11-26 13:02:24
In the pandas library many times there is an option to change the object inplace such as with the following statement... df.dropna(axis='index', how='all', inplace=True) I am curious what is being returned as well as how the object is handled when inplace=True is passed vs. when inplace=False . Are all operations modifying self when inplace=True ? And when inplace=False is a new object created immediately such as new_df = self and then new_df is returned? When inplace=True is passed, the data is renamed in place (it returns nothing), so you'd use: df.an_operation(inplace=True) When inplace

Pandas: peculiar performance drop for inplace rename after dropna

橙三吉。 提交于 2019-11-26 12:22:21
I have reported this as an issue on pandas issues . In the meanwhile I post this here hoping to save others time, in case they encounter similar issues. Upon profiling a process which needed to be optimized I found that renaming columns NOT inplace improves performance (execution time) by x120. Profiling indicates this is related to garbage collection (see below). Furthermore, the expected performance is recovered by avoiding the dropna method. The following short example demonstrates a factor x12: import pandas as pd import numpy as np inplace=True %%timeit np.random.seed(0) r,c = (7,3) t =

Jq to replace text directly on file (like sed -i)

大兔子大兔子 提交于 2019-11-26 07:44:39
问题 I have a json file that needs to be updated on a certain condition. Sample json { \"Actions\" : [ { \"value\" : \"1\", \"properties\" : { \"name\" : \"abc\", \"age\" : \"2\", \"other \": \"test1\" } }, { \"value\" : \"2\", \"properties\" : { \"name\" : \"def\", \"age\" : \"3\", \"other\" : \"test2\" } } ] } I am writing a script that makes use of Jq to match a value and update, as shown below cat sample.json | jq \'.Actions[] | select (.properties.age == \"3\") .properties.other = \"no-test\"