screenshot.py -full http://reddit.com full.jpg
Screenshot of the entire page (can be very high).
screenshot.py -window http://reddit.com window.jpg
Screenshot of the area that you see in the browser.
screenshot.py -thumb http://reddit.com thumb.jpg
Thumbnail of the area that you see in the browser.
When working with dates, I prefer the order yyyy-mm-dd (e.g. 2015-07-10). Its main advantage is that if you use it as a prefix and sort your entries, you get them in chronological order. (Another advantage is that in my home country we use this order, so this is much closer to my thinking).
So, I faced the following problem: having a date as a string (“2015-07-10″), calculate the date one day before and produce a string again (“2015-07-09″).
>>> from datetime import datetime, timedelta >>> date = "2015-07-10" >>> today = datetime.strptime(date, '%Y-%m-%d') >>> today datetime.datetime(2015, 7, 10, 0, 0) >>> yesterday = today - timedelta(days=1) >>> yesterday datetime.datetime(2015, 7, 9, 0, 0) >>> yesterday.strftime('%Y-%m-%d') '2015-07-09'
Back to dates: if I need to write a date in English, I write it like this: “May 12, 1984″. Avoid “05-12-1984″, because what is it? May 12? Or December 5? God knows only.
In the last two days I gave an intensive Python course at the University of Milan, Italy. It was good. As I saw the students liked it too :)
Here is the schedule of the course:
Day 1 ===== - introduction - string data type - list data type - loops (for, while) - tuple data type - list comprehension - control structures - functions Day 2 ===== - set - dictionary - global variables - file handling - classes, objects - modules - random numbers - downloading webpages - JSON serialization
In bash, the command “
touch” creates an empty file (with size 0). How to do this in Python?
Simply open a file in write mode and write an empty string to it.
With the stdlib:
with open("empty.txt", "w") as f: f.write("")
With the excellent unipath library:
p = Path("empty.txt") p.write_file("")
Note that this solution will overwrite your file if it exists. So be careful.
“Simplicity is the final achievement. After one has played a vast quantity of notes and more notes, it is simplicity that emerges as the crowning reward of art.”
In this post I found a detailed learning path on how to become proficient in data science.
They also made an infographic (see this post).
Click to see the full version.
(Here is a backup of the image if the original site went down.)