How to insert a line in python to make code easier to read

theknightD2

I have some python code. In order to shorten the rest of the script, I have placed all the values into something like this:

Data = 14,14,14,14,14,14,14,14,14,14,14,14

This is of course, hard to read, so I then wanted to add comments.

Data = 14,14,14 #1 14,14,14 #2 14,14,14 #3 14,14,14 #4

This of course did not work, as the comments commented out everything else. So I wanted to do this:

Data = 
14,14,14, #1
14,14,14, #2
14,14,14, #3
14,14,14, #4

This gives me a SyntaxError. Does anyone know if this is possible? And if so, how to do it? Thanks!

Samwise

Use parens to break statements up over multiple lines:

Data = (
    14, 14, 14,  # 1 
    14, 14, 14,  # 2 
    14, 14, 14,  # 3 
    14, 14, 14,  # 4
)

Note that you can multiply tuples; if 1 thru 4 are identical, it's simpler IMO to write:

Data = (14, 14, 14) * 4  # 1 thru 4

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to make IntelliJ IDEA insert a new line at every end of file?

From Dev

Making SQL INSERT statement easier to read

From Dev

How to make the graph easier to read ? Editing plot

From Dev

Make easier to read numbers in Lua

From Dev

How to read line by line

From Dev

how to read a line and ignore some words (python)

From Dev

how can I read line by line insert into an array with special condition?

From Dev

Decode High Level Python to easier code

From Dev

How to make string paragraph easier to read for source code

From Dev

How to insert Phone icon in every line in second Activity in Android code

From Dev

Are there flags for g++ that will make these errors easier to read?

From Dev

How does exponent bias make comparison easier

From Dev

Any way to format large numbers in code to make easier to read?

From Dev

How does python interpreter run the code line by line in the following code?

From Dev

How to make installing python correctly (Adding to PATH) easier for end user?

From Dev

Streamline C# code to make it easier to manage

From Dev

How to read integer command line arguments in Python?

From Dev

How to read line by line

From Dev

Make easier to read numbers in Lua

From Dev

How to make my Python code read from the second line for my lexer

From Dev

How can I make this substring extraction formula more efficient and easier to read?

From Dev

How to make Ubuntu text color easier to read?

From Dev

How to make the placement of asterisks in a barplot easier?

From Dev

How can I insert dimensions of a data matrix into a line of code?

From Dev

How to Matlab code combining to make it easier

From Dev

Modularize my Express/Mongoose API code to make it easier to work with

From Dev

Python: how to make this code simpler?

From Dev

How to make python wait for a program to stop before going to the next line of code

From Dev

jQuery code, how I can do easier to read

Related Related

  1. 1

    How to make IntelliJ IDEA insert a new line at every end of file?

  2. 2

    Making SQL INSERT statement easier to read

  3. 3

    How to make the graph easier to read ? Editing plot

  4. 4

    Make easier to read numbers in Lua

  5. 5

    How to read line by line

  6. 6

    how to read a line and ignore some words (python)

  7. 7

    how can I read line by line insert into an array with special condition?

  8. 8

    Decode High Level Python to easier code

  9. 9

    How to make string paragraph easier to read for source code

  10. 10

    How to insert Phone icon in every line in second Activity in Android code

  11. 11

    Are there flags for g++ that will make these errors easier to read?

  12. 12

    How does exponent bias make comparison easier

  13. 13

    Any way to format large numbers in code to make easier to read?

  14. 14

    How does python interpreter run the code line by line in the following code?

  15. 15

    How to make installing python correctly (Adding to PATH) easier for end user?

  16. 16

    Streamline C# code to make it easier to manage

  17. 17

    How to read integer command line arguments in Python?

  18. 18

    How to read line by line

  19. 19

    Make easier to read numbers in Lua

  20. 20

    How to make my Python code read from the second line for my lexer

  21. 21

    How can I make this substring extraction formula more efficient and easier to read?

  22. 22

    How to make Ubuntu text color easier to read?

  23. 23

    How to make the placement of asterisks in a barplot easier?

  24. 24

    How can I insert dimensions of a data matrix into a line of code?

  25. 25

    How to Matlab code combining to make it easier

  26. 26

    Modularize my Express/Mongoose API code to make it easier to work with

  27. 27

    Python: how to make this code simpler?

  28. 28

    How to make python wait for a program to stop before going to the next line of code

  29. 29

    jQuery code, how I can do easier to read

HotTag

Archive