is there a better way to walk a file system?

2005-07-01 Thread ina
I want to walk a folder structor and group all the files by extention.


Here is the code I put together is there a better way of doing this?

import os
folderKey = "Folders"
dicExt = {}
tDicKey = []
tDicKey.append(folderKey)
dicExt[folderKey] = []

walkPath = r"\\zek\C$\AST"

for d in os.walk(walkPath):
(dirpath, dirnames, filenames) = d
dicExt[folderKey].append(dirpath)
for fname in filenames:
fs = os.path.splitext(fname)
if dicExt.has_key(fs[-1]):
dicExt[fs[-1]].append(os.path.join(dirpath,fname))
else:
dicExt[fs[-1]] = []
dicExt[fs[-1]].append(fname)
tDicKey.append(fs[-1])


for k in tDicKey:
print k +" "+ str(len(dicExt[k]))

Right now it is just prints out the counts.

Thanks 

Erin

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


Re: Using win32com for web automation

2005-07-26 Thread ina
Look up pamie it should do all the work you need.  If it dosn't I can
send you ishyBrowser but pamie has more comunity support.

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


Re: How to quit a Windows GUI program gracefully with Python under Cygwin?

2005-08-11 Thread ina
Send the active program an alt-f4.  I do this through shell.send keys.
Hope this was of help.

KB wrote:
> Hi,
>
> I want to write a Python script that controls and automates a Windows
> GUI computation program.
>
> My problem is that I do not know how to quit the Windows GUI program
> gracefully with a command (program's or Python) in Cygwin.  'kill' or
> CTRL-C command in Cygwin does not finish it gracefully, meaning that
> some outputs do not come out normally.  The only thing I know is to
> click 'File-Exit' menu, but
> this requires a manual intervention that prevents scripting.
>
> Is there a way to quit a Windows GUI program gracefully with Python
> under Cygwin, of course, after the program finishes
> normal execution?
> 
> Thanks,
> 
> KB

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


Re: Put a url in a browsers address bar

2005-08-18 Thread ina
Here is a start.

http://www.ishpeck.net/?P=pytesting
This is all stuff based on windos.



Colin Gillespie wrote:
> Dear All,
>
> I would like to place a url in my browsers address bar, then execute.
> How can do this?
>
> e.g.
>
> def goToGoogle():
>   url = "www.google.com"
>   b = openBrowser()
>   b.goToUrl(url)  
>   return True
> 
> Thanks for any help
> 
> Colin

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


Re: WebScraping

2006-11-04 Thread ina
This might be of help to you.
http://phlik.ishpeck.net/index.php?P=a1141076600phlik

http://phlik.ishpeck.net/index.php?P=b1134168973phlik

Graham Feeley wrote:
> Can someone steer me to scripts / modules etc on webscraping please???
> Ultimately I would like someone to write a script for me.
> However i am still searching for documentation on this subject
> Thanks Graham

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


Re: using split function

2006-11-06 Thread ina

[EMAIL PROTECTED] wrote:
> Hi,
>
> I have to write a code in python to read a matrix from a text file and
> for that i am using following code. But it gives an error saying
> "NameError: name 'split' is not defined". Can anyone help me with this.
> -
> #!/usr/bin/python
> import numpy
> file = open('matrix.txt', 'r')
>
> count =  0
> ra = numpy.random
> A = ra.standard_normal((4,4))
> while 1:
> lineStr = file.readline()
> if not(lineStr):
> break
>
> count = count + 1
> row=split(lineStr)
> A[count,:]=row
>
> matrix.close()
> -
> Also, i want to initialize the matrix A by zeros, but using A=zeros([4,
> 4]) was giving a similar error "NameError: name 'zeros' is not
> defined".
>
> Thank you
> Amit
This is how I would do it.
for lineStr in file:
...row = lineStr.split()

you could also use str.split(lineStr) but the other way is cleaner

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


Re: odd problem with watsup and VB6 application with modal dialog

2006-11-11 Thread ina
At my work we had the same problem.  We found that the best solution
was to use a thread with the code to handle the model dialog.  This
worked best for us because the only models in our product are the error
messages, and using a thread gave us the ability to check and see if
the modal dialog was found.

In this post there is some example code.  I will post up a more
complete solution when I get to work on monday.

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ea9a63aaeaecb591/ee7ec7cf2d12801d?lnk=gst&q=findtopwindow&rnum=1&hl=en#ee7ec7cf2d12801d

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


Re: need guidance on sending emails with attachment with python.

2006-12-12 Thread ina
I put to gether a class to deal with this along time ago it might be of
help to you.
You can find it at
http://phlik.ishpeck.net/index.php?P=b1114201575phlik.

krishnakant Mane wrote:
> hello,
> I am a bit confused.
> I want to make a program that will take some data from a database and
> make a string of text.  and send it to the respective email id of a
> person.
> next I also want to send an attachment of a photo along with the email.
> I will be required to make this program run on windows xp.
> can some one guide me as to how I can achieve this?
> what I will need on windows to send emails?
> I believe yahoo, gmail, rediff and msn supports pop3 and smtp?
> correct me if I am wrong on this.
> secondly what library is used on windows to do this?
> I know there must be python libraries to do this,
> but apart from that I don't know what all I will need on my windows
> machine to send emails to mostly yahoo, gmail and msn.
> Please give me some idea about it.
> Krishnakant.

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


Re: re pattern for matching JS/CSS

2006-12-15 Thread ina

i80and wrote:
> I'm working on a program to remove tags from a HTML document, leaving
> just the content, but I want to do it simply.  I've finished a system
> to remove simple tags, but I want all CSS and JS to be removed.  What
> re pattern could I use to do that?
>
> I've tried
> ''
> but that didn't work properly.  I'm fairly basic in my knowledge of
> Python, so I'm still trying to learn re.
> What pattern would work?

I use  re.compile("",re.DOTALL)
for scripts.  I strip this out first since my tag stripping re will
strip out script tags as well hope this was of help.

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


Re: Any easy-to-use email send module?

2006-12-20 Thread ina
I put this together for some automated testing I do with an email
system.  I hope it is of help to you.

It dosn't do cc and bcc In this version but it would be simple to add
to the eMessage headder.

http://phlik.ishpeck.net/index.php?P=b1114201575phlik

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


Re: html + javascript automations = [mechanize + ?? ] or something else?

2007-01-16 Thread ina

John wrote:
> I have to write a spyder for a webpage that uses html + javascript. I
> had it written using mechanize
> but the authors of the webpage now use a lot of javascript. Mechanize
> can no longer do the job.
> Does anyone know how I could automate my spyder to understand
> javascript? Is there a way
> to control a browser like firefox from python itself? How about IE?
> That way, we do not have
> to go thru something like mechanize?
>
> Thanks in advance for your help/comments,
> --j

You want pamie, iec or ishybrowser.  Pamie is probably the best choice
since it gets patches and updates on a regular basis.

http://pamie.sourceforge.net/

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


Re: newbie - returned values from cscript.exe

2007-01-26 Thread ina
I did the same thing back before I knew about python and com.
I hope this example gets you on the right track.

It is just a simple script that does a dir and returns prints it out.

import os, sys
dCall = "dir"
resultFromCall = os.popen(dCall)
#get data back from the system call
mv = resultFromCall.read()
resultFromCall.close()
print mv



On Jan 24, 12:26 pm, "Rich" <[EMAIL PROTECTED]> wrote:
> I am writing my first python script and I'm guessing this is something
> obvious but I can't find any examples of doing something like this.  I
> have a python script that is running a vbscript through cscript.exe.
> The vbscript looks up a server name, username, password etc and returns
> these values in a delimited list using wscript.echo.  I can assign
> these values to variables using a Windows batch files with the
> following code
>
> FOR /F "tokens=1-6" %%a in ('cscript /nologo GetServerAccessInfo.vbs"')
> do (
> SET DB_SERVER_NAME=%%a
> SET DB_NAME=%%b
> SET NMDBO_USERNAME=%%c
> SET NMDBO_PASSWORD=%%d
> SET SU_USERNAME=%%e
> SET SU_PASSWORD=%%f
>
> I can't figure out how to do the same thing using a python script to
> call this instead of a batch file.
>
> I am running the vbscript by using the following command
> os.system('cscript /nologo GetServerAccessInfo.vbs')

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


Re: Running Python scripts from BASH

2007-02-28 Thread ina
On Feb 27, 11:16 pm, "Hendrik van Rooyen" <[EMAIL PROTECTED]>
wrote:
> "Ishpeck" <[EMAIL PROTECTED]> wrote:
>
> 8<--- a bash problem -
>
> If it were Python, the advice would have been to use the
> print statement to figure out what the content of the
> variables were.
>
> As it is Bash, you may have to stoop to something like
> echo to see what is in $i...
>
> hth - Hendrik

When you print the string in bash it looks correct. It isn't until you
try to execute it you have the problem.

os.system is the solution to this problem anyway.

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