🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.python
Article #16005

Re: Kawalek kodu do poprawienia

#16005
From: RobertSzefler
Date: Fri, 30 Jun 2006 12:24
48 lines
2488 bytes
Husio wrote:
> Mam problem z nastepujacym kodem...
> 
>   1 from pysqlite2 import dbapi2 as sqlite
>   2 import os, sys
>   3
>   4 mypath = os.path.dirname(os.path.abspath(__file__))
>   5 databasedir = os.path.join(mypath, 'a.db')
>   6
>   7
>   8 class DataBase(object):
>   9     databasedir = os.path.join( os.path.abspath(sys.argv[0]),
> 'brain.db')
>  10
>  11     def __init__(self):
>  12         self.con = sqlite.connect(databasedir)
>  13         self.cur = con.cursor()
>  14
>  15     def show_commands(self):
>  16         self.cur.execute('SELECT command FROM knowledge')
>  17         a = ''
>  18         for output in self.cur.fetchall():
>  19             a += output + ' | '
>  20         return  a
>  21
>  22     def write_to(self, command, text):
>  23         self.cur.execute('INSERT INTO knowledge (command, text)
> VALUES (?, ?)', (command, text))
>  24         self.con.commit()
>  25
>  26
>  27 print ' *************************************\n'
>  28 print mypath, '      ', databasedir
>  29 print ' *************************************\n'
>  30 print DataBase.show_commands()
>  31 print ' *************************************\n'
> 
> 
> Traceback (most recent call last):
>   File "a.py", line 30, in ?
>     print DataBase.show_commands()
> TypeError: unbound method show_commands() must be called with DataBase
> instance as first argument (got nothing instead)
> 
> Nie mam pojecia co z tym zrobic.

Zmień na DataBase().show_commands w 30 linii. Normalnie metody wołasz 
dla instancji, a nie klasy.
Technical Details
Message-ID: <e83557$1oes$1@news2.ipartners.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!nf1.ipartners.pl!news.ipartners.pl!ipartners.pl!not-for-mail
References: <1151670089.236583.64760@b68g2000cwa.googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!nf1.ipartners.pl!news.ipartners.pl!ipartners.pl!not-for-mail
From: RobertSzefler <NOSPAMrszeflerNOSPAM@murator.com.pl>
Newsgroups: pl.comp.lang.python
Subject: Re: Kawalek kodu do poprawienia
Date: Fri, 30 Jun 2006 14:24:07 +0200
Organization: Internet Partners
Lines: 48
Message-ID: <e83557$1oes$1@news2.ipartners.pl>
References: <1151670089.236583.64760@b68g2000cwa.googlegroups.com>
NNTP-Posting-Host: intranet.murator.com.pl
Mime-Version: 1.0
X-Trace: news2.ipartners.pl 1151670247 57820 217.153.39.22 (30 Jun 2006 12:24:07 GMT)
X-Complaints-To: abuse@ipartners.pl
NNTP-Posting-Date: 30 Jun 2006 12:24:07 GMT
In-Reply-To: <1151670089.236583.64760@b68g2000cwa.googlegroups.com>
X-Accept-Language: en-us, en
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit