Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Can python pickle files act as a small database system backend?

I'm writing a small app in python and usually I use sqlite as the backend for this sort of thing. However, I'm thinking that rather than iterating through a python list or dict and writing each record to sqlite cursor, why not just pickle the entire object and take it from then on? How feasible is this thing, have you ever tried it?

/r/Python
https://redd.it/5lf5ur
Peewee does not initialize database tables

I'm trying to create a blueprint based wiki. It's based on [these](https://gist.github.com/coleifer/5449d29f25e0d78bc2e8) code snippets. I'm using peewee as ORM and the playhouse.flask_utils package so I can use init_app in the application factory.

The database is created but it's empty.

https://gist.github.com/yhamdoud/dbd9d50e0863eaf6f4b36504dce98582

/r/flask
https://redd.it/5lgbwd
I created a bot that analyzes a user's comments and determines if they are positive or negative.

Just mention my username in a comment along with the username of the person you would like to analyze and /u/opfeels will respond with the analyzation results.

I use the Python Reddit API Wrapper to extract the most recent 100 comments from a user. I take those comments and extract sentences that aren't too long and aren't too short. Each sentence is then analyzed using the NLTK Sentiment Analyzer Vader Module and scored based on how positive, negative, and neutral it is. I then rank the analyzed users in order from most positive to least positive.

you can also use the website: [ruadick.com](http://ruadick.com)

EDIT: fixed bug "<bound method Redditor.index of <Redditor: Redditor object>>" remember the () when calling functions. =)



/r/Python
https://redd.it/5lgot5
2 Scoops of Django

I've seen 2 Scoops of Django recommended a few times, but the most recent version is for Django 1.8. If I'm totally new to Django, will this mess me up?

/r/django
https://redd.it/5lf9sb
Admin page suddenly gone!

Hi again /r/django!

So - I was coding my project and created some models. These models were registered to admin page and all worked as expected. I continued and added some html templates to a different app, and suddenly my admin-page is empty. the header text is gone and the only thing i can see when I go to localhost:8000/admin/ is "Site administration". That's it. The "Authentication and authorization" part is gone, and my other app is gone. However! If I now go to localhost:8000/admin/<myapp>/, the stuff for the app is shown. What have I done wrong? It happened after I added a "global" template folder in the project root, and added the path to this template folder in the TEMPLATES dict.

/r/django
https://redd.it/5lggur
Blog tutorial in Django 1.10

Hello friends! Happy New Year!

I am new to Django and I am seeking your support. I'm trying to build a pretty complex website with a blog section. I've tried numerous tutorials on YouTube and the documentation and I've ended up frustrated because either the tutorial doesn't really cover everything or I'm running into compatibility issues (Django 1.9 vs Django 1.10) which I couldn't figure out. These two do not really cut it:

https://www.youtube.com/watch?v=FNQxxpM1yOs&list=PLQVvvaa0QuDeA05ZouE4OzDYLHY-XH-Nd

https://www.youtube.com/watch?v=yfgsklK_yFo&list=PLEsfXFp6DpzQFqfCur9CJ4QnKQTVXUsRy

Could someone please point me to a full in depth Django 1.10 tutorial or some kind of template? I've pretty good at the Front End and I just want to get my first webapp off the ground.

Much appreciated

/r/django
https://redd.it/5lk67y
URL not appearing in DRF router!

I have all these router url's set up, but when I add search it doesn't work!
router.register(r'search', search_api.SearchViewSet, base_name='search-api')

i've narrowed it down to when i swap out where the view goes (search_api.SearchViewSet), then it shows up on the django 404 page.... I've tried many combinations of views and nothing makes it work! Why could this be. For example, my current view is :

class SearchViewSet(viewsets.ViewSet):
queryset = Data.objects.all()
renderer_classes = (JSONRenderer, )
def get(self, request, format=None):
print('test')
return Response({'test': 1})


/r/django
https://redd.it/5knjfe
Django or flask?

I am completely inexperienced these libraries. I wanted to see it it'd be feasible to build a site that would display some matplotlib graphs and pandas dataframes. Ideally, these dataframes could be filtered or sorted and exported. The underlying raw data would be refreshed every 30 minutes. Someone could visit and see overall performance and then customize their view.

Another big use case for me would be to allow people to update some "custom" dimension tables and to let me know when certain dimensions are expired or recycled. Right now this is done through csv files being overwritten on an sftp site. It'd be nice to have a front end.

My workflow is centered around using a few libraries to gather external data from SFTP sites, shared folders, and even web sites with selenium. I then read this data with pandas, do my formatting and cleaning, etc, and then I use psycopg2 COPY command to send the data to Postgres. Ultimately, his external data (all different formats and sources) comes together into internal reports.

Some of the data is used for reporting which is sent out through emails (attachments and to_html with pandas to display a table), tableau, and to various shared folders and sftp sites. I'd like to test having some of this on a website instead.

/r/Python
https://redd.it/5lk0or
How to Activate/Deactivate virtualenv on linux with subprocess.Popen?

I achieved to create and to activate the virtualenv on Linux but I cannot deactivate it.
The deactivate command is not available through subprocess.Popen even if shell argument is set to True.

Do you have any ideas?

/r/Python
https://redd.it/5lift9
[Question] I learnt java in high school. How I proceed with learning python?

I'm familiar with object oriented programming and other basic high school stuff. How do I start learning python and other languages?

/r/Python
https://redd.it/5lku9c
I made a small script for looking up word definitions

I've been reading a lot of old texts in school lately which meant I had to keep looking up old words, I noticed that the results almost always showed up in the first page of a google search and decided to try and automate the process.

The script use requests and beautiful soup to send a http search request to google, and then parse through the resulting html fetching any link which domain has a section in config.ini with a css selector for the desired content (the definition of the words).

The script then loops over all the links, extracting the content defined by the css selector in config.ini and displays it in the command line.

I don't know if this is that interesting to this sub, but I thinks is kind of cool and makes my life easier, so I decided to share it in case someone is in the same boat.

[GitHub Link](https://github.com/nikolajlauridsen/WordSearch)

/r/Python
https://redd.it/5lkvq2
User in class based view

Hi guys, im working in first project with django and i have to prepare for an exam. I ll have to make forms and views to create a register with "normal" views and class based views. It´s easy to do but i dont know how to set automatically de foreign key qhen i work with class based views. This foreign key has to be the User that is authentified.

When i work with simple views I get him using:
user_foreign=get_object_or_404(User, username=request.user.get_username())

When i work with class based views i dont know how to do it, can u help me?
Thanks a lot.

/r/django
https://redd.it/5lkmq0
Django admin giving 500 error on local server

I just started this app. I have a single view I was trying to write, that does work. I just tried to reach the django admin and got a 500 error. What is going on here?

main urls.py
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^account/', include('account.urls')),
]

account/views.py
from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth import authenticate, login
from .forms import LoginForm


# Create your views here.


def user_login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
user = authenticate(username=cd['username'],
password=cd['password'])
if user is not None:
if user.is_active:
login(request, user)
return HttpResponse('Authenticated ' \
'successfully')
else:
return HttpResponse('Disabled account')
else:
return HttpResponse('Invalid login')
else:
form = LoginForm()
return render(request, 'account/login.html', {'form': form})

account/urls.py
from django.conf.urls import url
from . import views

urlpatterns = {
# post views
url(r'^login/$', views.user_login, name='login'),
}

error
Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/

Django Version: 1.8.6
Python Version: 3.5.2
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'account')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')


Traceback:
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/contrib/admin/sites.py" in wrapper
254. return self.admin_view(view, cacheable)(*args, **kwargs)
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
110. response = view_func(request, *args, **kwargs)
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/contrib/admin/sites.py" in inner
233. return view(request, *args, **kwargs)
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/contrib/admin/sites.py" in index
421. model_dict['admin_url'] = reverse('admin:%s_%s_changelist' % info, current_app=self.name)
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/s
ite-packages/django/core/urlresolvers.py" in reverse
549. app_list = resolver.app_dict[ns]
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/core/urlresolvers.py" in app_dict
351. self._populate()
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/core/urlresolvers.py" in _populate
307. for name in pattern.reverse_dict:
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/core/urlresolvers.py" in reverse_dict
337. self._populate()
File "/home/swapnil/python_envs/bookmarks/lib/python3.5/site-packages/django/core/urlresolvers.py" in _populate
284. for pattern in reversed(self.url_patterns):

Exception Type: TypeError at /admin/
Exception Value: argument to reversed() must be a sequence


/r/djangolearning
https://redd.it/5kzsn6
py3redirect 1.1 (Chrome extension) - automatically redirects to Python 3 documentation when Python 2 docs page is requested

/u/yaph has posted a link to this Chrome extension some time ago. I am an author of this and recently updated the py3redirect to 1.1, which brings cache (so the extension can redirect immediately if it already knows py3 doc exists for given page) and a button for temporarily disabling redirecting. This version should also fixes the problem with back button - which caused the browser to reload the page (i.e. back to py2 docs, which were immediately redirected to py3), instead of actually going back.

I saw that some people appreciated this however simple work, so I hope you'll enjoy some improvements I made. If you have any other suggestions, that will be appreciated by me. :)

https://chrome.google.com/webstore/detail/py3redirect/codfjigcljdnlklcaopdciclmmdandig

/r/Python
https://redd.it/5ll06t