Posts by sergiopereira • 2,865 points
89 posts
-
12
votes3
answers17530
viewsA: Why do we have to use the attribute self as an argument in the methods?
If you follow the Python zen you will see that in Python: Explicit is better than implicit. And this is taken very seriously in all language and in all proposals for novelties for her. The same way…
-
2
votes3
answers1090
viewsA: Error installing Scrapy package in Python
Many Python packages are boring to install with PIP on Windows as they need other tools to compile. I would try to install already precompilated. Find the link to the package you want here…
-
1
votes1
answer257
viewsA: How to convert str to python
You can convert the value str for unicode thus: self.blocks.append(unicode(bloqueiosPermanentes.replace("\n", ""))) Or you can make this conversion when comparing: if o ==…
-
2
votes1
answer763
viewsA: What is the correct way to structure addresses in Mongodb?
I believe there is no correct answer either in RDBMS (SQL) or Nosql. The design of the data will always depend on the purpose of your system. If you are developing something that catalogues…
-
0
votes2
answers1224
viewsA: How to transfer data from tables to python?
If you refer to passing the data as parameters to your Python script, on the command line, I would suggest two alternatives: Pass as the path to a file: python meuscript.py /caminho/para/tabela.txt…
-
1
votes1
answer524
viewsA: How to save data from a JSON formed by arrays?
In Mongo you can extract the attributes from within the array like this: db.artigos.find({}, {'posts.thread.title': 1}).
-
6
votes1
answer2273
viewsA: Obfuscate CSS and Javascript for free
For JS the two tools I used directly are: Uglifyjs and Google Closure Compiler. Both go beyond a simple substitution of variable names. They analyze code and can produce an even smaller version of…
-
0
votes2
answers1223
viewsA: Mongo find em array dentro de Collection
This will return a list of the whole arrays to the user. If the user has more than one document in the collection, multiple arrays will return: db.suacolecao.find({userId: "xxxxxxxxx"}, {produtos:…
-
1
votes3
answers225
viewsA: Update Python on LE 4.0 (Ubuntu 10)
Evidently Ubuntu 10 is already very old and I do not have one available to test, but you should be able to install Python 2.7 side by side with the standard Python system. The important thing is not…
-
0
votes1
answer308
viewsA: Update array in Mongodb subdocument
I haven’t used it yet Bulk but in normal updates, like db.mycollection.update(query, updates, {multi: true}) you can only use the $ when the predicate (query) refers to some attribute within the…
mongodbanswered sergiopereira 2,865 -
2
votes1
answer706
viewsA: How to monitor changes in a folder?
You can use the Watchdog Install: > pip install watchdog Example: import sys import time import logging from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler…
-
0
votes2
answers240
viewsA: Identify database server (approval and production) in two different environments
If your goal is not to have to change the code between approval and production, my suggestion is to follow the guidelines of configuration in 12 Factor App. Make your application read the host name…
-
2
votes1
answer470
viewsA: Blueprints - what is the concept? for what?
The Blueprints, in my humble opinion, have a very bad name. If they were called "areas" or "sections" or "Subsites" nobody would be scratching their head to try to understand. In fact Blueprints are…
-
0
votes1
answer179
viewsA: Sending attachment with Flask-Mail
Check if you by chance set MAIL_ASCII_ATTACHMENTS = True. By doing so, you force yourself to use the type Unicode in the file name: arquivo = u'downloads/bbbb.txt' (note the u before the string) Or…
-
1
votes1
answer91
viewsA: Amazon S3 / Route 53 routing configuration
I never had to do this but I believe it is possible. I recommend looking the documentation. Something around here might work: <RoutingRules> <RoutingRule> <Condition>…
awsanswered sergiopereira 2,865 -
0
votes1
answer264
viewsA: Send attachments via Amazon SES ( Sendemail Function )
You have two options: Use an email sending library via SMTP and point it to your SES Create a low level email (raw), encoding the entire format of including a file manually (the whole process of…
-
0
votes2
answers254
viewsA: SIT tones using Python or C#
I never really had to do this but I would start looking for an audio library, like pyaudio. If she doesn’t have something that already solves her problem, another option is to use Scipy/Numpy for…
-
0
votes2
answers776
viewsA: Error while interpreting special characters
Check that your file . py is saved as Unicode (UTF-8) and not ASCII/ANSI. Also I would use the prefix u in string: u'//*[@data-qtip="Configurações"]'
-
0
votes1
answer165
viewsA: mongodb error: E QUERY Syntaxerror: Unexpected Identifier
The server log you posted does not seem to have anything to do with the original error. The log probably indicates that there is another mongodb active on the same port. Either you choose another…
mongodbanswered sergiopereira 2,865 -
1
votes2
answers1346
viewsA: Caused by: java.awt.Headlessexception: No X11 DISPLAY variable was set, but this program performed an Operation which re
Often this type of error occurs when some code running outside a graphical environment, as in your case, on a server, tries to run something that uses a graphics library. A good try is to install a…
-
2
votes2
answers91
viewsA: Windows Service Deploy for ec2
There are several ways to do this. Here are just a few suggestions. Depending on how critical your service is (whether it can go off the air for a few moments, or not) one of these may suit you: Use…
-
0
votes1
answer155
viewsA: AWS script to delete snapshot longer than 7 days
Just so as not to confuse anyone else (as you confused me when reading the title), it is AMI’s and not snapshots (EBS Snapshots from EC2). That said, I can suggest the use of tags: add tags to the…
-
2
votes1
answer85
viewsA: What modules do I use to perform data sharing for a Python file?
If the format is simple like this, without any novelty planned, use some parser library, such as the ANTLR, can take more work than doing what you’ve already done. If you have some control over the…
pythonanswered sergiopereira 2,865 -
2
votes1
answer1190
viewsA: Best practices for storing images in Amazon S3 and saving in Mysql
I would particularly try not to keep any of this in the database. I would create a GUID for each record and make the URL of each image be derived from that GUID. Example of a record: id: 123 name:…
-
2
votes2
answers698
viewsA: Python clock does not update
I imagine this code is blocking everything in an endless loop and no loophole for anything else to run: while 1: label.set_markup("<big>" + str(datetime.now().hour) + ":" +…
-
3
votes1
answer287
viewsA: What would dynamic javascript parameters be?
Dynamic parameters occur when your function accepts a variable number of arguments, type: minhaFuncao(x) minhaFuncao(x, y, z) The number of arguments can be finite, type 1 or 2 or 3 arguments…
javascriptanswered sergiopereira 2,865 -
0
votes1
answer311
viewsA: Permission denied - Logging
This mistake, number 13, is related to permissions. The process that is running your website is not authorized to create or modify the file error log. in the tried directory. As your example is from…
-
7
votes1
answer530
viewsA: Is Flask only used by beginners?
Not at all. Flask is a leaner framework with fewer opinions, which makes it easier to extend (and understand!). It’s a good way to get into the world of web development with Python but it’s not just…
-
4
votes2
answers878
viewsA: When to use list comprehension and not filter+lambda?
The answer depends somewhat on the version of Python you are using. In Python3 the filter was redone using itertools.ifilter python 2.x. The great advantage of ifilter is the smallest use of memory…
-
1
votes1
answer332
viewsA: Problems installing numpy module in windows by Pip
You already tried to download it precompiled?
-
3
votes2
answers1727
viewsA: Is token in the URL safe?
I don’t see much problem and it’s also a common practice. I would just make these suggestions: When generating the token, save the IP address and the creation date/time When validating the token…
phpanswered sergiopereira 2,865 -
3
votes1
answer1292
viewsA: IIS works only on localhost
Read about Security Groups in AWS. It’s quite possible that your instance in EC2 is not allowing access from the Internet. You may need to create a Security Group by opening doors 80 and/or 443 to…
-
0
votes2
answers187
viewsA: Python code error
If the problem really started after installing anaconda, most likely your scripts started using the wrong Python on your machine. Open a new Terminal window and type which python. Normally, in OS X,…
pythonanswered sergiopereira 2,865 -
2
votes1
answer794
viewsA: Reference collections in mongodb
As you know, Mongodb is not relational, so there is no way to define a native relationship between two documents. You have two alternatives most common in Mongo: Built-in documents (nested) Manual…
-
2
votes1
answer638
viewsA: Recovering list values from python lists
What I think is happening is that, the way you wrote, your data is being imported as strings. You also defined mensagem and no as two-dimensional, where each element is a separate vector. There, on…
-
2
votes3
answers100
viewsA: Will I lose my databases if I update SQL Server 2012 Express to Standard?
Every time I installed different versions of SQL Server side-by-side, they always coexisted without touching each other’s data. By the way, ever wondered how many distracted people would lose their…
-
5
votes1
answer130
viewsA: Should I avoid injecting "%" in a query where I use "LIKE"?
You can replace % for \%. Taking advantage, also replace _ for \_: $search = trim(Input::get('search')); $search = str_replace(['_', '%'], ['\_', '\%'], $search)…
-
0
votes1
answer1654
viewsA: RDS AMAZON - Difficulties to connect in Database
That page explains everything. To connect your PC to your RDS instance, you need to know: The endpoint of the instance, something like: meu-rds-sql-server.abcdefgh123.us-east-1.rds.amazonaws.com The…
-
5
votes2
answers188
viewsA: script.vbe - encrypted virus
I decoded some more for you. The script is not hard to read. It downloads two executables to the folder c: Users Voce Appdata MSRTVBE32. Files have random names and end with .exe. I imagine there is…
-
1
votes1
answer310
viewsA: Mongodb in production
This depends on what is stored in each Core. I usually identify the ones that represent user-created data versus the data that is needed for the application to run (type country and state lists).…
mongodbanswered sergiopereira 2,865 -
1
votes2
answers589
viewsA: Read the last 5 lines of a file through Python
My suggestion includes using an iterator with for...in. This uses relatively little memory and remains quite readable, in my opinion. def tail_file(file_name, number): lines = [] with…
-
0
votes1
answer1538
viewsA: UTF-8 code does not work
Try using the meta tag in the recommended format: <meta http-equiv="content-type" content="text/html; charset=UTF-8"> Also confirm that your server is not sending a header Content-Type with…
-
2
votes1
answer4297
viewsA: Configure FTP on AWS
The instructions vary a little depending on which distro you are using (Ubuntu, Amazon Linux, Centos, Redhat, etc.) These are the steps I followed to set up the SFTP service on an Ubuntu 14.04…
-
1
votes1
answer574
viewsA: Error with Flask Babel Python3 app (Windows)
In fact the author has executed the script run py., nothing about any Script folder. Are you using Python 3 or 2? There is one bug in Babel with Python 3. One of the suggestions is to uninstall…
-
5
votes3
answers392
viewsA: How to open remote content with python?
Use urllib2: import urllib2 def file_get_contents(url): return urllib2.urlopen(url).read()
pythonanswered sergiopereira 2,865 -
1
votes3
answers1144
viewsA: Is there any way to use script as configuration files in python?
I don’t know a way to make it identical to PHP, using Imports directly. But you can use a file. py for configuration if you create some convention. For example: # em config/db.py config = {…
-
0
votes1
answer156
viewsA: Problems with Psycopg2 on MAC
I don’t work with Psycopg2 then my answer is more generic, which can help with this kind of problem. How are you adding something to PATH before installing, it is possible that the same modification…
pythonanswered sergiopereira 2,865 -
5
votes1
answer492
viewsA: Understanding the pythonic way of dealing with properties
When you declare the getter, the method can then be used to mark the setter and the deleter (I omitted the deleter of my example to get shorter). class Pessoa(object): def __init__(self): self._nome…
-
0
votes1
answer230
viewsA: Python subprocess.check_output command
The right way to invoke subprocess.check_output() or subprocess.Popen() is passing each term of the command on an element of the list/array, and not creating a long string. You also need to watch…
-
2
votes1
answer181
viewsA: Creation and communication with daemon
You need to look for an inter-process communication solution. A popular way that works in a similar way across platforms and programming languages is to create a queue server (MQ). One of these is…