Skip to content

Commit 2e13661

Browse files
set up start of new structure -- restructured the setting up docs.
1 parent 0b0448a commit 2e13661

38 files changed

Lines changed: 4575 additions & 0 deletions

‎source/index.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ This site can be thought of as the textbook for Programming in Python: the first
1515

1616
Many of these modules can be useful on their own, but each assumes that you know concepts that were introduced earlier in the program, so working them in order can be helpful.
1717

18+
Topics in the Program
19+
=====================
20+
21+
.. toctree::
22+
:maxdepth: 1
23+
24+
topics/index
1825

1926
The Program
2027
===========
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
.. _py2_vs_py3:
2+
3+
########################
4+
Python 2 versus Python 3
5+
########################
6+
7+
8+
Much of the example code you'll find online is Python2, rather than Python3
9+
10+
For the most part, they are the same -- so you can use those examples to learn from.
11+
12+
There are a lot of subtle differences that you don't need to concern yourself with just yet.
13+
14+
But a couple that you'll need to know right off the bat:
15+
16+
print()
17+
-------
18+
19+
In Python2, ``print`` is a "statement", rather than a function. That means it didn't require parentheses around what you want printed:
20+
21+
.. code-block:: python
22+
23+
print something, something_else
24+
25+
This made it a bit less flexible and powerful.
26+
27+
But -- if you try to use it that way in Python3, you'll get an error:
28+
29+
.. code-block:: python
30+
31+
In [15]: print "this"
32+
File "<ipython-input-15-70c8add5d16e>", line 1
33+
print "this"
34+
^
35+
SyntaxError: Missing parentheses in call to 'print'
36+
37+
So -- if you get this error, simply add the parentheses:
38+
39+
.. code-block:: ipython
40+
41+
In [16]: print("this")
42+
this
43+
44+
Division
45+
--------
46+
47+
In python 3, the division operator is "smart" when you divide integers:
48+
49+
.. code-block:: ipython
50+
51+
In [17]: 1 / 2
52+
Out[17]: 0.5
53+
54+
However in Python2, integer division, will give you an integer result:
55+
56+
.. code-block:: ipython
57+
58+
In [1]: 1/2
59+
Out[1]: 0
60+
61+
In both versions, you can get "integer division" if you want it with a double slash:
62+
63+
.. code-block:: ipython
64+
65+
In [1]: 1//2
66+
Out[1]: 0
67+
68+
And in Python2, you can get the behavior of Python3 with "true division":
69+
70+
.. code-block:: ipython
71+
72+
In [2]: from __future__ import division
73+
74+
In [3]: 1/2
75+
Out[3]: 0.5
76+
77+
For the most part, you just need to be a bit careful with the rare cases where Python2 code counts on integer division.
78+
79+
Iterators vs Lists
80+
------------------
81+
82+
In Python2, a number of functions returned a full list of the contents. But most of the time, you didn't need a list -- you only needed a way to loop through all the items returned. Such an object is called an "iterable" -- more about that later in the class. But for now, if you get an error like::
83+
84+
TypeError: 'dict_keys' object does not support indexing
85+
86+
Then you likely got an iterator, rather than a "proper" list. You can fix this by making a list out of it::
87+
88+
list(an_iterator)
89+
90+
the list constructor will make a list out of any iterable. So you can now index it, etc.
91+
92+
Other Python2 / Python3 differences
93+
-----------------------------------
94+
95+
The most drastic difference (improvement!) is better Unicode support, and better bytes / Unicode separation.
96+
97+
Most of the other differences are essentially implementation details, like getting iterators instead of sequences -- we'll talk about that more when it comes up in a later lesson.
98+
99+
There are also a few syntax differences with more advanced topics: Exceptions, ``super()``, etc.
100+
101+
We'll talk about all that when we cover those topics as well.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. _setup_details:
2+
3+
==============
4+
Advanced Setup
5+
==============
6+
7+
Once you have the core tools running, there are a number of things you can do to really get your environment working well. It is well worth doing some of this customization right up front.
8+
9+
10+
Creating an IDE
11+
---------------
12+
13+
.. toctree::
14+
:maxdepth: 1
15+
16+
sublime_as_ide.rst
17+
atom_as_ide.rst
18+
vsc_as_ide.rst
19+
20+
Command Shells
21+
--------------
22+
23+
.. toctree::
24+
:maxdepth: 1
25+
26+
shell.rst
27+
ipython.rst
28+
windows_bash.rst
29+
virtualenv.rst
30+
Py2vsPy3.rst
31+
32+
33+
34+
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
.. _atom_as_ide:
2+
3+
##########################################
4+
Turning Atom Into a Lightweight Python IDE
5+
##########################################
6+
7+
Atom is the self-proclaimed "hackable text editor for the 21st Century." It has a nice modern interface, and is highly customizable yet can also be used productively with minimal setup and configuration.
8+
9+
10+
Requirements
11+
============
12+
13+
Any IDE should ease your development experience by providing the following:
14+
15+
* It should provide excellent, configurable syntax colorization.
16+
* It should allow for robust tab completion.
17+
* It should offer the ability to jump to the definition of symbols in other files.
18+
* It should perform automatic code linting to help avoid silly mistakes.
19+
* It should be able to interact with a Python interpreter such that when debugging, the editor will follow along with the debugger.
20+
21+
Atom does all this and more, but some functionality requires you to select and install packages.
22+
23+
24+
Which Version?
25+
==============
26+
27+
The latest version is the best version. Atom is regularly maintained, so the latest
28+
version will have the latest bug fixes and updates.
29+
30+
31+
Installation
32+
============
33+
34+
Go to the Atom website_.
35+
36+
.. _website: https://atom.io/
37+
38+
On the main page, click the big red button to download the installer, then run the installer.
39+
40+
If it is not offering the correct platform: on the main page, below the big red button, click Other Platforms and find the installer for your operating system.
41+
42+
If you already have Atom installed, but want to check for a newer version, go to
43+
``Help`` -> ``Check for Update``.
44+
45+
46+
Basic Settings
47+
==============
48+
49+
Atom can be used out of the box with no setup as a text editor. It automatically
50+
recognizes file types and helpfully highlights text accordingly. To use in this manner,
51+
write your Python files in Atom, then run them in your Python command prompt.
52+
53+
54+
Extending the Editor
55+
====================
56+
57+
When you first open Atom, a Welcome Guide appears. This provides some quick and helpful information on
58+
how to open projects, install packages, and customize your themes and styling.
59+
60+
Atom has great documentation_ on how to hack and configure it. Read the Flight Manual_ for tons of information on
61+
everything you can do. You can also watch a Getting Started video_.
62+
63+
.. _documentation: https://atom.io/docs
64+
.. _Manual: http://flight-manual.atom.io/
65+
.. _video: https://www.youtube.com/watch?v=U5POoGSrtGg
66+
67+
Atom has a configuration file which you can modify called config.cson.
68+
Access it via ``File`` -> ``Config...``
69+
70+
::
71+
72+
"*":
73+
core:
74+
themes: [
75+
"atom-dark-ui"
76+
"solarized-light-syntax"
77+
]
78+
editor:
79+
fontSize: 19
80+
"exception-reporting":
81+
userId: "6e2a9c3f-7ddb-7deb-b5f7-b58f2f87ac0d"
82+
"tree-view":
83+
hideVcsIgnoredFiles: true
84+
85+
Here you can quickly change the theme or font size. Some packages will require you to add configs
86+
or make adjustments here. Read the documentation carefully when installing packages.
87+
88+
In general, you can extend Atom by installing packages, and then accessing their functionality from the Packages
89+
drop-down menu. Access the Install Packages page from the Welcome Guide page. If the Welcome Guide is not open,
90+
you can open it via ``Help`` -> ``Welcome Guide``.
91+
92+
Keyboard shortcuts are specified in the packages menus if available.
93+
94+
The Useful Packages presented below are only a few options of many.
95+
96+
97+
Useful Packages
98+
===============
99+
100+
Running Scripts
101+
---------------
102+
103+
To run scripts within Atom, you will need to install the Script_ package. The Script package supports a ton of languages,
104+
including Python!
105+
106+
.. _Script: https://atom.io/packages/script
107+
108+
Autocompletion
109+
--------------
110+
111+
By default, Atom knows which Python packages you have imported, variables you have created
112+
and so on. Autocomplete_ ships with Atom and requires no setup.
113+
114+
.. _Autocomplete: http://flight-manual.atom.io/using-atom/sections/autocomplete/
115+
116+
Code Linting
117+
------------
118+
119+
To get code linting functionality in Atom, you will need to install a linting package
120+
of which there are many to choose from. linter-pylint_ works well, and requires minimal
121+
setup.
122+
123+
.. _linter-pylint: https://atom.io/packages/linter-pylint
124+
125+
White Space Management
126+
----------------------
127+
128+
Atom knows when you are writing Python and helps you out by dealing with spaces and tabs
129+
in the same way. When in a Python file, if you type 4 spaces, then hit delete, you are
130+
taken back a tab.
131+
132+
The Whitespace_ package ships with Atom and requires no setup. Under the ``Packages`` -> ``Whitespace`` menu,
133+
you will find tools to turn all tabs into spaces, all spaces into tabs, among other whitespace-related options.
134+
135+
.. _Whitespace: https://atom.io/packages/whitespace
136+
137+
Debugging
138+
---------
139+
140+
To use a Python debugger in Atom, you will need to install the python-debugger_ package. Once installed, turn on the
141+
debugger by going to ``Packages`` -> ``python-debugger`` -> ``Toggle``.
142+
143+
.. _python-debugger: https://atom.io/packages/python-debugger
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. _command_line_basics:
2+
3+
===================
4+
Command line basics
5+
===================
6+
7+
Windows
8+
-------
9+
10+
Tutorials
11+
.........
12+
13+
I honestly haven't found a really good tutorial for the Windows command line, but these will get you started. Please let us know if you find a better option!
14+
15+
http://www.digitalcitizen.life/command-prompt-how-use-basic-commands
16+
17+
http://www.bleepingcomputer.com/tutorials/windows-command-prompt-introduction/
18+
19+
Zed Shaw's tutorial in "Learn Code the Hard way" is excellent, but apparently is no longer available for free. However there is a tutorial in an appendix to Learn Python the Hard way:
20+
21+
`Command Line Crash Course <https://learnpythonthehardway.org/book/appendixa.html>`_
22+
23+
24+
Linux and OS-X
25+
--------------
26+
27+
Tutorials
28+
.........
29+
30+
* Software Carpentry had a nice introduction to the command line:
31+
32+
https://swcarpentry.github.io/shell-novice/01-intro/
33+
34+
* http://conqueringthecommandline.com/book
35+
36+
* Zed Shaw's tutorial in "Learn Code the Hard way" is excellent, but apparently no longer available for free. However there is one as an appendix to Learn Python the Hard way:
37+
38+
https://learnpythonthehardway.org/book/appendixa.html

0 commit comments

Comments
 (0)