当前位置: 首页>>代码示例>>Python>>正文


Python book.Book类代码示例

本文整理汇总了Python中book.Book的典型用法代码示例。如果您正苦于以下问题:Python Book类的具体用法?Python Book怎么用?Python Book使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Book类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_decrease_number_of_copies

 def test_decrease_number_of_copies(self):
     book = Book("Lords", "Steven Moore", 2000, "Thriller", 2, 15)
     book.decrease_number_of_copies(10)
     self.assertEqual(5, book.number_of_copies)
     book.decrease_number_of_copies(6)
     self.assertNotEqual(-1, book.number_of_copies)
     self.assertEqual(0, book.number_of_copies)
开发者ID:Ralitsa-Ts,项目名称:Bookstore_and_Chart,代码行数:7,代码来源:book_tests.py

示例2: test_increase_number_of_copies

 def test_increase_number_of_copies(self):
     book = Book("Lords", "Steven Moore", 2000, "Thriller", 2, 0)
     book.increase_number_of_copies(10)
     self.assertEqual(10, book.number_of_copies)
     book.increase_number_of_copies(5)
     self.assertNotEqual(10, book.number_of_copies)
     self.assertEqual(15, book.number_of_copies)
开发者ID:Ralitsa-Ts,项目名称:Bookstore_and_Chart,代码行数:7,代码来源:book_tests.py

示例3: delete_book

def delete_book():
    to_do = input('''We're going to delete a book.  Do you have the barcode? [y/N]: ''')
    if to_do.strip() == "" or to_do.strip().lower() == "n":
        results = search()
        i = 1
        for item in results:
            print((i + ") " + item))  # not sure how this will come out.
        del_me = input("Which one is it? ")

        del_me = int(del_me)

        del_me = results[del_me - 1]
        del_me = del_me.split(",")
        del_me = Book(del_me[0])  # this is really fudged atm.  serious testing needed
        the_db = Bdb(dbLocation)
        the_db.delete(del_me)
        print("Deleted.")

    elif to_do.strip().lower() == "y":
        del_me = input("Ok, enter it now: ")
        if del_me.strip() == "":
            print("Invalid input.")
        else:
            del_me = int(del_me)
            del_me = Book(del_me)
            the_db = Bdb(dbLocation)
            the_db.delete(del_me)
            print("Deleted.")
开发者ID:bjschafer,项目名称:pyberry,代码行数:28,代码来源:PyBerry.py

示例4: __init__

class Tractatus:
    # This is the book
    tractatus = None

    def __init__(self):
        """ Construct the Tractatus """

        # Build the Book object
        self.tractatus = Book()

        # Get the tractatus from text
        SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
        all_text = open(os.path.join(SITE_ROOT, "static", "tractatus.txt"), 'r')
        output = all_text.readlines()

        # Read the file line by line into self.tractatus
        # The actual content only begins at line 30 until the end
        for i in range(30, len(output)):
            complete_string = str(output[i])

            # We need to separate the index and the text
            split_string = complete_string.partition(" ")
            index = split_string[0]
            text = split_string[2].rstrip("\n")

            # Load them in
            self.tractatus.add_section(index, text)

        # print self.tractatus

    def get_book(self):
        return self.tractatus
开发者ID:AFFogarty,项目名称:wittgenste.in,代码行数:32,代码来源:tractatus.py

示例5: by_title

    def by_title(self, title):
        """
        Search for a book on OpenLibrary by title

        @param title: the title to search for
        @return: the raw data of all results
        """
        title = title.replace(' ', '+').lower()
        url = urllib.request.urlopen(self.search_url+'title='+title)
        data = simplejson.load(url)['docs']

        for result in data:
            book = Book(0)
            book.title = result['title']
            try:
                book.authors = ', '.join(result['author_name']) if isinstance(result['publisher'], list) else result['author_name']
            except KeyError:
                book.authors = "None"
            try:
                book.publisher = ', '.join(result['publisher']) if isinstance(result['publisher'], list) else result['publisher']
            except KeyError:
                book.publisher = "No publisher found."
            try:
                book.publ_year = result['first_publish_year']
            except KeyError:
                book.publ_year = 0
            try:
                book.description = ''.join(result['first_sentence'])
            except KeyError:
                book.description = "No description found."

            yield book
开发者ID:bjschafer,项目名称:pyberry,代码行数:32,代码来源:lookup.py

示例6: test_read_book

def test_read_book():
    book = Book('test/test_text_file.txt')
    book.read_book()
    chapters = book.get_chapters
    assert len(chapters) == 2
    assert chapters[0].get('title') == 'Chapter 1'
    sentences = chapters[0].get('sentences')
    assert len(sentences) == 4
开发者ID:mpralat,项目名称:bookParser,代码行数:8,代码来源:test_text_parser.py

示例7: parse_all_books

def parse_all_books():
    for file in glob.glob("{}/*.txt".format(book_dir)):
        print("Parsing... {}".format(file))
        book = Book(file)
        book.read_book()
        book.count_distinct_words()
        print(book)

        all_books.append(book)
开发者ID:mpralat,项目名称:bookParser,代码行数:9,代码来源:main.py

示例8: add_book

  def add_book(self, b_name, b_quantity):

    b = Book(name= b_name, quantity= int(b_quantity))

    urllib.unquote(b.name)

    self.response.write("> Voce cadastrou o livro: " + b.name  + " com "+ str(b.quantity))

    b.put()
开发者ID:IgorMarques,项目名称:pd-gae-middleware,代码行数:9,代码来源:library.py

示例9: delete

 def delete(self, conn):
     for row in self.select(conn):
         book = Book(
             row['id'],
             row['title'],
             None,
             row['published_in'],
         )
         book.delete(conn)
         print("")
开发者ID:BCNDojos,项目名称:pyDojos,代码行数:10,代码来源:books.py

示例10: update_location

def update_location(id):
    book = Book(id)

    if 'update_person' in request.form:
        new_location = request.form['location']
    else:
        new_location = request.form['shelf']
    book.update_location(new_location)

    return render_book_info(book)
开发者ID:blint,项目名称:dead_tree_book_tracker,代码行数:10,代码来源:application.py

示例11: read_book

 def read_book(self, bookname, read_what=None):
     if self.suffix == "":
         print bookname
         filename = self.dir + "/" + bookname
     else:
         print bookname + "." + self.suffix
         filename = self.dir + "/" + bookname + "." + self.suffix
     book = Book(filename)
     self.books.append(book)
     self.current_monad = book.read_linear(self.current_monad) + 1
开发者ID:Stevekav,项目名称:tischendorf,代码行数:10,代码来源:linearreader.py

示例12: run

def run():
    mbook = Book.parse(get_mtgox())
    bbook = Book.parse(bitfloor.book(level=2))

    mbook.flatten('0.01')

    our_book, our_book2 = get_our_book()

    # remove our stuff from bbook
    # bbook will have the orders we don't control
    bbook.subtract(our_book2)

    # mbook will now have the gap needed to be filled by our orders
    mbook.subtract(bbook)

    funds = get_funds()

    # get the total remaining area needed to fill
    # find which factor of it we can fill with our total funds
    sumb = sum(o.price*o.size for o in mbook.bids if o.size > 0)*D('1.04')
    bfactor = min(1, funds['USD']/sumb) if sumb > 0 else 1
    suma = sum(o.size for o in mbook.asks if o.size > 0)
    afactor = min(1, funds['BTC']/suma) if suma > 0 else 1

    print afactor, bfactor
    print suma, sumb

    # multiply everything positive by the factor
    # mbook will now have what we need to provide to bitfloor's book
    for o in mbook.bids:
        if o.size > 0:
            o.size *= bfactor
            o.size = o.size.quantize(D('0.00000001'), rounding=decimal.ROUND_DOWN)
    for o in mbook.asks:
        if o.size > 0:
            o.size *= afactor
            o.size = o.size.quantize(D('0.00000001'), rounding=decimal.ROUND_DOWN)

    # now, get the difference between what we need to provide and what we have
    mbook.subtract(our_book2)

    # cancel orders first which are above the gap
    cancel(mbook, our_book, 'bid')
    cancel(mbook, our_book, 'ask')

    # send in orders to fill the gaps
    for o in mbook.bids:
        if o.size > SIZE_LIMIT:
            print 'bid', o
            bitfloor.buy(size=str(o.size), price=str(o.price))
    for o in mbook.asks:
        if o.size > SIZE_LIMIT:
            print 'ask', o
            bitfloor.sell(size=str(o.size), price=str(o.price))
开发者ID:shadww,项目名称:trader.python,代码行数:54,代码来源:bitfloor_mirror_mtgox.py

示例13: _make_book

    def _make_book(self, cell, year):
        bookID, title, originalTitle = self._extract_titles(cell)

        book = Book(bookID, title, originalTitle, year)

        alt = filter(alt_text, cell)
        if alt:
            assert len(alt) == 1
            #noinspection PyUnresolvedReferences
            book.addTitles(*[x.strip() for x in re.split('\s*;\s+', alt[0].text.strip()[3:-1])])

        return book
开发者ID:dmzkrsk,项目名称:fantlab-fb2,代码行数:12,代码来源:author.py

示例14: update

 def update(self, conn, field, new_value):
     for row in self.select(conn):
         author_name = Authors(['name', '=', row[2]]).select(conn).fetchone()[1]
         if field == "name":
             author_name = new_value
         book = Book(
             row['id'],
             row['title'],
             author_name,
             row['published_in'],
         )
         setattr(book, field, new_value)
         book.save(conn)
开发者ID:BCNDojos,项目名称:pyDojos,代码行数:13,代码来源:books.py

示例15: create

 def create(username):
     index = r.hgetall(SESSION_PREFIX + username)
     # 检查库存
     for k, v in index.items():
         stock = Book.get_stock(k)
         if int(stock) < int(v):
             return False
     r.rename(SESSION_PREFIX + username, ORDER_PREFIX + username)
     for k, v in index.items():
         stock = Book.get_stock(k)
         Book.set_stock(k, int(stock) - int(v))
     db.orders.insert({'username': username, 'books': index})
     return True
开发者ID:zhougch5,项目名称:distributeCourse,代码行数:13,代码来源:order.py


注:本文中的book.Book类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。