Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f9a2e3f

Browse filesBrowse files
committed
2 parents 3fc975e + 6f43281 commit f9a2e3f
Copy full SHA for f9a2e3f

File tree

Expand file treeCollapse file tree

8 files changed

+237
-80
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+237
-80
lines changed
Open diff view settings
Collapse file

‎advanced/README.md‎

Copy file name to clipboard
+31Lines changed: 31 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[comment]: # (This file is automatically generated. Don't edit this
2+
file manually, run update-readmes.py instead.)
3+
4+
# Advanced
5+
6+
If you want to learn more advanced techniques, you can also read this
7+
section. Most of the techniques explained here are great when you're
8+
working on a large project, and your code would be really repetitive
9+
without these things.
10+
11+
You can experient with these things freely, but please **don't use these
12+
techniques just because you know how to use them.** Prefer the simple
13+
techniques from the Basics part instead when possible. Simple is better
14+
than complex.
15+
16+
1. [Handy data types](datatypes.md)
17+
2. [Advanced stuff with functions](functions.md)
18+
3. [Magic methods](magicmethods.md)
19+
4. [Iterables, iterators and generators](iters.md)
20+
21+
***
22+
23+
If you have trouble with this tutorial please [tell me about
24+
it](../contact-me.md) and I'll make this tutorial better. If you
25+
like this tutorial, please [give it a
26+
star](../README.md#how-can-i-thank-you-for-writing-and-sharing-this-tutorial).
27+
28+
You may use this tutorial freely at your own risk. See
29+
[LICENSE](../LICENSE).
30+
31+
[List of contents](../README.md#list-of-contents)
Collapse file

‎basics/README.md‎

Copy file name to clipboard
+40Lines changed: 40 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[comment]: # (This file is automatically generated. Don't edit this
2+
file manually, run update-readmes.py instead.)
3+
4+
# Basics
5+
6+
This section will get you started with using Python and you'll be able
7+
to learn more about whatever you want after studying it.
8+
9+
1. [What is programming?](what-is-programming.md)
10+
2. [Installing Python](installing-python.md)
11+
3. [Getting started with Python](getting-started.md)
12+
4. [ThinkPython: The way of the program](the-way-of-the-program.md)
13+
5. [Variables, Booleans and None](variables.md)
14+
6. [Using functions](using-functions.md)
15+
7. [Setting up an editor](editor-setup.md)
16+
8. [If, else and elif](if.md)
17+
9. [Handy stuff with strings](handy-stuff-strings.md)
18+
10. [Lists and tuples](lists-and-tuples.md)
19+
11. [Loops](loops.md)
20+
12. [Trey Hunner: zip and enumerate](trey-hunner-zip-and-enumerate.md)
21+
13. [Dictionaries](dicts.md)
22+
14. [Defining functions](defining-functions.md)
23+
15. [Writing a larger program](larger-program.md)
24+
16. [What is true?](what-is-true.md)
25+
17. [Files](files.md)
26+
18. [Modules](modules.md)
27+
19. [Exceptions](exceptions.md)
28+
20. [Classes](classes.md)
29+
30+
***
31+
32+
If you have trouble with this tutorial please [tell me about
33+
it](../contact-me.md) and I'll make this tutorial better. If you
34+
like this tutorial, please [give it a
35+
star](../README.md#how-can-i-thank-you-for-writing-and-sharing-this-tutorial).
36+
37+
You may use this tutorial freely at your own risk. See
38+
[LICENSE](../LICENSE).
39+
40+
[List of contents](../README.md#list-of-contents)
Collapse file

‎classes.md‎

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
This file has been moved [here](basics/classes.md).
2+
3+
***
4+
5+
If you have trouble with this tutorial please [tell me about
6+
it](./contact-me.md) and I'll make this tutorial better. If you
7+
like this tutorial, please [give it a
8+
star](./README.md#how-can-i-thank-you-for-writing-and-sharing-this-tutorial).
9+
10+
You may use this tutorial freely at your own risk. See
11+
[LICENSE](./LICENSE).
12+
13+
[List of contents](./README.md#list-of-contents)
Collapse file

‎common.py‎

Copy file name to clipboardExpand all lines: common.py
+26-10Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,33 @@ def find_links(file):
6969
def get_markdown_files():
7070
"""Yield the names of all markdown files in this tutorial.
7171
72-
This assumes that the README contains links to everything. The
73-
yielded paths use / as the path separator.
72+
The yielded paths use / as the path separator.
7473
"""
75-
yield 'README.md'
76-
with open('README.md', 'r') as f:
77-
for match, lineno in find_links(f):
78-
target = posixpath.normpath(match.group(2))
79-
# Currently he README links to itself, but we don't want to
80-
# break things if it will be modified not to link in the future.
81-
if target.endswith('.md') and target != 'README.md':
82-
yield target
74+
for root, dirs, files in os.walk('.'):
75+
for file in files:
76+
if not file.endswith('.md'):
77+
continue
78+
path = os.path.normpath(os.path.join(root, file))
79+
yield path.replace(os.sep, '/')
80+
81+
82+
def header_link(title):
83+
"""Return a github-style link target for a title.
84+
85+
>>> header_link('Hello there!')
86+
'hello-there'
87+
"""
88+
# This doesn't do the-title-1, the-title-2 etc. with multiple titles
89+
# with same text, but usually this doesn't matter.
90+
result = ''
91+
for character in title:
92+
if character in string.whitespace:
93+
result += '-'
94+
elif character in string.punctuation:
95+
pass
96+
else:
97+
result += character.lower()
98+
return result
8399

84100

85101
def askyesno(question, default=True):
Collapse file

‎make-html.py‎

Copy file name to clipboardExpand all lines: make-html.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import os
3333
import posixpath
3434
import shutil
35-
import string
3635
import sys
3736
import textwrap
3837
import webbrowser
Collapse file

‎strip.py‎

Copy file name to clipboardExpand all lines: strip.py
-69Lines changed: 0 additions & 69 deletions
This file was deleted.
Collapse file

‎update-readmes.py‎

Copy file name to clipboard
+116Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env python3
2+
3+
# This is free and unencumbered software released into the public
4+
# domain.
5+
6+
# Anyone is free to copy, modify, publish, use, compile, sell, or
7+
# distribute this software, either in source code form or as a
8+
# compiled binary, for any purpose, commercial or non-commercial, and
9+
# by any means.
10+
11+
# In jurisdictions that recognize copyright laws, the author or
12+
# authors of this software dedicate any and all copyright interest in
13+
# the software to the public domain. We make this dedication for the
14+
# benefit of the public at large and to the detriment of our heirs
15+
# and successors. We intend this dedication to be an overt act of
16+
# relinquishment in perpetuity of all present and future rights to
17+
# this software under copyright law.
18+
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
23+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24+
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
27+
# For more information, please refer to <http://unlicense.org>
28+
29+
"""Generate basics/README.md and advanced/README.md."""
30+
31+
import os
32+
import posixpath
33+
34+
import common
35+
36+
37+
BEGINNING = """\
38+
[comment]: # (This file is automatically generated. Don't edit this
39+
file manually, run update-readmes.py instead.)
40+
41+
"""
42+
43+
44+
def get_contents():
45+
"""Read descriptions and contents lists from README.
46+
47+
Return a {chaptername: content} dictionary.
48+
"""
49+
result = {}
50+
current_section = None
51+
52+
with open('README.md', 'r') as f:
53+
# move to where the content list starts
54+
while f.readline().strip() != "## List of contents":
55+
pass
56+
57+
for line in f:
58+
if line.startswith('### '):
59+
# new section
60+
current_section = common.header_link(line.lstrip('#').strip())
61+
result[current_section] = line[2:] # one # instead of 3
62+
elif line.startswith('## '):
63+
# end of content lists
64+
break
65+
elif current_section is not None:
66+
# we are currently in a section
67+
result[current_section] += line
68+
69+
return result
70+
71+
72+
def update_file(filename, content):
73+
"""Make sure that a file contains the content.
74+
75+
Return True if the file changed and False if it didn't.
76+
"""
77+
try:
78+
with open(filename, 'r') as f:
79+
# ignore the end
80+
old_content = f.read().split('\n***\n')[0].rstrip()
81+
if old_content == content:
82+
print("Has correct content:", filename)
83+
return False
84+
except FileNotFoundError:
85+
# the file doesn't exist yet, we'll create it
86+
pass
87+
88+
print("Writing new content:", filename)
89+
with open(filename, 'w') as f:
90+
print(content, file=f)
91+
return True
92+
93+
94+
def main():
95+
something_changed = False
96+
for directory, content in sorted(get_contents().items()):
97+
if not os.path.exists(directory):
98+
# something else under the list of contents than a chapter
99+
# list, doesn't have a separate subdirectory
100+
print("Not a directory:", directory)
101+
continue
102+
103+
# the links that point to the subdir must now point to the
104+
# current directory, so we fix that
105+
content = BEGINNING + content.replace(directory + '/', '').rstrip()
106+
path = os.path.join(directory, 'README.md')
107+
this_changed = update_file(path, content)
108+
something_changed = something_changed or this_changed
109+
110+
if something_changed:
111+
print()
112+
print("Run update-ends.py now so the files will have correct ends.")
113+
114+
115+
if __name__ == '__main__':
116+
main()
Collapse file

‎what-next.md‎

Copy file name to clipboardExpand all lines: what-next.md
+12Lines changed: 12 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ is a way to create generators
2828
| `from stuff import *` | imports everything
2929

3030
## Fun modules
31+
32+
***
33+
34+
If you have trouble with this tutorial please [tell me about
35+
it](./contact-me.md) and I'll make this tutorial better. If you
36+
like this tutorial, please [give it a
37+
star](./README.md#how-can-i-thank-you-for-writing-and-sharing-this-tutorial).
38+
39+
You may use this tutorial freely at your own risk. See
40+
[LICENSE](./LICENSE).
41+
42+
[List of contents](./README.md#list-of-contents)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.