Posts by Sidon • 6,563 points
288 posts
-
1
votes1
answer40
viewsA: Django returning to Valueerror
You treated the form when the method is POST and if it is GET? just an "oops"? Try to leave your view according to the code below, making the necessary adjustments. from django.shortcuts import…
-
3
votes2
answers107
viewsA: How to write user entries in python files?
Try running your code and you probably won’t be able to, there are some syntax errors. Try running the version below: import os f = open("products.txt", "w") dict = {} while True: pd = input('Type…
-
-1
votes2
answers1344
viewsA: How to Create an Auto Increment in Django that is not pk
Edited It seems that the original solution does not work, Django (v. 1.11) requires an autofield field to have the parameter primary_key=True, an error, in my view, for what is the parameter? The…
-
3
votes1
answer2406
viewsA: Using the Firebird SQL case statement
The syntax of the construction CASE does not agree with Firebird documentation, at least not with that link. To illustrate, let’s assume that we have the one bank with a table called Products, with…
-
1
votes3
answers7146
viewsA: How to run the method inside a.py file by linux terminal
Edited When I answered I focused strictly on the question itself, but then I saw in the comments that the author’s intention is to do something similar to devops or infra management using python,…
-
1
votes2
answers670
viewsA: Python - Path indication of a file for reading
Python uses the backslash for scape sequence start, i.e., when the interpreter finds a "backslash" he expects the next character to be "special", or "control". So what you have to do is inform that…
-
1
votes1
answer403
viewsA: List duplicate data
See if that’s it: select * from table1 a where ( data, valor ) in ( select data, valor from table1 group by data, valor having count(*) > 1 ) Run in SQL Fiddle.…
-
5
votes2
answers1008
viewsA: What is " x" in the Python strings?
It is an escape sequence, meaning that the following two characters should be interpreted as hexadecimal digits for character code interpretation: Try on the terminal: >>> 0x65 101…
-
2
votes2
answers2587
viewsA: Delete a particular line from a . csv using Python
Read the file to a list, like this: with open('csv1.csv', 'r') as f: linhas = csv.reader(f, delimiter=';') lst = list(linhas) From a print in the list to see its contents: print (lst) Then remove…
-
2
votes2
answers3297
viewsA: Iterate for with two variables
When I arrived with the zip, Isac had already responded, but I’ll still try to make a contribution with a little more pythonic shape to the function you want: def haspalin(_str): p='' for i in…
-
1
votes1
answer1345
viewsA: Where is Docker Store located on Ubuntu?
First login (example below my context, Ubuntu also): $ sudo docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to…
-
0
votes1
answer717
viewsA: Select widget in Django does not appear in the form
I don’t know if I understand the doubt correctly, but try to adapt your forms.py according to the fragment below: from .models import Inscricao # Outros imports class InscricaoForm(forms.Form): #…
-
2
votes1
answer311
viewsA: Problem using function . Join()
Join does what you want, but on a list: ' '.join(['nome', 'endereco', 'telefone']) 'nome endereco telefone' But if Voce, in the example, just wants to remove the semicolon from the original string,…
-
1
votes1
answer9332
viewsA: Line break in a file . txt
Use line break with the appropriate exhaust for this, just add '\n' at the end of the string. In the example below I read the strings from a list and add the line break when I write to the file:…
-
0
votes1
answer377
viewsA: How do you install kivy in the anaconda environment on mac os X10.9?
Consulting my anaconda found the kivy for osx-64, as its link is from 2016, it may be that the anaconda has included the package and the documentation has not registered I do not have a mac here to…
-
1
votes2
answers5942
viewsA: How to allow special characters in Python?
To do this, just look for the Unicode characters that you left "printar" and use the command: print(u'\u2551') ║ Example: box =…
-
3
votes1
answer195
viewsA: Error file path to run mp3
The so-called "backslash" used in windows has a function in python, Unix systems, regular expressions and some other programming languages such as C and Perl, its function is to indicate that the…
-
5
votes2
answers15185
viewsA: Formatting strings with ". format" and "%"
Yes, it has several differences, several improvements, in addition to the new style being much more elegant and pythonico, in my opinion. I haven’t read anywhere, it’s just achism, but I believe the…
-
0
votes1
answer449
viewsA: Text mining with Scikit-Learn
Which version of scikit are you using? In what Voce called the baseline class, soon start you make an import like this: from sklearn.cross_validation import StratifiedShuffleSplit But if consult the…
-
0
votes2
answers164
viewsA: How to coverter string for timestamp object?
Arrow pip install arrow import datetime timestamp = time.localtime() str_time = arrow.get(timestamp).format('DD-MM-YYYY HH:mm:ss ZZ') print (str_time) Exit: '27-07-2017 15:39:20 +00:00' Editing:…
-
3
votes3
answers450
viewsA: Annotate: Returning the cheapest product and supplier name (Django)
(TL;DR) If the table does not have zillions of records, Voce can load the entire table into memory and filter with pandas, see the example below. import pandas as pd import io # Simulando a tabela s…
-
3
votes1
answer282
viewsA: Doubts about virtualenv
The answer to the first question is: No! and it seems to make no sense, what I see (and no use) is the contrary, to venv be in a directory inside your project. Yes, No pycharm vc need to tell which…
-
0
votes1
answer218
viewsA: Insert data via SSH with PHP
Use PHP’s Shell_exec function, see the example below: <?php $output = shell_exec('scp <path/arquivo> <user@servidor>:</path/to/>'); echo "<pre>$output</pre>"; ?>…
-
1
votes1
answer127
viewsA: Include file in Java project
You are making reference to the directory via hard coded, this is not a good idea, in different environments this may not work, for example, Windows uses the so-called "backslash" to separate…
-
2
votes1
answer4275
viewsA: Read CSV file ,Columns
[TL;DR] There are several ways to do this, a very easy one would be using pandas: import pandas as pd import io # Simulando um CSV s = ''' Mesa,Entrada,Saida,Conta 01,16:00,18:00,95.00…
-
1
votes1
answer379
viewsA: Is it possible to use pyad (active directory module) on linux?
Unless the document is deliberately dubious, everything indicates that the package was made specifically for windows: pyad is a Python library Designed to provide a simple, Pythonic interface to…
-
1
votes1
answer1412
viewsA: Play video stored in python web
In python, Voce can play videos with Opencv. I never used to play videos stored remotely, but if you can, just download the video (within the app itself) to the location of the application and run…
-
1
votes2
answers409
viewsA: returning python list indexes
Whether your intention is to calculate the median of a list: Numpy: import numpy numbers = [1,2,3,4] numpy.median(numbers) 2.5 Numless def median(numbers): sortlist = sorted(numbers) len_numbers =…
-
0
votes1
answer106
viewsA: Cycle gives results Nan! How to get real values?
nan, means: "It is not a number", that is, a floating point value that you get when you perform a calculation whose result cannot be expressed as a number, any calculation that you perform with nan,…
-
1
votes1
answer941
viewsA: How to use both versions of anaconda on linux?
In reality you don’t need to use two versions of anaconda (and not this related to bashrc, bashrc just indicates the location of the installation), install only one version and you can have as many…
-
2
votes3
answers2710
viewsA: get the 3 largest numbers from a python list
Heapq An alternative would be the use of heapq: import heapq lst = [2, 3, 5, 6, 8, 4, 2, 1] # Os 3 maiores: heapq.nlargest(3,lst) [8, 6, 5] # Os 3 menores heapq.nsmallest(3,lst) [1, 2, 2]…
-
2
votes2
answers447
viewsA: Python assignment and OO
When I saw the question I remembered a chapter of the excellent book of Ramalho, Python Fluent,, when I returned to write there was already the answer of @Maniero, but to complement I decided to…
-
1
votes2
answers405
viewsA: Error copying files between servers
The error message says that the server refused the connection, it could be a blocking firewall, a router in the middle of the connection or the closed ssh port 22. Try the following (examples here…
-
2
votes1
answer138
viewsQ: Delphi 10 Seatle Error When Compiling Rxlib
Ambience: Windows 10, Delphi Seatle 10 Rxlibrary (http://www.micrel.cz/RxLib/dfiles.htm) I am trying to compile a system originally developed on D7 in Delphi Seatle and am getting the following…
-
1
votes1
answer1156
viewsA: keep only rows of a column with the value with Pandas
I do not know if I fully understood the question, but even so I tried to answer, if you want to see the result in a notebook jupyter, clicking here.* import pandas as pd import random # Random…
-
2
votes2
answers5626
viewsA: recursiveness to find odd numbers in a python list
def impares(l, i=0, lst_impares=[]): try: e = l[i] if l[i]%2!=0 else None i+=1 if e: lst_impares.append(e) return impares(l,i,lst_impares) except: return lst_impares…
-
0
votes3
answers4922
viewsA: python recursive function to compute sum of the elements of a list
A way that I consider to be well didactic to show the "mysteries" of recursion in this case: def recl(l, i=0): try: elmnt = l[i] i+=1 return elmnt + recl(l,i) except: return 0 print (recl([1,2])) 3…
-
2
votes2
answers88
viewsA: Organize string data flow by default
(TL;DR) If I understand what you want to do: lista = ['0004434-48.2010', 'UNIÃO', '(30 dias úteis) 03/07/2017', '13/07/2017', '0008767-77.2013', '2017', '(10 dias úteis) 03/07/2017', '13/07/2017']…
-
1
votes2
answers5956
viewsA: How to run a Python command with JS?
For this you need a layer between the back end and the front end, something like the Django templates, in which case Voce would have a button (which could be "controlled" by js or not) that would…
-
0
votes1
answer526
viewsA: Creating directories in Python
Try to do the tests below and if you get the same results, the error is in your file processing logic, if the results are different there is something rotten in the realm of :-) go to the command…
-
3
votes2
answers4641
viewsA: How to install Opencv
Look for the opencv package in python with Pip, in the example below I am in a Ubuntu 16, in an env python3: ~$ pip search opencv | grep "^opencv" opencv-python-armv7l (3.2.0) - opencv-python on…
-
1
votes1
answer1016
viewsA: Django runserver does not work
It seems to be a known python bug, where the runserver fails when the hostname contains "non-ASCII" characters, try one of the two alternatives: 1) Call runserver by spelling out the port and host:…
-
4
votes1
answer2076
viewsA: Select an option from the Selenium Python drop down menu
Seleneium has a class to work with select->option, try this: from selenium import webdriver from selenium.webdriver.support.ui import Select driver = webdriver.Firefox() driver.get('url') select…
-
4
votes2
answers572
viewsA: Manipulating strings in Python
from datetime import datetime lista = ['0004434-48.2010', 'UNIÃO', '(30 dias úteis) 03/07/2017', '13/07/2017', '0008767-77.2013', '2017', '(10 dias úteis) 03/07/2017', '13/07/2017'] for s in lista:…
-
2
votes4
answers17451
viewsA: How to check Postgresql logs?
Logs, no postgres, does not record changes to database data, but only events related to the state of server, such as, startup, readiness for connections and, mainly, errors. See an example of…
-
1
votes1
answer40
viewsA: Python - Conditional Expression
See another version without listcomps: responses = ['Y', 'Yes', 'No', 'no', '', 'Yep'] n=0 for x in responses: n+=1 if x: print(x,n) else: print ('o unico elemento em que x é false', n) Y 1 Yes 2 No…
-
0
votes1
answer523
viewsA: python error when importing fields with accentuated text
To make sure you are using the correct encoding, try the command: print (myConnection.encoding) The way out should be: UTF8 If you are not trying to configure with the command:…
-
3
votes1
answer205
viewsA: How to place a class within a JSON
Jsonpickle: Creating the class: import jsonpickle class Foo(): def test(self): return 'bar' foo = Foo() Converting the obejto into a JSON string: jfoo = jsonpickle.encode(foo) Recreating the python…
-
3
votes2
answers50
viewsA: I would like to know why python is saying that I have provided 3 arguments in this role?
In python 3 Voce should generate the random value Voce wants in this way: randrange: from random import randrange rnd = randrange(1,100) Output: print(rnd) 92 Or else: Choice: from random import…
python-3.xanswered Sidon 6,563 -
2
votes1
answer95
viewsA: Installation Codeblocks Centos
It is not enough to download and "extract", after unpacking Oce needs to install, if the file you downloaded contributes the sources, Oce will have to compile, usually has a file called README,…