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
Revamping design decisions - worth doing now?

So it's been about 1.5 months since I started building a project with Django. Looking at a lot of my old code, unsurprisingly I did not follow best practices. This is especially true with the names of views and models - instead of having a simple model name like **Subscriber**, I'd have something like **UserPremiumSubscription**. There are also major design decisions that I made which were bad, like creating 2 models when I should have just made 1.

I suppose my question applies to not just using Django, but all programming in general - Is it worth going back and changing all the minor nuances to follow best practices? Or should I just keep going and follow best practices for all the code in the future, and go back and do a final fix right before launching the project for production?

It would make sense to go back and fix things now, but what I am worried about is having to go back a 2nd or 3rd time in the future after I become more experienced with Django.

/r/django
https://redd.it/7cck3k
Flask-Security?

I am looking at Flask-Security documentation and noticed there is a basic configuration and one with session configuration.

Which one should I use? Is the setting with session worth the extra effort?

/r/flask
https://redd.it/7bw7f1
Parsing 1,000,000 Lines of Shell Scripts in 6,000 lines of Python

I thought some people here may be interested in a fairly elaborate parser written in Python.

[OSH 0.2 - Parsing One Million Lines of Shell](http://www.oilshell.org/blog/2017/11/10.html)

Source code:

https://github.com/oilshell/oil

Most of the parser is in the `osh/` directory, and the rest of the shell is in the `core/` directory.

I may be moving away from Python in the near future for speed/size reasons [1], but right now the parser is 100% Python.

There is a good amount of detail on the parser in the blog [2]

[1] http://www.oilshell.org/blog/tags.html?tag=OVM#OVM

[2] http://www.oilshell.org/blog/tags.html?tag=parsing-shell#parsing-shell



/r/Python
https://redd.it/7ccunw
Career Advice for an I.T. Field Consultant learning Python

I'm an I.T. field consultant based in NYC working for a MSP and learning Python to expand my skills and market myself for a new job in about a year. I don't have a degree but have managed to come a long way with my knowledge of networking, Linux, macOS, and Windows. I'm extremely calm and empathetic which is also one of my greatest professional skills along with my ability to solve computer problems. I'm learning Python3 and Django currently and I was just curious what job positions I should be looking at to market myself based on my current skill set.

Thanks so much.

/r/Python
https://redd.it/7ccjgk
Using a form to delete an object

I'm trying to delete an object using a form and DeleteView. What I have right now is giving me an error `Reverse for 'deleteblock' with arguments '('',)' not found. 1 pattern(s) tried: ['classroom/(?P<pk>[0-9]+)/deleteblock/$']` I get this error as soon as I load the template adjust.html.

models.py


class Classroom(models.Model):
BLOCK_NUMBER = (
('11', 'Block 1-1'),
('12', 'Block 1-2'),
('13', 'Block 1-3'),
('14', 'Block 1-4'),
('21', 'Block 2-1'),
('22', 'Block 2-2'),
('23', 'Block 2-3'),
('24', 'Block 2-4'),
)
class_list = models.TextField()
course_block = models.CharField(max_length=10, choices=BLOCK_NUMBER)

class DeleteForm(ModelForm):
class Meta:
model = Classroom
fields = ['course_block']

views.py


def adjust(request):
classroom = Classroom.objects.all()
if request.method == 'POST':
form = DeleteForm(request.POST)
if form.is_valid():
return render(request, 'classroom/adjust.html', {'form':form,'classroom':classroom})
else:
form = DeleteForm()

return render(request, 'classroom/adjust.html', {'form': form,'classroom': classroom})

class BlockDeleteView(DeleteView):
model = Classroom
slug_field = 'id'
success_url = reverse_lazy('classroom:classroom')

delete_block_view = BlockDeleteView.as_view()

urls.py


urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^classup/$', create_classroom_view, name='classroom'),
url(r'^(?P<pk>[0-9]+)/deleteblock/$', delete_block_view, name='deleteblock'),
url(r'^adjust/$', views.adjust, name='adjust'),
url(r'^random/$', views.block, name='random'),

template - adjust.html


<form action="{% url 'classroom:deleteblock' classroom.id %}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="submit" />
</form>


What I think should happen is the following. /adjust/ points to the adjust view. This view gets all of the Classroom objects and prepares DeleteView form. The modelform creats a choice list with course_block. I get a form with a list and I choose the course_block that I want to delete. When I click on the submit button, the chosen object's classroom.id matches a deleteblock url, which corresponds to the DeleteView for that object. The successful url from the DeleteView goes back to the classroom view.

For testing purposes, in the adjust view if I change the query to `classroom = Classroom.objects.all().first()`, I don't get an error and the form and form submission behave as expected - other than the fact that the form doesn't really do anything because it is classrooom.objects.all().first() that gets deleted.

I've read the documention on the djangoproject but I'm definitely missing something here.

/r/django
https://redd.it/7ce05n
Jupyter Notebook localhost servers...why so many running and how to shut them down...?


My Jupyter Notebook code modules have been running slower and slower...sometimes taking up to 2GB memory...sometimes locking up the system and causing a "Firefox not responding".

When the notebook was running... I used C:>jupyter notebook list...and I checked my Jupyter Notebook servers...

At one point there were 20 jupyter notebook servers listed...why so many...?

There was one localhost 8889 and the other 19 were localhost 8888. Also two severs had different "token" numbers on the same 8888 localhost.

I completely shut down my computer...with the hopes of stopping all the servers and start fresh...hoping to solve my slow programs and memory hog issues.

When I restarted my computer...before I ran any of my notebook programs...I immediately checked my C:>jupyter notebook list...and it showed 5 active jupyter notebook servers...and the Jupyter Notebook was not even running yet.

I did find and use "taskkill /PID 8889 /F" to try to close them...but it either didnt' find it...or...I got "Access Denied. Admin. permission needed (I am already logged on as Admin).

How is this possible that jupyter notebook servers are running before even I ran the jupyter notebook...and is there a way to close them all down to make sure they are not hogging resources...?

Here is the list of servers that came up...before I even ran jupyter notebook.

C:\Users\Robert2\jupyter notebook list

Currently running servers:

http://localhost:8889/ :: C:\Users\Robert2\A iPython Notebooks

http://localhost:8888/ :: C:\Users\Robert2\A iPython Notebooks

http://localhost:8888/ :: C:\Users\Robert2\A iPython Notebooks

http://localhost:8888/ :: C:\Users\Robert2\A iPython Notebooks

http://localhost:8888/ :: C:\Users\Robert2\A iPython Notebooks

Any help will be appreciated. Thanks,
Robert



/r/JupyterNotebooks
https://redd.it/7ca023
Cannot view the image uploaded through admin panel.

Hi everyone, I added a new model in my app that will provide optional images in my blog articles. But I have a problem. My model looks like that:

class Photo(models.Model):
imagename = models.CharField(max_length=200)
aricleimage =
models.ImageField(upload_to=
'blog/static/photos/%Y/%m/%d',
blank=True)

def __str__(self):
return self.imagename

It doesn't look nice because I had to break a few lines to put this code in this post. But anyway, I am able to (after registering) add a photo through admin panel. It creates the directory in the static dir as intended and photo is there and everything seems okay.
But when I try to preview it by viewing this object and clicking at the image URL, I get a notification that the photo with ID:

„4/change/blog/static/photos/2017/11/11/d79yUgm.jpg”

Does not exists and perhaps it was deleted. Well, I know where's the problem but how can I set the django so that when dealing with images it will use the upload directory instead of adding this `4/change`prefix? Thanks.

/r/django
https://redd.it/7c7xrv
Interacting with someone elses DRF API, making things easier?

I have limited experience with DRF itself, I work with a fair few other randomly written API's. All of those other ones I've had to write up classes to interact with them..etc. I'm hoping theres something easier for interacting with someone elses DRF.

I've looked into coreapi and I'm struggling with certain aspects, they say to run one command the output should be ... and I seem to get another response such as:

coreapi get http://127.0.0.1:8000
{
"users": "http://127.0.0.1:8000/users/",
"groups": "http://127.0.0.1:8000/groups/"
}

coreapi action list
No current document. Use `coreapi get` to fetch a document first.

coreapi action users list
No current document. Use `coreapi get` to fetch a document first.

What am I missing? This document it speaks of, seems to be something that needs to be done on the server side of things which doesn't help me since I have no control of that nor do they want to do anything for me.

/r/django
https://redd.it/7c62kf
Python Fractal Landscape

/r/Python
https://redd.it/7cffpd
Deconstructing Data Science

Hey everyone! 👋

Yesterday I launched the second post of a new Data Science blog, where I’m open-sourcing every resource I find and insight I come across in pursuit of becoming a world-class (top 5%) Data Scientist in < 6 months.

The purpose of this post is to empower others to start accelerating their own learning by:

1) deconstructing the complex craft of Data Science into it’s simple micro-skills

2) identifying the 20% of skills that contribute to 80% of outcomes

I'm writing this with learners like you and I in mind, so if you're also interested in accelerating your learning, check it out & feel free to share around:

https://ajgoldstein.com/2017/11/12/deconstructing-data-science/

/r/pystats
https://redd.it/7cgpom
I Made a Massively Multiplayer Board Game to Test Django Channels

http://codewords.io/

I've been trying to get permission to run a game of it from the publisher and designer (CGE & Vlaada Chvátil) but I haven't heard back. I've found demonstrating that there's interest in what you're doing is the best way to get ahold of people. So..

Anyone interested in trying a massive game of Codenames over Twitch? Not quite "For Science!" more "For Engineering!" Which, let's be honest here, has a much better ring to it.

If you'd like to know more, I put up an FAQ up here: http://codewords.io/faq/

If you'd like to sign up to help, there's a form over there: http://codewords.io/

Screenshots and a game play overview can be found somewhere under this: https://imgur.com/a/3xtZC

Never haven’t heard of Codenames?! You’re in for a treat, it's one of this (or any) decade's best games. Here’s the super short rulebook (https://czechgames.com/en/codenames/downloads/).. And a video: https://www.youtube.com/watch?v=emlI43ZE9-c

/r/django
https://redd.it/7cieeu
Please recommend good Python books for the following topics.

Hey Redditors,

I am looking for books on following topics using python programming:

* Automata with Python
* Design & Algorithm with Python
* Operational Research with Python
* Probability & Vectors with Python.

Thanks.

/r/Python
https://redd.it/7cj6v2
Show generated image file to html

I have generated image file from matplotlib with various filename, like this :

figure_name="Sentiment_Analysis_of_{}_Tweets_About_{}".format(number, query)
plt.savefig("{}.png".format(figure_name))
full_filename=figure_name+'.png'
return render_template("index.html", figure_filename=full_filename)

how to return the generated image to html?
I use this code but it doesn't work

<img src="/{{ figure_filename }}" class="img-fluid" alt="">

/r/flask
https://redd.it/7br7sx
Question about thread model of Flask application

Would it be safe to have the built-in Flask webserver running in the same process with other background tasks?
Performance should not be a problem as only 1-2 Users are accessing the system at a time. It would be very convenient to have only a single process with shared data running and the possibility to have application internal events shared between tasks.

/r/flask
https://redd.it/7bkv62
url variable

How do you get the url variable in flask.

http://localhost/page?a=22

How do I print the value of a in jinga2.

/r/flask
https://redd.it/7bcn72