python – Text Wrap using return and print

We give you a chain S and a width w.
Your task is to wrap the string in a paragraph of width w.
Input format
The first line contains a string, S.
The second line contains the width, w.

Example of input
Example of exit

I tried the code, but I did not get the required result. As 2 additional lines enter the exit.
Note: the last 4 lines of the code are immutable (not to be modified)

import textwrap

def wrap(string, max_width):

    for i in range(0,len(string),y):

if __name__ == '__main__':
    string, max_width = input(), int(input())
    result = wrap(string, max_width)

python – Implicit recursion when assigning a return function to a variable?

Hi guys, I started studying Python and I had a slightly strange behavior for me. It's like this: I have a file which contains functions. In another file, I've imported this and other files as modules. In the archives I created 3 functions (func1, func2, func3). In func1 I pass in parameter: a list and the reference of a function defined in
In func1 I attributed the return of func2 to 3 variables, all with the same parameters for func2:

a = func2(x_best,h,0.1)
b = func2(x_best,h,0.1)
c = func2(x_best,h,0.1)

However, the variables receive the values ​​as if func2 was run 3 times, always receiving as his own return from the previous run. Another thing I realized is that if I declare only two variables, the values ​​assigned to the variables are the equivalent of two executions of the variable. func2 taking as parameters the return of the previous run. My question is: is there an implicit recursion based on the number of variables I declare ??? I am quite confused by these results.

Below, I will specify the codes of what I'm trying to say. I will omit certain functions because they do not interfere with the problem. Thank you in advance for your help.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
import json
from openpyxl import *
from random import *
from math import *

def beale ():
    return (1.5 - ponto(0)+ponto(0)*ponto(1))**2+(2.25-ponto(0)+ponto(0)*ponto(1)**2)**2+(2.625-ponto(0)+ponto(0)*ponto(1)**3)**2

def tgo(problema):

    pontos = points_generator(100)
    matriz = t_matriz_generator(pontos, problema)
    indices = list() 
    melhores = list()
    for i in range(len(matriz)):
        j = 0
        while (j < 4):
            if(matriz(i)(j) < 0):
            if (j >= 3):
            j += 1
    for a in indices:
    return melhores, problema

from random import *
from teste import *
import math
import time

def LineSearch(Xtrial, Xbest, d, h):
    while (problema(Xtrial) < problema(Xbest)):
        Xbest = Xtrial
        h *= 2
    return Xbest, h

def trial_search(ponto, h, d):
    FinalPoint = ponto
    for i in range(len(FinalPoint)):
        FinalPoint(i) = (FinalPoint(i)+h)*d
        if (problema(FinalPoint) < problema(ponto)):
            FinalPoint(i) = ponto(i)
    return FinalPoint

def Unirandi(x0, problema):
    tol = 0.0001
    h = 1.0
    fails = 0
    x_best = x0

    a = trial_search(x_best,h,0.1)
    b = trial_search(x_best,h,0.1)
    c = trial_search(x_best,h,0.1)

p, problema = tgo(beale)
Unirandi((-0.05338583452963963, 4.311503781033389),problema)

The values ​​for the variables are:

a -> (0.11094661416547036, 0.11531150378103339) 
b -> (0.11094661416547036, 0.11531150378103339) 
c -> (0.11094661416547036, 0.11531150378103339)

If I only declare

a = trial_search(x_best,h,0.1)
b = trial_search(x_best,h,0.1)

as a result I have:

a -> (0.10946614165470361, 0.15311503781033392) 
b -> (0.10946614165470361, 0.15311503781033392)

and finally if I just declare

a = trial_search(x_best,h,0.1)


a -> (0.09466141654703604, 0.531150378103339)

How to get a return on investment?

Hello WHT,

This article is intended for multiple users / advertisers older than WHT. I am looking to get a package of advertising here, to increase … | Read the rest of

Web Development – The Most Effective Way to Return Results to a Web Page with a Sorting Algorithm

Recently, I created a search page where the user can enter his search criteria and the server will use a scoring and sorting algorithm to return the "best" results first. The flow of current is as follows:

  1. The user enters his search criteria.
  2. The server-side code (PHP) creates a query to retrieve all the results that match this criteria.
  3. The server uses a function to assign a "score" to each result.
  4. The server scans all the results and ranks the results from the highest score to the lowest score using a "quick sort" algorithm.
  5. The table is spliced ​​in order to take only the 15 best results. These are then passed to the web page to be displayed as results.

At the bottom of the results is a "Load More" button. When you click on it, the process is identical to the one described above (via AJAX), but instead shifts the array to a certain amount, but again, it only takes the following 15 results and returns them to the web page in JSON format, before adding them to the results. via JavaScript.

After review, this seems really ineffective. I ask the database to match the results each time the page is loaded or the user clicks "Load more", noting then sorting each one of them, only to take than 15 of these results.

Of course, I have to query all the corresponding results in order to provide the "best" results for the whole table, rather than on this one.

I thought maybe a better way to do it is to sort and score the entire table via a cronjob and give each line a "position ranking". When the user comes to load the web page, he can simply query the database to obtain the corresponding results in the same SQL statement, classify them in the "position evaluation" column, and then limit the results to 15 ( and use offset for the AJAX request). .

Would this process be much faster? The only drawback I can think of is that the ratings would be out of date, depending on how often the cronjob sorted the results.

Is it worth it to move to this new process or is my concern for efficiency unfounded?

algorithms – Find closed forms for return values

int coffee(int n) {
   int s = n * n;
   for (int q = 0; q < n; q++)
      s = s - q;
   for (int q = n; q > 0; q--)
      s = s - q;
   return s + 2;

int tea(int n) {
    int r = 0;
    for (int i = 1; i < n*n*n; i = i * 2)
    return r * r;

int mocha(int n) {
    int r = 0;
    for (int i=0; i<=n; i = i+16)
        for (int j=0; j

I'm trying to find the value back in terms of $ n $ for coffee, tea, mochabut I'm stuck right now.

I know coffee will return 2 as the code follows:

$ s = n ^ 2 $

$ s = n ^ 2 - displaystyle sum_ {q = 0} ^ {n-1} q = n ^ 2 - dfrac {n (n-1)} {2} $

$ s = n ^ 2 - dfrac {n (n-1)} {2} - displaystyle sum_ {q = 1} ^ nq = n ^ 2 - dfrac {n (n-1)} {2} - dfrac {n (n + 1)} {2} = 0 $

Then, $ s = 0 + 2 $.

However, I can not understand tea, mocha, and espressobecause they do not follow the increments of +1. Could someone help me calculate the return value in terms of $ n $?

algorithms – Finding the return value in terms of $ n $

int coffee(int n) {
   int s = n * n;
   for (int q = 0; q < n; q++)
      s = s - q;
   for (int q = n; q > 0; q--)
      s = s - q;
   return s + 2;

int tea(int n) {
    int r = 0;
    for (int i = 1; i < n*n*n; i = i * 2)
    return r * r;

int mocha(int n) {
    int r = 0;
    for (int i=0; i<=n; i = i+16)
        for (int j=0; j

I'm trying to find the value back in terms of $ n $ for coffee, tea, mocha, but I'm stuck for now.

I know that coffee will return 2 as the code follows:

$ s = n ^ 2 $

$ s = n ^ 2 - displaystyle sum_ {q = 0} ^ {n-1} q = n ^ 2 - dfrac {n (n-1)} {2} $

$ s = n ^ 2 - dfrac {n (n-1)} {2} - displaystyle sum_ {q = 1} ^ nq = n ^ 2 - dfrac {n (n-1)} {2} - dfrac {n (n + 1)} {2} = 0 $

Then, $ s = 0 + 2 $

, but I do not get to understand tea, mocha and espresso because they do not follow the increments of +1. Could someone help me calculate the return value in terms of $ n $?

PHP code to make a WHOIS request and return the received data

I've written a bit of PHP to make WHOIS queries and return the retrieved WHOIS record.

First, a function allows you to identify the TLS of the first level for the domain:

//Return the first-level TLD for a domain
function getTld($domain) {
    //If domain contains dot, find first-level TLD and return it
    if(strpos($domain, ".")) {
        return(pathinfo($domain, PATHINFO_EXTENSION));
    //If domain doesn't contain a dot, just return domain as-is
    } else {

Then the top-level TLD is prefixed to, and a WHOIS lookup is done on TCP port 43:

//Return raw WHOIS data for domain
function whois($domain) {
    $whoisServer = getTld($domain) . "";
    set_error_handler("whoisWarningHandler", E_WARNING);
    $whois = fsockopen($whoisServer, 43);
    stream_set_timeout($whois, 3);
    stream_set_blocking($whois, false);
    fwrite($whois, $domain . "rn");
    $read = ($whois); $retries = 1; $null = null;
    while(stream_select($read, $null, $null, 5) === false) {
        if($retries++ >= 5) {
        print("Retrying... (attempt " . $retries . ")");
    return(filter_var(fread($whois, 65535), FILTER_DEFAULT, FILTER_FLAG_STRIP_HIGH));

Finally, there is a custom warning manager to terminate the program if a connection to the WHOIS server can not be established:

//Custom warning handler for WHOIS fsock/stream
function whoisWarningHandler($errno, $errstr) {
    print("An error occurred while connecting to the WHOIS server.nnError output:nn" . $errstr . "n");

The code can then be called using, for example, print(whois(""));, which would print the WHOIS record for

Can any one indicate if the best practices in terms of quality, efficiency and code security have been followed, as well as the recommended adjustments / improvements that could be made?

oracle – Why does my continuous query notification script only return events from the production database?

What I use:
Python 3.7
Oracle 12c (development)
Oracle 10g (production)
RedHat 6
cx_Oracle 7
oracle_client 11.2.0

What am I doing:
Build a python listener that uses the query notification continues to update a collection of json files.

My problem:
Several months ago, I asked my database administrator to grant a change notification to a development database user at work to support a python listener using cx_Oracle . Listener manages the events and stores the results in json. Everything worked as expected. Last week (03/09/19), I asked the database administrator to grant the same notification to another user of my production database to test on the field my listener in the real world. As soon as this grant was completed, my development auditor stopped receiving events. The production auditor receives and manages the events as planned. Why did my development auditor stop receiving events? I would still like to test the code changes against dev before releasing updates.

Additional information (relevant?):

  1. The development user had more privileges than the production user.
    The production user can only select
  2. The development server is Oracle 12c, production is on Oracle 10g. (Weird, but we have no control over that)
  3. Dev and prod share the same port but reside on different hardware
  4. The development listening program always has the privilege of subscribing to events. it's just not handling them.

sql – How to check a query with an empty return?

I have a query with a lot of columns and when I go back empty, I want it to show 1.

However, I can not check because of the many columns and the GROUP BY.

A simple example follows below:

    (SELECT SUM(amount), p.staff_id from payment p
INNER JOIN staff s on s.staff_id=p.staff_id
GROUP BY p.staff_id),0)

However, I get the following error:

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

How can I check if a query is null and give it a value when it has more than one column?

c ++ – return type deduction – decltype – return (x) returns int &

What is happening here??

int x = 1;
decltype(auto) f() { return x; }  // return type is int, same as decltype(x)
decltype(auto) f() { return(x); } // return type is int&, same as dcltype((x))

** This is an excerpt from the documentation *

The question arises why decltype deduces that return (x) This is of the int type &

int x  = 1;
auto f(){
    return (x);    // return type is int&, same as decltype((x))

int main(){
    bool es_ref = std::is_reference::value;
    std::cout << es_ref;

I did the tests and yes, but my question is to know if there is an anonymous reference or what?
How are they different? return x of return (x)yeah () Act as an operator or as a c ++ theme.

I appreciate them they direct me to the light.

Function Declaration - Go to Return Type Deduction