4 ms·
I'm an avid python user and a big problem I have is that you can't finish a line with '.' and continue on the next line. For instance: some_object. do_so
by phzbOx 15y ago
I'm an avid python user and a big problem I have is that you can't finish a line with '.' and continue on the next line. For instance:
some_object.
do_something(..).
do_something_else(..).
Doesn't work. It needs to be written:
some_object.\
do_something().\
do_something_else()
or
some_object\
.do_something()\
.do_something_else()
It's ok to write \ a couple of time, but I feel like it makes chain-able functional methods really ugly to use because of that.
- pyre 15y agoYou don't need to escape line endings within parens: (someobject .do_something() .do_something())
- phzbOx 15y agoYeah. That's the hack I use, but it makes it a bit no pythonic.
- pyre 15y agoFrom what I gather, the Pythonic way to write that would be: some_object.do_something().do_something()\ .do_something().last_thing() Basically, go to the end of the line and wrap with an indent. That's the way that I see most function calls with a long list of arguments in Python. In Perl, you might see something like: GetOptions( 'h|help' => \my $help ); Whereas in Python you would see: parser.add_option('-h','--help',meta="HELP",target="HELP", help="Print help message",action="store_true",default=False)