From idiot1 at netzero.net Mon Mar 1 00:37:35 2004 From: idiot1 at netzero.net (Kirk Bailey) Date: Mon Mar 1 00:37:24 2004 Subject: [Tutor] set the mode of a file Message-ID: <4042CC1F.5080203@netzero.net> I want to set the mode of a text file to 666. How do I do it? -- Respectfully, Kirk D Bailey Pinellas county Florida USA think http://www.tinylist.org/ - $FREE$ software for liberty +-------+ http://www.pinellasintergroupsociety.org/ - In Her Service | BOX | http://www.listville.net/ - $FREE$ list hosting services +-------+ http://www.howlermonkey.net/ - $FREE$ email service kniht http://www.sacredelectron.org/ - My personal SCREED pit (C)2004 Kirk D Bailey, all rights reserved- but ask! From nick at javacat.f2s.com Mon Mar 1 03:27:01 2004 From: nick at javacat.f2s.com (nick@javacat.f2s.com) Date: Mon Mar 1 03:27:12 2004 Subject: [Tutor] problem creating a subclass In-Reply-To: <003c01c3ff2a$13c4a6b0$6401a8c0@xp> References: <20040229212845.60368.qmail@web12403.mail.yahoo.com><404269AE.3040605@venix.com> <20040229225218.7025d0bd@phatbox.local> <003c01c3ff2a$13c4a6b0$6401a8c0@xp> Message-ID: <1078129621.4042f3d5f0733@webmail.freedom2surf.net> DOH! I see now, thankyou for the clarification. Nick. Quoting Alan Gauld : > > > Maybe I'm missing something obvious here but I don't see how Chris' > > UList class is going to work at all. The class has no UList method, > so > > how is 'a = UList.UList(alist)' going to work ? > > Because this is in another file from ULIst(actually the >>> prompt). > So he imported the ULIst module and is accessing the ULIst class > within the UList module: > > import UList > L = UList.Ulist() # Ulist class within Ulist module > > Compare with: > > import sys > sys.exit() > > HTH > Alan G. > > ------------------------------------------------- Everyone should have http://www.freedom2surf.net/ From orbitz at ezabel.com Mon Mar 1 08:59:04 2004 From: orbitz at ezabel.com (orbitz@ezabel.com) Date: Mon Mar 1 09:00:44 2004 Subject: [Tutor] set the mode of a file In-Reply-To: <4042CC1F.5080203@netzero.net> References: <4042CC1F.5080203@netzero.net> Message-ID: <20040301085904.6f4948d0.orbitz@ezabel.com> http://www.python.org/doc/current/lib/os-file-dir.html Read the section on chmod On Mon, 01 Mar 2004 00:37:35 -0500 Kirk Bailey wrote: > I want to set the mode of a text file to 666. How do I do it? > > -- > > > Respectfully, > Kirk D Bailey > Pinellas county Florida USA > > think http://www.tinylist.org/ - $FREE$ software for liberty > +-------+ http://www.pinellasintergroupsociety.org/ - In Her Service > | BOX | http://www.listville.net/ - $FREE$ list hosting services > +-------+ http://www.howlermonkey.net/ - $FREE$ email service > kniht http://www.sacredelectron.org/ - My personal SCREED pit > > (C)2004 Kirk D Bailey, all rights reserved- but ask! > > > > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From vicki.stanfield at ROCHE.COM Mon Mar 1 09:35:04 2004 From: vicki.stanfield at ROCHE.COM (Stanfield, Vicki {D167~Indianapolis}) Date: Mon Mar 1 09:36:05 2004 Subject: [Tutor] accessing db data from pulldown on web page Message-ID: Is it possible to create a web site which contains a dropdown that searches a database based on what is selected from the dropdown? I have tried this in PHP and it doesn't seem possible (according to what "the experts" say). Here is what I want to do: I have a mysql database containing some information. I want to go to a web page (written in Python), select a name from the dropdown, and execute a SQL query based on the name selected. It sounds very simple to me, but I haven't done a lot of web work. --vicki -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20040301/6573993a/attachment-0001.html From vicki.stanfield at ROCHE.COM Mon Mar 1 09:40:16 2004 From: vicki.stanfield at ROCHE.COM (Stanfield, Vicki {D167~Indianapolis}) Date: Mon Mar 1 09:42:34 2004 Subject: [Tutor] why are these two uses different? Message-ID: I have a project which includes a big if/elif. I select on the value selected from a pulldown menu of the dictionary values created thusly: self.combo=wxComboBox(self, 30, " ", wxPoint(wxALIGN_LEFT), wxDefaultSize, self.Dict.values(),wxCB_DROPDOWN) I match the selected value with a hexadecimal value like this: if command in ('1D','48','52','50','73','65','67'): #Get command from dictionary fcommand=self.Dict.keys()[self.Dict.values().index(command)] I have this in the dictionary: self.Dict=('\x78':'78','\x65':'65','\x60':'60','\x1D':'1D') Each command triggers a whole sequence of serial writes and reads. This works fine. Now I want to create a section which allows me to do them individually. There are no timing issues since I am able to turn that off for the device I am writing to. But when I try to do this: do_it = wxMessageDialog(self,"do you want to continue?", "Send", wxYES_NO | wxICON_QUESTION) if do_it.ShowModal() == wxID_NO: do_it.Destroy() else: singledlg = wxTextEntryDialog (self, "Enter the hex value you'd like to send.", "Send Single", "Enter value here", wxOK | wxCANCEL) if singledlg.ShowModal() == wxID_OK: hexval = singledlg.GetValue() fcommand=self.Dict.keys()[self.Dict.values().index(hexval)] port.write(fcommand) If I type in the same string that is in the if statement, it sends the each digit of the hex value in hex itself. As in this example: hex 1D gets sent as 31 64. I have tried binascii.hexlify, but this didn't work. I have tried inputting the data with '1D', but that doesn't match the dictionary. Can I get a hint? I keep running into this same problem, so there must be a key piece of the pie that I'm still missing. --vicki "A pessimist sees the difficulty in every opportunity; an optimist sees the opportunity in every difficulty." -- Winston Churchill -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20040301/c787291c/attachment.html From magnus at thinkware.se Mon Mar 1 10:54:32 2004 From: magnus at thinkware.se (Magnus Lycka) Date: Mon Mar 1 10:54:50 2004 Subject: =?ISO-8859-1?B?UmU6IFtUdXRvcl0gd2h5IGFyZSB0aGVzZSB0d28gdXNlcyBkaWZmZXJlbnQ/?= Message-ID: > Each command triggers a whole sequence of serial writes and reads. This > works fine. Now I want to create a section which allows me to do them > individually. I guess here is where the problem lies. I'm guessing that you have a loop somewhere in your code, where you loop over something like ['1d', 'ff', 'c2'] in the working case. Now, you loop over '1d' instead, and that's just the same as looping over ['1', 'd']. Make sure to feed your loop with a list or tuple instead, and I think it will work. ['1d'] or ('1d',) should work, but notice that ('1d') is *not* a tuple, just a string in parenthesis. E.g. >>> x = '1d' >>> for i in x: print i 1 d >>> for i in (x): print i 1 d >>> for i in (x,): print i 1d >>> for i in [x]: print i 1d -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From hcohen2 at comcast.net Mon Mar 1 09:53:41 2004 From: hcohen2 at comcast.net (hcohen2) Date: Mon Mar 1 10:57:40 2004 Subject: [Tutor] set the mode of a file In-Reply-To: <4042CC1F.5080203@netzero.net> References: <4042CC1F.5080203@netzero.net> Message-ID: <40434E75.9030801@comcast.net> Kirk Bailey wrote: > I want to set the mode of a text file to 666. How do I do it? > Assuming Linux/UNIX $ chmod 666 /* Means read write for file owner, group, public [i.e. any user] is that what you really want? */ Explanation: 4 - read, 2 - write and 1 - executable, I usually make mine 755 on this one user machine. From vicki.stanfield at ROCHE.COM Mon Mar 1 11:08:10 2004 From: vicki.stanfield at ROCHE.COM (Stanfield, Vicki {D167~Indianapolis}) Date: Mon Mar 1 11:10:49 2004 Subject: [Tutor] why are these two uses different? Message-ID: I had tried '1D'. Now I have tried to input [1D], ['1D'] but both generate the ValueError: list.index(x): x not in list when I hit the 'fcommand=self.Dict.keys()[self.Dict.values().index(hexval)]' line. It doesn't seem to matter how I enter the data into the wxTextEntryDialog, it doesn't match. Given the following dictionary excerpt: self.Dict=('\x78':'78','\x65':'65','\x60':'60','\x1D':'1D') What needs to be entered into the wxTextEntryDialog to make it match this dictionary? --vicki -----Original Message----- From: Magnus Lycka [mailto:magnus@thinkware.se] Sent: Monday, March 01, 2004 10:55 AM To: Stanfield, Vicki {D167~Indianapolis}; tutor@python.org Subject: Re: [Tutor] why are these two uses different? > Each command triggers a whole sequence of serial writes and reads. > This works fine. Now I want to create a section which allows me to do > them individually. I guess here is where the problem lies. I'm guessing that you have a loop somewhere in your code, where you loop over something like ['1d', 'ff', 'c2'] in the working case. Now, you loop over '1d' instead, and that's just the same as looping over ['1', 'd']. Make sure to feed your loop with a list or tuple instead, and I think it will work. ['1d'] or ('1d',) should work, but notice that ('1d') is *not* a tuple, just a string in parenthesis. E.g. >>> x = '1d' >>> for i in x: print i 1 d >>> for i in (x): print i 1 d >>> for i in (x,): print i 1d >>> for i in [x]: print i 1d -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From vicki.stanfield at ROCHE.COM Mon Mar 1 15:13:21 2004 From: vicki.stanfield at ROCHE.COM (Stanfield, Vicki {D167~Indianapolis}) Date: Mon Mar 1 15:45:29 2004 Subject: [Tutor] RE: why are these two uses different? Message-ID: Well, I fixed it, but I am not sure that I know what I did. When I went to break out the non-functional code to post it here, the subsection of code worked, so I went back to try the main program, and it works too! I don't know how that could be, but I'll take it. Thanks to everyone who tried to help me figure this one out. --vicki -----Original Message----- From: Stewart Midwinter [mailto:stewart@midtoad.homelinux.org] Sent: Monday, March 01, 2004 2:56 PM To: Stanfield, Vicki {D167~Indianapolis} Cc: tutor@python.org Subject: RE: why are these two uses different? Maybe I'm jumping into the middle of this, but why not post a more complete portion of your code, perhaps structured as a complete python modules, to make it easier for someone to run your code and see what the problem is? (or did you do that already, and I missed it?). One other comment, is it possible to split up the following line: fcommand=self.Dict.keys()[self.Dict.values().index(hexval)] into several components to facilitate debugging? -- Stewart Midwinter Calgary, Alberta stewart 'at' midwinter 'dot' ca Quoting "Stanfield, Vicki {D167~Indianapolis}" : > I had tried '1D'. Now I have tried to input [1D], ['1D'] but both > generate the > > ValueError: list.index(x): x not in list > > when I hit the > 'fcommand=self.Dict.keys()[self.Dict.values().index(hexval)]' line. It > doesn't seem to matter how I enter the data into the > wxTextEntryDialog, it doesn't match. Given the following dictionary > excerpt: > > self.Dict=('\x78':'78','\x65':'65','\x60':'60','\x1D':'1D') > > What needs to be entered into the wxTextEntryDialog to make it match > this dictionary? > > --vicki From stewart at midtoad.homelinux.org Mon Mar 1 14:56:07 2004 From: stewart at midtoad.homelinux.org (Stewart Midwinter) Date: Mon Mar 1 15:47:59 2004 Subject: [Tutor] RE: why are these two uses different? In-Reply-To: References: Message-ID: <1078170967.4043955784645@midtoad.homelinux.org> Maybe I'm jumping into the middle of this, but why not post a more complete portion of your code, perhaps structured as a complete python modules, to make it easier for someone to run your code and see what the problem is? (or did you do that already, and I missed it?). One other comment, is it possible to split up the following line: fcommand=self.Dict.keys()[self.Dict.values().index(hexval)] into several components to facilitate debugging? -- Stewart Midwinter Calgary, Alberta stewart 'at' midwinter 'dot' ca Quoting "Stanfield, Vicki {D167~Indianapolis}" : > I had tried '1D'. Now I have tried to input [1D], ['1D'] but both > generate the > > ValueError: list.index(x): x not in list > > when I hit the > 'fcommand=self.Dict.keys()[self.Dict.values().index(hexval)]' line. It > doesn't seem to matter how I enter the data into the wxTextEntryDialog, > it doesn't match. Given the following dictionary excerpt: > > self.Dict=('\x78':'78','\x65':'65','\x60':'60','\x1D':'1D') > > What needs to be entered into the wxTextEntryDialog to make it match > this dictionary? > > --vicki From stewart at midtoad.homelinux.org Mon Mar 1 14:58:27 2004 From: stewart at midtoad.homelinux.org (Stewart Midwinter) Date: Mon Mar 1 15:48:04 2004 Subject: [Tutor] set the mode of a file In-Reply-To: <40434E75.9030801@comcast.net> References: <4042CC1F.5080203@netzero.net> <40434E75.9030801@comcast.net> Message-ID: <1078171107.404395e390962@midtoad.homelinux.org> If you were wanting to do it from within your Python program, you could use the os.system() command. If you want to check if the mode change was successful, you could monitor the return code from that command, by using os.popen2 or popen4, or even the new popen5 command. cheers -- Stewart Midwinter Calgary, Alberta stewart 'at' midwinter 'dot' ca Quoting hcohen2 : > Kirk Bailey wrote: > > > I want to set the mode of a text file to 666. How do I do it? > > > Assuming Linux/UNIX > > $ chmod 666 /* Means read write for file owner, group, > public [i.e. any user] is that what you really want? */ > > Explanation: 4 - read, 2 - write and 1 - executable, I usually make mine > 755 on this one user machine. > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > From magnus at thinkware.se Mon Mar 1 13:21:12 2004 From: magnus at thinkware.se (Magnus Lycka) Date: Mon Mar 1 15:49:29 2004 Subject: =?ISO-8859-1?B?UmU6IFtUdXRvcl0gYWNjZXNzaW5nIGRiIGRhdGEgZnJvbSBwdWxsZG93biBvbiB3ZWIgcGFnZQ==?= Message-ID: Vicki wrote: > Is it possible to create a web site which contains a dropdown that > searches a database based on what is selected from the dropdown? I have > tried this in PHP and it doesn't seem possible (according to what "the > experts" say). Here is what I want to do: > > I have a mysql database containing some information. I want to go to a > web page (written in Python), select a name from the dropdown, and > execute a SQL query based on the name selected. It sounds very simple to > me, but I haven't done a lot of web work. This is a completely normal thing to do. I'm not exactly sure what you mean by "a web page (written in Python)", since web pages are typically written in HTML or XHTML. How you create the web page containing the form with the dropdown doesn't matter. It can be created from a Python program, or written in notepad. The relevant thing is the (presumably) Python code that receives the call from the HTML form where the dropdown resides. This can be a simple CGI script, or developed in something more elaborate such as Zope or CherryPy. See http://www.python.org/cgi-bin/moinmoin/WebProgramming for plenty of choices. The typical thing is that the CGI script (or whatever) is called through the action connected to the SUBMIT button on the form, but you can also use JavaScript to make it call your script as soon as you select a row in the dropdown. If you want something PHP-like, with Python embedded in the HMTL, there are several options available, such as PSP. But you still need to handle the database call in a script outside the page. Any code embedded in the web page, be it PHP or PSP is executed on the server side before the web page is sent to the browser. If you want code actually running on the client side accessing your database, I guess need to do it in Java (or Jython). If you are in control of the web server, you could for instance try CherryPy, which I think is fairly neat. If you are not in control of the server, it's more tricky... But here is a pure Python solution based on my hack http://www.thinkware.se/cgi-bin/thinki.cgi/PyNetworkCheck It uses adodbapi, but I'm sure you can swap in the MySql module instead, and you need to change the content of global variable "tables". Run the script, feed it a database connect string, wait for it to display that it's serving HTTP, and surf to http://localhost:8000/ import BaseHTTPServer from StringIO import StringIO import shutil import adodbapi html = """Hello!

Hello!

%s
""" tables = ['TABLE1','TABLE2'] dsn = raw_input('DSN? ') def get_data(table): cn = adodbapi.connect(dsn) cr = cn.cursor() cr.execute('SELECT * FROM %s' % table) rows = cr.fetchall() return "\n".join(["|".join([" %s " % col for col in row]) for row in rows]).encode('latin-1') class MyHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): """Serve a GET request.""" f = self.send_head() if f: f = StringIO() options = "\n".join(["" % x for x in tables]) table = self.path.split('=')[-1] if table in tables: data = get_data(table) else: data = 'Please select a table' f.write(html % (options, data)) f.seek(0) self.copyfile(f, self.wfile) f.close() return f def do_HEAD(self): """Serve a HEAD request.""" f = self.send_head() if f: f.close() def send_head(self): path = self.path self.send_response(200) self.send_header("Content-type", 'text/plain') self.end_headers() f = StringIO() f.write("A test %s\n" % path) f.seek(0) return f def copyfile(self, source, outputfile): shutil.copyfileobj(source, outputfile) def main(HandlerClass = MyHTTPRequestHandler, ServerClass = BaseHTTPServer.HTTPServer): BaseHTTPServer.test(HandlerClass, ServerClass) if __name__ == '__main__': main() -- Magnus Lycka, Thinkware AB Alvans vag 99, SE-907 50 UMEA, SWEDEN phone: int+46 70 582 80 65, fax: int+46 70 612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From pete at freesome.com Mon Mar 1 17:31:33 2004 From: pete at freesome.com (PetesK) Date: Mon Mar 1 18:26:56 2004 Subject: [Tutor] Regular Expresions Message-ID: <4043B9C5.805@freesome.com> 1st post... hi! :-) I am trying to rip the href's from html documents, I've found a regular expression to do this, but it's for .net, and seems to use a slightly different format from python. The RegEx is in two parts the first part was href\s*=\s*\"(?[^\"]*)\" Ive found that Python needs a 'P' before the label, i.e, href\s*=\s*\"(?P[^\"]*)\" However the full regEx is, href\s*=\s*(?:(?:\"(?[^\"]*)\")|(?[^\s*] )) Which uses a 'non-capturing group' to combine the two regEx cases (in this case quotes or no quotes). I would be very grateful if someone could point me in the right direction on how to achieve the same effect in Python, as its complaining about the groups being defined twice rather than merging them into one 'url' group... Thanks From orbitz at ezabel.com Mon Mar 1 18:31:15 2004 From: orbitz at ezabel.com (orbitz@ezabel.com) Date: Mon Mar 1 18:31:33 2004 Subject: [Tutor] set the mode of a file In-Reply-To: <1078171107.404395e390962@midtoad.homelinux.org> References: <4042CC1F.5080203@netzero.net> <40434E75.9030801@comcast.net> <1078171107.404395e390962@midtoad.homelinux.org> Message-ID: <20040301183115.5683cedf.orbitz@ezabel.com> Why not just use os.chmod? On Mon, 01 Mar 2004 12:58:27 -0700 Stewart Midwinter wrote: > If you were wanting to do it from within your Python program, you could use > the os.system() command. If you want to check if the mode change was > successful, you could monitor the return code from that command, by using > os.popen2 or popen4, or even the new popen5 command. > > cheers > > -- > Stewart Midwinter > Calgary, Alberta > stewart 'at' midwinter 'dot' ca > > > Quoting hcohen2 : > > > Kirk Bailey wrote: > > > > > I want to set the mode of a text file to 666. How do I do it? > > > > > Assuming Linux/UNIX > > > > $ chmod 666 /* Means read write for file owner, group, > > public [i.e. any user] is that what you really want? */ > > > > Explanation: 4 - read, 2 - write and 1 - executable, I usually make mine > > 755 on this one user machine. > > > > > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor From stewart at midtoad.homelinux.org Mon Mar 1 18:50:43 2004 From: stewart at midtoad.homelinux.org (Stewart Midwinter) Date: Mon Mar 1 18:38:58 2004 Subject: [Tutor] set the mode of a file In-Reply-To: <20040301183115.5683cedf.orbitz@ezabel.com> References: <4042CC1F.5080203@netzero.net> <40434E75.9030801@comcast.net> <1078171107.404395e390962@midtoad.homelinux.org> <20040301183115.5683cedf.orbitz@ezabel.com> Message-ID: <1078185043.4043cc530f311@midtoad.homelinux.org> Even better, and more to the point! Quoting orbitz@ezabel.com: > Why not just use os.chmod? From sigurd at 12move.de Mon Mar 1 21:03:54 2004 From: sigurd at 12move.de (=?iso-8859-1?q?Karl_Pfl=E4sterer?=) Date: Mon Mar 1 21:08:09 2004 Subject: [Tutor] Regular Expresions In-Reply-To: <4043B9C5.805@freesome.com> (PetesK's message of "Mon, 01 Mar 2004 22:31:33 +0000") References: <4043B9C5.805@freesome.com> Message-ID: On 1 Mar 2004, PetesK <- pete@freesome.com wrote: > I am trying to rip the href's from html documents, I've found a > regular expression to do this, but it's for .net, and seems to use a > slightly different format from python. I won't go further here but your regepx won't find all hrefs in a document (e.g. href could be written as HREF (HTML 3.2) or some one used single quotes (unlikely but it may happen)). Consider using HTMlParser to extract elements. If you need help with it post here. But now to your regexp. [...] > Ive found that Python needs a 'P' before the label, i.e, > href\s*=\s*\"(?P[^\"]*)\" Right. > However the full regEx is, > href\s*=\s*(?:(?:\"(?[^\"]*)\")|(?[^\s*] )) > Which uses a 'non-capturing group' to combine the two regEx cases (in IMO there is one group too much. > this case quotes or no quotes). I would be very grateful if someone > could point me in the right direction on how to achieve the same > effect in Python, as its complaining about the groups being defined > twice rather than merging them into one 'url' group... If you wanted it to write like that you *have* to use two different names for the groups (which makes sense since if you wanted to use numbers for the groups you would write \1 and for the first respective \2 for the second group also you know that only one of them can match. The module reference is very clear about that: ,------------------------------------------------------------------------. | ``(?P...)'' | | Similar to regular parentheses, but the substring matched by the | | group is accessible via the symbolic group name NAME. Group names | | must be valid Python identifiers, and each group name must be | | defined only once within a regular expression. A symbolic group | | is also a numbered group, just as if the group were not named. So | | the group named 'id' in the example above can also be referenced | | as the numbered group 1. | | | `------------------------------------------------------------------------? So you could write your regexp as: reg = re.compile(r'href\s*=\s*(?P"[^"]*"|\S*(?:\s|$))') Now you need only one named group (and it's written a bit more nicely and a bit more robust than your solution). But: as I said above; that regexp won't find all hrefs; so either think about a more robust solution or use the parser module. Karl -- Please do *not* send copies of replies to me. I read the list From guillermo.fernandez at epfl.ch Tue Mar 2 07:15:36 2004 From: guillermo.fernandez at epfl.ch (Guillermo Fernandez Castellanos) Date: Tue Mar 2 07:15:43 2004 Subject: [Tutor] unittest problem Message-ID: <40447AE8.6000304@epfl.ch> hi, I think the mail did not arrive to the mailing list, so I send it again .Sorry if I send it twice... I'm doing a little test of unittest module. I'm having some problems making it run. I guess is more a problem of OO design that unittest problem though... ? have a test.py program with the following code: import os import unittest import begohandler import test_begohandler =>import test_statemachine import test_syslogparse class Base(unittest.TestCase): def setUp(self): if os.path.isfile('test.db'): begohandler.do_opendb('test.db') else: print 'No database to open! Create it first' sys.exit(1) def tearDown(self): begohandler.do_closedb() pass if __name__ == '__main__': runner=unittest.TextTestRunner() runner.run(unittest.makeSuite(test_syslogparse.syslogparseTest,'test')) runner.run(unittest.makeSuite(test_begohandler.begohandlerTest,'test')) => runner.run(unittest.makeSuite(test_statemachine.statemachineTest,'test')) When launching my program with the => lines commented, no problem. When no lines are commented, I obtain the following error: $ python test.py Traceback (most recent call last): File "test.py", line 5, in ? import test_begohandler File "/home/cfernand/bego/code/lib/test_begohandler.py", line 4, in ? import test File "/home/cfernand/bego/code/lib/test.py", line 6, in ? import test_statemachine File "/home/cfernand/bego/code/lib/test_statemachine.py", line 6, in ? class statemachineTest(test.Base): AttributeError: 'module' object has no attribute 'Base' I have veryfied again and again the error, but I'm unable to find what it is. I've also looked possible differences between test_begohandler.py and test_statemachine.py that could lead to an error, but I haven't finded any difference between both. Thanks a lot for any hint that could help me solve this problem. Enclosed are the other test_* files. Guille ________________________________________________________ test_statemachine.py: import unittest import statemachine import test class statemachineTest(test.Base): def testget_macsessions(self): statemachine.get_macsessions(['%']) def testget_apsessions(self): statemachine.get_apsessions(['%']) def testget_roamsessions(self): statemachine.get_roamsessions(['%']) def testget_macroamstats(self): statemachine.get_macroamstats(['%']) def testget_aproamstats(self): statemachine.get_aproamstats(['%']) def testget_maxmacapday(self): statemachine.get_maxmacapday(['%']) def testget_maxmacap(self): statemachine.get_maxmacap(['%']) if __name__ == '__main__': unittest.main() ________________________________________________________ test_begohandler.py: import unittest import begohandler import test class begohandlerTest(test.Base): def testget_apmaclist(self): begohandler.get_apmaclist(['%']) def testget_macaplist(self): begohandler.get_macaplist(['%']) def testget_aphistory(self): begohandler.get_aphistory(['%']) def testget_machistory(self): begohandler.get_machistory(['%']) def testget_macs(self): begohandler.get_macs() def testget_apnames(self): begohandler.get_apnames() def testget_msgstats(self): begohandler.get_msgstats() def testget_macmsgstats(self): begohandler.get_macmsgstats(['%']) def testget_apmsgstats(self): begohandler.get_apmsgstats(['%']) def testget_macsday(self): begohandler.get_macsday() def testget_daysmac(self): begohandler.get_daysmac() def testget_daysmacstat(self): begohandler.get_daysmacstat() def testget_apmacday(self): begohandler.get_apmacday() def testget_apdaymacs(self): begohandler.get_apdaymacs() if __name__ == '__main__': unittest.main() ________________________________________________________ test_syslogparse.py: import os import sys import unittest import syslogparse class syslogparseTest(unittest.TestCase): # first and second added to names in order to force to execute # first the parsefiledb and then the appendfiledb def testfirstdo_parsefiledb(self): try: os.remove('test.db') print 'test.db removed' except: pass if not os.path.isfile('./test.txt') or not os.path.isfile('./testappend.txt'): print 'guille' sys.exit(0) syslogparse.run('test.txt','test.db') def testseconddo_appendfiledb(self): syslogparse.run('testappend.txt','test.db',True) if __name__ == '__main__': unittest.main() ________________________________________________________ From elh at outreachnetworks.com Tue Mar 2 11:30:43 2004 From: elh at outreachnetworks.com (Eric L. Howard) Date: Tue Mar 2 11:30:52 2004 Subject: [Tutor] did I lose the value of record? Message-ID: <20040302163031.GD1754@outreachnetworks.com> I have a file that contains two columns delimited by ":". I can open the file for reading, re.search through the lines for a particular record and string.split the record into two parts which are assigned to two different variables. It's the third assignment that's causing the script to fall over on it's face [the pwd.getpwnam] In the interpreter - this works: >>> >>> record = "elhtest:elh" >>> userhome = pwd.getpwnam(string.split(record, ":")[1])[5] >>> print userhome /home/elh However - this doesn't appear to work: #!/usr/bin/env python import re, string, pwd listingsfile = open("listings","r") for record in listingsfile.readlines(): if re.search("elhtest", record): listing = string.split(record, ":")[0] owner = string.split(record, ":")[1] ownerhome = pwd.getpwnam(string.split(record, ":")[1])[5] print "The listing we're found is %s" % listing print "The owner for this listing is %s" % owner print "The owner's home dir is %s" % ownerhome listingsfile.close() I get the following: Traceback (most recent call last): File "./sa_setup.py", line 10, in ? ownerhome = pwd.getpwnam(string.split(record, ":")[1])[5] KeyError: 'getpwnam(): name not found' TIA... ~elh -- Eric L. Howard e l h @ o u t r e a c h n e t w o r k s . c o m ------------------------------------------------------------------------ www.OutreachNetworks.com 313.297.9900 ------------------------------------------------------------------------ JabberID: elh@jabber.org Advocate of the Theocratic Rule From sigurd at 12move.de Tue Mar 2 11:41:44 2004 From: sigurd at 12move.de (=?iso-8859-1?q?Karl_Pfl=E4sterer?=) Date: Tue Mar 2 11:47:18 2004 Subject: [Tutor] Regular Expresions In-Reply-To: (Karl =?iso-8859-1?q?Pfl=E4sterer's?= message of "Tue, 02 Mar 2004 03:03:54 +0100") References: <4043B9C5.805@freesome.com> Message-ID: On 2 Mar 2004, Karl Pfl?sterer <- sigurd@12move.de wrote: [...] > So you could write your regexp as: > reg = re.compile(r'href\s*=\s*(?P"[^"]*"|\S*(?:\s|$))') I made a mistake here. reg = re.compile(r'href\s*=\s*"?(?P[^"\s]*)', re.I) should be better. Reading the whole file with file(filename).readlines(), join() the result and test the result with findall() is probably the fastest solution (unless you have realy big files or scarce memory). Like that you might find string as href which weren't written as one; e.g. if someone wrote:

An href is written like href="foo"

you would find that also. For that a parser is better. The disadvantage of a parser might be that it doesn't play well with invalid documents. As I found that interesting I played a bit and wrote a solution which is a bit safer than a plain regexp albeit it is no real parser; so it might also find hrefs which are no real ones (but very unlikely since that could only happen in