Re: Python Love :)

2006-03-13 Thread rtilley
BWill wrote:
 and ixnay on the ubyray or else I'll tell you where to stick your 
 endblock delimiter :P

OK, I can't help it... which is more readable:

a_string.reverse(ruby)
a_string[::-1]  (python)

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


Jython

2006-03-11 Thread rtilley
Is development still going on with Jython? Version 2.1 came out in 2001 
and it's still the most current stable release.

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


Re: Python Evangelism

2006-03-09 Thread rtilley
Steve Holden wrote:
 Doug Bromley wrote:
 I can see Ruby overtaking Python if we don't ALL do something about it.

I think it's the name. Python. Let's change it to something nicer. Think 
about it... if you found a Ruby, you'd pick it up and put it in your 
pocket. If you ran across a Python, you'd run away.

Gems is nice too. Compare that to Cheese Shop... who came up with that 
:) Do you want a pretty gem stone or a smelly slice of cheese? I mean 
that in a literal sense. I don't think Python is smelly at all, but it 
certainly has chosen some slimy, smelly bad names for itself!

Psychology is important. Just as important as good design. I think this 
fact doesn't sink in to the Python community.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Evangelism

2006-03-09 Thread rtilley
Dale Strickland-Clark wrote:
 rtilley wrote:
 
 
Psychology is important. Just as important as good design. I think this
fact doesn't sink in to the Python community.
 
 
 You speak of fluff and ribbons and glitter.

Yes, I know. Great products, ideas and methods have lost mind share to 
lesser things (not that Ruby is inferior to Python or vice versa) 
because they lack fluff, ribbons and glitter :)

I hope Python gets more fluff... it already has lost of great technical 
merit :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Evangelism

2006-03-09 Thread rtilley
Andrew Gwozdziewycz wrote:
 On 3/9/06, rtilley [EMAIL PROTECTED] wrote:
 
 
Doug Bromley wrote:

I can see Ruby overtaking Python if we don't ALL do something about it.

I think it's the name. Python. Let's change it to something nicer. Think
about it... if you found a Ruby, you'd pick it up and put it in your
pocket. If you ran across a Python, you'd run away.
 
 
 Woah, are you actually serious? What would changing the name of language 
 you're
 trying to market do for the marketing campaign?

Yes I am. But I'm no one so there is no need to take my advice :)

Snakes are naturally thought of as bad or dangerous. Some large snakes 
eat our pets and other small, warm-blooded, furry mammals like us. 
People naturally kill snakes or run from them. We teach children to 
avoid snakes. It's almost instinct to fear them. So, you have a product, 
an idea, a method... don't name it after something that is so naturally 
repulsive. It's really that simple.

I've had people ask about the Python folder on their computer. They 
thought it must be a virus or malware simply based on its name.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Evangelism

2006-03-09 Thread rtilley
Andrew Gwozdziewycz wrote:
 What would changing the name of language you're
 trying to market do for the marketing campaign? 

I forgot to address this part... I think it would create a lot of hype. 
What well-established programming language has ever had the nerve to 
change its name after more than a decade of success? Think of the 
attention that alone would bring :) python would get slashdotted to 
death! CNN would probably write about it... maybe the BBC too.

Python could have a huge name changing contest/campaign and maybe some 
killer app could be released just as the name had changed. Guido could 
make some statement about dropping the cold-bloodedness of Python, 
becoming more warm and inviting, etc. etc.

It would be a smashing success.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Evangelism

2006-03-09 Thread rtilley
Paul Boddie wrote:
 I agree with you here, though. I want to be diplomatic here, but Cheese
 Shop - a name for a package repository, for those who are lost already
 - is really just a totally stupid name. Yes, I'm aware of the Monty
 Python sketch, mediocre by the high standards of the Pythons' various
 other works, but people really shouldn't have to buy into some kind of
 clique to decode terminology in order to get help, support, updates,
 and to learn more about the technology they're using. Some people
 haven't even seen Monty Python...

Even more reason to change the name.

Use a name that has lots of other widely known, well thought of names 
associated with it. The Ruby name is a very good example of this. 
Although, this was accidental and not planned.

People associate the words precious, valued, gem, treasured, stone 
solid, etc. with the word ruby. Also, a good product with a good name 
makes it easy for others to add value by building other good names 
around it.

What do you think of when you hear 'eggs'? Many people think 'rotten', 
'smelly' or something that made them throw-up once. The point of this is 
that names _matter_ and influence what others think even if only in a 
subconscious way.

I'll leave it at that. I like Python a lot. Technically, it's awesome. I 
don't think the language is bad... just the names associated with it.

Just my 2 cents.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Send email notification

2006-03-07 Thread rtilley
Ernesto wrote:
 Is there a special module for mail ?
 
 I'd like to send an email [to 'n' unique email addresses] from a python
 script.  

from email.MIMEText import MIMEText
import email.Utils
import smtplib

# 'users' is a list of email addys.
 for u in users:
try:
print Sending email to ... , u
f = FROM_NAME[EMAIL PROTECTED]
t = u

msg = MIMEText(MESSAGE BODY OF EMAIL)

msg[Subject] = MESSAGE SUBJECT
msg[Message-id] = email.Utils.make_msgid()
msg[From] = f
msg[To] = t

h = YOUR.SMTP.SERVER
s = smtplib.SMTP(h)
s.sendmail(f, t, msg.as_string())
s.quit()
except Exception, e:
 print e
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Learning different languages

2006-03-07 Thread rtilley
Rich wrote:
 Anyway, my question is: what experience you people have with working
 with different languages at the same time?

IMO, it's a good idea.

Currently, I'm using Python and Ruby. I'll write something in one and 
then try it in the other. I know Python better than Ruby, so it's a 
learning experience for me. I think it helps me to see things from a 
different perspective. I admire both languages and respect their 
different approaches to problem solving.

Knowing how to use a couple of different tools will benefit you and 
those around you.

Best of Luck!
Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: white space in expressions and argument lists

2006-03-02 Thread rtilley
John Salerno wrote:
 A minor concern, but I'm curious if there is any kind of best practice 
 for using whitespace within expressions and argument lists in the Python 
 world. For example:
 
 1 + 2  or   1+2

IMO, good style calls for spaces. Most companies have style guides for 
programmers to follow. Read this PEP:

http://www.python.org/peps/pep-0008.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: white space in expressions and argument lists

2006-03-02 Thread rtilley
Fredrik Lundh wrote:
 in his april 1st, 2005 paper ?
 
 http://www.artima.com/weblogs/viewpost.jsp?thread=101968

That was an April's Fools joke, right? I like it though :)
Maybe it'll happen!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: white space in expressions and argument lists

2006-03-02 Thread rtilley
John Salerno wrote:
 All of it was a joke?

You'd have to ask Guido that :)

I took it literally when I first read it b/c it made sense to me and I 
did not notice the date. I don't think it will ever be _required_ of all 
Python hackers, but I may be wrong.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why? [win32com/WMI]

2006-03-01 Thread rtilley
Tim Golden wrote:
 [Sergey]
 
 | import win32com.client
 | 
 | loc = win32com.client.Dispatch(WbemScripting.SWbemLocator)
 | svc = loc.ConnectServer(srv, root/cimv2, [EMAIL PROTECTED], **)
 | sys = svc.get(Win32_Process)
 | sys.create(notepad.exe)
 | 
 | =
 | 
 | Traceback (most recent call last):
 | File remote.py, line 6, in ?
 | sys.create(notepad.exe)
 | TypeError: 'int' object is not callable 
 
 I could explain (it's to do with the way in which
 WMI method calls are set up) but I suggest you look at
 this module trumpet-blowing:
 
 http://timgolden.me.uk/python/wmi.html
 
 which makes WMI much easier to work with.

I second that! Tim's WMI module works really well. Of course, you can do 
it however you like, but you should at least check out his WMI work. We 
use it with first class windows services, etc w/o problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spaces at ends of filenames or directory names on Win32

2006-02-27 Thread rtilley
[EMAIL PROTECTED] wrote:
  Please post your Python code.  I don't see the problem you're
 describing.

OK, here's a copy. This works on Mac/Unix/Linux yet has no effect on 
Windows:

-
import os
import os.path

for root, dirs, files in os.walk(os.getcwd()):
 for d in dirs:
 new_d = d.strip()

## Uncomment the next 4 lines just to print dirs with end spaces.
##if new_d != d:
##print d
##else:
##print No end spaces.

## Uncomment the next 7 lines to try a rename of dirs with end spaces.
##if new_d != d:
##try:
##new_path = os.path.join(root, new_d)
##old_path = os.path.join(root, d)
##os.renames(old_path, new_path)
##except Exception, e:
##print e
--
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spaces at ends of filenames or directory names on Win32

2006-02-27 Thread rtilley
[EMAIL PROTECTED] wrote:
  Please post your Python code.  I don't see the problem you're
 describing.

OK, here's a copy. This works on Mac/Unix/Linux yet has no effect on 
Windows:

-
import os
import os.path

for root, dirs, files in os.walk(os.getcwd()):
 for d in dirs:
 new_d = d.strip()

## Uncomment the next 4 lines just to print dirs with end spaces.
##if new_d != d:
##print d
##else:
##print No end spaces.

## Uncomment the next 7 lines to try a rename of dirs with end spaces.
##if new_d != d:
##try:
##new_path = os.path.join(root, new_d)
##old_path = os.path.join(root, d)
##os.renames(old_path, new_path)
##except Exception, e:
##print e
--
-- 
http://mail.python.org/mailman/listinfo/python-list


different ways to strip strings

2006-02-27 Thread rtilley
s = ' qazwsx '

# How are these different?
print s.strip()
print str.strip(s)

Do string objects all have the attribute strip()? If so, why is 
str.strip() needed? Really, I'm just curious... there's a lot  don't 
fully understand :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: different ways to strip strings

2006-02-27 Thread rtilley
Kent Johnson wrote:
 So...
 s.strip() gets a bound method object from the class and calls it with no 
 additional argument.
 str.strip(s) gets an unbound method object from the class and calls it, 
 passing a class instance as the first argument.
 
 Kent

Thank you Kent. That's a very informative explanation. It makes sense too :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spaces at ends of filenames or directory names on Win32

2006-02-27 Thread rtilley
This will at least allow me to ID folders that start with whitespace... 
from within Windows too :) yet I still cannot rename the folders after 
stripping the whitespace... attempting to gives an [Errno 2] No such 
file or directory. The strip seems to work right too according to the 
prints before and after.

import os
import os.path
import string

dirs =  os.listdir(os.getcwd())
path = os.getcwd()
##print path

for d in dirs:
 # If the first space in a folder name is whitespace.
 if d[0] in string.whitespace:
##print d
 try:
 new_path = os.path.join(path, d.strip())
 old_path = os.path.join(path, d)
 print new_path
 print old_path
 os.renames(old_path, new_path)
 except Exception, e:
 print e
 else:
 pass
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spaces at ends of filenames or directory names on Win32

2006-02-27 Thread rtilley
Roel Schroeven wrote:
 rtilley schreef:
 
 This will at least allow me to ID folders that start with 
 whitespace... from within Windows too :) yet I still cannot rename the 
 folders after stripping the whitespace... attempting to gives an 
 [Errno 2] No such file or directory. The strip seems to work right too 
 according to the prints before and after.
 
 
 Does the rename work if try with other names? 

Yes, the script can rename files that have no end whitespace. Also, I 
should note the the Windows GUI cannot rename the files. Same error... 
cannot stat the file. The only way I've been able to rename is through 
the cmd prompt using quotes like this:

ren  bad file with end spaces  good_file_no_end_spaces

I should also note that the code I posted earlier is misleading as 
os.listdir() gets dirs and files... not just dirs as I implied. Here's a 
better example that should get whitespace at either end (and does indeed 
on Mac and Unix... but not Windows)



import os
import os.path
import string

# dirs is actually files and folders, not just folders.
dirs =  os.listdir(os.getcwd())
path = os.getcwd()
print path

for d in dirs:

 # If folder name begins with whitespace.
 if d[0] in string.whitespace:
 print d
 try:
 new_path = os.path.join(path, d.strip())
 old_path = os.path.join(path, d)
 print new_path
 print old_path
 os.renames(old_path, new_path)
 except Exception, e:
 print e

 # If folder name ends with whitespace.
 elif d[-1] in string.whitespace:
 print d
 try:
 new_path = os.path.join(path, d.strip())
 old_path = os.path.join(path, d)
 print new_path
 print old_path
 os.renames(old_path, new_path)
 except Exception, e:
 print e

 # Folder name is OK, so skip it.
 else:
 pass
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: spaces at ends of filenames or directory names on Win32

2006-02-23 Thread rtilley
Larry Bates wrote:
 How about not naming files with leading and trailing spaces on
 the Mac?  Seems like a bad habit that needs breaking ;-).
 
 -Larry Bates

Users will be users! Tell that to the guys and gals on Macs who like to 
make a folder sort based on the number of spaces they've placed in the 
front of the filenames :)
-- 
http://mail.python.org/mailman/listinfo/python-list


urllib2 auth error

2006-02-20 Thread rtilley
I get this error:

HTTP Error 401: Authorization Required

When I do this:

try:
 handler = urllib2.HTTPBasicAuthHandler()
 handler.add_password('realm', 'website', 'user', 'pass')
 opener = urllib2.build_opener(handler)
 urllib2.install_opener(opener)
 f = urllib2.urlopen('http://website')
 print f.read()
 f.close()
except Exception, e:
 print e

I have the right username and password. I may be using the above code 
wrong. Any tips?

Thanks,
Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2 auth error

2006-02-20 Thread rtilley
rtilley wrote:
 I have the right username and password. I may be using the above code 
 wrong. Any tips?

I had the _wrong_ password... Sorry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: windows security descriptors

2006-02-15 Thread rtilley
The link changed... sorry.
http://opensource.w2k.vt.edu/Win32_Perms.php
-- 
http://mail.python.org/mailman/listinfo/python-list


%SystemDrive%

2006-02-15 Thread rtilley
Is there a proper way to get this variable from Windows? I know it's in 
the registry, but I'd rather not go there. I could not find a CSIDL 
shell constant for it either. I've been doing this:

os.chdir('/')
sys_drive = os.getcwd()
print sys_drive
C:\

This seems too much of a hack and maybe not 100% right all of the time. 
How could it be done better?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: %SystemDrive%

2006-02-15 Thread rtilley
Carsten Haese wrote:

 Is there a reason why os.environ['SYSTEMDRIVE'] shouldn't work?
 
 Hope this helps


I didn't know it was in os! It returns C: instead of C:\ like my method. 
Other than that, it seems to do the trick.

Thank you!
Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: %SystemDrive%

2006-02-15 Thread rtilley
Atanas Banov wrote:
 using
os.chdir('/')
os.getcwd()
 is plain wrong in Windows.
 
 what it does is change the current directory to root of the CURRENT
 DRIVE (i.e. the drive of the directory where script was started from),
 not the system drive. for example, if current directory was
 c:\myscripts and system drive is d:, this will return c:\ and not d:\.
 hence chdir doesnt do any good

Thanks for the explanation. I'll use the environ feature of os... I just 
didn't realize it existed :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to cat None

2006-02-14 Thread rtilley
LittlePython wrote:
I am not too sure I know what None really means.

It means null, void or lack of value. It is not an empty string. You 
can't add None to stings.

  r = None
  print r
None
  print type(r)
type 'NoneType'
-- 
http://mail.python.org/mailman/listinfo/python-list


readlines and break apart based on letters

2006-02-13 Thread rtilley
Hi,

While trying to better understand security descriptors on Windows. I've 
been examining text-based security descriptors. I have the security 
descriptors on individual lines stored in a text file. I want to break 
these lines apart based on owner, group, dacl and sacl. These areas are 
demarcated by O: G: D: and S:

There are no spaces in the lines. How can I read each line so that each 
area is broken out? I'd like output like this:

O: details
G: details or NONE
D: details or NONE
S: details or NONE

Here is an example SD:
O:owner_sidG:group_sidD:dacl_flags(string_ace1)(string_ace2)...(string_acen)S:sacl_flags(string_ace1)(string_ace2)...(string_acen)

I want to read this and break it apart like this:
O:owner_sid
G:group_sid
D:dacl_flags(string_ace1)(string_ace2)...(string_acen)
S:sacl_flags(string_ace1)(string_ace2)...(string_acen)

Any tips?
Brad

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


invert the order of a string

2006-02-13 Thread rtilley
s = list('some_random_string')
print s
s.reverse()
print s
s = ''.join(s)
print s

Surely there's a better way to do this, right?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: invert the order of a string

2006-02-13 Thread rtilley
Dave Hansen wrote:
 How about 
 
 s = some random string
 print s
 s = s[::-1]
 print s

That looks like Perl, but it works. Makes me wonder with the string 
module doesn't have a reverse or invert function?

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


Re: invert the order of a string

2006-02-13 Thread rtilley
Dave Hansen wrote:
 It's just simple slicing.  Well, maybe not so simple, or at least not
 so common, but with a syntax similar to the range function.  Consider
 the following (string chosen to make it obvious what's going on):
 
 s = 0123456789
 s[::]
 s[3::]
 s[:3:]
 s[::3]
 s[::-2]
 s[-2::-2]

Well, it turns out to be the best way to invert a string, IMO. The 
reversed() feature returns a reversed object... not a reversed string. 
In short, I have to fool with it again _after_ it has been inverted. The 
slicing takes care of the job right away and gives me what I want... no 
Computer Sciencey reversed object at 0xb6f6152c to deal with :)

I'm sure the reversed feature is much more generic though for dealing 
with other types.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: readlines and break apart based on letters

2006-02-13 Thread rtilley
I got this to work... just FYI:

s = 
'O:owner_sidG:group_sidD:dacl_flags(string_ace1)(string_ace2)...(string_acen)S:sacl_flags(string_ace1)(string_ace2)...(string_acen)'

SD = {}

S = str.split(s, 'S:')
SD['S_ACL'] = S[1]
D = str.split(S[0], 'D:')
SD['D_ACL'] = D[1]
G = str.split(D[0], 'G:')
SD['G_SID'] = G[1]
O = str.split(G[0], 'O:')
SD['O_SID'] = O[1]

for k,v in SD.iteritems():
 print k,v
-- 
http://mail.python.org/mailman/listinfo/python-list


python 2.5 and hashlib

2006-02-11 Thread rtilley
Is there a road map for python a 2.5 releases yet? I'd like to begin 
testing the new hashlib module with some old scripts I have that 
currently use the md5 and sha modules.

Thanks,
Brad
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python 2.5 and hashlib

2006-02-11 Thread rtilley
Alex Martelli wrote:
 http://python.org/peps/pep-0356.html -- but it's still a draft, being
 discussed in the last few days on python-dev.

Thank you, that's exactly what I was looking for!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is python very slow compared to C

2006-02-11 Thread rtilley
[EMAIL PROTECTED] wrote:
 I have just started to learn python. Some said that its slow. Can
 somebody pin point the issue.

It depends on what you are doing. Much of Python is just wrapped C. So 
many things are very fast.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problems opening IDLE

2006-02-09 Thread rtilley
Bennie Tilma wrote:
 I'm having trouble with opening the IDLE and running programs. Every 
 time I try to open it, it says:
 1. Socket error: Connection refused
 2. IDLE's subprocess didn't make connection. Either IDLE can't start a 
 subprocess or personal firewall software is blocking the connection.
 
 Point is, I allready entered python as an exception to my firewall and 
 when I disable it, the messages keep apearing. Can anyone help?

Call idle with the -n option

idle-python2.4 -n
idle.py -n
...

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


os.walk() dirs and files

2006-02-08 Thread rtilley
Hello,

When working with file and dir info recursively on Windows XP. I'm going 
about it like this:

for root, dirs, files in os.walk(path):
 for f in files:
 ADD F to dictionary
 for d in dirs:
 ADD D to dictionary

Is it possible to do something such as this:

for root, dirs, files in os.walk(path):
 for f,d in files, dirs:
 ADD F|D to dictionary

Just trying to save some lines of code and thought it wise to ask the 
gurus before trying it :)

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


Re: os.walk() dirs and files

2006-02-08 Thread rtilley
Duncan Booth wrote:

 How about just concatentating the two lists:
 
for root, dirs, files in os.walk(path):
for fs_object in files + dirs:
 ADD fs_object to dictionary

Thank you Duncan! that solves the problem perfectly!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.walk() dirs and files

2006-02-08 Thread rtilley
rtilley wrote:
 Hello,
 
 When working with file and dir info recursively on Windows XP. I'm going 
 about it like this:
 
 for root, dirs, files in os.walk(path):
 for f in files:
 ADD F to dictionary
 for d in dirs:
 ADD D to dictionary
 
 Is it possible to do something such as this:
 
 for root, dirs, files in os.walk(path):
 for f,d in files, dirs:
 ADD F|D to dictionary

Just to clarify. In this particular case, I do not need to differentiate 
between files and dirs... so would it be possible to do something such 
as this:

for root, dirs, files in os.walk(path):
 for fs_object in files, dirs:
 ADD fs_object to dictionary
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.walk() dirs and files

2006-02-08 Thread rtilley
George Sakkis wrote:

 Or a bit more efficiently (no need to allocate a new list for storing
 files+dirs):
 
 from itertools import chain
 for root, dirs, files in os.walk(path):
   for fs_object in chain(files,dirs):
   ADD fs_object to dictionary

I like that! itertools is cool... a bit abstract and computer sciencey, 
but it sure does work in a practical manner :)
-- 
http://mail.python.org/mailman/listinfo/python-list


spell check code

2006-02-08 Thread rtilley
What is the most common way to spell check comments in code? Are there 
any idle plugins or modules that do this?

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


_winreg doc unclear on DeleteValue()

2005-11-15 Thread rtilley
A portion from the _winreg Documnetation:
-
DeleteValue(key, value)
 1. Removes a named value from a registry key. -- OK
 2. key is an already open key, or one of the predefined HKEY_* 
constants. -- OK
 3. value is a string that identifies the value to remove. -- 
misleading
--

When I use EnumValue like this:

Value_Name, Value, Type = EnumValue(key, index)

I expect to use DeleteValue like this (as per the docs):

DeleteValue(open_run_key, Value)

When in fact, I should use it like this:

DeleteValue(open_run_key, Value_Name)

Perhaps this is nitpicking and I'm the only person in the world that 
finds the docs a bit mis-leading here, if so, just disregard this post.

rbt

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


IE Temporary Internet Files Python

2005-11-10 Thread rtilley
A bit off-topic, but Python related.

Below is a script that recursively deletes files from a directory. It 
works well on the two directories that I'm currently using it on:

C:\Documents and Settings\user\Cookies
C:\Documents and Settings\user\Temp

However, I'd like to use it on this directory as well:

C:\Documents and Settings\user\Temporary Internet Files

The script does not seem to work when used on Temporary Internet Files. 
I've googled around a bit, but haven't found any tips... thought I'd 
trouble the list for an answer or at least some explanations.

Feel free to critiqe the script as well. Perhaps it's a programmer error.

rbt



import os
import os.path

userpath = 'C:/Documents and Settings/'
userlist = os.listdir(userpath)

# Make sure that userlist only contains directories, no files.
for u in userlist[:]:
 if os.path.isdir(userpath+u):
 pass
 else:
 userlist.remove(u)

def remove_files(target_dir):
 fp = file('remove_temp_files.txt', 'a')
 for root, dirs, files in os.walk(target_dir):
 for f in files:
 try:
 os.unlink(os.path.join(root, f))
 print  fp, Removed:, os.path.join(root,f)
 except OSError:
 pass
 fp.close()

# Remove 'Local Settings|Temp' files
for username in userlist:
 target_dir = userpath+username+'/Local Settings/Temp/'
 #print target_dir
 remove_files(target_dir)

# Remove IE Cookies
for username in userlist:
 target_dir = userpath+username+'/Cookies/'
 #print target_dir
 remove_files(target_dir)

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


Re: IE Temporary Internet Files Python

2005-11-10 Thread rtilley
Laszlo Zsolt Nagy wrote:
 
 The script does not seem to work when used on Temporary Internet Files.  

 Doesn't work well? What does it mean? Is there an exception raised?
 
  Les
 

No exception. The files are not deleted.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IE Temporary Internet Files Python

2005-11-10 Thread rtilley
Tim Golden wrote:
 [rtilley]
 
 
Below is a script that recursively deletes files from a directory. It 
works well on the two directories that I'm currently using it on:
 
 
C:\Documents and Settings\user\Cookies
C:\Documents and Settings\user\Temp
 
 
However, I'd like to use it on this directory as well:
 
 
C:\Documents and Settings\user\Temporary Internet Files
 
 
The script does not seem to work when used on Temporary Internet
 
 Files. 
 
I've googled around a bit, but haven't found any tips... thought I'd 
trouble the list for an answer or at least some explanations.
 
 
Feel free to critiqe the script as well. Perhaps it's a programmer
 
 error.
 
 Temporary Internet Files is one of those special shell folders
 and, I suspect, isn't really a folder at all in the normal sense:
 it just presents itself as one to the O/S. (Might be wrong there).
 Probably means you have to use shell functions to access it.
 Quick trial with SHFileOperation works up to a point, but ultimately
 fails with a file-in-use error.
 
 This article: 
 
 http://www.codeguru.com/Cpp/I-N/ieprogram/article.php/c1245/
 
 uses a very different technique. The APIs in question aren't
 wrapped in pywin32. You could probably get at them via ctypes.
 Don't have time to try it myself at the moment.
 
 TJG
 
 PS Probably doesn't matter at the mo, but for general purpose
 use, those folders aren't always where your script hardwires
 them to be. You might need to look at the shell functions
 around SHGetPathFromIDList and SHGetSpecialFolderLocation.
 Tim

Thanks a lot Tim. I hadn't been using the win32 extensions... guess I'll 
have to now. How I love Windows ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


socket.setdefaulttimeout()

2005-10-08 Thread rtilley
Perhaps this is a dumb question... but here goes. Should a socket client 
and a socket server each have different values for 
socket.setdefaulttimeout() what happens? Does the one with the shortest 
timeout period end first?
-- 
http://mail.python.org/mailman/listinfo/python-list