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
Add multiple ordered similar arguments to manage command

I'm trying to build out a command that'll looker similar to this

`python manage.py gen-data primary=10-state with=30-users with=30-visits`

The goal here is to do test-data generation where the command doesn't become crazy for any of our front end devs. That command would do something like create 10 states, create 30 users who live in each state, and create 30 web visits for each of those users.

I know how to do the actual generation of the data, but I can't seem to find out how to handle having the same argument repeated like that.

Any help would be much appreciated.

Solved:
Turns out you can do a list object as a arg

parser.add_argument(
'--with', default=[], dest='withs', action='append',
help="Specify district ids by comma separated list.")

` python manage.py generate_data --model=user --with=Super --with=cali --with=frag --with=ilistice --with=xpial --with=idocious`

`['Super', 'cali', 'frag', 'ilistice', 'xpial', 'idocious']`


/r/django
https://redd.it/8q9scf
[D] Improving Language Understanding with Unsupervised Learning
https://blog.openai.com/language-unsupervised/

/r/MachineLearning
https://redd.it/8qbzom
[P] Simple Tensorflow implementation of StarGAN (CVPR 2018 Oral)

/r/MachineLearning
https://redd.it/8qh7e5
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/8qj87y
What's the right way to handle these workflows in DRF?

I've never that been that into external APIs. We honestly haven't needed them that much, and when we have, API views written for each situation has both made sense and (obviously) done exactly what we need.

We're planning to open some of our system up to our clients (and their clients). It's essentially a booking system with, amongst other thins, Booking and User Models.

Basic viewsets and permissions are all done. 10 minute job. But there are two operations that I'm finding difficult to translate (in my head as much as anywhere else) into whatever passes for the "proper" way to do in REST.

The first is booking state change. Advancing the booking from EDITING to CONFIRMED or REJECTED or ON_SITE or LEFT_SITE or CANCELLED, etc. There are quite a few. In the "old" views we have logic to say what states some users can go between. There are also availability checks performed when going from EDITING to a confirmed state.

Do I just assume somebody is going to `partial_update` or 'update' the state and I have to validate this? Or should I be abstracting state change to '/bookings/<id>/{cancel,edit,reject,arrived,left}` etc?

The other problem is some views *occasionally* need more data. One example is a user list. Normally the list of users is enough but occasionally we might want to show (even sort) by when a User last had a booking.

In a Django view this is pretty trivial to annotate in. It's an expensive query, but it's trivial. And that's the problem. There are some Viewsets where I don't want all these expensive annotated fields littering the response where they aren't needed.

Do I just hack in a `?booking_data=1`, or *should* I add a separate API view for Users with booking data?

Again, I realise there are many simple things I could do to hack these in but this is intended for an external audience who have to read —and understand— documentation to use our product. I'm conscious that doing everything via hacky querystrings might not give the best impression.

/r/django
https://redd.it/8qkwqv
[D] Keys to compete against industry when in academia

It seems from published papers that state\-of\-the\-art results are always coming out from industry, and that makes sense because of the much stronger compute power typically available in companies vs. universities. Traditionally, it is somewhat expected that university researchers should focus more on ideas and concepts while industry researchers should consider large scale implementations. However, one observation at recent NIPS/ICML/ICLR/CVPR/etc.. papers reveals a common trend of showing off empirical results. This has haunted me several times and resulted in papers being rejected. It is just too hard to generate empirical results as awesome as those from industry. I hence focus on the more theoretical and algorithmic aspects, but it gets so frustrating when reviewers only critique the empirical results. My question is how to compete with industry in the era where empiricism is becoming so strong in machine learning?

/r/MachineLearning
https://redd.it/8qmhmo
Somebody please help me convert some url patterns to the newer "path" syntax

So I was following what I thought was a Django 2.0 tutorial until we got [to this part](http://muva.co.ke/blog/lesson-4-defining-url-patterns-template-shop-products-django-2-0-python-3-6/) where I just couldn't continue because I can't understand how to read those URL patterns. I'm new to Django and only wanna consider the new "path" syntax for urls. Anyway, would somebody be kind enough to convert the patterns in the linked tutorial to be in the new syntax? By the way, I didn't expect this, had been getting along with what I thought was a version 2.0 tutorial, but oh, well.

/r/django
https://redd.it/8qnoy1
r/RoguelikeDev is running a summer dev-along tutorial series in python

Interested in making a traditional turn-based roguelike? Want to do it alongside other devs and beginners with a tutorial? Over at r/roguelikedev we're starting a [weekly summer event](https://i.imgur.com/EYJFgdI.png) on June 19th where you can do just that :D

Check out "[RoguelikeDev Does The Complete Roguelike Tutorial](https://www.reddit.com/r/roguelikedev/comments/8ql895/roguelikedev_does_the_complete_roguelike_tutorial/)" for more info, including the planned schedule.

The main tutorial we'll be following is in python, although some participants may opt to use other languages.

/r/Python
https://redd.it/8qnlcm
Does Flask-SQLAlchemy DB instance need to be closed?

I am converting the Flask\-SQLAlchemy tutorial (Which I have found the latest version to be kind of confusing) to use Postgres with Flask\-SQLAlchemy. I noticed in it that he creates used `.close()` to close the db connection. Do I need to do this same thing in Flask\-SQLAlchemy? I don’t see a `.close()` method in it. Also, when exactly is this `app.teardown_appcontext(close_db)` code run?

http://flask.pocoo.org/docs/1.0/tutorial/database/

/r/flask
https://redd.it/8qlf9l
How many of you Djangonauts here are full-time entrepreneurs?

I've been bootstrapping full\-time my startup idea, built using Django for the last year or so. I've really benefited tremendously from the advice I received here, from beginning to launch. Thank you so much.

A couple of weeks ago I got contacted by a firm in the industry I used to work in about a possible job opportunity. It would pay probably around 500k usd in total comp. What really surprised me is that, having worked on this idea single\-mindedly for around a year or so, the thought and possibility of going back to paid employment and the world of office politics really plunged me into something that feels like clinical depression. I knew I hated corporate employment but I didn't realize I hate it this much.

I'm not trolling here.

This made me want to find out: How many of you Djangonauts lurking here are in a similar situation? You are using technology and you really like Django in particular, not to get employment but to run away from it, as your ticket to freedom from soul\-crushing BS. Maybe you are self\-taught in everything from HTML to JS to Django like me. We should connect and probably start something together, or just share ideas.

Always, thanks to all in this community. I've gotten so much from you guys.

/r/django
https://redd.it/8qp1l3