Force flushing buffers
Hi I have a python application that writes a lot of data to a bunch of files from inside a loop. Sometimes, the application has to be interrupted and I find that a lot of data has not yet been writen (and hence is lost). How do I flush the buffer and force python to write the buffers to the files ? I intend to put this inside the loop. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Force flushing buffers
[EMAIL PROTECTED] wrote: > > Madhusudan> How do I flush the buffer and force python to write the > Madhusudan> buffers to the files ? I intend to put this inside the > loop. > > f = open("somefile", "w") > f.write("foo") > f.flush() > > Skip Thanks !! -- http://mail.python.org/mailman/listinfo/python-list
Re: Force flushing buffers
Robert Wierschke wrote: > Madhusudan Singh schrieb: >> Hi >> >> I have a python application that writes a lot of data to a bunch >> of files >> from inside a loop. Sometimes, the application has to be interrupted and >> I find that a lot of data has not yet been writen (and hence is lost). >> How do I flush the buffer and force python to write the buffers to the >> files ? I intend to put this inside the loop. >> >> Thanks. > disable the buffer! > > open( filename[, mode[, bufsize]]) > > open takes an optional 3ed argument set bufsize = 0 means unbuffered. > see the documentation of the in build file() mehtod as open is just > another name Though I will not be using this solution (plan to use flush() explicitly) for speed reasons, thanks ! I will file this away for future reference :) -- http://mail.python.org/mailman/listinfo/python-list
Reading IEEE 754 format strings directly into a floating point array
I am querying an instrument in a measurement application. The values are returned as IEEE format binary floating point numbers. There are 4 bytes per point. Multiple points are not separated by any delimiter. Is it possible to read these directly into a floating point array of the size of the string ? Alternatively, I could write a routine to do it, but wanted to find out if there was a simpler solution. -- http://mail.python.org/mailman/listinfo/python-list
Length of read in in python-gpib
python-gpib provides Gpib.py (see end of post) for Linux. I am trying to use the method called read. I usually use it without arguments (the default length being 512). However, I am trying to read in a string with some 16,000 comma separated floating point numbers. So, I have to pass a length parameter much much larger than 512. As is stands, the default read takes in only about 35-40 numbers, so I need about 512/35*16000 ~= 230,000. Not being sure if I could make python read in something that big, I started small - with 1024. This produces an list of numbers that has a malformed first number (I get 88309e-9 instead of something like 6.788309e-9.). Could this be a bug ? Second, does the length need to be a power of two for some reason ? python-gpib is an excellent library, but it suffers from an utter lack of documentation. Gpib.py - import gpib RQS = (1<<11) SRQ = (1<<12) TIMO = (1<<14) class Gpib: def __init__(self,name='gpib0'): self.id = gpib.find(name) def write(self,str): gpib.write(self.id, str) def writebin(self,str,len): gpib.writebin(self.id,str,len) def read(self,len=512): self.res = gpib.read(self.id,len) return self.res def readbin(self,len=512): self.res = gpib.readbin(self.id,len) return self.res def clear(self): gpib.clear(self.id) def wait(self,mask): gpib.wait(self.id,mask) def rsp(self): self.spb = gpib.rsp(self.id) return self.spb def trigger(self): gpib.trg(self.id) def ren(self,val): gpib.ren(self.id,val) def ibsta(self): self.res = gpib.ibsta() return self.res def ibcnt(self): self.res = gpib.ibcnt() return self.res def tmo(self,value): return gpib.tmo(self.id,value) -- http://mail.python.org/mailman/listinfo/python-list
Re: Length of read in in python-gpib
Further, if I use 131072 (2^17) as the length, I get an error : Traceback (most recent call last): File "takedata.py", line 74, in ? x=sr.querytrca(srs,1,0,4000,131072) File "/home/labmonkey/code/oledpmt/sr830.py", line 62, in querytrca trca=sr.read(n) File "/usr/lib/python2.3/site-packages/Gpib.py", line 22, in read self.res = gpib.read(self.id,len) gpib.error: Read Error: ibrd() failed Following this, an attempt to run the script again chokes at the first (harmless - just setting some instrument parameter - ibwrt() fails) gpib command and then locks the bus, freezing the whole system unless I reboot the system. This has happened twice. I am using the Agilent82357a USB to GPIB convertor. Have used it for numerous purposes with the same setup, but the library seems to be choking on this new application. The instrument I am trying to use is an SR830 lockin amplifier. -- http://mail.python.org/mailman/listinfo/python-list
List of strings to list of floats ?
Is it possible to convert a very long list of strings to a list of floats in a single statement ? I have tried float(x) and float(x[:]) but neither work. I guess I would have to write a loop if there isn't a way. -- http://mail.python.org/mailman/listinfo/python-list
Re: List of strings to list of floats ?
[EMAIL PROTECTED] wrote: > > Madhusudan> Is it possible to convert a very long list of strings to a > Madhusudan> list of floats in a single statement ? > > Madhusudan> I have tried float(x) and float(x[:]) but neither work. I > Madhusudan> guess I would have to write a loop if there isn't a way. > > Try: > > >>> los = ["123.0", "2", "1e-6"] > >>> map(float, los) > [123.0, 2.0, 9.9995e-07] > >>> [float(s) for s in los] > [123.0, 2.0, 9.9995e-07] > > Skip Thanks. Now, a slightly more complicated question. Say I have two lists of floats. And I wish to generate a list of floats that is a user defined function of the two lists. I tried : def rpyth(x,y): r=sqrt(pow(x,2.0)+pow(y,2.0)) return r r1n=map(rpyth,x2n[1:len(x2n)-1],y2n[1:len(y2n)-1]) And I get an error complaining about floats. -- http://mail.python.org/mailman/listinfo/python-list
Re: List of strings to list of floats ?
Steve Holden wrote: > Madhusudan Singh wrote: >> [EMAIL PROTECTED] wrote: >> >> >>>Madhusudan> Is it possible to convert a very long list of strings to >>>a Madhusudan> list of floats in a single statement ? >>> >>>Madhusudan> I have tried float(x) and float(x[:]) but neither work. I >>>Madhusudan> guess I would have to write a loop if there isn't a way. >>> >>>Try: >>> >>>>>> los = ["123.0", "2", "1e-6"] >>>>>> map(float, los) >>>[123.0, 2.0, 9.9995e-07] >>>>>> [float(s) for s in los] >>>[123.0, 2.0, 9.9995e-07] >>> >>>Skip >> >> >> Thanks. Now, a slightly more complicated question. >> >> Say I have two lists of floats. And I wish to generate a list of floats >> that is a user defined function of the two lists. >> >> I tried : >> >> def rpyth(x,y): >> r=sqrt(pow(x,2.0)+pow(y,2.0)) >> return r >> >> r1n=map(rpyth,x2n[1:len(x2n)-1],y2n[1:len(y2n)-1]) >> >> And I get an error complaining about floats. > > ... but the error message is a secret so you don't want to tell us what > it was? It's more helpful if you actually copied and pasted the exact > error traceback you see, as this avoids any potential answerer having to > guess what went wrong. > > A brief description of what you were trying to do is also helpful, since > it isn't obvious at first glance why you are omitting some of hte list > elements. > > regards > Steve I apologize for that. The error message is : Traceback (most recent call last): File "takedata.py", line 163, in ? r1n=map(rpyth,x2n[1:len(x2)-1],y2n[1:len(y2)-1]) File "takedata.py", line 15, in rpyth r=sqrt(pow(x,2.0)+pow(y,2.0)) TypeError: a float is required I understand why the error is occuring (pow is not overloaded to accept lists of floats instead of floats ?). How do I fix this ? -- http://mail.python.org/mailman/listinfo/python-list
Re: List of strings to list of floats ?
Erik Max Francis wrote: > Madhusudan Singh wrote: > >> Thanks. Now, a slightly more complicated question. >> >> Say I have two lists of floats. And I wish to generate a list of floats >> that is a user defined function of the two lists. > > result = [sqrt(x**2 + y**2) for x, y in zip(xs, ys)] > Works perfectly. Thanks ! -- http://mail.python.org/mailman/listinfo/python-list
Converting 2bit hex representation to integer ?
Hi I am using binascii.b2a_hex to convert some binary data to hex. The result is a two bit hex representation (i. e., without the leading 0x). How do I convert the resulting two bit representation into an integer ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting 2bit hex representation to integer ?
Larry Bates wrote: > Can you give us an example. I don't know what two bit > hex means (takes at least 4 bits to make a hex digit). Like 64(base 16)=100. I am referring to 64 in the above. > > Now I'm going to try to guess: > > If the data is binary then all you need to do is to > use the struct.unpack module to convert to integer. Doesn't unpack presume that the input is a string ? If so, is it safe to convert binary data to string using str() ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting 2bit hex representation to integer ?
Madhusudan Singh wrote: > Larry Bates wrote: > >> Can you give us an example. I don't know what two bit >> hex means (takes at least 4 bits to make a hex digit). > > Like 64(base 16)=100. > I am referring to 64 in the above. > >> >> Now I'm going to try to guess: >> >> If the data is binary then all you need to do is to >> use the struct.unpack module to convert to integer. > > Doesn't unpack presume that the input is a string ? If so, is it safe to > convert binary data to string using str() ? Followup to this : I just tried : n=str(x) print struct.unpack("b",n) I get (51,) The corresponding output of binascii.b2a_hex(x) is 33. And 51_10=33_16. So that checks out. What is the deal with the parenthesis and the comma ? -- http://mail.python.org/mailman/listinfo/python-list
GUI programming, embedding, real time plots, etc.
Hi I am still a rookie at python (can do some basic programming with the language), and have been using python gpib and matplotlib to control my instruments and do real time plots. Since I have more than one instrument to control, I was thinking of writing a GUI using Tkinter (looked at Page, but it not have a debian package and I saw quite a few bugs listed - Tkinter seems mature). I have some questions : 1. In using matplotlib (my code essentially involved creating a plot and show()'ing it inside a loop), the color of the plot changed. Is there a way to tell matplotlib to not treat each new invocation as a new plot, but to really overwrite the old one ? 2. Is it possible to embed the matplotlib o/p in the o/p GUI ? 3. Are there some other caveats that I should be aware of in using matplotlib ? -- http://mail.python.org/mailman/listinfo/python-list
Point and click GUI builder for Python
Is there such a thing for python ? Like Qt Designer for instance ? -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI programming, embedding, real time plots, etc.
[EMAIL PROTECTED] wrote: > apt-get install python-pwm > this will get you python mega widgets > one of the dependencies that apt will take care of for you is the > python2.whatever-tk. > depending on which version of debian you are using. > i run sarge with python 2.3 Thanks for the help. I tried to write a piece of code to plot some simulated data from a measurement : from Tkinter import * import Pmw steps=(0,) voltages=(0,) master=Tk() plot=Pmw.Blt.Graph(master) plot.pack(expand=1,fill='both') for i in range(1,10): steps=steps+(i,) setvolt=1.0*i/100 voltages=voltages+(setvolt,) plot.line_create("Plot",xdata=steps,ydata=voltages) master.mainloop() This quits with : Traceback (most recent call last): File "", line 15, in ? File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwBlt.py", line 266, in line_create self.tk.call((self._w, 'line', 'create', name) + self._options(kw)) _tkinter.TclError: element "Plot" already exists in ".-1222950836" Now, if I try to plot from outside the loop (move the last statement in the loop out of it), it plots ok. I need to plot this in realtime. So, what would be the best approach ? -- http://mail.python.org/mailman/listinfo/python-list
Chopping off spaces at both ends
Hi I am a newbie to python and am using it to interface some of my lab equipment. How does one get rid of spaces at both ends of a string ? A little like the trim() intrinsic in fortran 95. One of my instruments is returning a string that has one or more blanks in it, and that is complicating string matching tests in one of my functions. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Optional assignments ?
Hi Is it possible to have something like : a,b,c,d=fn(that returns 10 return values) ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Optional assignments ?
Robert Kern wrote: > Madhusudan Singh wrote: >> Hi >> >> Is it possible to have something like : >> >> a,b,c,d=fn(that returns 10 return values) ? > > a,b,c,d = fn()[:4] > Thanks ! -- http://mail.python.org/mailman/listinfo/python-list
Embedding a runtime graph in Qt3 designer generated UI
Hi Two questions : 1. Is it possible to use an import command in a qt3 designer code ? (I know that it is possible to write python inside the braces -- but is it possible to use an import command for some rather large libraries I wrote that I need to access ?). 2. In the same vein, how does one embed a runtime plot in a qt3 UI ? It will need to be a python solution since I am using python libraries to acquire the data. -- http://mail.python.org/mailman/listinfo/python-list
Adding custom widgets to Qt Designer
Hi I am trying to add a QwtPlot widget to Qt Designer. I have both PyQwt and libqwt installed. I first tried to add a Custom Widget from /usr/include/qwt/qwt_plot.h as QwtPlot. But I do not know what slot to add. If I add the widget so created, and double click on it, I am asked if I want to create a new ui.h. It does not seem that the widget was added correctly. I then found a link : http://www.pycs.net/lateral/stories/27.html Now, I do have a file qplt.py, but the above link presumes that the ui.h file is created before py file is generated using the pyuic translator. So, how does one add this new widget ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
pyuic and Qt Designer plugins
Hi I managed to compile and install the FileChooser plugin (.so file) in /usr/share/qt3/plugins/designer and use it in my form in Designer. Then I tried to use pyuic which generated the .py code from the ui file. An attempt to execute the python file quits with : Traceback (most recent call last): File "measure.py", line 16, in ? f = MEASURE() File "/home/m_singh/measure.py", line 422, in __init__ self.fileChooser1 = FileChooser(self.groupBox4,"fileChooser1") NameError: global name 'FileChooser' is not defined The wrapper in my .py file : from qt import * from measure import * import sys if __name__ == "__main__": app = QApplication(sys.argv) f = MEASURE() f.show() app.setMainWidget(f) app.exec_loop() What do I need to do to include the FileChooser plugin ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding a runtime graph in Qt3 designer generated UI
Phil Thompson wrote: >> 2. In the same vein, how does one embed a runtime plot in a qt3 UI ? It >> will >> need to be a python solution since I am using python libraries to acquire >> the data. > > Have a look at PyQwt which is a set of Python bindings for the Qt-based > Qwt plotting library. > > Phil Can a designer plugin be used this way ? I tried inserting a FileChooser (available as an .so file under designer plugins) object onto the main window and then used pyuic. Traceback (most recent call last): File "measure.py", line 16, in ? f = MEASURE() File "/home/m_singh/measure.py", line 422, in __init__ self.fileChooser1 = FileChooser(self.groupBox4,"fileChooser1") NameError: global name 'FileChooser' is not defined The wrapper in my .py file : from qt import * from measure import * import sys if __name__ == "__main__": app = QApplication(sys.argv) f = MEASURE() f.show() app.setMainWidget(f) app.exec_loop() An attempt to use QwtPlot gives the same kind of error. Or is the only way forward for me to generate a .py file from non-plugin objects, and then hand code the pyqwt part into that result (Or use Python: in the ui). -- http://mail.python.org/mailman/listinfo/python-list
Supressing argument renaming in the Qt Designer -> pyuic workflow
Hi Some of the functions I defined inside Qt Designer need to have some values passed to them. For instance : Code : void Form3::runningplot(n,plottitle,xname,x,y1name,y1,y2name,y2) is translated by pyuic to Python code : def runningplot(self,a0,a1,a2,a3,a4,a5,a6,a7): Now, while I understand that the first argument of the function has to be "self", the change in the names of the parameters in the function definition (and no corresponding change in the function body - which I would not expect anyways) messes up everything. Is there a way to tell pyuic to not translate plottitle -> a0, xname -> a1, etc., but keep the names as they are ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Using globals with classes
Hi I am relatively new to Python. I am using Qt Designer to create a UI for a measurement application that I use. Everything seems to be clear but the use of globals (defined in the module that is generated using pyuic, that contains the form class). I am using qwtplot to display a running plot : void Form3::runningplot(n,plottitle,xname,x,y1name,y1,y2name,y2) { if n==1 : plotkey1=self.runningqwtPlot.insertCurve(y1name,self.runningqwtPlot.xBottom,self.runningqwtPlot.yLeft) plotkey2=self.runningqwtPlot.insertCurve(y2name,self.runningqwtPlot.xBottom,self.runningqwtPlot.yRight) self.runningqwtPlot.setTitle(plottitle) self.runningqwtPlot.setXGrid(True) self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.yLeft) self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.yRight) self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.xBottom) self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.yLeft,y1name) self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.yRight,y2name) self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.xBottom,xname) self.runningqwtPlot.setCurveData(plotkey1,x,y1,n) self.runningqwtPlot.setCurveData(plotkey2,x,y2,n) self.runningqwtPlot.replot() else : self.runningqwtPlot.setCurveData(plotkey1,x,y1,n) self.runningqwtPlot.setCurveData(plotkey2,x,y2,n) self.runningqwtPlot.replot() } where the above routine is called repeatedly to display real time data. Now, plotkey1 and plotkey2 need to remain unchanged between successive invocations of setCurveData() and replot() above. I have defined these as globals (in the Form settings comment field with Python: as usual). However, when I run it, I get an error indicating that plotkey1 and plotkey2 are unknown outside. I also have a global variable named "globaldebug" that when set to True, shows some diagnostic information as different slots are called. That too fails with the same error : NameError: global name 'globaldebug' is not defined Is there a way to make a Python function "remember" the values of certain variables ? Or use fortran 95 like use module, only : varname, type of within a def ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Using globals with classes
Many thanks for an excellent solution to the problem and clearing up my mind about globals. In some sense, Python globals seem to be a little like the COMMON statement in the old Fortran 77 standard. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using globals with classes
Scott David Daniels wrote: > Madhusudan Singh wrote: >> I am using qwtplot to display a running plot : >> > The way I'd normally accomplish this is to separate the setup and use > by defining a class: > How would one enable dynamic autoscaling of the axes ? I am using setAxisAutoScale, and when the application ends, I do get correctly autoscaled axes, but not while the measurement is in progress. -- http://mail.python.org/mailman/listinfo/python-list
Standalone applications ?
Hi I just finished developing an application using Qt Designer in Python that uses pyqwt, gpib, etc. How does one create standalone executables for applications such as these ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Standalone applications ?
Paolo Alexis Falcone wrote: > On Sat, 13 Aug 2005 23:29:27 -0400, Madhusudan Singh wrote: > >> Hi >> >> I just finished developing an application using Qt Designer in Python >> that uses pyqwt, gpib, etc. How does one create standalone executables >> for applications such as these ? > > Generally, you can't, as Python is an interpreted programming language. > However, there are some projects like py2exe in Windows which approximates > what you want to do - port the Python code into a stand-alone application. I should have added that my platform is Linux. -- http://mail.python.org/mailman/listinfo/python-list
Re: Standalone applications ?
TPJ wrote: >> I should have added that my platform is Linux. > > In this case you shouldn't bother yourself with executables. Python is > available on any major distribution. > > My Python apps are available as pyc files for Linux (and for those > Windows users, who have Python installed) and as executables for Win > (for those Windows users, who have no Python installed). My python app uses a lot of modules, some custom developed by myself (and which I am not planning on releasing right now). Which is why I posed the question in the first place (that and curiosity). -- http://mail.python.org/mailman/listinfo/python-list
Dynamic autoscaling of axes with pyqwt ?
How does one enable dynamic autoscaling of the axes ? I am using setAxisAutoScale in an application which acquires data, and when the application ends, I do get correctly autoscaled axes, but not while the measurement is in progress. -- http://mail.python.org/mailman/listinfo/python-list
Testing for presence of arguments
Hi I know how to set optional arguments in the function definition. Is there an intrinsic function that determines if a certain argument was actually passed ? Like the fortran 95 present() logical intrinsic ? My required functionality depends on whether a certain argument is specified at all. (Setting default values is *not* good enough.). Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Diez B. Roggisch wrote: > I don't have the details ready - but in the ASPN cookbook are recipes > to e.g. figure insied a function f out how many results the caller of f > expects - and act accordingly. This boils down to inspect the > call-stack. So it ceratinly is possible. > > However, I'd say it is almost 100% a design flaw. Or can you give us a > compelling reason why you need this behaviour? > > Diez I am writing some code for a measurement application (would have used fortran 95 if a library had been available for linux-gpib, but python is a lot friendlier than C without the irritating and utterly pointless braces) where one of the input parameters for the GPIB command is optional, and depending on whether it is specified at all, an entire sequence of commands has to be sent to the GPIB bus plus some input parameters recalculated. Further, the sequence of commands depends on the range of values of the optional parameter. And some of these commands in turn have similar optional arguments. All in all, the above would have been a bunch of simple one-liners with a simple if block if python had something like the fortran 95 present() intrinsic, but I could not find it. Hence my query. Just because there is no simple and direct way of doing something in a language does not mean that the application that requires it has a design flaw. Unrelated question, how does one call a fortran 95 subroutine from python ? I need really high speed of execution for that call (needed for each measurement point, and is used to calculate some parameters for the excitation for the next measurement point) and a scripting language would not cut it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Benji York wrote: > Madhusudan Singh wrote: >> I know how to set optional arguments in the function definition. Is there >> an intrinsic function that determines if a certain argument was actually >> passed ? Like the fortran 95 present() logical intrinsic ? > > People generally use a value that isn't a valid option, often None. > > def my_func(a, b, c=None): > if c is None: > do something > > If None is a valid value, make one that isn't: > > unspecified = object() > > def my_func(a, b, c=unspecified): > if c is unspecified: > do something > -- > Benji York Now, that was a very good suggestion. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Dan Sommers wrote: > On Wed, 17 Aug 2005 11:13:03 -0400, > Madhusudan Singh <[EMAIL PROTECTED]> wrote: > >> I know how to set optional arguments in the function definition. Is >> there an intrinsic function that determines if a certain argument was >> actually passed ? Like the fortran 95 present() logical intrinsic ? > > def f(**kw): > if kw.has_key('required_argument'): > print "require_argument was present" > else: > print "require_argument was not present" > >> My required functionality depends on whether a certain argument is >> specified at all. (Setting default values is *not* good enough.). > > You can very nearly achieve this with carefully planned default > arguments. Put this into a module: > > class _SemiPrivateClass: > pass > > def f(required_argument=_SemiPrivateClass): > if required_argument == _SemiPrivateClass: > print "required_argument was probably not present" > else: > print "required_argument was present" > > It's not impossible fool f, but an external module has to try very hard > to do so. > > (All code untested.) > > Regards, > Dan > Thanks for the suggestion, but seems needlessly complicated for something very simple. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Peter Decker wrote: > On 8/17/05, Madhusudan Singh <[EMAIL PROTECTED]> wrote: > >> I know how to set optional arguments in the function definition. Is there >> an intrinsic function that determines if a certain argument was actually >> passed ? Like the fortran 95 present() logical intrinsic ? >> >> My required functionality depends on whether a certain argument is >> specified at all. (Setting default values is *not* good enough.). > > Could you just write the function as: > > myFunc(*args, **kwargs): > > ...and then figure out what was passed? > Seems a lot simpler than the other module suggestion, but another person has posted a suggestion that is a lot more quick and elegant. Thanks anyways. I might find this useful in some as yet unknown context. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Diez B. Roggisch wrote: > I still don't see why default arguments like None won't do the trick. > If The argument _can_ > be some value (let's say an int) or None, you still could go for a > default value like () or any other value > from a different domain. "None" works perfectly. Someone else on the thread suggested it. I did not know about the special intrinsic. >> Unrelated question, how does one call a fortran 95 subroutine from python >> ? I need really high speed of execution for that call (needed for each >> measurement point, and is used to calculate some parameters for the >> excitation for the next measurement point) and a scripting language would >> not cut it. > > Didn't ever try that, but either do it in C, or if fortran code can be > exposed as C lib, use that (ctypes is your friend). I'm not aware of a > fortran binding - but I never tried to find one. Basically Python can > interface with everything that can behave like C - which is the least > common denominator I think, so there should be some way. Hmm. Thanks for the pointers here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for presence of arguments
Peter Maas wrote: >> Thanks for the suggestion, but seems needlessly complicated for > > something very simple. > > What is "very simple"? The problem or the solution? :) If you examine The form of the solution. > this suggestion more closely you will note that it is more or less > the same as Benji York's one except Benji used a built-in class. Many good solutions have some similarity. From the point of view of a user trying to include some simple functionality in a already complicated application, Benji's answer was most definitely more useful. > > If you are interested in getting help on usenet you should abstain > from devaluating efforts to give you a useful reply. "Thanks for > the suggestion" or even no answer would have been sufficient. > One might have thought that a truthful assessment would have been appreciated at the other end. I myself help people on the Usenet on some other newsgroups, and am usually welcoming of responses that offer a relevant criticism. The exchange improves me as much as it improves them. Thanks for the suggestion, anyways :) -- http://mail.python.org/mailman/listinfo/python-list
Precise timings ?
Hi I am using time.clock() to get the current time of the processor in seconds. For my application, I need really high resolution but currently seem to be limited to 0.01 second. Is there a way to specify the resolution (say 1-10 microseconds) ? My processor is a 1.4 MHz Intel processor. Surely, it should be able to report times a few (or at least 10) microseconds apart. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Precise timings ?
Madhusudan Singh wrote: > Hi > > I am using time.clock() to get the current time of the processor in > seconds. For my application, I need really high resolution but currently > seem to be limited to 0.01 second. Is there a way to specify the > resolution (say 1-10 microseconds) ? My processor is a 1.4 MHz Intel > processor. Surely, it should be able to report times a few (or at least > 10) microseconds apart. > > Thanks. Correcting a typo (1.4GHz, not 1.4 MHz). And I am using Linux. -- http://mail.python.org/mailman/listinfo/python-list
Re: Precise timings ?
Bengt Richter wrote: > windows or unix? time.time and time.clock seem to reverse roles as > best-resolution time sources depending on which platform. > Linux. time.time() seems to report (using %e to format the o/p) a fixed number of the order ~1e9. > If you have a pentium with a rdtsc instruction, you can write an extension > module in c to get at it. In C on a 300mhz p2 I got down to 23ns minimum > delta between calls, IIRC. But even then I was subject to the small I do not need ns resolution. A few microseconds would be fine. > probability of an interrupt during my timing loop, and there are many > normally going on, so the longer the interval you are timing the greater > the probability that an interrupt will occur within it (assuming random > independence, which is also not necessarily true). This is why timing > frameworks generally either average brute force or discard outlier timings > and average, or return best-of. All these have different error properties, > and depend on lots of stuff. > > I'm wondering whats your application is. Maybe you need a real-time OS? No, no. All I am looking for is for the system to report its time with better resolution. I know it is possible on my hardware, because I can get at very precise timings using Fortran 95 intrinsics in my other code. However, with Python's time module, I do not seem to be able to access it. -- http://mail.python.org/mailman/listinfo/python-list
Problem with string -> int conversion ?
Hi I am working with an application that I designed with the Designer > pyuic workflow and I get the following error on trying to process the contents of a combobox : Traceback (most recent call last): File "measure.py", line 908, in acquiredata np=self.getNPrange() File "measure.py", line 1167, in getNPrange signalrange=int(signalrangestr) TypeError: int() argument must be a string or a number The code is : void Form3::getNPrange() { signalrangestr=self.NPcombobox.currentText() signalrange=int(signalrangestr) if globaldebug : print 'NP Signal range = ',signalrange return signalrange } The contents of the combobox are strings representing numbers in the range [0,6]. Isn't signalrangestr above a string ? Or at the very least, a number. I entered these numbers myself in designer, so they do not have any white-space (len(signalrangestr) returns 1). In any case, an attempt to use strip() fails with : Traceback (most recent call last): File "measure.py", line 908, in acquiredata np=self.getNPrange() File "measure.py", line 1169, in getNPrange signalrange=int(signalrangestr.strip()) AttributeError: strip -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with string -> int conversion ?
Fredrik Lundh wrote: >> The code is : >> >> void Form3::getNPrange() >> { > > what language is this? Its python embedded in the designer workflow. pyuic extracts stuff from it, and generates a python script from the ui.h file. > > if the callback code is Python, you should be able to add a print > statement to the line just before the failing "int" call: > > print repr(signalrangestr), type(signalrangestr) > signalrange = int(signalrangestr) > > that print statement should be all you need to figure out what > signalrangestr really is. Thanks for the hint. I get : <__main__.qt.QString object at 0xb7c1a3ec> The question is : How do I convert a QString to a plain string ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Precise timings ?
Fernando Perez wrote: > Madhusudan Singh wrote: > >> Madhusudan Singh wrote: >> >>> Hi >>> >>> I am using time.clock() to get the current time of the processor in >>> seconds. For my application, I need really high resolution but currently >>> seem to be limited to 0.01 second. Is there a way to specify the >>> resolution (say 1-10 microseconds) ? My processor is a 1.4 MHz Intel >>> processor. Surely, it should be able to report times a few (or at least >>> 10) microseconds apart. >>> >>> Thanks. >> >> Correcting a typo (1.4GHz, not 1.4 MHz). >> >> And I am using Linux. > > Then, this may be handy to give you an idea of the resolution you can > expect at > the python level (i.e., without writing extension code). Feel free to add > fancier statistics if you actually need them: > > planck[python]> cat tdelta.py > #!/usr/bin/env python > """quick and dirty test for time deltas. Under Linux, this is best done > using time.time() instead of time.clock()""" > > import commands > from time import time > > npts = 50 > times = [-(time()-time()) for i in xrange(npts)] > > print commands.getoutput('egrep "MHz|model name" /proc/cpuinfo') > print 'Min. time delta :',min(times),'s' > print 'Max. time delta :',max(times),'s' > print 'Avg. time delta :',sum(times)/float(npts),'s' > print 'Num. of timings :',npts > > # > For example, on my system: > > planck[python]> ./tdelta.py > model name : Intel(R) Pentium(R) 4 CPU 2.80GHz > cpu MHz : 2794.365 > Min. time delta : 2.86102294922e-06 s > Max. time delta : 9.05990600586e-06 s > Avg. time delta : 3.38554382324e-06 s > Num. of timings : 50 > > Cheers, > > f Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Equivalent for an internal write in Python ?
Hi I am looking to write a formatted string to a string variable : Say I have 1.067e-01, I need to write 106.700 to some string. In Fortran 95, this would be accomplished with a : character(len=7) :: stringvar real :: stringval ... write(stringvar,'(f7.3)') stringval How does one do something like this in Python ? I need a string formatted in this way for one of my applications. -- http://mail.python.org/mailman/listinfo/python-list
End or Identify (EOI) character ?
Hi I was wondering how does one detect the above character. It is returned by an instrument I am controlling via GPIB. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Embedding matplotlib into page GUI builder
After a successful but problematic experience with the QT Designer + python combo, I decided that I needed something simpler (read completely in python) for my lab applications with python linux-gpib bindings. I am looking at PAGE, which while not pretty, seems simple and fast to work with. How do I embed a realtime graphic o/p from matplotlib into this GUI builder ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list