Re: Dump interpreter history?

2011-03-25 Thread Daniel Mahoney
On Fri, 25 Mar 2011 17:03:55 -0400, Ken D'Ambrosio wrote:

> Hey, all.  A co-worker asked me a question, and I've got no idea how (or
> if) it can be done.  Bottom line: he'd like to save off the text from an
> interpreter session, his thinking being that you've already tried to get
> what you want, and now you just need to gussy it up in an editor.
> 
> Can this be done?
> 
> Thanks!
> 
> -Ken

import readline
readline.write_history_file([filename])

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good literature about python twisted

2011-03-15 Thread Daniel Mahoney
On Tue, 15 Mar 2011 04:34:52 -0700, gelonida wrote:

> Hi,
> 
> Just wanted to learn more about python twisted and wanted to buy the
> O'Reilly book.
> 
> However I noticed, that the book is from 2005.
> 
> 
> Is this book still worth it or is there anything better to learn about
> twisted.
> 
> I though about buying a paper book in order to be able to read in in the
> train.
> 
> If there is however a reall nice online document, then I wouldn't object
> of not buying a book at all.
> 
> 
> Thanks in advance for any suggestions

I bought and read that book a couple of years ago, and found that it 
didn't help me much. I came away with a very shaky understanding of 
Twisted's principles. I still am very shaky - I'd love to find some 
Twisted docs that will help the light bulb to go on, as Twisted seems 
like a very handy tool.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need an example program that implements rpm -pql via import rpm

2011-03-04 Thread Daniel Mahoney
On Thu, 03 Mar 2011 22:24:24 -0500, Steven W. Orr wrote:

> I look everywhere but I couldn't find anything. Could someone please
> point me to a small example program that does an import rpm, takes an
> rpm file as an argument and gets the list of files contained in the
> file, the same as if I had used the commandline
> 
> rpm -pql foo-1.23-4.i586.rpm
> 
> Much appreciated.
> 
> TIA

This is just a quick and dirty script, but how about:

import os
import rpm
import sys

ts = rpm.TransactionSet()
fd = os.open(sys.argv[1], os.O_RDONLY)
h = ts.hdrFromFdno(fd)
os.close(fd)

flist = h.fiFromHeader()
for file in flist:
print file[0]



Dan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can you recommend an Experienced Python/SQL contract developer for this 6 - 12 month contract in NYC?

2011-02-25 Thread Daniel Mahoney
> Thanks,
> 
> Ben Diamond
> The Forum Group
> Information Technologies Division
> 260 Madison Ave
> Suite 200
> NY, NY 10016
> T. 212 687 4050 x355
> 
> C. 201 313 6009
> www.forumgrp.com 


PLEASE, don't include all that Microsoft HTML crap at the end of your 
post! Good old plain text works just fine for both Usenet newsgroups and 
e-mail lists.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to gain root privileges

2011-02-16 Thread Daniel Mahoney
On Wed, 16 Feb 2011 21:26:26 +, GSO wrote:

> I'm sure this question is as old as time, but what is the best way to
> gain root privileges?  (Am using Python 2.6.5, pygtk2 v2.16, Gtk
> v2.18.9, on RHEL6.)

Gain root privileges for a script? Write a c wrapper to call the script, 
chown it (the wrapper) to root, and set it (the wrapper) suid.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Perl to Python using MqSQLdb

2008-08-12 Thread Daniel Mahoney
On Tue, 12 Aug 2008 05:51:19 -0700, Mike P wrote:

> Hi All,
> 
> I've been given a Perl script that i'm trying to convert into python.
> The aim of the script links to MqSQL database, but i'm stuck on one
> part
> 
>my $sth = $dbh->prepare($sql)||
>die "Could not prepare SQL statement ... maybe invalid?:$!\n$sql
> \n";
>$sth->execute()||
>die "Could not execute SQL statement ... maybe invalid?:$!\n$sql
> \n";
> 
>while (my @row= $sth->fetchrow_array())  {
>   my $combined = join(",", @row);
>   print "$combined\n";
>}
> 
> I don't know much MySQL or Perl..
> 
> Can anyone help to convert this for me?
> 
> Mike

You could try something like:

cursor=db.cursor()
cursor.execute(sql)
while (1):
row = cursor.fetchone()
if row == None:
break
combined = ', '.join(row)

This has NOT been tested.

More info available at http://www.kitebird.com/articles/pydbapi.html and
lots of other pages. Googling for "MySQLdb" should get you a decent list.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Determining when a file has finished copying

2008-07-09 Thread Daniel Mahoney
> Thanks for your replies, they are helpful. I should have included in
> my initial question that I don't have as much control over the program
> that writes (pgm-W) as I'd like. Otherwise, the write to a different
> filename and then rename solution would work great. There's no way to
> tell from the os.stat() methods to tell when the file is finished
> being copied? I ran some test programs, one of which continously
> copies big files from one directory to another, and another that
> continously does a glob.glob("*.pdf") on those files and looks at the
> st_atime and st_mtime parts of the return value of os.stat(filename).
> From that experiment it looks like st_atime and st_mtime equal each
> other until the file has finished being copied. Nothing in the
> documentation about st_atime or st_mtime leads me to think this is
> true, it's just my observations about the two test programs I've
> described.
> 
> Any thoughts? Thanks!
> Doug

Could you maybe us the os module to call out to lsof to see if anyone
still has the target file open? I am assuming that when the write process
finishes writing it would close the file.

Check "man lsof"


--
http://mail.python.org/mailman/listinfo/python-list


Re: I Need A Placeholder

2008-06-26 Thread Daniel Mahoney
On Thu, 26 Jun 2008 10:03:47 -0700, Ampedesign wrote:

> I'm trying to build a try/except case, and I want to have the except
> function like such:
> 
> try:
>   # Do some code here
>   var = 1 # For example
> except:
>   #Do nothing here
> 
> The only problem is if I leave a comment only in the except block, I
> get an error back saying that the except block is not properly
> formatted, since it has no content other than a comment.
> 
> So if anyone could suggest some code to put there as a placeholder
> that would be wonderful.

"pass" would work fine.

try:
 # Do something that can throw an exception
except:
 pass



--
http://mail.python.org/mailman/listinfo/python-list


Re: question relateding to parsing dbf files.

2008-06-18 Thread Daniel Mahoney
On Wed, 18 Jun 2008 18:20:20 +0530, Krishnakant Mane wrote:

> hello all.
> I need to parse some dbf files through python.
> the reason being that I have to migrate some old data from dbf files
> to postgresql.
> all that I need to know is if some one has got a working code sample
> using dbfpy.
> I found this module suitable for my work but can't figure out how to use it.
> else, if there is any other module, please recommend so.
> happy hacking.
> Krishnakant.

It's pretty simple, but there is a small example on dbfpy's Sourceforge
page (http://dbfpy.sourceforge.net/).

Also, it's really the long way around, but ActiveState's cookbook section
has a recipe for reading and writing DBF files in Python without using
dbfpy. It's at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715

--
http://mail.python.org/mailman/listinfo/python-list


Re: Handling some isolated iso-8859-1 characters

2008-06-04 Thread Daniel Mahoney
> ...   print ord(c), unicodedata.name(c)
> ...
> 65 LATIN CAPITAL LETTER A
> 110 LATIN SMALL LETTER N
> 97 LATIN SMALL LETTER A
> 239 LATIN SMALL LETTER I WITH DIAERESIS
> 115 LATIN SMALL LETTER S

Looks like I need to explore the unicodedata class. Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Handling some isolated iso-8859-1 characters

2008-06-04 Thread Daniel Mahoney
> No, it's not you, those headers are formatted following RFC 2047  
> 
> Python already has support for that format, use the email.header class,  
> see 

Excellent, that's exactly what I was looking for. Thanks!

--
http://mail.python.org/mailman/listinfo/python-list


Handling some isolated iso-8859-1 characters

2008-06-03 Thread Daniel Mahoney
I'm working on an app that's processing Usenet messages. I'm making a
connection to my NNTP feed and grabbing the headers for the groups I'm
interested in, saving the info to disk, and doing some post-processing.
I'm finding a few bizarre characters and I'm not sure how to handle them
pythonically.

One of the lines I'm finding this problem with contains:
137050  Cleo and I have an anouncement!   "Mlle. =?iso-8859-1?Q?Ana=EFs?="
<[EMAIL PROTECTED]>  Sun, 21 Nov 2004 16:21:50 -0500
<[EMAIL PROTECTED]>  447869 Xref:
sn-us rec.pets.cats.community:137050

The interesting patch is the string that reads "=?iso-8859-1?Q?Ana=EFs?=".
An HTML rendering of what this string should look would be "Anaïs".

What I'm doing now is a brute-force substitution from the version in the
file to the HTML version. That's ugly. What's a better way to translate
that string? Or is my problem that I'm grabbing the headers from the NNTP
server incorrectly?



--
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for up to date documentation for Python/Tkinter

2008-02-21 Thread Daniel Mahoney
On Thu, 21 Feb 2008 07:47:35 -0800, Kintaro wrote:

> Oh wise usenet users,
> 
> Please speak unto me the URL which contain the latest documentation on
> Python/Tkinter programming.
> 
> I have seen Fredrik Lundh's introduction to tkinter (and others) and
> it appears to be for an earlier version of Python. I am working with
> Python 2.5 and most doc I am finding are for Python 2.2 or earlier.
> 
> Many thanks

One of my favorites is http://effbot.org/tkinterbook/

-- 
http://mail.python.org/mailman/listinfo/python-list