Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
MASTERING PYCHARM

You're reading from   MASTERING PYCHARM Use PyCharm with fluid efficiency to write idiomatic python code

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher
ISBN-13 9781783551316
Length 232 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Nafiul Islam Nafiul Islam
Author Profile Icon Nafiul Islam
Nafiul Islam
Arrow right icon
View More author details
Toc

Debugging workflow


A friend of mine, who used Java in his day job, sent me a code snippet that he needed help with. He was new to Python and was still getting used to the differences between Java and Python. He mostly worked with databases, so he was exploring the different ORMs that were available. He tried SQLAlchemy, the Django ORM, and eventually, found that he liked a still very new ORM called Pony. At that time, the documentation for Pony was still in its infancy, so he sent me the code so that I could help him out. It looked similar to this:

__author__ = "John Doe"

import string
import random

from pony.orm import db_session, commit, Database, Required

db = Database()


class Person(db.Entity):
    name = Required(str)
    age = Required(int)


vowels = 'aeiou'
consonants = str(letter for letter in string.ascii_lowercase if letter not in vowels)


def gen():
    return random.choice(consonants) + random.choice(vowels)


names = [(gen() for _ in range(random.randint(3, 4))) for i...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime