Posts by stderr • 30,356 points
651 posts
-
1
votes1
answer160
viewsA: Problems with Python Frames
Initially the room number is 1. def quarto1(self): # ... Shakespeare.quarto=1 # .... In the first Frame which is displayed if you type EAST, in the method ir_para, the line below is executed:…
-
2
votes3
answers3733
viewsA: Set width and height in text box
The tkinter.Entry only lets you set the width. Alternatively the tkinter.Text which makes such changes. Typeerror: get() Missing 1 required positional argument: 'index1' Other than tkinter.Entry.get…
-
1
votes1
answer694
viewsA: How to check if a Resultset is empty?
You can check whether the method ResultSet.html#isBeforeFirst returns false: con = DriverManager.getConnection( ... ); stmt = con.prepareStatement( ... ); ResultSet rs = stmt.executeQuery(); if…
-
3
votes1
answer151
viewsA: Problems to display cookies
In function setcookie indicate the path where the cookie will be available. Use / to indicate that it works for the entire site and not just the directory where it is being set up:…
-
4
votes1
answer498
viewsA: Error with scrapy requests
There are at least two ways to solve this. The first is to specify to the middleware that you want to handle response codes that are outside the range 200-300, do it on handle_httpstatus_list: class…
-
8
votes2
answers13627
viewsA: Python second degree equation
There are conflicts between variables and function names. You have the functions delta and raizes: def delta(a,b,c): delta = (b**2) - (4*a*c) return {"delta":delta} def raizes(a,b,c,delta): x1 =…
-
2
votes4
answers541
viewsA: Concatenate 2 PHP variables into SQL statement
Using the point to concatenate didn’t work. Any hints? It did not work as expected because the attempt at concatenation is being made between quotation marks, the . is being interpreted as any…
-
0
votes1
answer88
viewsA: Make the user enter information
Use the set @echo off set /p NOME="Por favor insira seu nome: " echo Bem-vindo %NOME% The /p is to display a message before reading the user input.…
-
2
votes2
answers48
viewsA: New instance overwrites old values
Can you explain why I created the s2 the values of s1 are exchanged? Because the variables point and view are class attributes Signal and not of the instance. Class attributes are attributes whose…
-
5
votes1
answer165
viewsA: I can’t save the information to a local database!
Caused by: java.util.Illegalformatconversionexception: %d can’t format java.lang.String Arguments In the method confirmar, in class Usuario, when using the String.format you are using the format %d…
-
8
votes2
answers215
viewsA: How to determine if a number is infinite using Javascript?
You can use the function isFinite(): console.log(!isFinite(Number.MAX_SAFE_INTEGER)); // false console.log(!isFinite(Infinity)); // true Another way is to compare the value with…
javascriptanswered stderr 30,356 -
4
votes2
answers2340
viewsA: Iterating over nested dictionaries (Pythonic)
Another alternative is itertools.chain.from_iterable: from itertools import chain dic = {'section1': {'key1': 'value1', 'key2': 'value2'}, 'section2': {'key3': 'value3', 'key4': 'value4'} } valores…
-
1
votes1
answer292
viewsA: Object assignment in Python
Can anyone tell me why in the first iteration the assignment retangulo = retangulo() works, but on Monday? Because in the first iteration the class name is overwritten with an instance of the class…
-
3
votes1
answer360
viewsA: You can use a foreach of a query within a function
As mentioned in commenting, you can pass the variable $consulta as an argument: function executarForeach($consulta) { foreach ($consulta as $key) { echo $key["InfoDado"]; } } And to call the…
-
4
votes1
answer731
viewsA: Questions in Python (Try and except)
You can automate questions in a function: def perguntar(area): try: n = int(input("Quantas questões de {} você acertou? ".format(area))) except ValueError: n = -1 return n Create a dictionary to…
-
2
votes2
answers520
viewsA: Changing Rows in Datagridview / Opening a form with different design
Another alternative is to use a control variable to indicate what behavior the button will have. In the secondary form create the variable modo: namespace WindowsFormsApplication1 { public partial…
-
0
votes3
answers6535
viewsA: Sequence reading of space-separated numbers
You can use the fgets to take the entrance and strtok to break into pieces: char entrada[100]; // Para obter até 100 caracteres da entrada int * elementos[10]; // Array com capacidade para 10…
-
1
votes1
answer51
viewsA: dialog with problem when using --item-help
This is because --item-help recognizes "mouse" as help text of the first checkbox. It is necessary to specify the help text for each checkbox. dialog --title 'Seleção dos Componentes' --item-help…
-
1
votes1
answer74
viewsA: How to make Numericupdown return to the minimum value when Upbutton is clicked and the current value is the maximum?
One way to solve would be to compare the current value with the minimum and maximum allowed value. When the value reaches the minimum, change the value to the maximum and when it reaches the…
-
17
votes6
answers7015
viewsA: How to get unique values in a Javascript array?
SE6+ From ES6 you can also use the Set The Set Object Lets you store Unique values of any type, whether Primitive values or Object References. Take an example: var valores = ['a', 'b', 'b', 'c',…
-
2
votes1
answer134
viewsA: Porting a Python 2 code to Python 3: Scan ICMP with errors
"Nameerror: name 'Unicode' is not defined" In Python 3, unicode was renamed to str, and str for bytes. More information. # Altere essa linha ip_network = ipaddress.ip_network(unicode(ips),…
-
2
votes2
answers435
views -
0
votes1
answer228
viewsA: Problem to execute a query in Sqlite
Resolution: I was forgetting to put the create in the right place. public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { try { TableUtils.createTable(connectionSource,…
-
2
votes2
answers58
viewsA: Shopping list within function
Use the isset before checking whether the variable has been defined. function verificarProduto($produto, $quantidade) { $produtos = array('Leite' => array('preco' => 0.8, ), 'Iogurte' =>…
-
4
votes3
answers1915
viewsA: What are [ ] bash for?
Both [ and [[ are used to assess what is between [..] or [[..]], can be compared strings and check file types. [ is a synonym for test, [[ is a keyword. In doing if [ condicao ] can be said to be…
-
2
votes1
answer51
viewsA: Creating txt file from another txt file
Read line by line from the file and check with the function String#contains if the line contains the desired character: try (BufferedReader br = new BufferedReader(new FileReader("foo.txt"))) {…
-
1
votes2
answers1154
viewsA: Add Information to a file on a specific line
One way is to read the file and put it in one array, by index you indicate the line and change the value. $linhas = explode(PHP_EOL, file_get_contents("arquivo1.txt")); $numeroLinha = 2;…
-
0
votes2
answers2513
viewsA: Exception in thread "main" java.util.Inputmismatchexception
According to the documentation: The exception InputMismatchException is launched by the instance of Scanner when the token recovered does not match the type expected. InputMismatchException extends…
-
3
votes3
answers514
viewsA: Return number of days for the end of the year
Another alternative is to use the function toDays of Duration.between: import static java.time.temporal.TemporalAdjusters.lastDayOfYear; //... LocalDate hoje = LocalDate.now(); LocalDate…
-
3
votes2
answers27501
viewsA: How to verify if a number is even or odd?
Another alternative with the operator bitwise &: $numero = 3; if ( $numero & 1 ) { echo "$numero é impar!"; } else { echo "$numero é par!"; } The operator & makes the comparison of the…
-
0
votes2
answers72
viewsA: Problems with PHP PDO
Probably the error is on that line: if ($stmt = Conn::con() != null) { The expression above evaluates whether Conn::con() is not null, and the result is a value boolean which is assigned the…
-
1
votes1
answer62
viewsA: Use file data in php code
To read the contents of the text file, you can use the file_get_contents: $linhas = file_get_contents('mapa.txt'); To get the data you want, use the method preg_match_all:…
-
1
votes2
answers150
viewsA: Retrieve PHP data within a text
The Miguel replied very well the question, follows only another alternative using the functions strpos and substr: function recuperarTags($texto){ $inicio = 0; $tags = []; while (($inicio =…
-
2
votes1
answer2024
viewsA: Problems executing commands in CMD with Python
Exception: [Winerror 2] The system cannot find the file specified This exception is cast because the system does not recognize dir as an executable, you must pass it as an argument to cmd.exe.…
-
1
votes3
answers12149
viewsA: How to check if a number is within a range in Python?
Another alternative, however limited depending on what is verified is the range: numero = 101 if numero in range(100, 200): print ("{} está no intervalo!".format(numero)) else: print ("{} não consta…
-
3
votes1
answer899
viewsA: Error opening Sqlconnection
string connectionString = @"Data Source=VBSS019\\ZONESOFTSQL;Initial Catalog=ServerDown;Integrated Security=True"; The prefix @ indicates that the string must be literally interpreted, it is not…
-
2
votes1
answer812
viewsA: How to send special characters from CMD to a file?
Use the escape character ^: echo casa ^> cidade ^> Estado > Arquivo.txt
-
2
votes2
answers7910
viewsA: Read text file and play the content in positions in an array!
Follow below another way using the explode and file_get_contents: $linhas = explode("\n", file_get_contents('mapa.txt')); echo $linhas[0] . "\n"; // city=A(100,80); echo $linhas[1] . "\n"; //…
-
6
votes2
answers418
viewsA: How to reverse FILTER_SANITIZE_SPECIAL_CHARS
Use the function html_entity_decode: $foo = filter_var ("hug' o", FILTER_SANITIZE_SPECIAL_CHARS); echo html_entity_decode($foo, ENT_QUOTES, "utf-8"); // hug' o…
-
3
votes1
answer51
viewsA: Qcombobox.addItems: called with Wrong argument types
According to the documentation, a list is expected, you are passing a function. Pass the list directly: self.option = QComboBox(self) self.data = {'image' : ['planet.jpg', 'cat.png',…
-
2
votes3
answers316
viewsA: Separate values from a string and execute a function with the same
Use the explode: $numeros = "13|123456789\n14|123456780\n"; $contador = 0; $vezes = 3; while ($contador < $vezes) { $linhas = explode("\n", $numeros); foreach($linhas as $linha){ list($ddd,…
-
1
votes1
answer118
viewsA: Creating an ARPING
ans, unans = srp(Ether(dst = "ff:ff:ff:ff:ff:ff")/ARP(pdst = ips), timeout = 2, iface = interface, inter= 0.1) The function srp has the same purpose as sr (explained here), the difference is that…
-
1
votes2
answers518
viewsA: Problem with form placement
This happens because the event OnCreate is executed only once, when the form is created. You must put this code in the event OnShow, which occurs each time the form is displayed. void __fastcall…
-
5
votes2
answers305
viewsA: Is it possible to run Acrobat Reader without putting all the way of its executable?
But sometimes it may be that the Acrobat executable is not in this path, the question is possible to run Acrobat by without having to indicate all its path in Java? Will the file have to be opened…
-
1
votes1
answer229
viewsA: IDLE: Your Python may not be configured for Tk
According to the AP, the problem was solved by installing the tk: sudo slapt-get --install tk
-
0
votes1
answer177
viewsA: Implementing a TCP traceroute
ans, unans = sr(IP(dst=target, ttl=(1, 30)) / TCP(dport = port, flags = "S")) According to the documentation, the function sr is used for sending packages, the result is a tuple with the unanswered…
-
4
votes1
answer1127
viewsA: Selecting Row on a Datagrid from a query. C#
You can go through the rows of DataGrid and compare the values with the text of TextBox. string pesquisar = textBox1.Text.ToLower(); dataGridView1.ClearSelection(); foreach (DataGridViewRow row in…
-
4
votes1
answer6497
viewsA: Creating a chat program. How to make two talk simultaneously?
The above program in Python 2.7 worked when changing input for raw_input and I don’t know why. In Python 2.x the method input is used to interpret and evaluate expressions, see an example: Python…
-
1
votes1
answer722
viewsA: Dns.Resolve() vs Dns.Gethostentry()
This happens because the method GetHostEntry tries to make a reverse search before returning the IP, if this procedure fails, the error is returned WSAHOST_NOT_FOUND - Host not found. Alternatively,…
-
2
votes3
answers1866
viewsA: How to Display Json in PHP
Use the json_decode: $leads = $client->leads->getLeads(['email' => '[email protected]']); $clients = json_decode(json_encode($leads), true); foreach ($clients as $chave => $valor){ echo…