Hari Sekhon wrote:
Is it better to do:
message = This is line1.
This is line2
This is line3\n
or
message = This is line1.\n
message = message + This is line2\n
message = message + This is line3\n
Since the first method does not follow python's clean and easy looking
indentation
Frank Millman wrote:
How about
message = (This is line1.
This is line2
This is line3\n)
The brackets mean that the lines are automatically treated as
continuous, without the need for the ugly '\' continuation character.
The opening/closing
Hari Sekhon wrote:
Is it better to do:
message = This is line1.
This is line2
This is line3\n
or
message = This is line1.\n
message = message + This is line2\n
message = message + This is line3\n
Since the first method does not follow python's clean and easy looking
Frank Millman wrote:
How about
message = (This is line1.
This is line2
This is line3\n)
The brackets mean that the lines are automatically treated as
continuous, without the need for the ugly '\' continuation character.
The opening/closing
Fredrik Lundh wrote:
Frank Millman wrote:
How about
message = (This is line1.
This is line2
This is line3\n)
The brackets mean that the lines are automatically treated as
continuous, without the need for the ugly '\' continuation
Hari Sekhon wrote:
Since the first method does not follow python's clean and easy looking
indentation structure but the second just looks crude and ugly anyway.
If you want indented and pretty is important to you:
from textwrap import dedent as D
message = D(\
This is line1.
Hari Sekhon wrote:
Is it better to do:
message = This is line1.
This is line2
This is line3\n
or
message = This is line1.\n
message = message + This is line2\n
message = message + This is line3\n
Since the first method does not follow python's clean and easy looking
Claudio Grondi wrote:
clever stuff to di indentation
When necessary to skip first line _and_ indentation:
message =
This is line 1
This is line 2
This is line 3
.replace('\n ', '\n')[1:] # adjust here '\n ' to indentation
Riffing on this idea:
message =
Scott David Daniels wrote:
Claudio Grondi wrote:
clever stuff to di indentation
When necessary to skip first line _and_ indentation:
message =
This is line 1
This is line 2
This is line 3
.replace('\n ', '\n')[1:] # adjust here '\n ' to indentation
Riffing on this idea:
I just have a basic style question here. Suppose you have the program:
def foo1():
do something
def foo2()
do something else
Assume that you want to call these functions at execution. Is it more
proper to call them directly like:
foo1()
foo2()
or in an if __name__ == __main__
that the script runs its main functions when called as a standalone
program, but you can also import the code and do something with it
without setting off those functions.
THN
Brian wrote:
I just have a basic style question here. Suppose you have the program:
def foo1():
do something
def foo2
Brian wrote:
I just have a basic style question here. Suppose you have the program:
def foo1():
do something
def foo2()
do something else
Assume that you want to call these functions at execution. Is it more
proper to call them directly like:
foo1()
foo2
Just curious about people's sense of style:
To delete all the elements of a list, should one do:
lst[:] = []
or
del(lst[:])
I seem to see the first form much more often in code, but
the second one seems more clearly *deleting* elements,
and less dangerously mistaken for the completely
gry@ll.mit.edu wrote:
To delete all the elements of a list, should one do:
lst[:] = []
or
del(lst[:])
del lst[:]
Note that del is not a function - the parentheses are not needed, and in
fact obscure the intent.
Tim Delaney
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, 19 Sep 2005, Adam Monsen wrote:
Is there anything wrong with using something like super(type(self),
self).f() to avoid having to hardcode a type?
What happens when that method gets called by an overriding method in a
derived class?
For example:
class A(object):
def f(self):
As Tom said, using super(type(self), self) will fail when your class
gets subclassed. Otherwise we wouldn't have needed that kind of syntax
in the first place.
You may be interested in my self.super recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195
and the considerably
201 - 216 of 216 matches
Mail list logo