with open(input_file, 'r') as in_file, open(output_file, 'w') as out_file:
for line in in_file:
out_file.write(line)
Using the shutil module:
import shutil
shutil.copyfile(src, dst)
The following variables set up the below example:
var COOKIE_NAME = "Example Cookie"; /* The cookie's name. */
var COOKIE_VALUE = "Hello, world!"; /* The cookie's value. */
var COOKIE_PATH = "/foo/bar"; /* The cookie's path. */
var COOKIE_EXPIRES; ...
var expiry = new Date();
expiry.setTime(expiry.getTime() - 3600);
document.cookie = name + "=; expires=" + expiry.toGMTString() + "; path=/"
This will remove the cookie with a given name.
This a Basic example for using the MVVM model in a windows desktop application, using WPF and C#. The example code implements a simple "user info" dialog.
The View
The XAML
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
...
The following snippet encodes the data stored in d into JSON and stores it in a file (replace filename with the actual name of the file).
import json
d = {
'foo': 'bar',
'alice': 1,
'wonderland': [1, 2, 3]
}
with open(filename, 'w') as f:
json.dump(d, f)
The following snippet opens a JSON encoded file (replace filename with the actual name of the file) and returns the object that is stored in the file.
import json
with open(filename, 'r') as f:
d = json.load(f)
git diff
This will show the unstaged changes on the current branch from the commit before it. It will only show changes relative to the index, meaning it shows what you could add to the next commit, but haven't. To add (stage) these changes, you can use git add.
If a file is staged, but was modi...
git diff --staged
This will show the changes between the previous commit and the currently staged files.
NOTE: You can also use the following commands to accomplish the same thing:
git diff --cached
Which is just a synonym for --staged or
git status -v
Which will trigger the verbose sett...
You can upvote (or downvote, if you want...) examples you created.
Although you won't get any reputation for doing so, upvoting your the example will influence the examples' ordering on the page.
Any previous contributors to the examples will get reputation.
On the other hand, you might consider ...
Overview
Checkboxes and radio buttons are written with the HTML tag <input>, and their behavior is defined in the HTML specification.
The simplest checkbox or radio button is an <input> element with a type attribute of checkbox or radio, respectively:
<input type="checkbox&quo...
Calculating the length of the hypotenuse
math.hypot(2, 4) # Just a shorthand for SquareRoot(2**2 + 4**2)
# Out: 4.47213595499958
Converting degrees to/from radians
All math functions expect radians so you need to convert degrees to radians:
math.radians(45) # Convert 45 degrees t...
Python's string type provides many functions that act on the capitalization of a string. These include :
str.casefold
str.upper
str.lower
str.capitalize
str.title
str.swapcase
With unicode strings (the default in Python 3), these operations are not 1:1 mappings or reversible. Most of thes...
str.split(sep=None, maxsplit=-1)
str.split takes a string and returns a list of substrings of the original string. The behavior differs depending on whether the sep argument is provided or omitted.
If sep isn't provided, or is None, then the splitting takes place wherever there is whitespace. Howe...
Python's str type also has a method for replacing occurences of one sub-string with another sub-string in a given string. For more demanding cases, one can use re.sub.
str.replace(old, new[, count]):
str.replace takes two arguments old and new containing the old sub-string which is to be replace...
window.setInterval() returns an IntervalID, which can be used to stop that interval from continuing to run. To do this, store the return value of window.setInterval() in a variable and call clearInterval() with that variable as the only argument:
function waitFunc(){
console.log("This wil...