您的位置:首页 > 编程语言 > Python开发

python 学习笔记2

2015-11-12 00:17 609 查看
The Setup

This exercise has no code. It is simply the exercise you complete to get your computer to run Python. You should follow these instructions as exactly as possible. For example, Mac OSX computers already have Python 2, so do not install Python 3 (or any Python).

设置

这个练习没有代码。这就是锻炼你完全让你的计算机运行Python。你应该尽可能地遵循这些指示。例如,MAC OSX 电脑已经有Python 2,所以没有安装Python 3(或任何Python)。

WARNING! If you do not know how to use PowerShell on Windows or the Terminal on OSX or “Bash” on Linux, then you need to go learn that fi rst. I have included an abbreviated version of my book The Command Line Crash Course in the appendix. Go through that
first and then come back to these instructions.

警告!如果你不知道如何使用PowerShell窗口或终端 在OSX或“Bash”Linux,那么你需要去学习,第一。我已经包括了我在附录中的命令行崩溃过程的简化版本。去通过第一个,然后再回到这些指令。

Mac OSX

To complete this exercise, complete the following tasks:

1. Go to http://www.barebones.com/products/textwrangler with your browser, get the TextWrangler text editor, and install it.

2. Put TextWrangler (your editor) in your dock so you can reach it easily.

3. Find your Terminal program. Search for it. You will fi nd it.

4. Put your Terminal in your dock as well.

5. Run your Terminal program. It won’t look like much.

6. In your Terminal program, run python. You run things in Terminal by just typing the name and hitting RETURN.

7. Hit CTRL- Z (^Z), Enter, and get out of python.

8. You should be back at a prompt similar to what you had before you typed python. If not, fi nd out why.

9. Learn how to make a directory in the Terminal.

10. Learn how to change into a directory in the Terminal.

11. Use your editor to create a fi le in this directory. You will make the fi le, “Save” or “Save As . . . ,” and pick this directory.

12. Go back to Terminal using just the keyboard to switch windows.

13. Back in Terminal, see if you can list the directory to see your newly created file.

OSX: What You Should See

Here’s me doing this on my computer in Terminal. Your computer would be different, so see if you can figure out all the differences between what I did and what you should do.

MAC OSX

完成这项工作,完成下列任务:

1。去http://www.barebones.com/products/textwrangler浏览器,得到TextWrangler的文本编辑器,并安装它。

2。把(编辑器)TextWrangler在您的船坞所以你可以很容易达到。

3。找到你的终端程序。寻找它。你会找到它。

4。把你的码头在你的码头。

5。运行您的终端程序。它不会看起来像多。

6。在你的终端程序,运行Python。你只需输入姓名就可以在终端上运行,然后返回。

7。按Ctrl - Z(^ Z),输入,和滚出去Python。

8。你应该回到一个提示,类似于你之前键入Python。如果没有,找出为什么。

9。学习如何在终端中制作一个目录。

10。学习如何在终端目录中转换成一个目录。

11。使用编辑器来创建这个目录中的一个网络连接。你要的文件,“保存”或“另存为 。 。,“选择这个目录。

12。回到终端只使用键盘切换窗口。

13。回到终端,看看是否可以列出目录,看看你的新创建的文件。

OSX:你应该看到

这是我在我的电脑上做这件事。你的电脑会有所不同,所以看你能不能找出我做了什么和你应该做什么。

Last login: Sat Apr 24 00:56:54 on ttys001

~ $ python

Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)

[GCC 4.0.1 (Apple Inc. build 5465)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> ^D

~ $ mkdir mystuff

~ $ cd mystuff

mystuff $ ls

# ... Use TextWrangler here to edit test.txt....

mystuff $ ls

test.txt

mystuff $

Windows

1. Go to http://notepad-plus-plus.org with your browser, get the Notepad++ text editor, and install it. You do not need to be the administrator to do this.

2. Make sure you can get to Notepad++ easily by putting it on your desktop and/or in Quick Launch. Both options are available during setup.

3. Run PowerShell from the Start menu. Search for it and you can just hit Enter to run it.

4. Make a shortcut to it on your desktop and/or Quick Launch for your convenience.

5. Run your Terminal program. It won’t look like much.

6. In your Terminal program, run python. You run things in Terminal by just typing the name and hitting Enter.

a. If you run python and it’s not there (python is not recognized.), install it from http://python.org/download.
b. Make sure you install Python 2, not Python 3.

c. You may be better off with ActiveState Python, especially if you do not have adminis-trative rights.

d. If after you install it python still isn’t recognized, then in PowerShell enter this: [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")

e. Close PowerShell and then start it again to make sure Python now runs. If it doesn’t, restart may be required.

7. Type quit() and hit Enter to exit python.

8. You should be back at a prompt similar to what you had before you typed python. If not, fi nd out why.

9. Learn how to make a directory in the Terminal.

10. Learn how to change into a directory in the Terminal.

11. Use your editor to create a fi le in this directory. Make the file, Save or Save As... and pick this directory.

12. Go back to Terminal using just the keyboard to switch windows.

13. Back in Terminal, see if you can list the directory to see your newly created file

Windows

1。http://notepad-plus-plus.org去拿你的浏览器,记事本+ +文本编辑器,和安装它。你不需要管理员这样做。

2。确保你可以得到由记事本+ +很容易把它和/或在您的桌面上,快速启动。连接这两个选项的设置。

3。PowerShell的运行从开始菜单。搜索它,你可以打回车运行它。

4。创建一个快捷方式在您的桌面上,快速启动和/或为您的方便。

5。终端运行你的程序。它不会看起来像很多。

6。在你的终端程序,运行Python。在终端运行的东西你只是打字的名称和设置键。

A.如果你运行它在Python(蟒蛇)是不需要的,它和安装的要求。)http://python.org /下载。

B.确保你安装Python Python需要2,3。

C.你可能是一个更好的关C. activestate Python。如果你没有权利trative南。

D.如果你的Python安装后的沉默不是公认的,然后在这个环境PowerShell:[回车]::setenvironmentvariable(“路径”“$ ENV:python27路径;C:\”,“用户”)

E.关闭PowerShell开始一遍,然后确保Python现在运行。如果它不重启可能是必需的。

7。型退出(退出)和命中进入到Python。

8。你应该及时反馈在一个类似于你在你的Python类。如果需要找出为什么。

9。学习如何做一个目录中的终端。

10。了解如何改变一个目录中的终端。

11。使用你的编辑器创建一个文件在这个目录。FI很乐,保存或保存为…这和拾取目录。

12。回到终端窗口使用一个键盘转换器。

13。终端湖回来,如果你能看到你的列表目录中创建新文件

WARNING! If you missed it, sometimes you install Python on Windows and it doesn’t confi gure the path correctly. Make sure you enter [Environment]::SetEnvironment Variable("Path", "$env:Path;C:\Python27", "User") in PowerShell to configure it correctly.
You also have to either restart PowerShell or restart your whole computer to get it to really be fixed.

警告!如果你错过了它,有时你安装Windows平台上并没有限制的路径是正确的。请确保您输入[环境]::setenvironment变量(“路径”,“$ ENV:路径;C:\ python27”,“用户”)在PowerShell配置是否正确。你也可以重新启动或重新启动计算机PowerShell得到它真的是固定的。

Windows: What You Should See

Windows:你应该看到什么

> python

ActivePython 2.6.5.12 (ActiveState Software Inc.) based on

Python 2.6.5 (r265:79063, Mar 20 2010, 14:22:52) [MSC v.1500 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> ^Z

> mkdir mystuff

> cd mystuff

... Here you would use Notepad++ to make test.txt in mystuff ...

>

<bunch of unimportant errors if you installed it as non- admin - ignore them - hit Enter>

> dir

Volume in drive C is

Volume Serial Number is 085C- 7E02

Directory of C:\Documents and Settings\you\mystuff

04.05.2010 23:32 <DIR> .

04.05.2010 23:32 <DIR> ..

04.05.2010 23:32 6 test.txt

www.it-ebooks.info

9THE SETUP

1 File(s) 6 bytes

2 Dir(s) 14 804 623 360 bytes free

>

You will probably see a very different prompt, Python information, and other stuff, but this is the general idea.

你可能会看到一个非常不同的提示,Python的信息,和其他的东西,但这是一般的想法。

Linux

Linux is a varied operating system with a bunch of different ways to install software. I’m assuming if you are running Linux then you know how to install packages, so here are your instructions:

1. Use your Linux package manager and install the gedit text editor.

2. Make sure you can get to gedit easily by putting it in your window manager’s menu.

a. Run gedit so we can fix some stupid defaults it has.

b. Open Preferences and select the Editor tab.

c. Change Tab width: to 4.

d. Select (make sure a check mark is in) Insert spaces instead of tabs.

e. Turn on Automatic indentation as well.

f. Open the View tab and turn on Display line numbers.

3. Find your Terminal program. It could be called GNOME Terminal, Konsole, or xterm.

4. Put your Terminal in your dock as well.

5. Run your Terminal program. It won’t look like much.

6. In your Terminal program, run Python. You run things in Terminal by just typing the name and hitting Enter.

a. If you run Python and it’s not there, install it. Make sure you install Python 2, not Python 3.

7. Type quit() and hit Enter to exit Python.

8. You should be back at a prompt similar to what you had before you typed python. If not, find out why.

9. Learn how to make a directory in the Terminal.

10. Learn how to change into a directory in the Terminal.

11. Use your editor to create a file in this directory. Typically you will make the file, Save or Save As..., and pick this directory.

12. Go back to Terminal using just the keyboard to switch windows. Look it up if you can’t figure it out.

13. Back in Terminal, see if you can list the directory to see your newly created file.

Linux

是一个不同的操作系统,有一堆不同的安装软件。我假设你是在运行的,然后你知道如何安装包,所以这里是你的指令:

1。使用你的Linux软件包管理器安装gedit文本编辑器。

2。确保你可以很容易把gedit它在你的窗口管理器的菜单。

A.运行gedit可以修复一些愚蠢的默认了。

打开首选项,选择“编辑”标签。

改变标签宽度:4。

选择(确保检查标记)插入空格,而不是标签。

自动缩进,以及。

打开“视图”选项卡,打开显示行数。

3。找到你的终端程序。可以称之为GNOME终端,konsole,或xterm。

4。把你的码头在你的码头。

5。运行您的终端程序。它不会看起来像多。

6。在你的终端程序,运行Python。你只需输入姓名就可以在终端上运行,然后进入。

如果你运行Python和它的不存在,安装它。确保你已经安装了Python 2,不是Python 3。

7。型quit()回车退出Python。

8。你应该回到一个提示,类似于你之前键入Python。如果没有,找出为什么。

9。学习如何在终端中制作一个目录。

10。学习如何在终端目录中转换成一个目录。

11。使用编辑器来创建这个目录中的文件。通常,你会把文件,保存或保存为…,并选择这个目录。

12。回到终端只使用键盘切换窗口。如果你不知道它,看它。

13。回到终端,看看是否可以列出目录,看看你的新创建的文件。

Linux: What You Should See

$ python

Python 2.6.5 (r265:79063, Apr 1 2010, 05:28:39)

[GCC 4.4.3 20100316 (prerelease)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>

$ mkdir mystuff

$ cd mystuff

# ... Use gedit here to edit test.txt ...

$ ls

test.txt

$

You will probably see a very different prompt, Python information, and other stuff, but this is the general idea.

你可能会看到一个非常不同的提示,Python的信息,和其他的东西,但这是一般的想法。

Warnings for Beginners

You are done with this exercise. This exercise might be hard for you, depending on your familiarity with your computer. If it is difficult, take the time to read and study and get through it, because until you can do these very basic things, you will find it
difficult to get much programming done.

If a programmer tells you to use vim or emacs, just say “no.” These editors are for when you are a better programmer. All you need right now is an editor that lets you put text into a file. We will use gedit, TextWrangler, or Notepad++ (from now on called “the
text editor” or “a text editor”) because it is simple and the same on all computers. Professional programmers use these text editors, so it’s good enough for you starting out.

初学者的警告

你做这项练习。这个练习对你很难,这取决于你对电脑的熟悉程度。如果很难,花时间去读,去学习,通过它,因为直到你能做这些非常基本的事情,你会发现很难得到很多编程。

如果一个程序员告诉你使用Vim和Emacs,只是说“不”,这些编辑是当你是一个优秀的程序员。你现在需要的是一个编辑器,让你把文本放入一个文件中。我们将使用gedit,TextWrangler,或记事本+ +(现在被称为“文本编辑器”或“文本编辑器”)因为它是简单的,在所有的计算机一样。专业程序员使用这些文本编辑器,所以这对你来说很好。

A programmer may try to get you to install Python 3 and learn that. Say, “When all the Python code on your computer is Python 3, then I’ll try to learn it.” That should keep him or her busy for about 10 years.

A programmer will eventually tell you to use Mac OSX or Linux. If the programmer likes fonts and typography, he’ll tell you to get a Mac OSX computer. If he likes control and has a huge beard, he’ll tell you to install Linux. Again, use whatever computer you
have right now that works. All you need is an editor, a Terminal, and Python.Finally, the purpose of this setup is so you can do four things very reliably while you work on the exercises:

1. Write exercises using your text editor, gedit on Linux, TextWrangler on OSX, or Notepad++

on Windows.

2. Run the exercises you wrote.

3. Fix them when they are broken.

4. Repeat.

Anything else will only confuse you, so stick to the plan.

一个程序员可能会让你安装Python 3和学习。说,“当所有的Python代码在您的计算机上是Python 3,然后我会努力学好它。”,应该让他或她忙活10年。

一个程序员最终会告诉你使用MAC OSX和Linux。如果程序员喜欢的字体和排版,他会告诉你到MAC OSX电脑。如果他喜欢控制,并有一个巨大的胡子,他会告诉你安装。再次,使用任何你有权现在的计算机。所有你需要的是一个编辑,一个终端,和Python。最后,这个设置的目的是让你可以做四件事情非常可靠,当你在练习:

1。使用你的文本编辑器gedit写练习,对Linux,TextWrangler在OSX,或记事本+ +在窗户上。

2。运行你写的练习。

3。修理他们,当他们被打破。

4。重复。

任何事情都只会让你迷惑,所以坚持计划。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: