while-loop

Automating a Python Web Crawler - How to prevent raw_input all the time?

前提是你 提交于 2019-12-12 19:12:57
问题 I have been trying to create a Python Web Crawler that finds a web page, read a list of links, returns the link in pre-specified position, and does that for a certain number of times (defined by the count variable). My issue is that I have not been able to find a way to automate the process, and I have to continuously input the link that the code finds. Here is my code: The first URL is http://pr4e.dr-chuck.com/tsugi/mod/python-data/data/known_by_Brenae.html The count_1 is equal to 7 The

Breaking parent loop in tcl

不打扰是莪最后的温柔 提交于 2019-12-12 18:14:16
问题 I have a for loop in a while loop. I have a condition to break the while in the for loop. Here is the code : while {[gets $thefile line] >= 0} { for {set i 1} {$i<$count_table} {incr i} { if { [regexp "pattern_$i" $line] } { for {set break_lines 1} {$break_lines<$nb_lines} {incr break_lines} { if {[gets $thefile line_$break_lines] < 0} break } } #some other process to do } I want to skip $nb_lines in the file parsed to do other thing further. Here the break, breaks the for loop, so it doesn't

c++ while loop condition isn't playing nice with stack.empty() [closed]

强颜欢笑 提交于 2019-12-12 17:21:33
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . So I'm flustered by this bit of code - can't understand why it's misbehaving. The only thing I can think of is that stack.empty() isn't working properly with the while loop, but that seems ridiculous. You'll see

index a list inside the while_loop TensorFlow function

别等时光非礼了梦想. 提交于 2019-12-12 16:56:18
问题 Hello. I have an issue. I actually have a list ( real python list ) of placeholders. My list is of length n ( = T in the below code) and is as follow: my_list = [[D0, K], [D1, K], ... [Dn, K]] Where the Di are not necessary of the same size. That is why I used a list (because I cannot convert this list to a tensor without padding) What I want to do is that: temp = [] for step in range(T): temp.append(tf.reduce_sum(x[step], axis=0)) sum_vn_t = tf.stack(temp) Where x = my_list of length n

How to use for loop and add one day (timedelta) every time

不羁的心 提交于 2019-12-12 15:10:02
问题 Here is my code: import datetime date = datetime.date(2015,10,1) today = datetime..today() oneday = datetime.timedelta(days = 1) date_counter = 0 while not date == today: date_counter+=1 date += oneday In this code I use while loop to achieve my goal--to count the days between today and the specific day chosen by users. However, I want to use for loop to do the same thing. Can it rewrite by for? 回答1: The approach that you are using is not advised. The better approach would be to not use a

Alternating between even and odd in a while loop in PHP

混江龙づ霸主 提交于 2019-12-12 14:42:06
问题 Hey guys, Been working on couple of lines of code but I can't seem to get it to work. Basically I want to alternate between even and odd table-styles via a while loop. What am I doing wrong? Seems as though it only loops through the if() everytime. Thanx! <?php include 'connect.php'; echo "<table id='hor-zebra'>"; $i = 0; while($row = mysql_fetch_array($result)) { if(i%2 == 0) { echo "<tr class='even'>"; echo "<td>" . $row['departure'] ." ✈ ". $row['destination'] . "</td>"; echo "</tr>"; }

How to insert text from inside a vimscript loop?

天涯浪子 提交于 2019-12-12 14:31:44
问题 It appears from the :help while documentation that : NOTE: The ":append" and ":insert" commands don't work properly inside a ":while" and ":for" loop. And I can confirm they don't. But what should I use then to insert text from inside a loop? 回答1: The :insert and :append commands are mostly meant for interactive use. In a Vimscript, you can instead use the lower-level setline() and append() functions, which do work well in a loop. (They are also easier to use, because you can directly pass a

Python while loop for finding prime numbers

﹥>﹥吖頭↗ 提交于 2019-12-12 14:04:01
问题 As a first exercise with Python, I'm trying to write a program using loops to find primes. Everything works with a for loop so I am trying to use a while loop. This works but the program returns a few incorrect numbers. import math # looking for all primes below this number max_num = int(input("max number?: ")) primes = [2] # start with 2 test_num = 3 # which means testing starts with 3 while test_num < max_num: i = 0 # It's only necessary to check with the primes smaller than the square #

Interrupt cin while loop without the user entering input

女生的网名这么多〃 提交于 2019-12-12 12:23:47
问题 In main , I give the user the ability to enter a command to stop the application: while( run_processes && cin >> command_line_input ){ I'd also like to stop the application elsewhere by setting run_processes = false; . However, when I set run_processes to false , the above loop doesn't stop without the user entering input. How can I properly interrupt the loop without the user entering input? 回答1: It is not possible to interrupt std::cin in a portable way. You could however resolve to non

Display 3 items per row - while loop - php/mysql

无人久伴 提交于 2019-12-12 10:25:34
问题 I am currently working on a loop to display items from a mysql table. Is there a simple way to display 3 items per row. So far I managed to display all the items in a single row inside an html table . I would appreciate any help; code (without html table tags) below: <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <?php $database_name = "vog"; $conn = mysql_connect("localhost","root","toor"); mysql_select_db($database_name); $sql = "select * from client1"; $result =