Re: How do I pass a variable to os.popen?
On Mon, 31 Oct 2011 13:16:25 -0700, extraspecialbitter wrote: cmd = 'ethtool %interface' Do you perhaps mean: cmd = 'ethtool %s' % (interface, ) -- http://mail.python.org/mailman/listinfo/python-list
Re: mystery string code - help!
As a newbie Pythoner, I understand [] -1] but would some tell me how '::' does its magic? Uncle Ben The -1 is the stride or step argument. It's described at http://docs.python.org/release/2.3.5/whatsnew/section-slices.html Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: list from FTP server to a text file
On Thu, 06 Jan 2011 10:51:42 -0500, Ahmed, Shakir wrote: Hi, I am trying to create a list in a txt file from an ftp server. The following code is retrieving the list of the files but could not able to write in a text file. Any help is highly appreciated. Thanks import os import time from ftplib import FTP ftp = FTP(*.org,,) # connect to host, default port ftp.login() ftp.cwd(/pub/remotefolder/) ftp.retrlines('NLST') ** WARNING: I am a newbie! Expect more pythonic ways to do this in other replies from ftplib import FTP ftp = FTP(host, user, pass) ftp.cwd(/pub/myfolder) files = ftp.nlst(.) f = open('files.txt', 'w') for file in files: f.write('%s\n' % (file,)) f.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: find in smartpdf files
On Thu, 06 Jan 2011 08:11:34 -0800, Wanderer wrote: We generate PCB assembly files in pdf format using SmartPDF. This allows us to search for a component in the assembly using the find feature. We would like to be able to generate a list of components sorted by part type and then use that list to cycle through a search by ref designator in the pdf file. Is there a way to use Python scripts to interface PDF files? Thanks Would PDFMiner help with your task? http://www.unixuser.org/~euske/python/pdfminer/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to decide between PHP and Python
On Tue, 04 Jan 2011 12:20:42 -0800, Google Poster wrote: About once a year, I have to learn yet another programming language. Given all the recommendations (an outstanding accolade from Bruce Eckel, author of Thinking in Java) I have set my aim to Python. Sounds kinda cool. The indentation-as-block is unique, but that is how I always indent, anyway. Can any of you nice folks post a snippet of how to perform a listing of the current directory and save it in a string? Something like this: $ setenv FILES = `ls` Bonus: Let's say that I want to convert the names of the files to lowercase? As 'tolower()' TIA, -Ramon 1) import os files = ' '.join(os.listdir('/home/dan')) 2) import os import string files = string.lower(' '.join(os.listdir('/home/dan'))) As to choice between Python and PHP, I would say learn anything but PHP. Even Perl has fewer tentacles than PHP. -- http://mail.python.org/mailman/listinfo/python-list
Re: Trying to decide between PHP and Python
On Tue, 04 Jan 2011 12:32:28 -0800, Google Poster wrote: Not to mention that it took me 9 minutes to get a reply from you... Quite speedy community support. That is a very important parameter in my technology decisions these days. Thanks! -Ramon This Usenet group is a truly awesome resource. I'm a Python newbie myself, and the times I've posted here looking for direction I have been very pleased with the results. Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: Hosting a Python based TCP server
On Thu, 23 Dec 2010 04:01:03 -0800, Oltmans wrote: Hi all, I'm writing a very small TCP server(written in Python) and now I want to host it on some ISP so that it can be accessed anywhere from the Internet. I've never done that before so I thought I should ask for some advice. Do you guys know any good ISP that can let me do that? Most importantly, what is usually involved in order to make this happen? Please pardon my ignorance and I will really appreciate your reply. Thanks in advance. Amazon Web Services is offering micro-instances (essentially a small virtual server) free for one year. Since you would have root access to the instance, you can run anything you want that doesn't violate Amazon's terms of service. Send me an e-mail directly (catdude at gmail dot com) if you have questions about it. Dan -- http://mail.python.org/mailman/listinfo/python-list
Newbie needs regex help
I'm getting bogged down with backslash escaping. I have some text files containing characters with the 8th bit set. These characters are encoded one of two ways: either =hh or \xhh, where h represents a hex digit, and \x is a literal backslash followed by a lower-case x. Catching the first case with a regex is simple. But when I try to write a regex to catch the second case, I mess up the escaping. I took at look at http://docs.python.org/howto/regex.html, especially the section titled The Backslash Plague. I started out trying : d...@dan:~/personal/usenet$ python Python 2.7 (r27:82500, Nov 15 2010, 12:10:23) [GCC 4.3.2] on linux2 Type help, copyright, credits or license for more information. import re r = re.compile('x([0-9a-fA-F]{2})') a = This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 characters \xefn \xeft. m = r.search(a) m No match. I then followed the advice of the above-mentioned document, and expressed the regex as a raw string: r = re.compile(r'\\x([0-9a-fA-F]{2})') r.search(a) Still no match. I'm obviously missing something. I spent a fair bit of time playing with this over the weekend, and I got nowhere. Now it's time to ask for help. What am I doing wrong here? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie needs regex help
On Mon, 06 Dec 2010 10:29:41 -0500, Mel wrote: What you're missing is that string `a` doesn't actually contain four- character sequences like '\', 'x', 'a', 'a' . It contains single characters that you encode in string literals as '\xaa' and so on. You might do better with p1 = r'([\x80-\xff])' r1 = re.compile (p1) m = r1.search (a) I get at least an _sre.SRE_Match object at 0xb749a6e0 when I try this. Mel. That's what I had initially assumed was the case, but looking at the data files with a hex editor showed me that I do indeed have four-character sequences. That's what makes this such as interesting task! -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie needs regex help
On Mon, 06 Dec 2010 16:34:56 +0100, Alain Ketterlin wrote: Dan M d...@catfolks.net writes: I took at look at http://docs.python.org/howto/regex.html, especially the section titled The Backslash Plague. I started out trying : import re r = re.compile('x([0-9a-fA-F]{2})') a = This \xef file \xef has \x20 a bunch \xa0 of \xb0 crap \xc0 The backslash trickery applies to string literals also, not only regexps. Your string does not have the value you think it has. Double each backslash (or make your string raw) and you'll get what you expect. -- Alain. D'oh! I hadn't thought of that. If I read my data file in from disk, use the raw string version of the regex, and do the search that way I do indeed get the results I'm looking for. Thanks for pointing that out. I guess I need to think a little deeper into what I'm doing when I escape stuff. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie needs regex help
On Mon, 06 Dec 2010 09:44:39 -0600, Dan M wrote: That's what I had initially assumed was the case, but looking at the data files with a hex editor showed me that I do indeed have four-character sequences. That's what makes this such as interesting task! Sorry, I misunderstood the first time I read your reply. You're right, the string I showed did indeed contain single-byte characters, not four-character sequences. The data file I work with, though, does contain four-character sequences. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie needs regex help
On Mon, 06 Dec 2010 18:12:33 +0100, Peter Otten wrote: By the way: print quopri.decodestring(=E4=F6=FC).decode(iso-8859-1) äöü print r\xe4\xf6\xfc.decode(string-escape).decode(iso-8859-1) äöü Ah - better than a regex. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: [Q] get device major/minor number
On Tue, 30 Nov 2010 21:09:14 +0100, Thomas Portmann wrote: Hello all, In a script I would like to extract all device infos from block or character device. The stat function gives me most of the infos (mode, timestamp, user and group id, ...), however I did not find how to get the devices major and minor numbers. Of course I could do it by calling an external program, but is it possible to stay within python? In the example below, I would like to get the major (8) and minor (0, 1, 2) numbers of /dev/sda{,1,2}. How can I get them? I think the os.major() and os.minor() calls ought to do what you want. import os s = os.stat('/dev/sda1') os.major(s.st_rdev) 8 os.minor(s.st_rdev) 1 d...@dan:~$ ls -l /dev/sda1 brw-rw 1 root disk 8, 1 2010-11-18 05:41 /dev/sda1 -- http://mail.python.org/mailman/listinfo/python-list
Re: [Q] get device major/minor number
On Tue, 30 Nov 2010 21:35:43 +0100, Thomas Portmann wrote: Thank you very much Dan, this is exactly what I was looking for. Tom You're very welcome. -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLite3 and lastrowid
On Tue, 16 Nov 2010 13:08:15 -0800, fuglyducky wrote: On Nov 16, 12:54 pm, Ian ian.g.ke...@gmail.com wrote: On Nov 16, 1:00 pm, fuglyducky fuglydu...@gmail.com wrote: Before I added the second table I could simply run 'print(cursor.lastrowid)' and it would give me the id number. However, with two tables I am unable to do this. It would help if you would show the code where you're trying to do this. Without your actual code to look at, we can't tell you why it doesn't work. Does anyone know if there is a way to reference one table or another to get lastrowid? cursor.lastrowid is always in reference to the last query executed by the cursor, not in reference to a table. If you don't capture the value, and then you execute another query on the same cursor, the previous value of cursor.lastrowid no longer exists. If you need it now, then either you should have captured it when you had the chance, or you should not have executed another query on the same cursor. But perhaps this is not what you're actually trying to do. I can't tell, because I haven't seen the code. Cheers, Ian Thanks for the input. Sorry...I should have included the code...it's just a simple query... # import sqlite3 import random db_connect = sqlite3.connect('test.db') cursor = db_connect.cursor() print(cursor.lastrowid) # Choose random index from DB - need to understand lastrowid #row_count = cursor.lastrowid #random_row = random.randrange(0, row_count) cursor.execute(SELECT * FROM table1 WHERE id = 2002) print(cursor.fetchmany()) Perhaps insert here: cursor.execute(SELECT count() from table2) table2lastRow = cursor.lastrowid() #for row in cursor: # print(row) db_connect.commit() cursor.close() # -- http://mail.python.org/mailman/listinfo/python-list
Re: What people are using to access this mailing list
On Wed, 03 Nov 2010 08:02:29 +, John Bond wrote: Hope this isn't too O/T - I was just wondering how people read/send to this mailing list, eg. normal email client, gmane, some other software or online service? My normal inbox is getting unmanageable, and I think I need to find a new way of following this and other lists. Thanks for any suggestions. Cheers, JB. Pan newsreader -- http://mail.python.org/mailman/listinfo/python-list
Re: python script to read google spreadsheet
On Mon, 01 Nov 2010 01:14:09 -0700, charu gangal wrote: This is the page i am getting on localhost 8080. The code is showing me thr result only in Eclipse but not through google app engine launcher. Traceback (most recent call last): File C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py, line 3211, in _HandleRequest self._Dispatch(dispatcher, self.rfile, outfile, env_dict) File C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py, line 3154, in _Dispatch base_env_dict=env_dict) File C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py, line 527, in Dispatch base_env_dict=base_env_dict) File C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py, line 2404, in Dispatch self._module_dict) File C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py, line 2314, in ExecuteCGI reset_modules = exec_script(handler_path, cgi_path, hook) File C:\Program Files (x86)\Google\google_appengine\google\appengine \tools\dev_appserver.py, line 2210, in ExecuteOrImportScript exec module_code in script_module.__dict__ File C:\Users\Admin\Pythonworkspace\pythonsample12\src \engineapp202\main.py, line 4, in module import gdata.spreadsheet.service ImportError: No module named gdata.spreadsheet.service I'm something of a Python newbie, but could Eclipse be modifying your PYTHONPATH by adding the directory in which gdata.spreadsheet.service is installed? -- http://mail.python.org/mailman/listinfo/python-list
Newbie question - parsing MIME(?) strings
I'm working on a script that grabs messages from a Usenet server and does some work with them. All works nicely except for a few issues with the data I retrieve. For example, in one newsgroup I find occasional lines containing bits like: Re: Mlle. =?ISO-8859-1?Q?Ana=EFs_introdooses_her_ownself=2E?= Is this some sort of bizarre MIME encoding? Looking at the data I can see how what the =EF and =2E mean, but that stuff after the first = has me confused. And more to the point, is there a python module to handle this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question - parsing MIME(?) strings
On Thu, 28 Oct 2010 15:05:56 -0500, Dan M wrote: Ok, I didn't research enough before I posted this. I see now that this *is* indeed a MIME message, and the '?Q' bit says that the next piece is quoted-printable, and that the encoding is defined in RFC2047. So the question the becomes, do we have a library for reading info like this? -- http://mail.python.org/mailman/listinfo/python-list
[issue1362] Simple mistake in http://docs.python.org/tut/node6.html
Dan M added the comment: Yes, it is normally suppressed. The problem is the condition when it is suppressed. The documentation states that it's suppressed when it's the only value to be written. It is suppressed when it's *not* the only value to be written. -or- (removing the double negative of suppressed(not displayed) and not) It is displayed when it would be the only value written. The example immediately following this mistake is correct, which makes the actual behavior obvious even if this particular statement is wrong. __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1362 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1362] Simple mistake in http://docs.python.org/tut/node6.html
New submission from Dan M: In section 4.6 it says: Writing the value None is normally suppressed by the interpreter if it would be the only value written. When it should say: Writing the value None is normally displayed by the interpreter if it would be the only value written. Or less wordy: The value None is (normally) displayed by the interpreter when it would be the only value written. -- components: Documentation messages: 56948 nosy: dmazz severity: minor status: open title: Simple mistake in http://docs.python.org/tut/node6.html __ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1362 __ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
os.link makes a copy, not a link
I'm a little bit confused. According to the sources I've looked at on the net, os.link('file1', 'file2') should make a hard link from file1 to file2. But what I'm finding is that it's actually making a copy. Am I forgetting a step or something? Python 2.3.4 running on CentOS 4.3 -- http://mail.python.org/mailman/listinfo/python-list
Re: TSV to HTML
1) in the code define a css 2) use a regex to extract the info between tabs In place of this, you might want to look at http://effbot.org/librarybook/csv.htm Around the middle of that page you'll see how to use a delimiter other than a comma 3) wrap the values in the appropriate tags and insert into table. 4) write the .html file Thanks again for your patience, Brian -- http://mail.python.org/mailman/listinfo/python-list
Re: I'm just not cut out for web programming, I guess :)
On Wed, 17 May 2006 20:51:07 +, John Salerno wrote: Ok, I've tinkered with this thing for a while, and I keep fixing little problems, but I always get a 500 Internal Server error when I go to this site: I don't necessarily even want help just yet, I'd like to figure it out myself, but can someone at least tell me why I'm not getting helpful feedback from the cgitb module? Am I using it wrong? The webpage just displays the internal server error. Thanks. Having to debug web scripts on hosts where you don't have shell access can be a major pain. If you are referring to the wrong path in the bang-path line, you'd get that error non-message. Likewise if the file permissions were wrong. -- http://mail.python.org/mailman/listinfo/python-list
Re: script to read emails and extract attachments from cron
On Mon, 06 Feb 2006 10:57:23 -0800, [EMAIL PROTECTED] wrote: Hi: I am looking for advice on the best way to set up a process to read incoming emails (from a normal unix mailbox on the same host) containing a gzipped telemetry attachment. I'd like the script to extract the attachment into a directory where another process will pick it up. I plan to run it every minute out of cron, so it would probably start by moving the mbox file to another name so that incoming emails and later instances of itself won't be affected. You might want to take a look at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/86675 and http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/86676 I'm using those two recipes for a project very similar to what you described. Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: Code Feedback
2) Anybody know how to alter the while 1: pass section to make the app stoppable? That one I think I can help with! See below. while 1: pass try: while 1: pass except KeyboardInterrupt: break -- http://mail.python.org/mailman/listinfo/python-list
Re: Redirecting stdin/stdout to self
And if I'm reading it correctly, the Perl script's process starts tcpdump, but redirects its output to its own input, and reads it line by line. And to clarify, what the Perl script is doing is redirecting the standard error to standard out. STDIN is file handle 0, STDOUT is file handle 1, and STDERR is file handle 2. -- http://mail.python.org/mailman/listinfo/python-list
Re: copying a file from windows file system to ext2 and ext3
On Tue, 10 Jan 2006 15:59:01 -0800, muttu2244 wrote: hi all could anybody please tell me how can i copy a file from windows file systems like FAT12, FAT16,FAT32 and NTFS to EXT2, and EXT3. Is their any function in python that we can do the above Thanks in advance Yogi I'm sure more experienced hands will add comments here, but I believe that's strictly dependent upon having the correct filesystem drivers available on the system in question. Once you've mounted a Windows-type file system on Linux you can manipulate the files that live there just as if they were created on a real OS :) Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: urlretrieve() questions
Pretty straight forward...but what I'm finding is if the url is pointing to a file that is not there, the server returns a file that's a web page displaying a 404 error. Anyone have any recommendations for handling this? You're right, that is NOT documented in a way that's easy to find! What I was able to find is how to what you want using urllib2 instead of urllib. I found an old message thread that touches on the topic: http://groups.google.com/group/comp.lang.python/browse_thread/thread/3f02bee97a689927/88c7bfec87e18ba9?q=%22http+status%22+%2Burllibrnum=3#88c7bfec87e18ba9 (also accessable as http://tinyurl.com/952dw). Here's a quick summary: --- Ivan Karajas Apr 28 2004, 11:03 pm show options Newsgroups: comp.lang.python From: Ivan Karajas [EMAIL PROTECTED] - Find messages by this author Date: Wed, 28 Apr 2004 23:03:54 -0800 Local: Wed, Apr 28 2004 11:03 pm Subject: Re: 404 errors Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse On Tue, 27 Apr 2004 10:46:47 +0200, Tut wrote: Tue, 27 Apr 2004 11:00:57 +0800, Derek Fountain wrote: Some servers respond with a nicely formatted bit of HTML explaining the problem, which is fine for a human, but not for a script. Is there some flag or something definitive on the response which says this is a 404 error? Maybe catch the urllib2.HTTPError? This kind of answers the question. urllib will let you read whatever it receives, regardless of the HTTP status; you need to use urllib2 if you want to find out the status code when a request results in an error (any HTTP status beginning with a 4 or 5). This can be done like so: import urllib2 try: asock = urllib2.urlopen(http://www.foo.com/qwerty.html;) except urllib2.HTTPError, e: print e.code The value in urllib2.HTTPError.code comes from the first line of the web server's HTTP response, just before the headers begin, e.g. HTTP/1.1 200 OK, or HTTP/1.1 404 Not Found. One thing you need to be aware of is that some web sites don't behave as you would expect them to; e.g. responding with a redirection rather than a 404 error when you when you request a page that doesn't exist. In these cases you might still have to rely on some clever scripting. -- I hope that helps. Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question - deleting records from anydbm database
Now how can I go about deleting that record when it's too old? (untested) try del db[ipAddress] Yep, that did it. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: doubt on csv file
here is what am trying to do, first am trying to open it in a read mode, and checking each row by row , if it is not found till my last row, i want to append it to the last row , so how should i do that. file = open ('C:\some.csv','r') reader = csv.reader(file) for row in reader: print row How can i update at the last row. This newbie's idea is that you'd want to keep track of whether you'd found the item you are looking for. If not found, close the file, reopen it in append mode, and write the new row. For example: f = open ('C:\some.csv','r') rdr = csv.reader(file) found = 0 for row in rdr: if row[0] == 'YYY': found = 1 print row if found: print No need to do anything more else: f.close() f = open(c:\\some.csv, 'a') f.write(The new row data) f.close() I am admittedly a newbie; I'm sure more experienced users will have more efficient suggestions. Note that I did change file to f to avoid hiding the file method and changed reader to rdr for the same reason. HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: doubt on csv file
On Thu, 15 Dec 2005 16:09:51 -0800, muttu2244 wrote: hey thanks a lot for that it worked . Excellent! Glad to be of assistance :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple (?) question about print statement
On Wed, 14 Dec 2005 15:27:58 -0800, TY wrote: So I guess then my next question is why does adding comma to print statement cause buffering, but not when you don't have comma? Because of the line buffering. If you don't have a comma at the end, the print statement prints the numeric value and a newline, which signals the end of the line. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to get select label?
On Wed, 14 Dec 2005 13:56:24 -0800, lli wrote: I build web application. So I use CGI. I need to show select text in the html page. Now I can only display select value such as '001'. But I need to display its text 'AAA'. LLI I'm a Python newbie, so by all means verify this answer with more experienced folks. But what you're running into is a limitation of HTML/HTTP/CGI. When your form contains a SELECT element, the values that get passed to the CGI are the VALUE elements. If you want to get, for example, AAA then you would need to put AAA in the VALUE field. -- http://mail.python.org/mailman/listinfo/python-list
Newbie question - deleting records from anydbm database
I've been Googling like a mad fiend and flipping through my hard-copy Python books, but still haven't located the one little bit of info I need. I've put together a simple SMTP-after-IMAP script that gets the authorized IP info from the mail log (I know, it's not elegant but it works). All works fine up until I go to scan the database of added IP addresses to delete the old ones. The problem is, I don't know how to drop a record from an anydbm database! The database file in question is compatible with the database built using makemap hash imapauth imapauth - in fact, I'm using makemap to check the file contents against what I'm expecting. I'm adding records with code such as: db = anydbm.open(accessDbPath, w) db[ipAddress] = str(time.time()) Now how can I go about deleting that record when it's too old? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: executing a system command from my Python app
Few points points: 1. Generally: I would try to minimize system calls. They make your code less portable. Excellent point. In this case the app will never live anywhere other than one specific FreeBSD machine, but I do appreciate the value of the advice anyway. Therefore... 2. Look into the shutil module for recursive deletion. 3. Use os.path to construct paths. Try to avoid, for example, c:\blah\blah on dos, '/blah/blah' on unix, etc. Have done so. Thanks for pointing out the shutils module! I keep finding more and more excellent modules available. Do we have a Python equivalent to Perl's CPAN? 4. If you only have one argument, you don't need a tuple for string formatting. 5. (dateYest) is not a tuple anyway--the parentheses are superfluous 6. Single item tuples can be created with (anitem,) (notice the comma). That helps. I had somehow gotten the mistaken idea that string formatting always needed a tuple, and overlooked the trailing comma. I've applied that correction to several of my other Python scripts as well. -- http://mail.python.org/mailman/listinfo/python-list
Newbie: executing a system command from my Python app
I'm writing a Python replacement for a particularly ugly shell script. we are running mimedefang on our mail server, moving spam and virus messages to a quarantine directory. This little python script successfully chdir's to the quarantine directory, identifies all of the quarantine subdirectories for yesterday's messages, and stuffs them into a tar file in an archive directory. I then want to delete for successfully tarred files and the subdirs they live in. By way of further explanation, quarantined messages get broken into files named ENTIRE_MESSAGE, HEADERS, RECIPIENTS, SENDER, and SENDMAIL-QID, and get stored in subdirectories named qdir--MM-DD-hh.mm.ss-nnn, where Y-M-D is the date received, hms is time received, and nnn is to allow for up to 10 messages to quarantined any given second. I know I can do this by descending into the directories I've identified and unlink()ing each of the files, but I'd like to take a shortcut like: retval = os.system('rm -rf /var/spool/MD-Quarantine/qdir-%s*' % (dateYest)) and indeed code written that executes without any errors. Unfortunately it also leaves a bunch of qdir-2005-12-11-* files sitting around when I run it on 12-11. Have I overlooked some basic operation of the os.system() call? From all I've seen in the online docs and O'Reilly's Programming Python it looks like it should be working. Here's my complete script: #!/usr/local/bin/python import glob, os, tarfile, time, datetime DATE_FMT = %Y-%m-%d filelist = [] yest = datetime.date.today() + datetime.timedelta(days = -1) dateYest = yest.strftime(DATE_FMT) os.chdir(/var/spool/MD-Quarantine) try: tar = tarfile.open(/usr/local/archives/MD-Q/%s.tar.gz % (dateYest), w:gz) for file in glob.glob(qdir-%s* % (dateYest)): tar.add(file) filelist.append(file) tar.close() except TarError: print The quarantine file archiving program threw a TarError exceptionexit() cmd = rm -rf /var/spool/MD_Quarantine/qdir-%s* % (dateYest) print About to execute , cmd retval = os.system(cmd) -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie: executing a system command from my Python app
On Mon, 12 Dec 2005 13:25:14 -0800, Dan M wrote: I'm writing a Python replacement for a particularly ugly shell script. we are running mimedefang on our mail server, moving spam and virus messages to a quarantine directory. This little python script successfully chdir's to the quarantine directory, identifies all of the quarantine subdirectories for yesterday's messages, and stuffs them into a tar file in an archive directory. I then want to delete for successfully tarred files and the subdirs they live in. Never mind - the flaw was in how I was building the command to be executed by os.system. It's working fine now. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python web publishing framework like Cocoon?
Is there a Python web publishing framework like Cocoon? I found Maki http://maki.sourceforge.net/ but it was last updated in 2003 and its author says that he doesn't want to make another release... How about: http://www.cherrypy.org/ http://www.turbogears.org/ http://www.djangoproject.com/ http://karrigell.sourceforge.net/ just to name a few of my favorites. Take a look at http://wiki.python.org/moin/WebProgramming for a more complete list. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to handle two forms in cgi?
My question is: How let these two form works together? I try to use two codes for these two forms, e.g. Login.py for login form and search.py for search form. But when user input data in search form and click its submit button, it just comes back to login form. Second form doesn't work. Any help is appriciated! It sounds like the action attribute in the 2nd form's form tag is not pointing to search.py. -- http://mail.python.org/mailman/listinfo/python-list
Timeout in urllib2
I'm writing a system monitor script that needs to load web pages. I'm using urllib2.urlopen to get the pages, and I'm attempting to set the timeout value using socket.defaulttimeout. Specifically, I'm calling socket.defaultttimeout(10), then calling urllib2.urlopen to fetch a web page that never gets delivered. My code waits about 30 seconds before terminating. I am about to add threading to my app so that delays on a few servers won't be a critical issue, but I'd still like to understand why the call to socket.defaulttimeout doesn't affect the timeout on my urlopen calls. My code follows. #!/usr/local/bin/python import socket, time socket.setdefaulttimeout(10) import urllib2 def doHttpTest(): url = http://url.that.never.returns; t_start = time.time() if httptest(url): print Error on site , url t_end = time.time() t_diff = t_end - t_start def httptest(url): timeout = 10 socket.setdefaulttimeout(timeout) try: req = urllib2.Request(url) urllib2.urlopen(req) except urllib2.HTTPError, e: if e.code == 401: return 1 elif e.code == 404: return 1 elif e.code == 503: return 1 else: return 1 except urllib2.URLError, e: return 1 else: return 0 if __name__ == '__main__': try: doHttpTest() except KeyboardInterrupt: print Exiting... -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Which Version of Linux
On Sat, 05 Nov 2005 04:26:38 -0600, blahman wrote: ok, i m going to use Linux for my Python Programs, mainly because i need to see what will these fork() and exec() do. So, can anyone tell me which flavour of linux i should use, some say that Debian is more programmer friendly, or shold i use fedora, or Solaris. Because these three are the only ones i know of that are popular and free. Personally I would recommend staying away from Fedora unless you have a friend who is well-versed in it and willing to help. I like the distributin ok (I run it on the laptop I'm writing this from) but it uses RPMs for package distribution, and the rpm tools don't know how to automatically downloaded dependencies like yum or apt do. Because of that I have to say that the RPM package tools suck quite badly. Debian and SUSE are both pretty good choices. -- http://mail.python.org/mailman/listinfo/python-list
Re: query a port
On Sat, 29 Oct 2005 23:21:16 -0700, eight02645999 wrote: thanks alot! that's all there is to it..so it's just a simple connect. If all you want to do is check that the given port is open on the given host, that's it. I tried it on my local box. When connecting to port 25, it made the connection fine. Trying to connect to port 26 raised a socket.error. -- http://mail.python.org/mailman/listinfo/python-list
Building 2.4.2 on OpenBSD 3.8
I've been working with python 2.2.3 for the last couple of weeks, but would like to move up to 2.4. I grabbed the 2.4.2 tarball and attempted to install, but I get: gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE -o Modules/python.o Modules/python.c In file included from /usr/include/sys/select.h:38, from Include/pyport.h:116, from Include/Python.h:55, from Modules/python.c:3: /usr/include/sys/event.h:53: error: syntax error before u_int /usr/include/sys/event.h:55: error: syntax error before u_short *** Error code 1 Stop in /usr/local/src/Python-2.4.2. immediately upon running make. I took at look at event.h to see if I could find and fix the problem, but the error isn't immediately apparent to me. Has anyone successfully built 2.4.2 on OpenBSD? If so, how did you do it? -- http://mail.python.org/mailman/listinfo/python-list
Re: query a port
On Sat, 29 Oct 2005 20:21:20 -0700, eight02645999 wrote: hi in python, how do one query a port to see whether it's up or not? thanks I'm an absolute beginner, but let's see if I can help. Assuming you want to check a port on another machine, import socket port=25 # Port we want to test host=machine.to.test# Either IP address or FQDN s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect((host, port)) print We made the connection except socket.error: print Sorry, that port is not open s.close Does that help? Dan -- http://mail.python.org/mailman/listinfo/python-list
Python 2.3.4, Berkeley db 1.85, db file format not recognized
I'm working on a script that will interface with sendmail on my FreeBSD box. I'm trying to read my access.db file (yes, it's for a quick and dirty SMTP-after-POP application). I'm trying: import bsddb bsddb.hashopen(access.db) but I get: bsddb._db.DBInvalidArgError: (22, 'Invalid argument -- access.db: unexpected file type or format') This suggests to me that my bsddb is too new. I really don't want to rebuild sendmail with a more current db, as I'm afraid of breaking sendmail. Any suggestions on how to read this file? FWIW, file access.db returns access.db: Berkeley DB 1.85 (Hash, version 2, native byte-order) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.3.4, Berkeley db 1.85, db file format not recognized
On Wed, 26 Oct 2005 14:23:49 -0500, skip wrote: Dan import bsddb Dan bsddb.hashopen(access.db) Dan but I get: Dan bsddb._db.DBInvalidArgError: (22, 'Invalid argument -- access.db: unexpected file type or format') Dan Any suggestions on how to read this file? See if the bsddb185 module is available: It is, and it works. Thanks so much! -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing XML - Newbie help
Hi rh0dium wrote: I am relatively new to python and certainly new to XML parsing. Me too. However there are plenty of good docs/tutorials available to help with both XML and using it in Python. For XML you may wish to look at http://www.w3schools.com/. It has a very accessible set of tutorials on XML and related technologies, which I find make it very quick to get up and running. For what you are trying to do you may wish to look at XPath, or ideally XQuery although I'm not sure there is an XQuery implementation in Python. For Python and XML there is Mark Pilgrim's excellent chapter on Parsing XML with xml.dom.minidom (http://diveintopython.org/xml_processing/index.html). The is also the PyXML project at Sourceforge (http://pyxml.sourceforge.net/). A list of useful links is maintained there (http://pyxml.sourceforge.net/topics/). You may also wish to investigate resources at the Python XML SIG page (http://www.python.org/sigs/xml-sig/). These are just some of the sources of information I am using. Hope this helps. Cheers Dan -- http://mail.python.org/mailman/listinfo/python-list