Cómo puedo usar una variable dentro de un loop que ha sido llamada usando la función locals() en python

El siguiente código es una serie de tiempo horaria, en donde guardo el resultado en diccionarios con diferentes nombres de acuerdo al loop:

from glob import glob filenames = glob('*.csv') dataframes = [pd.read_csv(f, parse_dates=['Fecha_Hora'],  index_col='Fecha_Hora') for f in filenames]  for i in range(len(dataframes)):     locals()['d1_'+str(i)] = {'media_diaria_dataframes_var1_'+str(i):dataframes[i].set_index(dataframes[i].index).groupby(pd.Grouper(freq='D'))['var1'].mean(),'media_diaria_dataframes_var2_'+str(i):dataframes[i].set_index(dataframes[i].index).groupby(pd.Grouper(freq='D'))['var2'].mean()} 

y quiero usar cada diccionario como un dataframe pero no sé como usar los nombres que se guardan con la función locals() dentro del mismo loop.

Alguna idea.

Gracias de antemano.

getEnumerator causing collection has not been initialized error inside of async call inside of a loop in a script editor web part

This is an issue I’ve been struggling with – What I am doing is using a script editor web part and when a user clicks the button, I check to see if a list exists inside of a loop (in this example, it could be called Data1 – Data10) and if so, then I want to pull all of the items from that list based on the query, which is based on filters with other controls (Ignore the datepickers/filters – I know the query works)

The problem I’m hitting is that I’m running these async calls inside of my ‘does the list exist’ loop and getting to the getEnumerator line where I receive the error :

Error: The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

I had previously posted a simplified version of this question and didn’t receive a response so was hoping if I posted the entirety of my solution that it may give me an answer.

Thanks

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js "></script>     <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">     <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>     <script type="text/javascript" language="javascript">      $  (function() {         $  ( "#datepickerStart" ).datepicker();         $  ( "#datepickerEnd" ).datepicker();     });      var valStopped = 10;     var allItems;     function getListData()      {         var _clientContext;         var _web;         _clientContext = new SP.ClientContext.get_current();         _web = _clientContext.get_web();         var lists = _web.get_lists();         _clientContext.load(lists,'Include(Title)');         //Get all lists...         var listTitle = "";         var arrayOfMatchedLists = [];         var responses = {exists:false,record:0};         var arrayOfPromises = [];          for (var j = 1; j < valStopped; j++) //loop through all potential lists and see if they exist         {             listTitle = "Data" + j;             arrayOfPromises.push(get_isListExists(listTitle,j,function(listExists,counter){             if (listExists){                 responses = {exists:listExists,record:counter};                 arrayOfMatchedLists.push(responses);             }             },function(sender,args){}));         }         $  .when.apply($  , arrayOfPromises).done(function() {         var largest = 0;         for (var item in arrayOfMatchedLists)          {         //Get the largest list index             if (arrayOfMatchedLists[item].record > largest)             {                 largest = arrayOfMatchedLists[item].record;             }         }         populateList(largest);             });      }       function populateList(counter)      {      for (var i = 1; i <= counter; i++)         {              var _clientContext;             var _web;             _clientContext = new SP.ClientContext.get_current();             _web = _clientContext.get_web();             var listTitle = "Data" + i; //+ i;             var list = _web.get_lists().getByTitle(listTitle);             var myquery = new SP.CamlQuery();             if ($  ("Data6").val() !== "All") //get Data6 as a filter if it's not all, else don't use Data6 as a filter.             {                 myquery.set_viewXml('<View><ViewFields><FieldRef Name=\'Data1\'/><FieldRef Name=\'Data2\'/><FieldRef Name=\'Data3\'/><FieldRef Name=\'Data4\'/><FieldRef Name=\'Data5\'/><FieldRef Name=\'Data6\'/><FieldRef Name=\'Data7\'/><FieldRef Name=\'Data8\'/><FieldRef Name=\'Data9\'/><FieldRef Name=\'Data10\'/></ViewFields></View>');             }             //else set query as all facilities             allItems = list.getItems(myquery);              _clientContext.load(allItems, 'Include(Data1,Data2,Data3,Data4,Data5,Data6,Data7,Data8,Data9,Data10)');             _clientContext.executeQuery(Function.createDelegate(this, this.onQuerySucceeded()), Function.createDelegate(this, this.onQueryFailed));         }                }      function onQuerySucceeded()      {         var Data1 = null;         var Data2 = null;         var Data3 = null;         var Data4 = null;         var Data5 = null;         var Data6 = null;         var Data7 = null;         var Data8 = null;         var Data9 = null;         var Data10 = null;         var txtHTML = "";          console.log("before enum");         var listEnumerator = allItems.getEnumerator();         console.log("get enumerator");             while (listEnumerator.moveNext()) {                     console.log("before got current");                     var currentItem = listEnumerator.get_current();                     console.log("got current");                     Data1 = currentItem.get_item('Data1');                     Data2 = currentItem.get_item('Data2');                     Data3 = currentItem.get_item('Data3');                     Data4 = currentItem.get_item('Data4');                     Data5 = currentItem.get_item('Data5');                     Data6 = currentItem.get_item('Data6');                     Data7 = currentItem.get_item('Data7');                     Data8 = currentItem.get_item('Data8');                     Data9 = currentItem.get_item('Data9');                     Data10 = currentItem.get_item('Data10');                     var row = document.createElement("tr");                      txtHTML = txtHTML + "<tr>";                     txtHTML = txtHTML + "<td>";                     if (Data1 != null) {                         txtHTML = txtHTML + "<p>" + Data1 + "</p>";                     }                     txtHTML = txtHTML + "</td>";                      txtHTML = txtHTML + "<td>";                     if (Data2 != null) {                         txtHTML = txtHTML + "<p>" + Data2 + "</p>";                     }                     txtHTML = txtHTML + "</td>";                      txtHTML = txtHTML + "<td>";                     if (Data3 != null) {                         txtHTML = txtHTML + "<p>" + Data3 + "</p>";                     }                     txtHTML = txtHTML + "</td>";                      txtHTML = txtHTML + "<td>";                     if (Data4 != null) {                         txtHTML = txtHTML + "<p>" + Data4 + "</p>";                     }                     txtHTML = txtHTML + "</td>";                                                      txtHTML = txtHTML + "<td>";                     if (Data5 != null) {                         txtHTML = txtHTML + "<p>" + Data5 + "</p>";                     }                     txtHTML = txtHTML + "<td>";                     if (Data6 != null) {                         txtHTML = txtHTML + "<p>" + Data6 + "</p>";                     }                     txtHTML = txtHTML + "</td>";                         txtHTML = txtHTML + "<td>";                     if (Data7 != null) {                         txtHTML = txtHTML + "<p>" + Data7 + "</p>";                     }                     txtHTML = txtHTML + "</td>";                         txtHTML = txtHTML + "<td>";                     if (Data8 != null) {                         txtHTML = txtHTML + "<p>" + Data8 + "</p>";                     }                     txtHTML = txtHTML + "</td>";                         txtHTML = txtHTML + "<td>";                     if (Data9 != null) {                         txtHTML = txtHTML + "<p>" + Data9 + "</p>";                     }                     txtHTML = txtHTML + "</td>";                         txtHTML = txtHTML + "<td>";                     if (Data10 != null) {                         txtHTML = txtHTML + "<p>" + Data10 + "</p>";                     }                     txtHTML = txtHTML + "</td>";                         txtHTML = txtHTML + "</tr>";             }             console.log("ran");         $  ("#tblCustomListData").append(txtHTML);     }      function onQueryFailed(sender, args)      {         alert("failed Message" + args.get_message());     }      function get_isListExists(listTitle, counter, OnSuccess, OnError){          var ctx = SP.ClientContext.get_current();         var web = ctx.get_web();         var lists = web.get_lists();         ctx.load(lists);          var outValue = $  .Deferred();         ctx.executeQueryAsync(           function() {           if (counter <= valStopped){             var listExists = false;               var le = lists.getEnumerator();             while (le.moveNext()) {                     var list = le.get_current();                     if(list.get_title() == listTitle) {                         listExists = true;                         break;                     }                 }                 }            outValue.resolve();           OnSuccess(listExists,counter);           OnError();             });         return outValue.promise();     }  </script>        <p> Data6: <select id="Data6">       <option value="Op1">Op1</option>       <option value="Op2">Op2</option>       <option value="Op3">Op3</option>       <option value="Op4">Op4</option>       <option value="Op5">Op5</option>       <option value="Op6">Op6</option>     </select> </p>     <p>Start Date: <input type="text" id="datepickerStart">     End Date: <input type="text" id="datepickerEnd"></p>     <center><button ID="retrieveList" onclick="ExecuteOrDelayUntilScriptLoaded(getListData(), 'sp.js');return false">Retrieve List</button></center></br>     <table id="tblCustomListData" border="1">         <thead>             <tr>                 <th>Data1                 </th>                 <th>Data2                 </th>                 <th>Data3                 </th>                 <th>Data4                 </th>                 <th>Data5                 </th>                 <th>Data6                 </th>                 <th>Data7                 </th>                 <th>Data8                 </th>                 <th>Data9                 </th>                 <th>Data10                 </th>                                    </tr>         </thead>     </table> 

Ayuda con tabla PHP 2 tablas sql distintas dentro del mismo loop

Saludos tengo este código para mostrar dos tablas con información de tablas diferentes, necesito ayuda para unir estas dos tablas en una sola les muestro el código

$  link = new PDO('mysql:host=localhost;dbname=felpchil_sistemaplaza', 'felpchil_sistemaadmin', 'bitacora*1212');  ?>   <div id="tabla22" class="col-md-6">      <h3>Tabla Gantt</h3> <table id="tabla2" class="table table-striped table-responsive-md btn-table fl-table">          <thead>         <tr>             <th>Nombre</th>             <th>Fecha de Inicio</th>             <th>Fecha Termino</th>          </tr>         </thead>  <?php foreach ($  link->query('SELECT * from tasks') as $  row){  ?>  <tr>     <td><?php echo $  row['name'] ?></td>     <td><?php echo $  row['actualStart'] ?></td>     <td><?php echo $  row['actualEnd'] ?></td>  </tr> <?php     } ?></table></div>  <div id="example_wrapper"  class="col-md-6">     <h3>Tabla Bitacoras</h3>  <table id="tabla" class="table table-striped table-responsive-md btn-table fl-table">     <thead>         <tr>             <th>Nombre</th>             <th>Fecha de Termino</th>             <th>Estado</th>           </tr>         </thead>         <tbody> <?php foreach ($  link->query('SELECT * from tbltasks') as $  row){  $  status=$  row['status']; $  id=$  row['rel_id'];   ?> <tr>     <td><?php foreach ($  link->query('SELECT name from tblprojects where id = '.$  id.'') as $  row2){ echo $  row2[name];} ?></td>     <td><?php echo $  row['dateadded'] ?></td>     <td><?php if ($  status = "5") {     echo "Completo!"; } else {     echo "Por realizar"; }?></td>   </tr> <?php     }  ?>  </tbody> </table></div> 

La información a mostrar están en las tablas tasks y tbltasks

De la tabla tasks necesito mostrar Nombre, fecha inicio y fecha de termino.

De la tabla tbltasks necesito mostrar Nombre, fecha de termino y status.

¿Alguna idea de como hacerlo? Gracias a todos de antemano.

Oracle – loop through list of databases to check status

I have a table with database names and connection strings. Do you know any method to loop through the list of database names (and/or the connection details) and test database connectivity (just need to know if database is up)? The only problem is that I do not have DBLinks pointing to these databases, but we do use OID if that could be of any help/use.

Thanks!

Does it make sense to write one unit test and loop it through similar components?

I have a situation where I have different forms, each with 4 or 5 steps (components), and I decided to write one unit test per step.

After doing it, I noticed they were very similar and I could just loop through them, changing some values based on the loop index. All good and worked fine, until one of the forms failed and I couldn’t figure out which step was failing . I could provide another generic solution for it, but this failure made me wonder if it really makes sense to reuse code for tests like this.

Well… as developers, we always want to reduce code duplicates, but I think for unit/snapshot tests, it’s a best practice to have every test explicit. The advantage I see by duplicating code in this situation is that it makes it more clear, easy to debug when a failure happens and also, once it’s test code, it doesn’t impact production code. What are your thoughts on it? Does it worth to have generic code to test several similar components, or is it better and safer to have it more explicit, even if you have to duplicate the code?

I also read this article on twitter, a few days ago that opened my mind for this approach even more: https://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction WDYT?

How to detect infinite loop exist in linear bounded automata (LBA)?

The following theorem from Michael Sipser’s book “Introduction to the Theory of Computation” states:

$ A_{\textrm{LBA}}= \{ \langle M, w \rangle \mid \text{$ M$ is an LBA that accepts string $ w$ } \}$ .

THEOREM: $ A_{\mathrm{LBA}}$ is decidable.

On the proof part, it states:

The idea for detecting when $ M$ is looping is that as $ M$ computes on $ w$ , it goes from configuration to configuration. If $ M$ ever repeats a configuration, it would go on to repeat this configuration over and over again and thus be in a loop.

I do not understand this: “If $ M$ ever repeats a configuration, it would go on to repeat this configuration over and over again”. What if $ M$ only repeat one configuration, then halts?

Cómo obtengo las estrellitas de woocommerce en un loop personalizado

Este es el código básico, funciona muy bién, solo me falta mostrar las estrellitas de la puntuación del producto. He agotado recursos, Cualquier idea sería de gran ayuda. Muchas Gracias

     <?php              global $  wpdb;              $  loop = new WP_Query($  args);                  if ($  loop ->have_posts()) :                             while ($  loop ->  have_posts()) :$  loop -> the_post();                          global $  product; ?>                             <a class="imagen">                                 <?php the_post_thumbnail('full'); ?>                              </a>                  //AQUÍ QUIERO MOSTRAR LA PÚNTUACIÓN                             <a class="puntuacion">ESTRELLITAS</a>                              <a class="nombre">                                              <?php echo $  product->get_name(); ?>                                                          </a>                             <p class="precio">                                 <?php echo $  product->get_price_html();  ?>                             </p>                     <?php endwhile;                  endif;          ?>