Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Long string on multiple line

Is there a correct way to show file paths (hard coded) longer than 79 characters (based on pep8) on multiply lines or is it best to keep the file path on a single line?

Eg

photos = "D:\MyWork\FieldWork\Year2015\January\MountainPass\Area1\Site1\Campsite2\Inspections\photos1"

Would the above example work best on multiple lines or a single line?

like image 645
TsvGis Avatar asked May 23 '15 03:05

TsvGis


1 Answers

I personally use this method, and have seen it used in the PEP8 materials:

long_string = ('this is a really long string I want '
               'to wrap over multiple lines')

You can also do:

long_string = 'this is a really long string I want '\
              'to wrap over multiple lines'

According to PEP8 you should try to keep the maximum width of code to 79 characters, and generally docstrings and comments to 72.

I also recommend taking a look at os.path.

like image 190
Lillian Seabreeze Avatar answered Oct 05 '22 23:10

Lillian Seabreeze