Posts by Rui Lima • 1,558 points
56 posts
- 
		1 votes1 answer59 viewsA: At what stage should the data be edited?After a more exhaustive search I discovered that the process I referred to is called data munging (also known as wrangling of data), which involves the cleaning of extracted data to a more… 
- 
		2 votes1 answer59 viewsQ: At what stage should the data be edited?I am currently removing data from a website, with data in English, through web scraping. If we want, for example, to translate the names or values of the fields into Portuguese, or to complete… 
- 
		2 votes1 answer931 viewsA: Python import error modulesI don’t recommend importing modules belonging to a "parent folder". That said, if there is no other solution, my advice is to create a package with your module and make a relative import. Then you… 
- 
		1 votes1 answer132 viewsA: Python multidimensional arrayYou are trying to define a Dict as a list. Try setting Dict in parentheses instead { }, in this way: movies = { 'movie': { 'legenda': ['dub', 'leg', 'nac'], 'time': [1, 2, 3, 4, 5] } .... } A Dict,… 
- 
		0 votes2 answers2527 viewsA: How to import Python libraries that are in another hierarchy?Just put an empty file with the name in the same folder: __init__.py For example: src\ conectores\ __init__.py mysql.py bibliotecas auxiliares teste\ chamarMysql.py All folders belonging to your… 
- 
		1 votes1 answer1363 viewsA: Push 'infinitely' keyboard buttonThe "press()" function is no more than the use of the "keyDown()" and "keyUp()" functions in sequence. It may be that the two functions are evoked with an interval too short between them to be… 
- 
		0 votes3 answers12149 viewsA: How to check if a number is within a range in Python?I believe the most correct form is the one you described: if n >= 100 and n <= 200: The way I see it: if n in range(100, 201): It will consume more resources unnecessarily since it will create… 
- 
		4 votes7 answers52205 viewsA: Is there a way to print everything without breaking the line?If you are using python 2.7 you can do the following: print "t", print "e", print "s", print "t", print "e" If you also don’t want the character spacing: import sys print "t", sys.stdout.write("")… 
- 
		5 votes1 answer761 viewsA: Creating a program to get important news on a websiteYour class is not complete: feed-post-body-title gui-text-title gui-color-primary Should be: feed-post-body-title gui-text-title gui-color-primary gui-color-hover In Beautifulsoup whenever you try… 
- 
		4 votes1 answer270 viewsA: Developing a BOT for polls with wordpress plugin PolldaddyI believe that the correct use of this module will be: from vote import vote poll_id = 9484127 answer_id = 43276282 number_of_votes = 1000 vote(poll_id, answer_id, number_of_votes)… 
- 
		4 votes3 answers6679 viewsA: creating a python voting botThere are rare exceptions where it is not possible to fill in form fields using a browser simulator such as Selenium. In such cases, and if you are using python 3 you can use as an alternative last… 
- 
		0 votes1 answer76 viewsA: append string and looping 'for'Just set a string for this effect at the beginning, before looping: def conf_dir_exist(lines): temp = '' print(lines) #isso e uma tuple. string_final = '' for line_a in lines: for line_b in line_a:… 
- 
		2 votes2 answers5127 views
- 
		2 votes2 answers4804 viewsA: Ping manipulation in PythonUse this function, works on linux and windows, for python 2.7 or 3: def ping(host): import os, platform if platform.system().lower()=="windows": ping_str = "-n 1" else: ping_str = "-c 1" resposta =… 
- 
		0 votes1 answer64 viewsA: Error installing ffvideo python packageIt seems that this error is common when the python-dev package is not installed or with the correct version. If your version of Raspbian is jessie, try installing the following on the command line:… 
- 
		-1 votes1 answer865 viewsQ: Conversion from flowchart to codeI am trying to convert a sizable size flowchart to Arduino code. The flowchart is as follows:: Considering your size, I’d feel more comfortable using the remote goto as a flow control. However I… 
- 
		1 votes1 answer1721 viewsA: Arduino mandar GET to PHP pageYou can replace your line: client.print("GET http://meudominio.com.br/teste_arduino.php?nivel=elevado"); For the following: client.println("GET… 
- 
		0 votes1 answer200 viewsA: Is there a specific library to work with android and Arduino?You can communicate with an android application through a Bluetooth module such as the HC-06 connected to the Internet. Such an application could be created, for example, with the Phonegap and a… 
- 
		1 votes1 answer81 viewsA: Xpath does not recognize XML elementsXpath is not working because XML namespaces are being used (namespaces are for solving name conflicts between HTML tags). To resolve the situation, what you can do is write the following expression:… 
- 
		2 votes1 answer123 viewsA: List compreension vs ciclo forTesting with the first script: def is_even(num): if(num % 2 == 0): return True return False lista = range(5000000) pares = [i for i in lista if is_even(i)] And with the second script: def… 
- 
		0 votes1 answer370 viewsA: Communication HC-06 with androidYou can read what is received by the HC-06 module, with the Arduino, as a normal serial entry. An example of code (to read and write) can be this: #include <SoftwareSerial.h> // Define os… 
- 
		2 votes1 answer955 viewsA: Make 1 figure with 3 graphsI think you should use the subplot command, if I’m not mistaken the code should look like this: y = [1,2,3] x = [5,6,7] def funcao1(): pylab.subplot(221) pylab.title("crimes") pylab.xlabel("Anos")… 
- 
		1 votes2 answers2514 viewsA: Unicodedecorror: 'utf-8'Instead of the code line: open(os.path.join(url,file), encoding = "utf8") Try putting the following: path = os.path.join(url,file).decode("utf8") open(path, encoding = "utf-8") Do not forget to also… 
- 
		1 votes1 answer3028 viewsA: How to create more than one graph in matplotlib?You must use the command subplot for each graph, an example of its use may be this: import numpy as np import matplotlib.pyplot as plt def f(t): return np.exp(-t) * np.cos(2*np.pi*t) t1 =… 
- 
		0 votes3 answers1388 viewsA: Minimum search from a list ignoring zero valuesAnother approach, without recourse to internal functions, would be: B=[6, 9, 4, 0, 7, 10, 2, 5, 0, 0, 0, 4, 11] minimo = B[0] indice = 0 contador = 0 for num in B: if num < minimo and num != 0:… 
- 
		0 votes1 answer189 viewsQ: How to extract data from simple non-standard texts?I would like to extract fields for a database from text files. However the fields are positioned in different ways in each text being difficult to obtain the values by common methods, for example:… 
- 
		1 votes1 answer189 viewsA: How to extract data from simple non-standard texts?For this purpose I created the package Masstextextractor to load it simply install, via Pip, on the command line: sudo pip install MassTextExtractor An example of its use for the "local" and "proof"… 
- 
		0 votes2 answers317 viewsA: How to write in sublime text?The main() function may not accept the void as return. You can try the following: #include <stdio.h> int main() { int x; scanf("%d", &x); printf("%d", x); return 0 }… 
- 
		0 votes2 answers317 viewsA: How to write in sublime text?Try placing at the end of the code the following expression: scanf("%d", &x); The code would look like this: #include <stdio.h> void main() { int x; scanf("%d", &x); printf("%d", x);… 
- 
		1 votes1 answer50 viewsA: Syntaxerror when unpacking elements of iterablesIn python 3 print is used with parentheses: print("A resposta é:", 2*2) 
- 
		4 votes2 answers1498 viewsQ: How to preview file . Md during editing?I would like to create markdown documentation for a library on github. However since I have no way to preview what I am doing, it is common to make mistakes that are only discovered when the file is… 
- 
		2 votes2 answers1498 viewsA: How to preview file . Md during editing?It is possible to do it online through this website or use one of the packages that already comes by default with the Atom, called markdown-preview. To have access to the view of what is being… 
- 
		1 votes2 answers65 viewsA: How to make a link on my site open only when clicked on the same page?You can divide parts of the code by if/Else, for example: if(isset($_POST['formulario'])) { // código após formulário ou link ser submetido } else { // código do formulário ou link } This way you… 
- 
		0 votes1 answer1017 viewsA: Product of a functionTry the following on: from functools import reduce # caso utilizes python 3 import operator reduce(operator.mul, (2, 3, 4), 1) Being 2, 3 and 4 the numbers to multiply. A similar answer can be seen… 
- 
		4 votes2 answers42 viewsA: How to not serialize a particular type of element with jQueryTry the following on: var form = $('#service-item-form') .find('input, textarea, select') .not(':checkbox') .serialize() 
- 
		4 votes2 answers880 viewsA: Removing a part of the text inside a txt fileIf I understand correctly you want to replace "null" with a newline in the txt file. I believe that for that you have to do the following: $trocar = preg_replace("\n", null, $leituraFinal);… 
- 
		0 votes2 answers1883 viewsA: How to remove spaces at the beginning and end of an XLS outputI believe that spaces can be easily removed as follows: for linha in xlread("teste.xls"): for item in linha: print item.strip() As for the special characters I think you should leave so, when they… 
- 
		8 votes2 answers19595 viewsA: How to use a variable contained in another PHP page?Knowing that the file "other_file.php" has: <?php $frase = "abcdef"; ?> In another file (from the same directory) the variable can be included as follows: <?php… 
- 
		4 votes1 answer90 viewsA: Is there any way to get back to the last branch in git?I believe it is enough to do the following at the command line: git checkout @{-1} As exemplified in these answers.… 
- 
		1 votes2 answers84 viewsA: Doubt with function jsReplaces: $('#sidebar-menu li ul').slideUp(); For: $('#sidebar-menu li ul').slideDown(); 
- 
		3 votes2 answers410 viewsA: Variable value changing according to a selectIs this what you’re looking for? <?php tem_desconto = 0; tem_desconto = $_POST["modo_pagamento"]; $soma_produtos = 0 if (tem_desconto == 1) $desconto = $soma_produtos * 0.05 $total =… 
- 
		0 votes1 answer241 viewsA: Twisted Critical unhandled error in scrapy tutorialIt may be due to the pywin32 module that has only been loaded but not installed. Try to install it this way: python python27\scripts\pywin32_postinstall.py -install A similar problem can be seen… 
- 
		3 votes2 answers288 viewsA: Decimal home approximation in JavascriptThis is due to floating-point accuracy errors, since it is not possible to map 1.1 to a finite binary value. A similar issue can be seen here. This behavior can be changed through the toFixed… javascriptanswered Rui Lima 1,558
- 
		1 votes4 answers788 viewsA: Generate random values from a distribution in PythonI personally believe the most correct way to import the library would be: from scipy import special A similar question can be seen here. Importing the library as you suggest doesn’t seem possible.… 
- 
		15 votes4 answers33522 viewsA: How to read a CSV file in Python?The simplest way to read the file: import csv ficheiro = open('ficheiro_csv.csv', 'rb') reader = csv.reader(ficheiro) for linha in reader: print linha However it is good practice to open the file… 
- 
		3 votes1 answer615 viewsA: How to check the size of a javascript object (in memory)It does not seem possible, however there is a library able to estimate the size of an object. After added just use the sizeof() function. For example: var tamanho = sizeof(objeto);… javascriptanswered Rui Lima 1,558
- 
		0 votes2 answers56 viewsA: How to remove a position from an Arraybuffer in javascript?Just use the operator '-='. Let’s imagine that we have the following: val valor = ArrayBuffer('1', '2', '3', '4', '21') To remove the value 21: valor -= '21' If we want to eliminate more than one… javascriptanswered Rui Lima 1,558
- 
		2 votes2 answers2267 viewsA: What is the __init__.py file for in python modules?__init__.py files are used to declare to the python interpreter that the directory they are in contains python script files. Example: diretoria/ __init__.py ficheiro_a.py ficheiro_b.py ficheiro_c.py… 
- 
		9 votes3 answers7119 viewsA: How to see the methods or attributes of an object in Python?Just use the dir() function. An example of its use: dir(objeto) 
- 
		3 votes1 answer1220 viewsA: Background Ordova / phonegapPersonally I have never tried to create an application capable of working in the background, however I know that there is a plugin capable of doing this:…