How to remove trailing whitespaces for multiple files?

You want sed –in-place ‘s/[[:space:]]\+$//’ file That will delete all POSIX standard defined whitespace characters, including vertical tab and form feed. Also, it will only do a replacement if the trailing whitespace actually exists, unlike the other answers that use the zero or more matcher (*). –in-place is simply the long form of -i. I … Read more

Updating a java map entry

Use table.put(key, val); to add a new key/value pair or overwrite an existing key’s value. From the Javadocs: V put(K key, V value): Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. … Read more

Python Math – TypeError: ‘NoneType’ object is not subscriptable

lista = list.sort(lista) This should be lista.sort() The .sort() method is in-place, and returns None. If you want something not in-place, which returns a value, you could use sorted_list = sorted(lista) Aside #1: please don’t call your lists list. That clobbers the builtin list type. Aside #2: I’m not sure what this line is meant … Read more

Difference between a -= b and a = a – b in Python

Note: using in-place operations on NumPy arrays that share memory in no longer a problem in version 1.13.0 onward (see details here). The two operation will produce the same result. This answer only applies to earlier versions of NumPy. Mutating arrays while they’re being used in computations can lead to unexpected results! In the example … Read more

Understanding inplace=True in pandas

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=False is passed (this is the default value, so isn’t necessary), performs the operation and returns a copy of the object, so you’d use: df = df.an_operation(inplace=False)

In-place edits with sed on OS X

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/oldword/newword/’ file1.txt Will give you two files: one with the name file1.txt that contains the substitution, and one with the name file1.txt.bu that has the original content. Mildly dangerous If you … Read more

What is the difference between `sorted(list)` vs `list.sort()`?

sorted() returns a new sorted list, leaving the original list unaffected. list.sort() sorts the list in-place, mutating the list indices, and returns None (like all in-place operations). sorted() works on any iterable, not just lists. Strings, tuples, dictionaries (you’ll get the keys), generators, etc., returning a list containing all elements, sorted. Use list.sort() when you … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)