[Tutor] boa constructor font?

2004-12-17 Thread Jeff Peery
my eyes are going bad... anyone know how to change the font size in the editor window of the boa constructor? this seems to be a simple but not easy thing to do. thanks!
 
Jeff___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


[Tutor] os.popen4 help!

2010-03-16 Thread Jeff Peery
Hello,
I'm trying to run an executable file from a python script. the executable is 
"opcenum.exe".

OPCENUM.EXE
 is an executable that is usually found on computers with OPC software; 
such as OPC Servers or OPC Clients. The purpose of OPCENUM.EXE is 
to provide an interface into the local 
machine's Component Category Manager that can be accessed by remote OPC 
clients over DCOM.  OPCEnum.exe provides several useful methods
IOPCServerList::EnumClassesofCategory
 - gets available OPC servers for a specified category of OPC server
I want to use IOPCServerList::EnumClassesofCategory but I am having some 
trouble. currently I do the below:

import os
cmd = 'opcenum.exe/IOPCServerList/EnumClassesofCategory 
63D5F432-CFE4-11d1-B2C8-0060083BA1FB'
fin,fout = os.popen4(cmd)
result = fout.read()

this doesn't work, and it hangs up on fout.read(). I'm do not understand the 
syntax of the arguments in popen4, i.e., I'm using slashes to get to the 
EnumClassesofCategory method, but should I use periods or what. The long number 
at the end is the argument to EnumClassesofCategory, and is the component 
category CLSID. 

details are here: http://opcactivex.com/Support/General/OPCEnum/opcenum.html

how can I improve things here?

thanks,
Jeff



  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] browing windows registry

2010-03-17 Thread Jeff Peery
hello,
I want to browse the windows registry for the program ids listed under the 
categories:
63D5F430-CFE4-11d1-B2C8-0060083BA1FB
63D5F432-CFE4-11d1-B2C8-0060083BA1FB

where might be the best way to learn how to do that with python?

thanks,
Jeff



  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how do I post event to thread?

2009-08-26 Thread Jeff Peery
hello,
I've read a bit about multi thread communication, and found that most people 
use a queue, which makes sense. however in my case I simply have two threads, a 
main thread and one other. the main thread is doing many different things and 
the second thread is receiving numerical data via a serial port.. when data 
comes in, I want to post the data to the main thread so it can use the it. I 
don't want to use a queue because I don't want to lock up my main thread in a 
loop that is always looking at the queue waiting to get something out of it. I 
would prefer to do something like post an event. The alternative would be to 
simply have a method in my main thread called OnResult(data), and when data 
comes in to the second thread I could call main_thread.OnResult(data). This 
would solve my problem, but I'm not sure if that is an ok thing to do... 
calling a main thread method from within a second thread?
 
is there a way to post an event to the main thread from a second thread?
 
Is it ok to pass the main thread (self) into the second thread and have the 
second thread
call a main_thread.OnResult(data) method to pass the data into the main thread? 
I'm not sure how the main thread handles this, my guess is that it can only do 
one thing at a time so it might be exactly that same as 'posting an event'.
 
any thoughts would be much appreciated. thanks!
 
Jeff


  ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how do I post event to thread?

2009-08-27 Thread Jeff Peery
Hi,
thanks for all the good responses. I appreciate your thoughts. I was sightly 
confused about how these threads work together.
 
I am using python 2.6, no GUI at the moment, so I can't use the wxEvent class 
or the equivalent. 
 
The program basically pulls data from a serial port and then calculates some 
stats and writes data to a file. eventually I will put a GUI on it.
 
I think you are correct that since my logic is in its own thread I can put a 
portion of code that watches the queue.
 
Thanks for the advice!
 
Jeff


--- On Thu, 8/27/09, Kent Johnson  wrote:


From: Kent Johnson 
Subject: Re: [Tutor] how do I post event to thread?
To: "Jeff Peery" 
Cc: tutor@python.org
Date: Thursday, August 27, 2009, 4:00 AM


On Wed, Aug 26, 2009 at 9:38 PM, Jeff Peery wrote:
> hello,
> I've read a bit about multi thread communication, and found that most people
> use a queue, which makes sense. however in my case I simply have two
> threads, a main thread and one other. the main thread is doing many
> different things and the second thread is receiving numerical data via a
> serial port. when data comes in, I want to post the data to the main thread
> so it can use the it. I don't want to use a queue because I don't want to
> lock up my main thread in a loop that is always looking at the queue waiting
> to get something out of it. I would prefer to do something like post an
> event. The alternative would be to simply have a method in my main thread
> called OnResult(data), and when data comes in to the second thread I could
> call main_thread.OnResult(data). This would solve my problem, but I'm not
> sure if that is an ok thing to do... calling a main thread method from
> within a second thread?

As Dave explained, this will run OnResult() in the data thread.

> is there a way to post an event to the main thread from a second thread?

There is no way I know of to just force a function to run in another
thread. The main thread needs to poll in some way for a notification
from the data thread. If the main thread is running a GUI toolkit,
there is probably a way for the data thread to post an event to the
main thread. Most GUI toolkits also have idle loop callbacks so you
could schedule an idle task to look for data from the data thread.

Does your current main thread have an idle loop where you could poll
the queue for data?

Kent



  ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] thread causes idle to crash

2009-08-28 Thread Jeff Peery
hello,
I've been working on threads and queues and I think I have it working well. The 
problem seems to be that when I run a thread via the IDLE it crashes. if I 
simply double click the file it appears to run ok. I'm not sure if I'm doing 
something incorrectly or not. it seems pretty straight forward. my sample code 
is listed below. I'm using Python 2.6.2, and I'm running on Microsoft Vista. 
Any thoughts would be much appreciated. thanks!
Jeff
 
import threading
import Queue
import time, random
WORKERS = 2
 
class Worker(threading.Thread):
    def __init__(self, queue):
    self.__queue = queue
    threading.Thread.__init__(self)
    def run(self):
    while 1:
    item = self.__queue.get()
    if item is None:
    break # reached end of queue
    # pretend we're doing something that takes 10-100 ms
    time.sleep(random.randint(10, 100) / 100.0)
    print "task", item, "finished"
#
# try it
queue = Queue.Queue(0)
for i in range(WORKERS):
    print 'starting'
    Worker(queue).start() # start a worker
for i in range(10):
    print 'putting'
    queue.put(i)
for i in range(WORKERS):
    print 'putting None'
    queue.put(None) # add end-of-queue markers
 


  ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python queue

2009-09-16 Thread Jeff Peery
Hello,
Does anyone know if there is there a way to look at a queue's contents? Or 
prevent duplicate messages from being put into a queue? The docs don't show 
anything useful. The reason is that I'm collecting and drawing data. one thread 
collects, and one thread draws. each time one sample is collected by the 
collector thread, a "draw message" is put into the queue to notify the drawing 
thread. the dataset is shared between the threads and is continuously growing 
as data is appended. The queue is used to notify the drawing thread that it 
should draw. I use threading.Lock() to prevent any "sharing issues".
 
The problem is that if the data collector thread is putting messages into the 
queue faster than the drawing thread is getting them, then the drawing thread 
is forced to redraw more times than it needs to and appears slow. However since 
the dataset is shared the drawing thread only needs to draw once to be updated 
for all the new samples. For example if 10 samples have been appended by the 
data collector thread while the drawing thread drew once, then there are now 10 
messages for the drawing thread to get. yet it only needs to draw once to 
reflect the 10 samples. so there are 9 redraws that are a waste of energy. 
 
I was hoping there was some feature in the queue class the would prevent or 
discard a duplicate message. This way my drawing thread won't draw more than it 
needs to.
 
thanks!
Jeff


  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] numpy and py2exe

2009-11-21 Thread Jeff Peery
Hello I have a python app that uses wxPython, numpy, and I'm trying to package 
it with py2exe. I get the below error. I tried putting a dummy __init__.py file 
in the distutils.tests directory but this did not solve the problem. how may I 
fix this?
 

*** searching for required modules ***
Traceback (most recent call last):
  File "C:\Users\Jeff\Documents\Working\App\setup.py", line 298, in 
    cmdclass = {"py2exe": build_installer},
  File "C:\Python26\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python26\lib\distutils\dist.py", line 975, in run_commands
    self.run_command(cmd)
  File "C:\Python26\lib\distutils\dist.py", line 995, in run_command
    cmd_obj.run()
  File "C:\Users\Jeff\Documents\Working\App\setup.py", line 273, in run
    py2exe.run(self)
  File "C:\Python26\lib\site-packages\py2exe\build_exe.py", line 243, in run
    self._run()
  File "C:\Python26\lib\site-packages\py2exe\build_exe.py", line 296, in _run
    self.find_needed_modules(mf, required_files, required_modules)
  File "C:\Python26\lib\site-packages\py2exe\build_exe.py", line 1342, in find_n
eeded_modules
    mf.import_hook(package, None, ["*"])
  File "C:\Python26\lib\site-packages\py2exe\mf.py", line 719, in import_hook
    return Base.import_hook(self,name,caller,fromlist,level)
  File "C:\Python26\lib\site-packages\py2exe\mf.py", line 137, in import_hook
    m = self.load_tail(q, tail)
  File "C:\Python26\lib\site-packages\py2exe\mf.py", line 217, in load_tail
    raise ImportError, "No module named " + mname
ImportError: No module named numpy.distutils.tests
 
 
thanks,
Jeff


  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] py2exe

2005-04-15 Thread Jeff Peery

hello, I am using py2exe. for most of my applications it has been great. although this last one I built and when I try to execute it I get an error:
 
RunTime Error: this application has requested the runtime to terminate in an unusual way. please contact the applications support team for more info.
 
does anyone know what this means? thanks.
 
Jeff
 
 ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] py2exe

2005-04-19 Thread Jeff Peery
Ok, thanks again Greg. Although I didn't see a log file, where would it appear and what would the name be... just in case I missed it. thanks.
 
JeffGreg Hasseler <[EMAIL PROTECTED]> wrote:
I meant to send my first reply the list..oops. If it doesn't leave anylog file then I would suggest maybe sending the program source codeitself to the list so that others can review it for potential error.On 4/18/05, Jeff Peery <[EMAIL PROTECTED]>wrote:> Hi Greg, thanks for the help. the program does not launch, it crashes> immediately, and I did not see a log file. I also ran py2exe several times> over and always the same result. the program runs great in regular python> mode. any ideas? thanks. > > Jeff> > Greg Hasseler <[EMAIL PROTECTED]>wrote: > Does the application launch at all or does it just immediately crash?> Look and see if there are any logs available. You may also consider> running py2exe again.> > On 4/15/05, Jeff Peery wrote:> > > !
 >
 hello, I am using py2exe. for most of my applications it has been great.> > although this last one I built and when I try to execute it I get an> error: > > > > RunTime Error: this application has requested the runtime to terminate in> an> > unusual way. please contact the applications support team for more info. > > > > does anyone know what this means? thanks. > > > > Jeff > > > > > > ___> > Tutor maillist - Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor> > > > > >>___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] py2exe

2005-04-24 Thread Jeff Peery
I am using python 2.3.4. thanks.
 
JeffGreg Hasseler <[EMAIL PROTECTED]> wrote:
Hi Jeff. I can't tell if you sent the last email to just me or me andthe list, but make sure to send it to the list (don't just hit reply).Also, what version of wxPython are you using?On 4/21/05, Jeff Peery <[EMAIL PROTECTED]>wrote:> > OK, thanks again. I attached my code. I if anyone has an idea as to why the> executable fails after running py2exe please let me know. thanks for the> help! > > Jeff> > Greg Hasseler <[EMAIL PROTECTED]>wrote: > If the application was named test.exe, I find that they are typically> named test.exe.log then or similar.> > On 4/19/05, Jeff Peery wrote:> > Ok, thanks again Greg. Although I didn't see a log file, where would it> > appear and what would the name be... just in case I missed it. thanks. > > > &!
 gt;
 Jeff> > > > Greg Hasseler wrote: > > I meant to send my first reply the list..oops. If it doesn't leave any> > log file then I would suggest maybe sending the program source code> > itself to the list so that others can review it for potential error.> > > > > > On 4/18/05, Jeff Peery wrote:> > > Hi Greg, thanks for the help. the program does not launch, it crashes> > > immediately, and I did not see a log file. I also ran py2exe several> times> > > over and always the same result. the program runs great in regular> python> > > mode. any ideas? thanks. > > > > > > Jeff> > > > > > Greg Hasseler wrote: > > > Does the application launch at all or does it just immediately crash?> > > Look and see if there are any logs available. You may also consider> !
 > >
 running py2exe again.> > > > > > On 4/15/05, Jeff Peery wrote:> > > > > > > ! > hello, I am using py2exe. for most of my applications it has been> > great.> > > > although this last one I built and when I try to execute it I get an> > > error: > > > > > > > > RunTime Error: this application has requested the runtime to terminate> > in> > > an> > > > unusual way. please contact the applications support team for more> info.> > > > > > > > does anyone know what this means? thanks. > > > > > > > > Jeff > > > > > > > > > > > > ___> > > > Tutor maillist - Tutor@python.org> > > > http://mail.python.org/mailman/listinfo/tutor!
 >
 > > > > > > > > > > >> > >> > > > ___> > Tutor maillist - Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor> > > > > >> >___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] missing module?

2005-04-28 Thread Jeff Peery
Hello, I get an error message from py2exe that it can't find a module ntpath.py.  I pasted the error message below:
 
Traceback (most recent call last):  File "wxApp1.py", line 4, in ?  File "wx\__init__.pyc", line 42, in ?  File "wx\_core.pyc", line 4, in ?  File "wx\_core_.pyc", line 9, in ?  File "wx\_core_.pyc", line 3, in __load  File "C:\Python24\lib\os.py", line 62, in ?    import ntpath as pathzipimport.ZipImportError: can't find module 'ntpath'
 
I can find ntpath why can't py2exe? how can I get this thing working? thanks for the help.
 
jeff___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] wxpython error when upgrading?

2005-04-28 Thread Jeff Peery
hello, I recently upgraded my wxpython to 2.5, now I get an error message when I try to edit a dialog in the boa constructor that says : collection body not in init, body, fin form - anyone have an idea what this means? thanks.
 
Jeff___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] printing documents

2005-05-20 Thread Jeff Peery
hello, 
 
I am writing a program to store name/contact/business transaction information. I would like the ability to print out a form for each client with all this stored information.  Can somone point me in the write direction for printing documents. How do I go about setting up a printable page with all the variables I have for each client? thanks
 
Also I would like to take the information I input and store it as an images.  Essentially take the above mentioned document (the one I want to print out a hard copy) and save it as an image so I can view it later. Any ideas? 
 
I'm operating on windows and I'm using wxpython. thanks.
 
Jeff___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] passing variables between frames?

2005-05-23 Thread Jeff Peery
Hello, I am having trouble with passing variables between frames (Frame1 and Dialog1).  I'm using wxpython to write an application. when I run my application the parent frame appears and within the parent frame I can assign values to variables.  I then have a button that launches a child dialog.  I want to access the values from the parent frame in the dialog.  for example say I had a listbox in the parent frame and I choose the first entry 'a' from the list.  I then launch the child dialog and I want to put the value of the selection from the list box into a text field - when I lauch the child dialog a text field appears with the value '0'. From within Frame1 I can use the getselection() function to get the listbox selection. although in the child dialog I tried to use Frame1.listBox.getselection() to get the selection from Frame1. this doesn't work. not sure what to do here? any ideas? thanks.
 
Jeff___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] passing variables between frames?

2005-05-24 Thread Jeff Peery
ok, thanks. that makes sense; however I do not know how to pass a variable from my parent frame to the dialog.  I have tried this before unsuccessfully. could you provide a quick example of how to pass a variable to a dialog from a frame. I am not sure how this works. thanks.
 
JeffKent Johnson <[EMAIL PROTECTED]> wrote:
Jeff Peery wrote:> Hello, I am having trouble with passing variables between frames (Frame1 > and Dialog1). I'm using wxpython to write an application. when I run my > application the parent frame appears and within the parent frame I can > assign values to variables. I then have a button that launches a child > dialog. I want to access the values from the parent frame in the > dialog. for example say I had a listbox in the parent frame and I > choose the first entry 'a' from the list. I then launch the child > dialog and I want to put the value of the selection from the list box > into a text field - when I lauch the child dialog a text field appears > with the value '0'. From within Frame1 I can use the getselection() > function to get the listbox selection. although in the child dialog I > !
 tried to
 use Frame1.listBox.getselection() to get the selection from > Frame1. this doesn't work. not sure what to do here? any ideas? thanks.It's hard to know specifically what is broken without seeing code or error messages. My guess is that the variable Frame1 is not in scope in the dialog box code. But I would suggest a different approach...- Make the dialog box code independent of the values of variables in Frame1. Generally for me this means packaging up the dialog box in a function or class that is passed the values it needs to use and returns some result to the user. A very simple example is a dialog box that presents an error message; you could make a function showError(msg) that doesn't know anything about its caller.- In the event handler for the button in Frame1, gather the values needed by the dialog, launch it, get the result and handle it.This style keeps your dialog code independent of the rest of the pro!
 gram. An
 immediate benefit is that you can write a simple test driver that exercises the dialog without having to create any infrastructure. (This is the way I create most dialog boxes. I run it standalone until I am happy with its appearance and function, then I integrate it into the rest of the app.) Another long-term benefit is the dialogs are reusable; you may not see a need for this but in the long run some of them will probably have more than one use.HTH,Kent___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] passing variables between frames?

2005-05-24 Thread Jeff Peery
actually I got it to work! thanks for the help.
 
JeffKent Johnson <[EMAIL PROTECTED]> wrote:
Jeff Peery wrote:> ok, thanks. that makes sense; however I do not know how to pass a > variable from my parent frame to the dialog. I have tried this before > unsuccessfully. could you provide a quick example of how to pass a > variable to a dialog from a frame. I am not sure how this works. thanksCan you post your (maybe broken) dialog code with a placeholder for the variable you want?Kent___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] wxpython button icons?

2005-05-31 Thread Jeff Peery
Hello, does anyone know if there is a list of widows icons available? I'm creating an application for windows and I'd like to use standard icons for things like a "print" button or "save" button etc. thanks.
 
Jeff
 ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] IDLE not working?

2005-06-01 Thread Jeff Peery
Hello, I upgraded python to 2.4 and now my IDLE isn't working. There is an error indicating something is wrong with my configuration file for the IDLE settings. Any suggestions for how to solve this problem would be much appreciated. thanks.
 
Jeff___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] imbedding python into another program?

2005-06-01 Thread Jeff Peery


hello, is it possible to add something like the python IDLE into another program, say if I wanted to simply run scripts from within a wxPython program? Could someone point me to the correct reference? thanks.
 
Jeff___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] imbedding python into another program?

2005-06-01 Thread Jeff Peery
ok, thanks! that helps.  I have an application that reads a data file, crunches some numbers, and spits out some graphs.  In addition to this I would also like users to be able to write small python scripts to operate on the data that is available within the program. I suppose this could be accomplished by simply reading a text input and sending off the command to the command module and then returning the result to the user?? Is this feasible? 
 
thanks for the help!
 
JeffDanny Yoo <[EMAIL PROTECTED]> wrote:
On Wed, 1 Jun 2005, Jeff Peery wrote:> hello, is it possible to add something like the python IDLE into another> programHi Jeff,Getting IDLE to work within wxPython is technically possible, but probablya little tricky, since it'll involve getting the GUI event loops tocooperate.I believe it is doable --- there's code in the Twisted Python project, forexample, that allows the Tkinter event loop to integrate into Twisted'sevent loop. That being said, this might be overkill for what you'retrying to do.> say if I wanted to simply run scripts from within a wxPython program?> Could someone point me to the correct reference? thanks.Hmmm... do you necessarily have to have those scripts run through IDLEthen? What kind of scripts are you trying to run through wxPython?Would s!
 omething
 like the 'commands' module be useful for you?http://www.python.org/doc/lib/module-commands.htmlBest of wishes to you!___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] resizing an array of strings?

2005-06-06 Thread Jeff Peery
Hello, I'm having a bit of trouble resizing/reshaping an array of strings. here's what I'm trying to do:
 
myString = ['hi','my','name','is','Jeff']
reshape(myString, (2,2))
 
What I get from this is something like:
 
[['h','i'],
['m','y']]
 
What I want is:
[['hi','my'],
['name','is']]
 
How might this work best?___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] fourier transform

2005-07-29 Thread Jeff Peery
Hello, I have a signal that I want to do a fourier transform on. I tried using FFT.fft(data).real but I don't understand the output.  what is output from this function, and why doesn't it require amplitude and time as inputs? 
 
thanks.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fourier transform

2005-08-01 Thread Jeff Peery
thanks for the help. I think I'm understanding this a bit better. although I still don't completely understand the output. here is an example... for the input I have 1024 samples taken from a 1 Hz square wave with amplitude = 1.  for the output I would expect an infinite number of frequencies. the output from FFT.fft(myData).real is this:
 
.
.
.
-0.498 10.0 2-0.498 30.0 4-0.498 50.0 6-0.498 70.0 8-0.498 90.0 10-0.498 110.0 12-0.498 130.0 14-0.498 150.0 16-0.498 17
.
..
 
I'm not sure why the output alternates from 0 and 0.498. I would expect 0.498 at all frequencies? why the oscillation?
 
Christian Meesters <[EMAIL PROTECTED]> wrote:
Jeff Peery wrote:>> Hello, I have a signal that I want to do a fourier transform on. I > tried using FFT.fft(data).real but I don't understand the output. > what is output from this function, and why doesn't it require > amplitude and time as inputs?Hi Jeff,As Danny wrote, your input are real numbers and your output will be complex numbers. I don't want to point you to the numarray documentation once more, but you might to check out this: http://mathworld.wolfram.com/FourierSeries.html as for why you get complex numbers back. (To get only the real value part try real_fft() in numarrayl.)In general in numerical computation your input is simply a series of real numbers - of equal spacing in the dimension you want to consider. Which dimension you choose (amplitudes and time/phase or amplitudes and
 spacial frequencies and so on) is up to you. It depends on your physical or mathematical question. IMHO the best introduction you can get on Fourier Transforms & programming can be found in Numerical Recipies (here the "Numerical Recipies in C"-link http://www.library.cornell.edu/nr/bookcpdf.html - check chapter 12).Have fun with FFTs!CheersChristian___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fourier transform

2005-08-01 Thread Jeff Peery
ok, this makes more sense. what I want to know is the amplitude for the output frequencies. I'm using import FFT, and FFT.fft(). the first element of the output is the DC constant? not sure what this is. is the amplitude for all other elements plus the DC equal to the actual amplitude?
 
thanks.Pawel Kraszewski <[EMAIL PROTECTED]> wrote:
> Hello, I have a signal that I want to do a fourier transform on. I tried> using FFT.fft(data).real but I don't understand the output. what is output> from this function, and why doesn't it require amplitude and time as> inputs?Please write the package you use for FFT. Standard Python doesn't have one. Perhaps you use some custom Python? Like Enthought Python? If so, the exhaustive guide is delivered with it in CHM (windows help) format.1. In general FFT algorithms require you to supply just N complex values (complex contains both amplitude and phase of signal). If you supply real values, the system assumes phase=0 for each sample and takes given value for amplitude.2. You DO supply a time information, you just didn't think of it this way: each consecutive sample is taken one fixed clock tick later, so p!
 osition
 of sample in data gives you the time it was taken.3. Results of FFT are in the form of complex vector of the same length as data. Starting from position 0 it gives you an constant (DC factor), position 1 an amplitude and phase (remember - complex number gives you both amplitude and phase) of wave of the length table/2 and so on. If you take real value of this, you discard part of the information. AFAIR - taking real part gives you sine component, taking imaginary part gives you cosine component, taking absolute value gives you total amplitude and taking angle gives you phase.4. The answer is symmetrical - usually you take only half of it. I don't remember the exact difference between the halves, but you may find it in any article on FFT.Best regards,Pawel Kraszewski___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fourier transform

2005-08-01 Thread Jeff Peery
ok, this makes more sense. what I want to know is the amplitude for the output frequencies. I'm using import FFT, and FFT.fft(). the first element of the output is the DC constant? not sure what this is. is the amplitude for all other elements plus the DC equal to the actual amplitude?
 
thanks.Pawel Kraszewski <[EMAIL PROTECTED]> wrote:
> Hello, I have a signal that I want to do a fourier transform on. I tried> using FFT.fft(data).real but I don't understand the output. what is output> from this function, and why doesn't it require amplitude and time as> inputs?Please write the package you use for FFT. Standard Python doesn't have one. Perhaps you use some custom Python? Like Enthought Python? If so, the exhaustive guide is delivered with it in CHM (windows help) format.1. In general FFT algorithms require you to supply just N complex values (complex contains both amplitude and phase of signal). If you supply real values, the system assumes phase=0 for each sample and takes given value for amplitude.2. You DO supply a time information, you just didn't think of it this way: each consecutive sample is taken one fixed clock tick later, so p!
 osition
 of sample in data gives you the time it was taken.3. Results of FFT are in the form of complex vector of the same length as data. Starting from position 0 it gives you an constant (DC factor), position 1 an amplitude and phase (remember - complex number gives you both amplitude and phase) of wave of the length table/2 and so on. If you take real value of this, you discard part of the information. AFAIR - taking real part gives you sine component, taking imaginary part gives you cosine component, taking absolute value gives you total amplitude and taking angle gives you phase.4. The answer is symmetrical - usually you take only half of it. I don't remember the exact difference between the halves, but you may find it in any article on FFT.Best regards,Pawel Kraszewski___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fourier transform

2005-08-02 Thread Jeff Peery
Hi Christian, 
 
sorry for the lack of detail. how about I use a sine wave because I know what the output should look like - amplitude of one at frequency equal to the frequency of the sine wave. 
 
one period of a sin wave that cycles at one hertz:
period = 1
input = sin(arange(0,64)*3.14159*2/64.0)
 
do the fft:myFFT = FFT.real_fft(myData)
the change in time between elements is:
delta_time = period/64
 
inverse of time is the frequency:
delta_freq = 1/delta_time
 
print the results:
for i in range(1,len(myFFT)):    print myFFT[i], delta_freq*i
 
hope this is more clear. from the output I would expect that two spikes appear with amplitude = 1.  one spike is the positive frequency (first half of the fft) and another spike is the negative frequency (second half), the first half and second half are symmetrical about the midpoint of the fft. but this is what I get:
 
-8.22612478587e-005 64.02.65354186171e-006 128.02.65357174311e-006 192.02.65358011376e-006 256.02.65358370024e-006 320.02.65358557785e-006 384.02.65358668451e-006 448.02.65358739808e-006 512.02.65358788076e-006 576.02.65358822231e-006 640.0
.
.
.
I don't understand the output amplitudes. they should all be zero except for at one herz it should be one. not sure about the frequency for that matter either. I gotta dig up my math book and figure this out. in the meantime any suggestions for what this is outputing would be greatly appreciated! thanks.
 
Jeff
Christian Meesters <[EMAIL PROTECTED]> wrote:
HiPawel Kraszewski wrote:> 4. The answer is symmetrical - usually you take only half of it. I > don't> remember the exact difference between the halves, but you may find it > in any> article on FFT.The real part is identical the imaginary part has the opposite sign ("same amplitude, opposite phase").Jeff Peery wrote:> thanks for the help. I think I'm understanding this a bit better. > although I still don't completely understand the output. here is an > example... for the input I have 1024 samples taken from a 1 Hz square > wave with amplitude = 1. for the output I would expect an infinite > number of frequencies. the output from FFT.fft(myData).real is this:>> .> .> .> -0.498 1> 0.0 2> -0.498 3> 0.0 4> -0.498 5&g!
 t; 0.0
 6> -0.498 7> 0.0 8Frankly, I don't understand this. After your description I thought your input is like "array([0, 1, 0, ..., 1, 0, 1])". But this can't be. Could you show us how exactly your input array looks like?And how do we have to read your output? Is this a 1d-array? What do the two numbers per line mean?CheersChristianPS Sorry for the late reply.___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] fourier transform

2005-08-03 Thread Jeff Peery
Hi again, is there a good reason why the output is dependant upon the sampling rate. in the example if you increase from say 64 to 128 samples the output increases by a factor of 2.
 
Christian Meesters <[EMAIL PROTECTED]> wrote:
Hi Jeff,On 3 Aug 2005, at 02:03, Jeff Peery wrote:> hope this is more clear. from the output I would expect that two > spikes appear with amplitude = 1. [snip]> I don't understand the output amplitudes. they should all be zero > except for at one herz it should be one. not sure about the frequency > for that matter either. I gotta dig up my math book and figure this > out. in the meantime any suggestions for what this is outputing would > be greatly appreciated! thanks.>  Yes, well, the math book idea might be a good one ;-). No, but seriously: You are just making a little mistake. First of all you are NOT exactly calculating a Fourier transform but a numerical estimation of it (you are dealing with an array of discrete data points, which is unavoidable when dealing with comp!
 uters
 ;-)). Look on your sine wave. Is it a perfect one? Then, what do you see when you plot your data? Some 'noise' and one little peak. The noise is due to errors which have to do with floating point arithmetics (see http://docs.python.org/tut/node16.html). It's really small and in most cases I'm sure it's neglectable as well.But when looking on your idea of what you would expect, I'm wondering whether you actually want a power spectrum estimation (see http://mathworld.wolfram.com/PowerSpectrum.html)? TrymyFFT = abs(fft.fft(inp))instead ofmyFFT = fft.real_fft(inp)This a least might come close to what I think you want to see, right?You might have a look onmyFFt = fft.fft(inp).realas well, because it might make things to appear a little clearer.One more remark: Try to avoid overwriting python key words like 'input'.Hope this helped.CheersChristianPS Here is !
 the code
 I used. It looks a bit different from yours - I hope the comments help a bit:from numarray import *import numarray.fft as fft#at least one of the numbers should be floating point hereperiod = 1.0#use numarray's / Numpy's pi instead of 3.14...inp = sin(arange(0,64)*pi*2/64.0)myFFT = abs(fft.fft(inp))#or#myFFt = fft.fft(inp).real#or#myFFT = fft.real_fft(inp)#depending on what you really wantdtime = period/64.0dfreq = 1.0/dtimefor i in range(len(myFFT)):print myFFT[i], dfreq*i___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] imbedding python into another program?

2005-08-03 Thread Jeff Peery
Andre, thanks for the help with this. I put it to work yesterday and it works perfectly.
 
was wondering if it is possible to import modules without a users having to type 'import whatever'. for example in my application I would like the user to just start operating on arrays that exist in my program. But I have to load both the arrays and Numeric into the python shell that I created. how can I do this? thanks.André Roberge <[EMAIL PROTECTED]> wrote:
Jeff Peery wrote:> hello, is it possible to add something like the python IDLE into> another program, say if I wanted to simply run scripts from within a> wxPython program? Could someone point me to the correct reference?> thanks.> Hi Jeff,you may want to have a look at PyCrust, PyShell and the like.I do something like this in my rur-ple app (on sourceforge).The relevant lines of code are:import wx.py as py[inside a wx.Notebook]win = py.shell.Shell(self.window, -1,introText = tr.INTERPRETER_INTRO_TEXT)self.window.AddPage(win, tr.PYTHON_INTERPRETER)HTH,André___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] commercial use of python?

2005-08-03 Thread Jeff Peery
hello, I was wondering about the license agreement for python. if I use python to create an application that is intended to sell commercially for profit is that violating the agreement listed in www.opensource.com? Or is that only for the interpreter? for example if I embed the python interpreter into a application written in pthon that is intended to be sold for profit is that violating the license agreement? 
 
thanks.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] fftpack

2005-08-04 Thread Jeff Peery
Hello, does anyone know how to open the fft function? I want to view it in the IDLE although the only file i have is the fftpack.pyd which I beleive is a compiled file and it looks like mush.
 
 ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] fyi - re: fft

2005-08-04 Thread Jeff Peery
hello, thought I'd post my progress with fiddling with the FFT.
 
import FFT
 
I've been using fft by taking the real part with: myFFT = abs(FFT.fft())
 
the returned values are the fourier coefficients starting with a0
 
the old thing is that the output is symmetrical about N/2 where n>N/2 is the negative frequencies. also all outputs are multiplied by N, so to get anything meaningful (at least in my case) you must divide the output by N. so to get a0 you want myFFT[0]/float(N).
 
I compared several inputs with the output and I also used the output to calculate the fourier series and it all looks like it should.
 
thanks for those that had input.
 
Jeff
 
thats all I got.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] whats the best way to structure my data?

2007-05-10 Thread Jeff Peery
hello, I was wondering what might be the best way to structure my data within 
python. I am sampling data points, and in each there is a time, value, and text 
string associated with that sample. so I was thinking I'd make a list of 
'measurement objects' and each object would have the attributes: time, value, 
and text... but I want to operate on the numerical values to find the average 
and stdev... so I'm not sure how to operate on my data if it is inside an 
object.

right now I have three arrays, a date array, a value array, and a text array. 
so I can operate on each array without trouble. but it'd be cleaner in my code 
and easier to deal with if I had a list of these measurement objects.

for example:

# a class for my measurements
class measurement:
def __init__(self):
self.text = ''
self.value=0
self.time=datetime.today()

# I start with an empty list
measurements = []

# as I collect data in my code I append an object to the list
measurements.append(sample)
measurements[-1].value = value
measurements[-1].text = text
measurements[-1].time = time

# now I don't know what to do here. I want the mean of all my data
# but I need a list or array to operate on but instead my data is inside each 
object
# I don't really want to make a temporary array, is there a way to operate on 
the
# data in all my objects as if it were an array or list?

mean = numpy.mean()

is there a way to operate on the data when it is structured like this?

thanks.
Jeff


  
-
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] whats the best way to structure my data?

2007-05-10 Thread Jeff Peery
ok, thanks. so is there a difference in performance if I do it this way versus 
if I use say a numpy function on an array? thanks.
 
 Jeff

John Fouhy <[EMAIL PROTECTED]> wrote: On 11/05/07, Jeff Peery  wrote:
> hello, I was wondering what might be the best way to structure my data
> within python. I am sampling data points, and in each there is a time,
> value, and text string associated with that sample. so I was thinking I'd
> make a list of 'measurement objects' and each object would have the
> attributes: time, value, and text... but I want to operate on the numerical
> values to find the average and stdev... so I'm not sure how to operate on my
> data if it is inside an object.
[...]
> mean = numpy.mean()
>
> is there a way to operate on the data when it is structured like this?

You could use a list comprehension or a generator expression.

eg:

mean = sum(m.value for m in measurements)/len(measurements)

Also, here is an alternative way you could store your data: as a list
of tuples.  You could write code like:

# measurements is a list of tuples.  Each element is a triple (value,
text, time).
measurements = []

Then, later on, when you get a new measurement, something like:

measurements.append((value, text, time))

You can find the mean in the same way:

mean = sum(m[0] for m in measurements)/len(measurement)

-- 
John.


  
-
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] locking files

2007-06-13 Thread Jeff Peery
does anyone know if there is a way in python to lock a file so others cannot 
open it, or can only read it? I have a program that read/writes to a file and I 
would like to lock others out of it while I'm operating on it. 
   
  thanks.
   
  Jeff

 
-
We won't tell. Get more on shows you hate to love
(and love to hate): Yahoo! TV's Guilty Pleasures list.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] performance

2007-09-16 Thread Jeff Peery
Hello, 
  I've got a quick question regarding performance of lists. I am taking 
measurements and building up a list of objects for each measurement. the class 
I created for the objects has attributes of time, numerical value, person's 
name who collected the sample etc. I also have functions within my class (I 
think they are properly named 'accessors'?) that get a piece of data within the 
object, for example 'self.GetSampleTime()'. I'm wondering what happens to my 
performance as I add more accesors to my class. How are the accesors managed? 
will each object in my list of objects contain the data for each accesor or do 
all the objects look to the sample module for the accesor? will my list of 
objects become huge and slow as I add more accessors? thanks.
   
  Jeff

   
-
Don't let your dream ride pass you by.Make it a reality with Yahoo! Autos. ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pickle question

2007-09-25 Thread Jeff Peery
hello, 
   
  I have a question about the pickler. I'm using it to save objects in a 
program of mine that I can later reload to use. I was wondering how the pickle 
works and how it references the class module when I unpickle the pickled 
objects. for example I save some objects using the pickler, then I continue to 
develop my program so the class module is changed and additional attributes and 
methods are added. What happens now when I unpickle the pickled data and try to 
operate on it using the new methods and new attributes?
   
  here's an example if I didn't explain myself well...
   
  I create a class of data called 'var'
   
  class var:
def __init__(self):
self.data = numpy.array([1,2,3,4])
  self.color = 'blue'
   
  def operate(self):
return self.data+1
   
  now create the instance: 
  myVariable = var()
  I then pickle it to some file. and now I continue to develop my class module:
   
  class var:
def __init__(self):
self.data = numpy.array([1,2,3,4])
  self.color = 'blue'
  self.name = 'bob'
   
  def operate(self):
return self.data+1
   
  def GetName(self):
return self.name
   
  So now I unpickle my object from before using my new program. and I use 
MyVar.GetName(). does this work? If not, how do people usually handle this type 
of problem? or do they not use the pickler to save program data?
   
  big thanks!
   
  Jeff

   
-
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel 
and lay it on us.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] setstate trouble when unpickling

2008-01-24 Thread Jeff Peery
Hello,
   
  I've got a fairly simple class instance that I'm pickling. I'm using setstate 
to update the instance when I unpickle. Although the setstate doesn't seem to 
be called upon unpickling... here's an example, if anyone see's what I'm doing 
wrong, please let me know. Thanks!
   
  so I say start out with this class:
   
  class dog:
  def __init__(self):
  self.num_legs = 4
   
  then I pickle the instance of:
  sparky = dog()
   
  then I update my dog class to:
  class dog:
  def __init__(self):
  self.hair_color = 'brown'
  self.num_legs = 4
   
  def __setstate__(self, d):
  if 'hair_color' not in d:
  d['hair_color'] = 'brown'
  self.__dict__.update(d)
  print 'did this work?'
   
  Now when I unpickle the original pickled object sparky I would hope to see 
'did this work' and I would also hope that sparky would have updated to have 
the attribute 'hair_color' but nothing of the sort happens. if just unpickles 
sparky without updating the attributes as I was hoping.
   
  Thanks!
   
  Jeff



   
-
Never miss a thing.   Make Yahoo your homepage.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] distutils?

2005-08-10 Thread Jeff Peery
Hello, I was wondering what is the difference between the distutils core and py2exe... they look the same to me? thanks.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] changes made if IDLE not updating when application executed?

2005-08-11 Thread Jeff Peery
Hello, I am running  a script I wrote with IDLE. if I edit the script them hit 'F5' to run it again, it seems to run the old script prior to the last save. I have to close down the IDLE then start it again and hit 'F5' to get the changes to execute. is there a way to fix this?
 
Jeff___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] reading excel and access files

2005-08-22 Thread Jeff Peery
hello, can python read excel and access files? If so where do I go to read about how this would work? thanks.
 
Jeff___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reading excel and access files

2005-08-23 Thread Jeff Peery
Great, this is lots of good info. thanks everyone for your input!
 
JeffKent Johnson <[EMAIL PROTECTED]> wrote:
Jeff Peery wrote:> hello, can python read excel and access files? If so where do I go to > read about how this would work? thanks.There are some resources here that might be helpful:http://www.python.org/pypi?%3Aaction=search&name=&version=&summary=&description=&keywords=excel&_pypi_hidden=0Kent___Tutor maillist - Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] installation programs

2005-09-21 Thread Jeff Peery


Hello, I want to create an installation program. Can anyone tell me what the best program would be to use... maybe inno setup or install shield? do these work with python programs? do they require programming in another language? thanks.
 
Jeff___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] hiding a notebook page

2005-09-28 Thread Jeff Peery
hello, I'm using wxpython to write a windows app. I want to be able to hide a page in a notebook and I'm not sure how to do it. functionally its the same as doing:
 
notebook.Show(False)
 
but I want that to work for just one notebook page and not the whole notebook. I tried the wxpython list but didn't have much luck. any help would be much appreciated. thanks!
 
Jeff___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2005-10-12 Thread Jeff Peery
hello, I am trying to find the source code for FFT. I found the FFT.py module athough I cannot find the actual code that runs the FFT. Is it in a compiled form or can I view its source?
 
thanks.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] comiling python to microchip?

2005-10-12 Thread Jeff Peery
is it possible to take python code and compile it for use in a microprocessor?___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2005-11-10 Thread Jeff Peery
 
 
		 Yahoo! FareChase - Search multiple travel sites in one click.

 

 ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] (no subject)

2005-11-10 Thread Jeff Peery
 
 
		 Yahoo! FareChase - Search multiple travel sites in one click.

 

 ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] numeric typeError

2005-11-10 Thread Jeff Peery
hello, I'm getting this strange error:
 

myArray1[1:2]   = myArray2[3:4]
 
TypeError: Array can not be safely cast to required type
 
everytime I try to copy a slice from one array to the next this error occurs. the slices are the same size and I initialized the arrays using Numeric.zeros(10, 'Float').
 
anyone have an idea why this happens? thanks.
 
Jeff
		 Yahoo! FareChase - Search multiple travel sites in one click.

 

 ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] PLC communication with python?

2006-03-07 Thread Jeff Peery
Hello, I would like to write a python script that communicates with a  PLC (programmable logic controller) as well as instruments like  calipers and things. I'm completely in the dark here and not sure where  to start reading and learning. could someone point me in the right  direction for learning this stuff? thanks!Jeff  
		Yahoo! Mail
Bring photos to life! New PhotoMail  makes sharing a breeze. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] numpy speed problems

2006-06-09 Thread Jeff Peery
hello, I am having some trouble with the speed of numpy. I'm crunching some numbers (see the attached script) and in total I have 1,000,000 grid points over which I am integrating. I'm doing a bunch of adding, mulitply, divide, powers, etc, but in total there are 1,000,000 points to do these operations over and it really shouldn't take this long... as far as I know. my last simulation took about 8+ hours.What might I be doing wrong in my code to cause this to be so slow? big thanks!!Jeff __Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com from numpy import *

"""
function definitions
"""
def GetPressure(x_coord, y_coord, x_r, y_r, z_r, dx, dy, w_mn, rho, v_mn, k_mn, 
n, m):
#   intialize pressure
p   = 0.0 + 1j

#   sum contributions from all point sources to receiver
for ii in range(n):
for jj in range(m):
r   = ((x_r  - x_coord[ii])**2.0 + (y_r - y_coord[jj])**2.0 + (z_r 
- 0.0)**2)**0.5
p   +=  (1j*w_mn*rho*v_mn[ii][jj])*exp(1j*k_mn*r)*dx*dy/(2.0*pi*r)

p   = sqrt(p*conjugate(p))
return abs(p)


"""
vaiables and constants
"""

"""problem definition parameter"""
n   = arange(1,70) #mode number in x direction
m   = arange(1,70) #mode number in y direction
mode_n  = 10  #mode number - 1
mode_m  = 10   #mode number - 1
L   = 1.2   #piston length(m)
W   = 0.6   #piston width(m)

"""material properties fluid"""
c   = 343.0 #speed sound in water  (m/s)
rho_a   = 1.21  #density of air (kg/m^3)

"""piston material properties"""
E   = 7.0e10#youngs modulus (N/m^2) (stainless 
steel)
nu  = 0.29  #poisson's ratio (stainless steel
rho = 2700.0#density of piston (stainless steel) 
(kg/m^3)
t   = 0.0015#piston thickness (m)

"""wave speed, wave number, frequency"""
c_l = (E/(rho*(1 - nu**2)))**0.5#longitudinal wave speed in 
piston
k_x = n*pi/W#wave number x direction
k_y = m*pi/L#wave number y direction
k_mn= (k_x[mode_n]**2 + k_y[mode_m]**2)**0.5#bending wave number for n 
and m mode
w_c = (c**2)/(1.8*c_l*t)#critical frequency (Hz)
w_mn= (k_mn**2)*1.8*c_l*t/(2.0*pi)**2   #frequency for n and m (see 
notes 5/15/06)
k_c = 2.0*pi*(w_c/(1.8*c_l*t))**0.5 #critical wave number
k_a = 2.0*pi*w_mn/c#wave number in 
acoustic medium (air)

"""piston grid"""
dx  = 1.0/k_a   #x direction step in space   (m)
dy  = 1.0/k_a   #y direction step in space   (m)

if dx < 0.005:
dx = 0.005
dy = 0.005

num_y   = int(L/dy) #number of nodes in y direction
num_x   = int(W/dx) #number of nodes in x direction

#piston grid coordinates
x_coord = arange(num_x, dtype=float)*W/num_x - W/2.0
y_coord = arange(num_y, dtype=float)*L/num_y - L/2.0

"""field grid"""
a   = 1
b   = 50
d   = 50
x_r = arange(a, dtype=float)*1.0/float(a) #x position of receiver  (m)
y_r = arange(b, dtype=float)*1.0/float(b) #y position of receiver  (m)
z_r = arange(d, dtype=float)*10.0/float(d)#z position of receiver  (m)

"""acoustic variables"""
p   = 0 #amplitude of pressure at receiver   
(Pa)
r   = 0 #distance from origin to receiver(m)
p_field = zeros((a,b,d), dtype=float)   #pressure field  (m)

"""calculate piston surface velocity amplitude"""
U_mn= zeros((len(x_coord), len(y_coord)), dtype=float)
for i in range(len(x_coord)):
for j in range(len(y_coord)):
#amplitude of piston surface displacement
U_mn[i][j] = 
sin(n[mode_n]*pi*(L/2.0+x_coord[i]))*sin(m[mode_m]*pi*(W/2.0+y_coord[j]))
#amplitude of piston surface velocity(m/s)
V_mn   = w_mn*U_mn


"""
numerical integration of Raleigh's equation
"""
for i in range(a):
for j in range(b):
for k in range(d):
p_field[i][j][k] = GetPressure(x_coord, y_coord, x_r[i], y_r[j], 
z_r[k], dx, dy, w_mn, rho, V_mn, k_mn, num_x, num_y)
print '%d Percent Complete'%(100.0*j/b)

p_field = 20.0*log10(p_field)

fileHandle  = file('beam pattern.dat', "w")
fileHandle.write('TITLE = "HW 4"\n')
fileHandle.write('VARIABLES = "x"\n"y"\n"z"\n"pressure"\n')
fileHandle.write('ZONE T="%s"\n' % 'pressure field')
fileHandle.write('I=%d, J=1, ZONETYPE=Ordered\n' % (a*b*d))
fileHandle.write('DATAPACKING=POINT DT=(DOUBLE DOUBLE DOUBLE DOUBLE)\n')
for ii in range(a):
for jj in range(b):
for kk in range(d):
fileHandle.write('%f %f %f %f\n' % (x_r[ii], y_r[jj], z_r[kk], 
p_field[ii

[Tutor] treelistctrl help!

2006-06-28 Thread Jeff Peery
hello, I'm having some trouble with treelistctrl in wx python and I was  wondering if there is someone who would share their code as an example.  thanks!Jeff   
		Do you Yahoo!? Everyone is raving about the  all-new Yahoo! Mail Beta.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] modbus communication with python?

2006-07-05 Thread Jeff Peery
Hello, I need to talk read write to a modbus so that I can work with a PLC. I have not a clue how this all works. does python have a modbus module or where might I look to find how to do this? thanks.Jeff 
		Do you Yahoo!? Everyone is raving about the  all-new Yahoo! Mail Beta.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] modbus communication with python?

2006-07-05 Thread Jeff Peery
Hello, I need to talk read write to a modbus so that I can work with a PLC. I have not a clue how this all works. does python have a modbus module or where might I look to find how to do this? thanks.Jeff 
		How low will we go? Check out Yahoo! Messenger’s low  PC-to-Phone call rates.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to post an event?

2006-07-07 Thread Jeff Peery
Hello, I am having a bit of trouble figuring out how to post an event. I attached my sample program. I assigned a button event to each button in the program. I want to post an event when the second button is pressed that executes the first button. thanks.Jeff 
		Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.#!/usr/bin/env python
#Boa:App:BoaApp

import wx

import Frame1

modules ={'Frame1': [1, 'Main frame of Application', 'Frame1.py']}

class BoaApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
self.main = Frame1.create(None)
self.main.Show()
self.SetTopWindow(self.main)
return True

def main():
application = BoaApp(0)
application.MainLoop()

if __name__ == '__main__':
main()
#Boa:Frame:Frame1

import wx

def create(parent):
return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, 
] = [wx.NewId() for _init_ctrls in range(3)]

class Frame1(wx.Frame):
def _init_coll_boxSizer1_Items(self, parent):
# generated method, don't edit

parent.AddWindow(self.button2, 1, border=10, flag=wx.ALL | wx.GROW)
parent.AddWindow(self.button1, 1, border=10, flag=wx.ALL | wx.GROW)

def _init_sizers(self):
# generated method, don't edit
self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)

self._init_coll_boxSizer1_Items(self.boxSizer1)

self.SetSizer(self.boxSizer1)

def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
  pos=wx.Point(467, 234), size=wx.Size(324, 386),
  style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
self.SetClientSize(wx.Size(316, 359))

self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='button1',
  name='button1', parent=self, pos=wx.Point(10, 189),
  size=wx.Size(296, 159), style=0)
self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
  id=wxID_FRAME1BUTTON1)

self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label='button2',
  name='button2', parent=self, pos=wx.Point(10, 10),
  size=wx.Size(296, 159), style=0)
self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
  id=wxID_FRAME1BUTTON2)

self._init_sizers()

def __init__(self, parent):
self._init_ctrls(parent)

def OnButton1Button(self, event):
print 'hello'

def OnButton2Button(self, event):
event.Skip()
"""what do I do here to post an event that executes 'OnButton1Button()' 
?"""
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to post an event?

2006-07-10 Thread Jeff Peery
Ah, yes it works, thanks. I had previously tried to simply call the function (OnButton1Button() from OnButton2Button()) instead of posting an event but I guess I did this wrong and abandoned the effort assuming that it wouldn't work. Anyhow, I got it working now, thanks again!JeffAlan Gauld <[EMAIL PROTECTED]> wrote: > Hello, I am having a bit of trouble figuring out how to post an > event.Do you really need to post an event?>self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,>  id=wxID_FRAME1BUTTON2)could you just bi8nd the same method to both buttons?>def OnButton1Button(self, event):>print 'hello'>>def OnButton2Button(self, event):>event.Skip()>"""what do I do here to post an
 event that executes > 'OnButton1Button()' ?"""Or could you call OnButton1Button(self,event) directly?Does it have to involve an event being posted to the Q - sometimesneeded I know but not often...Alan G.>  
		Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] modbus communication with python?

2006-07-11 Thread Jeff Peery
okay, yes thank you! I have seen this, although I looked a the code and it appears that this is actually a modbus server (please correct me if I am wrong, I am really new to modbus and PLC's). We are already using a modbus server (KEPDirect for PLC's, automation direct) and I beleive we are using a Koyo PLC. but I simply want to read and write values stored on the modbus server, I don't actually want to create a new server. I'm not sure that this module is the way to go (although again I might be wrong), what might be my other options and where should I go to learn about this? thanks!JeffJason Massey <[EMAIL PROTECTED]> wrote: Googling for modbus python turned up:https://lintouch.org/repos/lintouch/lsp-modbus/trunk/tests/ On 7/5/06, Jeff Peery <[EMAIL PROTECTED]> wrote: Hello, I need to talk read write to a modbus so that I can work with a PLC. I have not a clue how this all works. does python have a modbus module or where might I look to find how to do this? thanks. JeffHow low will we go? Check out Yahoo! Messenger's low   PC-to-Phone call rates. ___Tutor maillist  -  Tutor@python.org http://mail.python.org/mailman/listinfo/tutor  
		Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python processing of web html forms

2006-08-03 Thread Jeff Peery
Hello, I want to use python to process information input into a HTML form on my website. how is this typically performed? I saw cherrypy and also quixote for web python stuff... I have no experience with python on the web. Thanks.jeff 
		Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] threading

2006-08-15 Thread Jeff Peery
hello, how do I stop a thread? do I need to kill it or can I simply call a stop function... kinda like the start function? I read a bit on google and it sounded like using a kill isn't recommended for some reason... so how is this thing stopped? thanks!Jeff 
		Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] threading

2006-08-15 Thread Jeff Peery
h, ok, well that is what I am currently doing but something is causing it to continue... guess I have some digging around to do. thanks for the help!JeffJohn Fouhy <[EMAIL PROTECTED]> wrote: On 16/08/06, Jeff Peery <[EMAIL PROTECTED]> wrote:> hello, how do I stop a thread? do I need to kill it or can I simply call a> stop function... kinda like the start function? I read a bit on google and> it sounded like using a kill isn't recommended for some reason... so how is> this thing stopped? thanks!The only good way for a thread to stop is for its run() method to exit.It kinda depends what your thread is doing, and what technique you areusing to keep it alive, but one possibility is to do something like:class Worker(threading.Thread):def run(self):   
 self.running = Truewhile(self.running):# do stuffdef stop(self):self.running = FalseIn this case, the you call .stop() on your Worker object, and thethread will exit when it next gets to the top of the while loop.-- John. 
		Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls.  Great rates starting at 1¢/min.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how do I find where my program is installed?

2006-09-06 Thread Jeff Peery
hello, I created an executable using py2exe and innosetup for windows. I need to figure out where the user has installed my program so that I can direct the program to the installation files that it needs to run. I ran into this problem because I have a file type that my program reads and I have registered this type in the windows registry so that when this file type is double clicked my application is launched. when this happens my program thinks the working directory is the directory where that registered file was located... not the installation directory where it should be working in needless to say that lots of things go wrong when my program is launched this way. so I need to tell my program to set the working directory back to the installation directory... but where is this?thanks!Jeff 
		Stay in the know. Pulse on the new Yahoo.com.  Check it out. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how do I find where my program is installed?

2006-09-07 Thread Jeff Peery
Thanks Bill, I read the link you sent, and I am not sure what they mean by "You cannot rely on __file__, because __file__ is not there in the py2exed main-script." can't I use _file_ in my application though? This is what I just added to my application and it seems to do the trick... is there an exception that I am not aware of?using your method, what do you do with 'installDir' in py2exe?thanks for the help. [EMAIL PROTECTED] wrote: > way. so I need to tell my program to set the working directory back to the> installation directory... but where is this?>Here's what I do in my py2exe app:installDir = os.path.dirname(os.path.abspath(sys.argv[0]))and take a look at this
 link:http://www.py2exe.org/index.cgi/WhereAmIHTH,Bill 
		Do you Yahoo!? 
Get on board. You're invited to try the new Yahoo! Mail.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python shell not working like it used to

2007-02-25 Thread Jeff Peery
hello, I just upgraded to python 2.5 and wxpython 2.6. I'm not sure the correct 
list for this but I'm trying to shove some variables into a py shell using the 
below code. this worked pretty well before, but now it gives me an error on the 
last line of my brief example. The error is:
   
  'dict' object has no attribute 'this' 
   
  it occurs on line 171 in shell.py. so I looked in shell.py and it looks like 
this:
   
  def __init__(self, other):
"""Create a ShellFacade instance."""
d = self.__dict__
d['other'] = other
d['helpText'] = HELP_TEXT
d['this'] = other.this
   
  "other" here is the dictionary I pass in (I think), so it's for some reason 
looking for some attribute in my dictionary called 'this'. of course my 
dictionary doesn't have this attribute. I have no idea what this is. any ideas? 
my few lines of code are below.
   
   
  import py
  import wx.py as py
   
  partList = {'this is some dictionary':1}
  pyWindow2  = py.editor.EditWindow(py.editor.Editor, splitterWindow1, 
-1)
pyWindow1  = py.shell.Shell(splitterWindow1, -1, introText = None)
pyWindow1.interp.locals['partList'] = py.shell.ShellFacade(partList)

 
-
Never Miss an Email
Stay connected with Yahoo! Mail on your mobile. Get started!___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python shell not working like it used to

2007-02-26 Thread Jeff Peery
well the __init__() funciton is not my code, it is in:
 
 C:\Python24\Lib\site-packages\wx-2.6-msw-unicode\wx\py\shell.py
 
as I mentioned I upgraded wxpython... maybe I should email there... anyhow I 
just want to use my dictionary in the shell, but I'm not sure what the 
attribute 'this' is... it seems to be something different from my previous 
version of wxpython.

thanks. 
J

Alan Gauld <[EMAIL PROTECTED]> wrote: "Jeff Peery"  wrote 

>  def __init__(self, other):
>d['this'] = other.this
>   
>  "other" here is the dictionary I pass in (I think), 
> so it's for some reason looking for some attribute in 
> my dictionary called 'this'. 

other is whatever you pass in.
The code expects it to be dictionary like and to 
have a this attribute

> of course my dictionary doesn't have this attribute. 

So why is your code trying to access one if you know 
it doesn't exist? And why are you surprised at the 
error message? (Or is the init() not your code?)

> I have no idea what this is. any ideas? 

Youu seem to have answered your own question.
You are passing a dictionary into init() that does not 
have a this attribute but the code inside the init() is 
trying to access a this attribute. It can't find one so 
it raises an error.

Either remove the this access in init or add a thus 
attribute to your dictionary argument. Or pass an 
argument that does have a this attribute.

I'm slightly confused about what you are asking us to tell you?

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



-
Everyone is raving about the all-new Yahoo! Mail beta.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] recommendation for good OO book?

2007-03-07 Thread Jeff Peery
Hello, I've been using python for a few years now and I really like it. 
Although i am beginning to realize I really don't utilize this object oriented 
stuff in a good way. Does anyone have a favorite book regarding the 
basics/intro to object oriented programming, how to write good OO code??

thanks,
Jeff

 
-
Don't get soaked.  Take a quick peek at the forecast 
 with theYahoo! Search weather shortcut.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sorting data from multiple arrays

2007-03-22 Thread Jeff Peery
hello, I typically run into this problem and I'm not always sure of the most 
efficient way to handle it. I often work with multiple arrays of data, say 
arrays a, b, and c, and I want to sort the elements of b and c based on a. for 
example:

a = [3,2,1,4]
b = ['hi', 'my','name', 'is']
c = [5,2,4,2]

I order 'a' from small to large and do the same rearrangement to 'b' and 'c':
a = [1,2,3,4]
 b = ['name', 'my','hi', 'is']
 c = [4,2,5,2]

usually I do some terrible looking for loops and iterate over the whole 
mess is there a clean, efficient way to do this, or is there a nice 
function that would reorder the elements of b and c based on the soring of a?

thanks

 
-
Don't be flakey. Get Yahoo! Mail for Mobile and 
always stay connected to friends.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sorting data from multiple arrays

2007-03-22 Thread Jeff Peery
Thanks for all the responses, that is a huge help!

Jeff

Kent Johnson <[EMAIL PROTECTED]> wrote: Jeff Peery wrote:
> hello, I typically run into this problem and I'm not always sure of the 
> most efficient way to handle it. I often work with multiple arrays of 
> data, say arrays a, b, and c, and I want to sort the elements of b and c 
> based on a. for example:
> 
> a = [3,2,1,4]
> b = ['hi', 'my','name', 'is']
> c = [5,2,4,2]
> 
> I order 'a' from small to large and do the same rearrangement to 'b' and 
> 'c':
> a = [1,2,3,4]
> b = ['name', 'my','hi', 'is']
> c = [4,2,5,2]
> 
> usually I do some terrible looking for loops and iterate over the whole 
> mess is there a clean, efficient way to do this, or is there a nice 
> function that would reorder the elements of b and c based on the soring 
> of a?

Decorate-sort-undecorate 
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234)
to the rescue:

In [12]: a = [3,2,1,4]
In [13]: b = ['hi', 'my','name', 'is']
In [14]: c = [5,2,4,2]
In [15]: temp = zip(a, b, c)
In [16]: temp
Out[16]: [(3, 'hi', 5), (2, 'my', 2), (1, 'name', 4), (4, 'is', 2)]
In [17]: temp.sort()
In [18]: _, b, c = zip(*temp)
In [19]: b
Out[19]: ('name', 'my', 'hi', 'is')
In [20]: c
Out[20]: (4, 2, 5, 2)

Or, if you are a fan of one-liners:
In [21]: _, b, c = zip(*sorted(zip(a, b, c)))

Methinks there should be a clever way to do this with the key= argument 
to sort, but I can't think of it at the moment...

Kent


 
-
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel 
bargains.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sorting data from multiple arrays

2007-03-22 Thread Jeff Peery
... what is '*' in '*temp'? thanks!
J

Kent Johnson <[EMAIL PROTECTED]> wrote: Jeff Peery wrote:
> hello, I typically run into this problem and I'm not always sure of the 
> most efficient way to handle it. I often work with multiple arrays of 
> data, say arrays a, b, and c, and I want to sort the elements of b and c 
> based on a. for example:
> 
> a = [3,2,1,4]
> b = ['hi', 'my','name', 'is']
> c = [5,2,4,2]
> 
> I order 'a' from small to large and do the same rearrangement to 'b' and 
> 'c':
> a = [1,2,3,4]
> b = ['name', 'my','hi', 'is']
> c = [4,2,5,2]
> 
> usually I do some terrible looking for loops and iterate over the whole 
> mess is there a clean, efficient way to do this, or is there a nice 
> function that would reorder the elements of b and c based on the soring 
> of a?

Decorate-sort-undecorate 
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234)
to the rescue:

In [12]: a = [3,2,1,4]
In [13]: b = ['hi', 'my','name', 'is']
In [14]: c = [5,2,4,2]
In [15]: temp = zip(a, b, c)
In [16]: temp
Out[16]: [(3, 'hi', 5), (2, 'my', 2), (1, 'name', 4), (4, 'is', 2)]
In [17]: temp.sort()
In [18]: _, b, c = zip(*temp)
In [19]: b
Out[19]: ('name', 'my', 'hi', 'is')
In [20]: c
Out[20]: (4, 2, 5, 2)

Or, if you are a fan of one-liners:
In [21]: _, b, c = zip(*sorted(zip(a, b, c)))

Methinks there should be a clever way to do this with the key= argument 
to sort, but I can't think of it at the moment...

Kent


 
-
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] where to look for help with modbus TCP/IP

2007-04-05 Thread Jeff Peery
hello, I want to use python to communicate (pluck data out of registers) with a 
controller (walchem, 
http://www.walchem.com/nav/CMImage.aspx?CMID=0&Name=180277_Modbus_C.pdf). I 
found great documentation using python sockets and TCP/IP; however I am very 
unfamiliar with modbus and how modbus TCP/IP is related to TCP/IP. Does anyone 
know where I might find sample code or a good book describing how to do this? 
thanks.

Jeff

 
-
Sucker-punch spam with award-winning protection.
 Try the free Yahoo! Mail Beta.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] closing a internet explorer com object

2008-06-24 Thread Jeff Peery
hello,
  I'm using internet explorer to print out html documents and I'm not sure how 
to close it once it is created. How do I do this? below is the simple bit of 
code I use to print documents.
   
  thanks!
  Jeff
   
  ie = win32com.client.Dispatch("InternetExplorer.Application")
ie.Visible = 0
ie.Navigate(doc_name)
if ie.Busy: sleep(1)
# print the current IE document without prompting
# the user for the printerdialog
ie.ExecWB(win32com.client.constants.OLECMDID_PRINT, 
  win32com.client.constants.OLECMDEXECOPT_DONTPROMPTUSER)

   ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] executing a script from a script

2008-08-26 Thread Jeff Peery
Hello,

I have a simple wx app that I need some help with. This application uses the
serial ports to communicate with an industrial product. I first check that
my python application is compatible with the industrial product by asking
the industrial product for its revision number. If the revision number is
too old I want to kill my python application and launch an older python
application. To do this I am using the following:

 

# launch old program

execfile('theoldpythonprogram.py')

# kill this App (wx.Frame object)

self.Destroy()

 

The problem is that the self.Destroy() seems to kill both the current python
program and the one I just launched. How can I launch a new program and kill
the current one without killing the new one as well?

 

Thanks!

 

Jeff

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] file locations

2008-11-24 Thread Jeff Peery
  Hello,
  I have a wxapp from which I would like to execute another wxapp. the 'child' 
wxapp is located in a sub directory of the 'parent' wxapp. The problem I'm 
having is that I execute the child app from the parent app and it cannot find 
the modules/images/files etc that it needs because it is looking in the parents 
directory location and not its own. I want to keep the child wxapp in its own 
sub directory for organizational purposes, but what is the best way to deal 
with this problem?
   
  thanks,
  Jeff
  


   ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problem Automating Internet Explorer Printing

2011-05-04 Thread Jeff Peery
Hello,
I'm using the code pasted below to print a document. The code worked great on 
my XP machine. I moved it to my W7 machine and it gives the error below. The 
weird thing is that it works great if printing a html doc from the web (such as 
www.google.com), but it errors when printing a html doc from my desktop. The 
document loads as I can see it on the screen, but it chokes when printing.
any ideas?
thanks,
Jeff

line 23, in Print
win32com.client.constants.OLECMDEXECOPT_DONTPROMPTUSER)
File 
"C:\Python27\lib\site-packages\win32com\gen_py\EAB22AC0-30C1-11CF-A7EB-C05BAE0Bx0x1x1.py",
 line 1186, in ExecWB
, cmdexecopt, pvaIn, pvaOut)
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 456, in 
_ApplyTypes_
self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, 
-2147221248), None)
import win32com.client
from time import sleep
class Printer():
def __init__(self):
pass

def WaitBusy(self, ie):
while ie.Busy:
sleep(0.5)

def WaitUntilReady(self, ie):
while ie.ReadyState!=4:
sleep(0.5)

def Print(self, doc_name):
ie = win32com.client.Dispatch("InternetExplorer.Application")
ie.Visible = 1
ie.Navigate(doc_name)
# wait for ie to open before printing
self.WaitBusy(ie)
ie.ExecWB(win32com.client.constants.OLECMDID_PRINT,
win32com.client.constants.OLECMDEXECOPT_DONTPROMPTUSER)

## ie.Quit()
p = Printer()
p.Print('test.htm')

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading elements in a file

2011-05-04 Thread Jeff Peery
Greg,
You might try…

Import sting
delimiter = ‘.’
f = open('words.txt', "r")
lines = f.readlines()
for line in lines:
line_items = string.split(line,delimiter)


From: tutor-bounces+jeffpeery=seametrics@python.org 
[mailto:tutor-bounces+jeffpeery=seametrics@python.org] On Behalf Of Greg 
Christian
Sent: Wednesday, May 04, 2011 11:38 AM
To: tutor@python.org
Subject: [Tutor] Reading elements in a file

I am kind of stuck on what is probably a simple thing:

If we have a file of words like this: 
“first”,”word”,”in”,”that”,”another”,”part”,”of”,”this”

f = open('words.txt', "r")
words = f.read()

will read the whole file, is there a way to read just the words: first word in 
that another part of this

I guess I have to separate on the “,” but I am not quite sure how to go about 
this.

Any input would be appreciated.

Regards,

Greg
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] USB volume unique volume info

2012-01-09 Thread Jeff Peery
Hello,
I am writing a python script to install a program onto a customer computer from 
a USB drive. To prevent piracy, I want to know if the user has copied my 
install program to another USB drive. Do USB drives have some unique volume 
info or another feature that I might query to detect if the program is still 
operating on the original USB drive?

Thanks,
Jeff
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor