concept line in category python

This is an excerpt from Manning's book Tiny Python Projects: Learn coding and testing with puzzles and games.
for line in args.text.splitlines(): print(line)

This is an excerpt from Manning's book Math for Programmers: 3D graphics, machine learning, and simulations with Python.
We could measure whether the stock is going up or down by finding a line of “best fit” that approximately follows the direction the price is moving. This process is called linear regression, and we cover it in part 3 of this book. Based on the variability of data, we can calculate two more lines above and below the “best fit” line that show the region in which the price is wobbling up and down. Overlaid on the price graph, figure 1.2 shows that the lines follow the trend nicely.
The problem at hand is to decide whether the laser beam hits the asteroid. To do this, we’ll look at each line segment defining the asteroid and decide whether it intersects with the segment defining the laser beam. There are a few algorithms we could use, but we’ll solve this as a system of linear equations in two variables. Geometrically, this means looking at the lines defined by an edge of the asteroid and the laser beam and seeing where they intersect (figure 7.6).
Figure 7.6: The laser hitting an edge of an asteroid (left) and the corresponding system of linear equations (right).
![]()
Once we know the location of the intersection, we can see whether it lies within the bounds of both segments. If so, the segments collide and the asteroid is hit. We first review equations for lines in the plane, then cover how to find where pairs of lines intersect. Finally, we write the code for the does_intersect method for our game.
If we start with a line through the origin and translate it by another vector u, we can get any possible line. The points on this line have the form u + t · v for some scalar t. For instance, take v = (2, -1). Points of the form t · (2, -1) lie on a line through the origin. But if we translate by a second vector, u = (2, 3), the points are now (2, 3) + t · (2, -1), which constitute a line that doesn’t pass through the origin (figure 7.7).
Figure 7.7: Vectors u = (2, 3) and v = (2, -1). Points of the form u + t · v lie on a straight line.
![]()
Any line can be described as the points u + t · v for some selection of vectors u and v and all possible scalar multiples t. This is probably not the general formula for a line you’re used to. Instead of writing y as a function of x, we’ve given both the x- and y-coordinates of points on the line as functions of another parameter t. Sometimes, you’ll see the line written r(t) = u + t · v to indicate that this line is a vector-valued function of the scalar parameter t. The input t decides how many units of v you go from the starting point u to get the output r(t).
The advantage of this kind of formula for a line is that it’s dead simple to find if you have two points on the line. If your points are u and w, then you can use u as the translation vector, and w − u as the vector that is scaled (figure 7.8).
Figure 7.8: Given u and w, the line that connects them is r(t) = u + t · (w − u).
![]()
def secant_line(f,x1,x2): def line(x): return f(x1) + (x-x1) * (f(x2)-f(x1))/(x2-x1) return line

This is an excerpt from Manning's book Python Workout: 50 ten-minute exercises.
def passwd_to_dict(filename): users = {} with open(filename) as passwd: for line in passwd: if not line.startswith(('#', '\n')): #1 user_info = line.split(':') #2 users[user_info[0]] = int(user_info[2]) return users print(passwd_to_dict('/etc/passwd'))

This is an excerpt from Manning's book Hello World! Third Edition.
>>> RESTART: C:/HelloWorld/examples/error1.py I love pizza! pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza Traceback (most recent call last): #1 File "C:/HelloWorld/examples/error1.py", line 3, in <module> #2 print("yum " + 40) #3 TypeError: must be str, not int #4 >>>The line starting with Traceback is the beginning of the error message. The next line tells you where the error happened—the filename and line number. Then it displays the bad line of code. This helps you find where the problem is in your code. The last part of the error message tells you what Python thinks is wrong. Once you know more about programming and Python, it will be easier to understand what the message means.
>>> RESTART: C:/HelloWorld/examples/error1.py I love pizza! pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza pizza Traceback (most recent call last): #1 File "C:/HelloWorld/examples/error1.py", line 3, in <module> #2 print("yum " + 40) #3 TypeError: must be str, not int #4 >>>
You can also put comments at the end of a line of code, like this:

This is an excerpt from Manning's book Get Programming: Learn to code with Python.
def area(shape, n): # write a line to return the area # of a generic shape with a parameter of n return shape(n)
Using lists provides a simple, one-line solution to this problem. With the preceding emails string, you can do this:
Write a function named is_permutation. It takes in two lists, L1 and L2. The function returns True if L1 and L2 are permutations of each other. It returns False otherwise. Every element in L1 is in L2, and vice versa, only arranged in a different order. For example,

This is an excerpt from Manning's book Geoprocessing with Python.
You’ll learn how to work with the two main types of spatial data, vector and raster. Vector data is made up of points, lines, and polygons, while raster data is a two- or three-dimensional array of data values such as the pixels in a photograph. A dataset containing country boundaries is an example of vector data. In this case, each country is generally represented as a polygon. Datasets that use lines to represent roads or rivers, or points to show the location of weather stations, are other examples. Early primitive maps, such as those drawn on cave walls, only showed the features themselves. Later maps contained labels for features of interest such as cities or seaports; for example, the Portolan map of northwest Africa shown in figure 1.1.
As mentioned earlier, lines are a sequence of vertices, or points, connected by straight line segments. Figure 6.6 shows a line with its vertices, although normally you don’t see markers for the vertices when a line is drawn. A line can’t change direction, no matter how slightly, without a vertex to end one segment and start another. Therefore, a line that looks like a smooth curve is a large number of short straight segments, all joined together by vertices.
Adding more vertices, and therefore a larger number of shorter segments, gives you more control over the shape of the line. Think about how you’d draw the coastline of Great Britain using a series of straight lines. As you can see from figure 6.7, accuracy is greatly improved by using shorter lines. The same concept applies to any line geometry. The more detail required, the more vertices you need to add. Keep in mind that the more vertices you have, the more complicated the geometry object is and the more time it takes to process, so don’t add unnecessary vertices. In fact, you might want to simplify geometries so that they use fewer vertices if you’re going to serve data over the web. See the Simplify function in appendix C if you need to do this. (Appendixes C through E are available online on the Manning Publications website at https://www.manning.com/books/geoprocessing-with-python.)
Figure 6.7. The solid line follows the coast of Great Britain more closely because it has more vertices, and therefore more and shorter line segments, than the dotted line. More detail for lines and polygons can be achieved by using more vertices.
![]()
Lines can be used to represent linear features such as roads, streams, or pipelines. A line is a good choice if you want to show one coastline of an island, such as the example in figure 6.7, but a polygon is a better choice if you want to represent the entire island. You’ll use a simple line object to model the sidewalk bordering the make-believe yard and the oddly shaped parking strip (figure 6.8).
The line you’ll build for the sidewalk contains a small number of vertices, but the technique for working with longer and more-complex lines is exactly the same.

This is an excerpt from Manning's book Hello App Inventor!: Android programming for kids and the rest of us.

This is an excerpt from Manning's book Hello! Python.
In the bottom half, look for the line named Path and double-click it. In the edit box that appears, you need to add ;c:\python26 at the end of the line and click OK.
Traceback (most recent call last): File "D:/Documents and Settings/Anthony/.../test_todo.py", line 2, in <module> import todo ImportError: No module named todo
The question still remains, though: what do you want the program to do when a line is too long? If you don’t have a clear answer for that, then it’s hard to write a test! You could trim the string down to a fixed width if it was too long—but you’d like all the information to still be visible. A better way to do it would be to wrap each to-do.