Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79753

Re: Classes and the command line

Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'preferably': 0.05; 'debugging': 0.07; 'classes.': 0.09; 'editor.': 0.09; 'function,': 0.09; 'interview,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'separately': 0.09; 'spaces': 0.09; 'subject:command': 0.09; 'terms,': 0.09; 'python': 0.11; 'def': 0.12; '2.7': 0.14; 'changes': 0.15; 'windows': 0.15; 'editor,': 0.16; 'finney': 0.16; 'invoking': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sadly': 0.16; 'statement.': 0.16; 'subject:Classes': 0.16; 'tool.': 0.16; 'tweak': 0.16; 'ignore': 0.16; 'code.': 0.18; 'trying': 0.19; 'file,': 0.19; 'command': 0.22; '>>>': 0.22; 'code,': 0.22; 'platforms': 0.22; 'separate': 0.22; 'shell': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'right.': 0.26; 'switch': 0.26; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; '(this': 0.29; 'quickly': 0.29; 'statement': 0.30; 'strongly': 0.30; 'code': 0.31; 'url:wiki': 0.31; 'bunch': 0.31; 'enabled': 0.31; 'writes:': 0.31; 'file': 0.32; 'class': 0.32; 'run': 0.32; 'text': 0.33; 'community': 0.33; 'becomes': 0.33; 'subject:the': 0.34; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'adjust': 0.36; 'licensed': 0.36; 'url:org': 0.36; 'operating': 0.37; 'step': 0.37; 'system,': 0.38; 'actions': 0.38; 'ben': 0.38; 'same.': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'supporting': 0.39; 'to:addr:python.org': 0.39; 'system.': 0.39; 'received:org': 0.40; 'major': 0.40; 'how': 0.40; 'commands': 0.60; 'deleting': 0.60; 'units': 0.60; 'free': 0.61; 'affect': 0.61; 'skip:* 10': 0.61; 'save': 0.62; 'more': 0.64; 'skip:\xe2 10': 0.65; 'prompt': 0.68; 'press': 0.70; '8bit%:43': 0.74; '\xe2\x80\x93': 0.77; '8bit%:46': 0.78; 'history,': 0.84; 'pasting': 0.84; 'received:125': 0.84; 'x):': 0.84; 'good,': 0.91; 'mistake': 0.91; '\xe2\x80\x9cthe': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Classes and the command line
Date Mon, 27 Oct 2014 14:06:11 +1100
References <8uar4a1pa6d631ktr33h8rau1ilf2rjvi3@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host jigong.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
Cancel-Lock sha1:MMbprHdsRLNOU1Rpm8iaAKUqyik=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15220.1414379184.18130.python-list@python.org> (permalink)
Lines 64
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414379184 news.xs4all.nl 2837 [2001:888:2000:d::a6]:46708
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:79753

Show key headers only | View raw


Seymore4Head <Seymore4Head@Hotmail.invalid> writes:

> I am trying to learn classes.
> I am currently using Python 2.7 at the command line.

(I think you mean “the interactive Python interpreter”, or just “the
Python shell”.)

Since you are learning Python, I will strongly recommend you ignore
Python 2 unless it becomes unavoidable.

Instead, learn Python 3 primarily; it is much better because it omits a
bunch of legacy behaviour you don't need.

> If you try to type commands at the [interactive shell] and make the
> slightest mistake you have to start over.

Right. There is line-by-line history, and editing enabled with the
“readline” plug-in. (This is an advantage of using a programmer-friendly
operating system, which MS Windows sadly is not.)

> I was trying to copy and paste these instructions into the
> [interactive Python shell].
>
> http://en.wikibooks.org/wiki/Python_Programming/Classes
> >>> class Foo:
> ...     def setx(self, x):
> ...         self.x = x
> ...     def bar(self):
> ...         print self.x
>
> There is really no way to do that without pasting line by line is
> there and adding deleting spaces?  And if you use spaces and tabs,
> they are not the same.

Right on all counts.

The interactive Python shell is good for very quickly experimenting and
demonstrating how Python actually behaves, statement by statement. But
as you point out, it is not a good choice for anything more complex. It
is a good learning and debugging tool.

When you start to write larger units of code, like a class or a
function, you can trade immediacy for flexibility: write your code into
a text editor, save it to a file ‘foo.py’, then run that code at a
separate OS command prompt by invoking ‘python foo.py’ in the terminal.

That way, you can continue to adjust and tweak the code as you learn how
your changes affect the code. You do need to keep invoking the actions
separately – edit the file, save the file, run the file with Python –
but this is what's needed when you want to run a program more than once
anyway, so it's a good step to take.

Find a good, *general-purpose* programmer's editor. Preferably licensed
under free software terms, with a strong community supporting it, and
available on all major platforms for when you switch to a decent
programmer-friendly operating system.

-- 
 \        “When you go in for a job interview, I think a good thing to |
  `\                  ask is if they ever press charges.” —Jack Handey |
_o__)                                                                  |
Ben Finney

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Classes and the command line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-26 22:27 -0400
  Re: Classes and the command line Rustom Mody <rustompmody@gmail.com> - 2014-10-26 20:05 -0700
    Re: Classes and the command line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-26 23:28 -0400
      Re: Classes and the command line Terry Reedy <tjreedy@udel.edu> - 2014-10-28 00:14 -0400
  Re: Classes and the command line Ben Finney <ben+python@benfinney.id.au> - 2014-10-27 14:06 +1100
    Re: Classes and the command line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-26 23:32 -0400
      Re: Classes and the command line alister <alister.nospam.ware@ntlworld.com> - 2014-10-27 11:17 +0000
        Re: Classes and the command line Chris Angelico <rosuav@gmail.com> - 2014-10-27 22:33 +1100
      Re: Classes and the command line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-27 09:34 -0400
  Re: Classes and the command line Chris Angelico <rosuav@gmail.com> - 2014-10-27 14:10 +1100
    Re: Classes and the command line Rustom Mody <rustompmody@gmail.com> - 2014-10-26 20:18 -0700
      Re: Classes and the command line Chris Angelico <rosuav@gmail.com> - 2014-10-27 14:24 +1100
      Re: Classes and the command line Rustom Mody <rustompmody@gmail.com> - 2014-10-26 20:30 -0700
      Re: Classes and the command line Terry Reedy <tjreedy@udel.edu> - 2014-10-28 00:08 -0400
      Re: Classes and the command line Chris Angelico <rosuav@gmail.com> - 2014-10-28 15:57 +1100
    Re: Classes and the command line Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-26 23:33 -0400

csiph-web