[Tutor] Use flag to exit? (OT - PEP 8 Gripe)
Steve Willoughby
steve at alchemy.com
Fri Jun 25 18:08:16 CEST 2010
On 25-Jun-10 08:23, Emile van Sebille wrote:
> On 6/25/2010 1:33 AM ALAN GAULD said...
>>> Copy and pasting is a PITA.
>>
>> Why would you want to copy and paste?
>
> Because it makes it easy to work on code. My preferred editor (TextPad)
> allows block selection of indented text such that I can copy and paste
> functions and methods into the python CLI and work with them there. I
If what you're trying to do is a PITA, that should raise two questions:
First, is it because the tools you're using are ill-suited to the task
at hand? There may be better tools (a text editor which allows you to
select a range and execute it via some shell command, an IDE which
allows you to run selected code fragments, whatever).
Second, is it because the way you're solving the problem isn't the right
approach, which is why the tools, assuming they've been thought through
and used by enough people before you, don't support that particular use
case? Stepping back and questioning your assumptions and approach is
often healthy to do. Maybe structuring your code so that a python
interpreter can just "import" your module and call into it easily? Or
maybe using a unit testing framework which lets you invoke individual
test cases in which you can experiment without cutting and pasting? Or
maybe putting experimental code in a "if __name__ == '__main__'" block
in your module after defining classes and functions which can be
triggered just by clicking on the source file?
> find it very easy when developing to keep the CLI open for this purpose
> and interactively test as I write. Unfortunately, PEP 8 doesn't support
> this use case as once the blank lines separating methods are pasted in,
> your class definition is complete. So I either put hash marks in or
> leave the blank lines out...
yeah, that's admittedly a problem which highlights the different needs
of an interactive environment which needs to know when you're finished
defining a block without being able to see a static source file, in a
language without explicit syntax (such as a closing brace or "end"
keyword). Again, it feels like you're having to go to inconvenient
measures to strain to use a particular solution (cut and paste) when you
might be better served to learn to solve your problem in a different way
altogether.
But what you're doing is still possible, of course. If your choice of
tools is otherwise exactly what you want to stick with, this is simply
the price you need to pay for that. If the tradeoff is still worth it
for you, then stick with it.
--steve
More information about the Tutor
mailing list