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
[R] StarGAN: Unified Generative Adversarial Networks for Multi-Domain Image-to-Image Translation

/r/MachineLearning
https://redd.it/7fro3g
Python Guess The Number Game

Just made my first real app in python and was wondering if anyone wanted to give some feedback on it. All is appreciated!

Code:

import random

# Prints credits
print("\t\t\tGuess The Number")

print("\t\t\t \\ \\ \\ \\ \\ \\ \\ \\")
print("\t\t\t\tby")
print("\t\t\t Brook Jeynes")
print("\t\t\t \\ \\ \\ \\ \\ \\")

# Setting values
number_of_guesses = 3
computer_choice = random.randint(1,10)

# Testing number choice
while number_of_guesses != 0:
user_choice = int(input("\nI'm thinking of a number
between 1 and 10:\n"))
# If you guess the number print VVV
if user_choice == computer_choice:
print("Congratulations, you guessed my number")
print("My number was", computer_choice)
number_of_guesses = number_of_guesses - 1
print("You had", number_of_guesses, "guesses left")
number_of_guesses = number_of_guesses + 1
break
# If you didn't guess the number print VVV
elif user_choice != computer_choice:
print("You did not guess my number:\n")
if user_choice > computer_choice:
print("Your guess is too high. Guess lower...")
elif user_choice < computer_choice:
print("Your guess is too low. Guess higher...")
number_of_guesses = number_of_guesses - 1
print("You have", number_of_guesses, "guesses
left")

# Test number of guesses
if number_of_guesses == 0:
print("""
_______ _______ _______ _______ _______ _______ _______
( ____ \( ___ )( )( ____ \ ( ___ )|\ /|( ____ \( ____ )
| ( \/| ( ) || () () || ( \/ | ( ) || ) ( || ( \/| ( )|
| | | (___) || || || || (__ | | | || | | || (__ | (____)|
| | ____ | ___ || |(_)| || __) | | | |( ( ) )| __) | __)
| | \_ )| ( ) || | | || ( | | | | \ \_/ / | ( | (\ (
| (___) || ) ( || ) ( || (____/\ | (___) | \ / | (____/\| ) \ \__
(_______)|/ \||/ \|(_______/ (_______) \_/ (_______/|/ \__/
""")
print("You did not guess my number")
print("My number was", computer_choice)



/r/Python
https://redd.it/7ftn3c
Need help with passing href parameters!

So I'm having trouble with passing an argument through href. I'm using twitter api and trying to return info on users, but it's returning nothing. What am I doing wrong in the view?

base.html:

<a href="{% url 'users' get_user=search.user.screen_name %}" class="user-profile" name="user">

urls.py:

from django.conf.urls import url, include
from . import views

urlpatterns = [
url(r'^$', views.index, name='views'),
url(r'^user/(?P<get_user>\w+)', views.user, name='users'),

views.py:

def index(request):

if request.GET.get('get_user', None):
user_search = request.GET.get('get_user', None)
get_user = api.GetUser(user_id=None, screen_name=user_search)

return render(request, 'scrape/user/users.html', {'get_user': get_user})

trends = api.GetTrendsCurrent(exclude=None)
searches = api.GetSearch(term='moments', raw_query=None, geocode=None, since_id=None,
max_id=None, until=None, since=None, count=30,
lang=None, locale=None, result_type="popular", include_entities=None)

return render(request, 'scrape/base.html', {'trends': trends, 'searches': searches})

def user(request, get_user):

return render(request, 'scrape/user/users.html', {'get_user': get_user})

/r/django
https://redd.it/7fsm87
What are the benefits of using Django to create a website as opposed to using something like WordPress?



/r/djangolearning
https://redd.it/7fpmcp
A general query about django / javascript patterns and how to best organize/encapsulate

I am currently coding webapps in django and using a bit of javascript to do this and that. Naturally, I sometimes want my javascript apps from knowing the context of my Django template, so the way I've been doing it is hardcoding the js into the .html file.

Example

<script>
var my_var = {{ my_var_from_context }}

Clearly this is ugly as all hell as it forces me to keep my javascript code inside of the .html file. I'd like to make my .js file separate and load it.

Clearly thee are some options like write a function that takes arguments that can be captured in the template then passed.

e.g.

var my_var = {{ my_django_var }}
myFunctionFromScript(my_var)

Is this the best way to be doing this? Is there a better pattern? What are others doing?

Thanks for your help.

-Joe

/r/django
https://redd.it/7fwzqk
Paypal, Django, Local Bank, Integration

I'm thinking about making a web system where people can send me money through their local bank account for buying an online item and I'll buy them that item using my paypal account. So this would be 2 step process. At first they will send me money through their local account and then I'll convert that money into paypal dollars and use those dollars to buy that item for them. I want to know is that possible and if it is, then from where should I start?

/r/djangolearning
https://redd.it/7etabj
Best API for scheduled tasks currently?

I need to set up automatic scheduled tasks. The tasks are pretty simple, like set `is_active_subscriber` to `False` when a user's subscription ends and auto-renewal is off.

I'm aware of cron, but I see that it hasn't been updated for a few years. For simple scheduled tasks, what API is the best option right now?

Thanks.

P.S. I'm building a MVP so I'll be expecting only a small amount of traffic when I first go live. So whatever method I end up using, it should be sufficiently scalable.



/r/django
https://redd.it/7fzled
I'm releasing a free code for the "Automate the Boring Stuff with Python" Udemy course

Use this link to sign up for the "Automate the Boring Stuff with Python" Udemy online course: https://www.udemy.com/automate/?couponCode=PY_ALL_THE_THINGS

It's free until the end of Friday, Dec 1, 2017. Afterwards it goes back to its normal $50 price. (Though you can use this link https://www.udemy.com/automate/?couponCode=FOR_LIKE_10_BUCKS to buy it for $10. And it's an open secret that if you browse Udemy in privacy mode, they'll show you the discount price to lure in a "new" customer. But course creators get a much larger cut when people use their referral codes.)

The course follows the book of the same name, which is available for free, in full, at https://automatetheboringstuff.com under a Creative Commons license. ([Which I encourage you to use to share your own creative works.](https://creativecommons.org/licenses/))

The course is 50 videos and made for people with no previous programming experience. The first 15 videos are free to view on YouTube: https://www.youtube.com/watch?v=1F_OgqRuSdI&list=PL0-84-yl1fUnRuXGFe_F7qSH1LEnn9LkW

And now I will go self-flagellate to atone for my part in legitimizing "cyber monday".

/r/Python
https://redd.it/7fxp46
Free Python Games - Basic Python Games for Beginners
http://www.grantjenks.com/docs/freegames/

/r/Python
https://redd.it/7fzu88
Django URL Issue

I am building a blog. In the navigation menu, there are options for going through "Home" (which is index.html) and "Blog." "Home" is not working unless I place the index.html in the static folder and insert the following line in the code of navigation menu:
<a href="{% static "html/index.html" %}"

In short, when I click on "Home," the URL is being displayed as "http://127.0.0.1:8000/static/html/index.html" in the browser. But when I click on "Blog," the URL becomes "http://127.0.0.1:8000/blog/", which looks to be pretty standard. How can I change "http://127.0.0.1:8000/static/html/index.html" to simply "http://127.0.0.1:8000/index/".

I am a beginner. So, pardon if I make any silly mistake.

/r/djangolearning
https://redd.it/7g2f5h
i wrote a script to make it easier to update my pythonAnywhere server whenever my code changes, help me make it better !

Hello !

Whenever I am happy with my code, I commit it to my Git repository, sync it up, and then use the following two files :

## update.bat
set login=brachamul
plink %login%@ssh.pythonanywhere.com -m update.txt
@echo "Work complete !"
This will open an SSH connection with pythonanywhere, and call my script from there.

## update.txt
echo
echo [Pulling from git]
git pull
echo
echo [Collecting static files]
workon MyEnv
python manage.py collectstatic --noinput
echo
echo [Migrating]
python manage.py migrate
echo
echo [Testing new setup]
python manage.py test
echo
echo [Reloading web app]
touch /var/www/www_mysite_com_wsgi.py

This will pull the new code from git, reload static files, migrate if migrations are needed, trigger the tests (but won't change anything if the tests are wrong, I don't know how to do that) and finally reload the app.

How can I improve on this code ? How do **you** do it ?

/r/djangolearning
https://redd.it/7elu71
What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.


/r/Python
https://redd.it/7g4dnf