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
Anyone can do a layman's guide to accessing a jupyter remotely from another computer?

do explain in simple terms!

/r/IPython
https://redd.it/7ezpe8
[Research] [Project] Leela Zero: a community open source project for machine learning in Go software. Call for help!

For all machine learning and AI enthusiasts, there is a great chance to take part to a project which is going to be a milestone in the history of Go software.

What can you do? You can offer your machine time and run a tiny self-playing software generating new games and data to be used for training Leela Zero and make it stronger and stronger.

We need your help! We need everyone's help in order to speed up the training process. Be part of a great open source and community driven project and let's all make history!

Please visit the links below to know more. Thank you.


https://github.com/gcp/leela-zero

http://zero.sjeng.org/

https://www.reddit.com/r/cbaduk/

General information about Go game: https://en.wikipedia.org/wiki/Go_(game)

General information about Go computing and software: https://en.wikipedia.org/wiki/Computer_Go

/r/MachineLearning
https://redd.it/7ezd1q
Have any of you made money/have a passive income by automating a process with python?



/r/Python
https://redd.it/7f52lf
Does anyone have an example of a navbar with search?

I want to see how you did your routing.

/r/flask
https://redd.it/7ezjks
Converting HTML tags to custom code

For example i have following HTML code:

<p>Check our new website </p>
<p>at www.example.com and convert </p>
<p>more than this. </p>
<p> </p>
<p align='center'><b>Tester </b></p>

Now the old system is using some weird way of handling text to print and instead of HTML tags it uses word combination so the text should look like:

NLCheck our new website
NLat www.example.com and convert
NLmore than this.
NL
BCTester

So basically it uses combination of word for example NL(Normal Left), BC(Bold Center) so total of 6 combinations (NL,BL,NR,BR,NC,BC). What way would i take to convert this, is there any lib to parse the html tags and check their attributes or what way to choose?


/r/Python
https://redd.it/7f76ns
Whats wrong here? It always says "you chose right"

/r/Python
https://redd.it/7f7j1b
Best practices with captchas - Am I doing this right?

I got application with server-side sessions. When user comes, I will generate captcha image server-side and set the solution as one of session variables.

This way, when the user submits the captcha, I will simply compare the solution to the saved session variable.

This works fine in testing single-threadedly using sqlite in memory as database but when in production using several workers and postgresql for the sessions, the validation fails from time to time several times in a row.

I am suspecting some kind of caching between my app and database messes up with the logic.

Is this bad way to implement captchas? What would be better way?

/r/flask
https://redd.it/7b5cii
6 Experts share amazing ways a beginner can learn Python programming.
https://coolpythoncodes.com/best-way-learn-python-programming/

/r/Python
https://redd.it/7f9bpb
Suggestions for a python IDE for a relatively new developer

I know that most of you will react with "Here we go again... another IDE post...", but bare with me here please.

I am relatively new to python and I was using PyCharm up until yesterday, when I switched from Windows 10 to Fedora 27. Right now I am hesitating, whether to install PyCharm again or not. Why?

1. Ate my memory.
2. I am using docker and I felt I did not use PyCharm to it's fullest potential, because I was running it from the terminal :/.

Prior to writing the post, I did read multiple other IDE posts ( there are a lot of them, so if I lose some karma points today, I will understand) and people mostly suggested Spyder and VIM (some were advising to stay as far away as possible from VIM tho).

Long story short, after reading numerous threads on this topic, I could not decide, as everyone suggested something different and not everyone was in my position with the docker and "amazing" developer skills.

I would be grateful if you could give your humble opinions on the different python IDEs and a small recommendation that can help me pick one :).

/r/Python
https://redd.it/7fa34z
[AF] Apache deployment questions

After a bit of struggling with mod_wsgi, I've successfully deployed my first flask app on EC2!

However, once I set up my apache virtual host configuration, I started getting a 404 on my domain in browser (flask routes work, though). I realize this is because of how I set up my virtual host config, but I'm trying to figure out what the best way to deliver the pages is (different apache configuration, serve everything through flask, or maybe something else).

I have an EC2 instance running apache and mod_wsgi to serve my flask app with the following vhost.confd:


<VirtualHost *:80>
ServerName domain.com

WSGIDaemonProcess flask_app user=username group=groupname threads=5
WSGIScriptAlias / /var/www/flask_app/deploy.wsgi

<directory /var/www/flask_app>
WSGIProcessGroup flask_app
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
</directory>
</VirtualHost>

I think what I would like to do is just have apache serve up var/www/html when someone goes to domain.com, but have the flask traffic routed to something like domain.com/flask_traffic/name_of_route or flask.domain.com/name_of_route.

Is it possible to route traffic that way with a different apache configuration?

I've also considered just having my API traffic go to a different port, or serving all of my static content with Flask, but I'm not confident either of those are good solutions.

/r/flask
https://redd.it/7fbfs1
Sending a file via POST using Django using Javascript instead of HTML Form (X-post from /r/webdev)

I have a PDF file saved in a variable 'report.'

I am using Django and want to pass it to a function in my views.py file using POST --

@xframe_options_exempt
@csrf_exempt
def process_report(request):
if request.method == 'POST'
report_file = request.FILES['docfile']
....
return response
How can I send a ajax POST request with this file? The filetype is a PDF.

I was using an HTML form to do this before, but I wanted to style the form upload using javascript. I tried styling the button using javascript (changing colors and text depending on file type uploaded), but the file was no longer being able to be passed through the POST request. Now I just have the file saved in a javascript variable, and am trying to just pass it via POST without using form. I understand it's impossible to prepopulate a form with a file.

My old code:
<form id="boring" action="{% url "process_report" %}" method="post"
enctype="multipart/form-data">

{% csrf_token %}
{{ form.non_field_errors }}
{{ form.docfile.label_tag }} {{ form.docfile.help_text }
{{ form.docfile.errors }}
{{ form.docfile }}

</form>

What I have been trying to do with ajax

var formdata = new FormData(report);
$.ajax({
url: 'process_report',
type: 'POST',
processData: false,
contentType: false,
dataType : 'application/pdf',
data: {
'content': 'formdata',
'csrfmiddlewaretoken': '{{ csrf_token }}',
}





/r/djangolearning
https://redd.it/7fcdfi
[AF][Flask-SQLAlchemy] How do I execute this query?

Hello, everyone!

I have the following relationship ([shitty diagram](https://i.imgur.com/QXgidVX.png)) and would like to fetch row(s) from the `Payments` table. Now obviously, what gets returned is `(id, employer_id, employee_id, payment_date)`. What is the correct way to fetch `(id, employer_name, employee_name, payment_date)`?

What I currently have:

# views.py
@app.route("/dashboard")
@login_required
def dashboard():
payments = Payment.query.all()
# TODO: Find a 'cleaner' way to fetch the relevant info for payments.
for payment in payments:
payment.employee_name = Employee.query.filter_by(id=payment.employee_id).first().name
payment.employer_name = Employer.query.filter_by(id=payment.employer_id).first().name

return render_template("dashboard.html", payments=payments)


---

# dashboard.html
...
<tbody>
{% for payment in payments %}
<tr>
<td>{{ payment.id }}</td>
<td>{{ payment.employer_name }}</td>
<td>{{ payment.employee_name }}</td>
<td>{{ payment.payment_date }}</td>
</tr>
{% endfor %}
</tbody>

Admittedly, I don't have much knowledge about databases aside from the basic ORM commands. I don't even know the correct terms to search for! Anyway, I'd like to know:

1. What is the correct way of doing what I did with the above code?
2. What would it look like in plain SQL?
3. What topics should I be reading up on?

Thanks a lot, r/flask!

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