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
sqlalchemy not working

I'm trying to build a site and every time I try to use sqlalchemy I can't get the errors to go away. So I tried to just try to do a simple sqlalchemy tutorial to try to figure it out and I'm getting an error with the simplest thing. Please help me.

Code I'm running is just to build a database with a table:

>import os

>import sys

>from sqlalchemy import Column, ForeignKey, Integer, String

>from sqlalchemy.ext.declarative import declarative_base

>from sqlalchemy.orm import relationship

>from sqlalchemy import create_engine
>
>Base = declarative_base()
>
>class Person(Base):

> __tablename__ = 'person'

> id = Column(Integer, primary_key=True)

> name = Column(String(250), nullable=False)
>
>class Address(Base):

> __tablename__ = 'address'

> id = Column(Integer, primary_key=True)

> street_name = Column(String(250))

> street_number = Column(String(250))

> post_code = Column(String(250), nullable=False)

> person_id = Column(Integer, ForeignKey('person.id'))

> person = relationship(Person)
>
>engine = create_engine('sqlite:///sqlalchemy_example.db')
>
>Base.metadata.create_all(engine)


I'm getting the following error:

>sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file (Background on this error at: http://sqlalche.me/e/e3q8)

I did what the error suggested and tried adding pool_pre_ping=True to my engine. It didn't make any difference. Also I ran the code on python anywhere and it worked as expected.

Any idea

/r/flask
https://redd.it/argyej
Just noticed that the code in "Ralph Breaks the Internet" is in python

/r/Python
https://redd.it/ariypt
[D] Did weight decay fall out of favor for regularizing NNs?

At least this is my impression based on it no being used anymore in newer papers. But how come? By contrast to other techniques it actually has a very solid theoretical foundation.

​

/r/MachineLearning
https://redd.it/arlq1d
My Django note taking tool for my engineering journal

I wanted to share my first django project should it be of any use to anyone. I use it for keeping an engineering journal at work but it can be easily used for taking notes related to a book you're reading or even a course at school.

[https://gitlab.com/shanedora/bornstellar](https://gitlab.com/shanedora/bornstellar)

Cheers\~S

/r/django
https://redd.it/arll1o
Lil cheatsheet

/r/Python
https://redd.it/arp3z9
This media is not supported in your browser
VIEW IN TELEGRAM
Python-powered IoT device shows total # of humans online (live) on Python Discord server

/r/Python
https://redd.it/aroyp9
This media is not supported in your browser
VIEW IN TELEGRAM
My ASCII generator (image2text, image2image and video2video) written in Python (Source code: https://github.com/vietnguyen91/ASCII-generator)

/r/Python
https://redd.it/arqh4i
Does it make sense to use flask-restful to write restapi instead of use the original Flask?

Hi all,

I am new in the rest world. I have a big question, why people use the `flask-restful` or `flask-restplus` to writing the rest apis? I didn't see any advantages of that!

​

In my point of view, use Flask directly,

* you can reuse the original models, this is very convenient, if you change the models in the future, you don't need to change the api models... (I mean, in the case you also use Flask to build frontend. )
* you can use the `wtforms` to validate the form inputs. wtforms has a lot of Built-in validators. You can also create your own validators...
* `flask-restful` and `flask-restplus` are third party libraries, which are very possibly not to be maintained in the future...

/r/flask
https://redd.it/arr6za
Simple, clear and fast Web Crawler framework build on python3.6+, powered by asyncio.

## Features

* Useful http client out of box
* Things(request, response and item) can though pipelines(in async or not)
* Item extractor, it\`s easy to define and extract(by xpath, jpath or regex) one item we want from html, json or strings.
* Custom "ensure\_future" and "as\_completed" api provide a easy work flow

## Install

pip install ant\_nest

## Usage

Create one demo project by cli:

`>>> ant_nest -c examples`

Then we have a project:

`drwxr-xr-x 5 bruce staff 160 Jun 30 18:24 ants`

`-rw-r--r-- 1 bruce staff 208 Jun 26 22:59 settings.py`

Presume we want to get hot repos from github, let\`s create "examples/ants/example2.py":

from ant_nest import *
from yarl import URL


class GithubAnt(Ant):
"""Crawl trending repositories from github"""
item_pipelines = [
ItemFieldReplacePipeline(
('meta_content', 'star', 'fork'),
excess_chars=('\r', '\n',

/r/Python
https://redd.it/aru9lm
~8 years ago (I was ~14) I started this beautiful riddle and tonight i finally finished it!

/r/Python
https://redd.it/arv2qj
Got this book at pycaribbean yesterday!

/r/Python
https://redd.it/arvtmf
I need to learn Flask in 5 days for Hackathon. How do I go about this? All help is appreciated!

I have been incorporated into a hackathon team due to the untimely unavailability of a member. I have to learn flask in 5 days and implement our project in it. How can I effectively do this?

Edit: I have no prior web dev experience

/r/flask
https://redd.it/arvoyy
[AF] Best practices for multi-page forms?

Hi all,

As the complexity of my application grows, I'm noticing that I need to create forms that span multiple pages.

A simple use case I'm experiencing is when I have a form that requires a foreign key to another object (we'll call it Foo). However, my database has over 10,000 Foo records. What I would like to do is have a new screen which allows a user to search for a Foo record and return this information back to the original form screen without losing previously entered form data.

How do you all handle similar scenarios?

/r/flask
https://redd.it/ary049
[AF] Have no idea how to deal with this error: 'KeyError: <flask.cli.ScriptInfo object at [...]>'

Python 3.7.1
Flask==1.0.2

I've been using Miguel Grinberg's wonderful 'FLASK WEB DEVELOPMENT' as a reference guide when building a Social Media clone project.

I built some of it not completely following the flow of the book, so had some things he talks about later in the book set up already, but got to the point where it was time to re-structure my project as it had become quite large.

In the book, he talks about using an 'application factory' with a config.py file, and then calling from that when creating the app instance so you can use different configuration set-ups. Here is the config.py file, copied straight from the book:


import os
basedir = os.path.abspath(os.path.dirname(__file__))

class Config:
SECRET_KEY = os.environ.get('SECRET_KEY') or 'mysecretkey'
MAIL_SERVER = os.environ.get('MAIL_SERVER', 'smtp.googlemail.com')
MAIL_PORT = os.environ.get('MAIL_PORT', '587')
MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS', 'true').lower() in \
['true', 'on', '1']
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')


/r/flask
https://redd.it/arzfgt