line

Deleting a line in a file

半世苍凉 提交于 2019-12-18 09:48:23
问题 I am having an issue with a timetracker program, where I am trying to identify a line in a file by iterating over it and then writing the lines UNLESS there is anything with the variable "delete" in it, for some reason its going through the file and saying it is deleted, but the loop doesn't delete any lines. date = input(" What is today's date? month-day-year format please. (E.G. 01-14-2003) ") if os.path.exists(date): today = open(date, "r") print(today.read()) delete = input(" Which

Bresenham lines w/o diagonal movement

和自甴很熟 提交于 2019-12-18 09:36:21
问题 Is there a modified Bresenham algorithm, where the step from one pixel to the next one isn't allowed to be diagonally, just horizontally or vertically? Or any other algorithm which does that? (PHP preferred) Right: 0 0 0 1 0 0 1 1 0 1 1 0 1 1 0 0 Wrong: 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 回答1: Should be a trivial modification - let's say you're in the quadrant I - i.e. going up and to the right. Instead of doing a diagonal, do an up... and then a right. Instead of: for x from x0 to x1 plot(x,y)

Storing each line of a text file into an array

巧了我就是萌 提交于 2019-12-18 09:31:19
问题 I am trying to save each line of a text file into an array. They way I am doing it and works fine so far is this : char *lines[40]; char line[50]; int i = 0 ; char* eof ; while( (eof = fgets(line, 50, in)) != NULL ) { lines[i] = strdup(eof); /*Fills the array with line of the txt file one by one*/ i++; } My text file has 40 lines , which I am accessing with a for loop for( j = 0; j <= 39 ; j++) { /*Do something to each line*/}. So far so good. My problem is that i define the size of the array

Extract Array of Coordinates from Line (C++ OpenCV)

青春壹個敷衍的年華 提交于 2019-12-18 08:57:18
问题 Using C++ / OpenCV I've drawn a line on an image using cv::line and now I'm trying to extract an array of its coordinates. I've tried assigning the line to cv::Mat but I get an error stating I cannot convert from void to cv::Mat . Is there a simple way to obtain these coordinates? Thanks for the help! 回答1: You have at least a couple of options. Assuming that you know the two endpoints A and B of the line: 1) Draw the line with line(...) on an zero initialized mask of the same size of your

python 迭代器

房东的猫 提交于 2019-12-18 08:46:30
学习材料: learning python 4th 例子代码: 1 ### file: script1.py2 3 # A first Python script4 import sys # Load a library module5 print(sys.platform)6 print(2 ** 100) # Raise 2 to a power7 x = 'Spam!'8 print(x * 8) # String repetition 开始测试: 结果1: 1 >>> f = open('script1.py') 2 >>> f.readline() 3 '### file: script1.py\n' 4 >>> f.readline() 5 '\n' 6 >>> f.readline() 7 '# A first Python script\n' 8 >>> f.readline() 9 'import sys # Load a library module\n'10 >>> f.readline()11 'print(sys.platform)\n'12 >>> f.readline()13 'print(2 ** 100) # Raise 2 to a power\n'14 >>> f.readline()15 "x = 'Spam!'\n"16 >>> f

Change matplotlib line style mid-graph

十年热恋 提交于 2019-12-18 07:46:13
问题 I'm graphing some data (two lines) and I'd like to change the line style for the portions of the lines where the difference between them is statistically significant. So, in the below image (now a link b/c anti-spam policies don't allow me to post an image) I'd like the lines to look different (i.e. dashed perhaps) up until they start converging at about 35 on the x axis. line plot Is there a way to do this easily? I have the values for the x axis where the differences are significant, I'm

Draw parallel Line

陌路散爱 提交于 2019-12-18 07:25:39
问题 I have a set of points representing a line. It might be a closed shape or an open one. I need to draw a parallel line that goes besides the original one without any intersection. I have the following code to return the generated line. I have problems in the angles of the shape. Some point goes over the original line. My Code is: PointF[] GetParrarel(PointF[] lst, double width, float distance) { List<PointF> final = new List<PointF>(); width = width + distance; for (int i = 0; i < lst.Length-1

How do you replace a line of text in a text file (python) [duplicate]

岁酱吖の 提交于 2019-12-18 07:17:39
问题 This question already has answers here : Search and replace a line in a file in Python (13 answers) Closed 6 years ago . I have a text file that looks like this: unknown value 1 unknown value 2 unknown value 3 unknown value 4 unknown value 5 How can I choose a line and replace its contents with another string? For example: Change unknown value 1 to unknown value 0 . How can I accomplish this? 回答1: import fileinput for line in fileinput.input('inFile.txt', inplace=True): print line.rstrip()

Connecting two WPF canvas elements by a line, without using anchors?

拈花ヽ惹草 提交于 2019-12-18 07:12:22
问题 I have a canvas for diagramming, and want to join nodes in the diagram by directed lines (arrow ends). I tried the anchor approach, where lines only attach at specific points on the nodes but that did not work for me, it looked like crap. I simply want a line from the centre of each object to the other, and stop the line at the nodes' edge in order for the arrow end to show properly. But finding the edge of a canvas element to test intersections against has proven difficult. Any ideas? 回答1: I

C# line break every n characters

僤鯓⒐⒋嵵緔 提交于 2019-12-18 06:06:24
问题 Suppose I have a string with the text: "THIS IS A TEST". How would I split it every n characters? So if n was 10, then it would display: "THIS IS A " "TEST" ..you get the idea. The reason is because I want to split a very big line into smaller lines, sort of like word wrap. I think I can use string.Split() for this, but I have no idea how and I'm confused. Any help would be appreciated. 回答1: Let's borrow an implementation from my answer on code review. This inserts a line break every n