Cathing several potential errors?


if i do try: something except TypeError, IndexError: pass only the first error will get caught. I dont want to use Exception and catch all errors, but just 2. how can i do that...
Posted On: Sunday 11th of November 2012 08:30:19 PM Total Views:  224
View Complete with Replies

RELATED TOPICS OF Python Programming PROGRAMMING LANGUAGE




f2py Error - module crashes after several iterations...

, I have a module created from a Fortran file to read in unformatted binary fortran output. It works fine for some datasets, but crashes with others. The strange thing is it will loop through several files before it crashes, then suddently giving me this output: *** glibc detected *** python: munmap_chunk(): invalid pointer: 0xb34ac008 *** ======= Backtrace: ========= /lib/libc.so.6[0x7b0874] /usr/lib/python2.5/site-packages/numpy/core/multiarray.so[0x44a24b] /usr/lib/libpython2.5.so.1.0[0x55cf0cf] /usr/lib/libpython2.5.so.1.0(PyEval_EvalCodeEx+0x579)[0x5636c59] /usr/lib/libpython2.5.so.1.0[0x55d0eb2] /usr/lib/libpython2.5.so.1.0(PyObject_Call+0x37)[0x55b10b7] /usr/lib/libpython2.5.so.1.0(PyEval_EvalFrameEx+0x466f)[0x5633e7f] /usr/lib/libpython2.5.so.1.0(PyEval_EvalCodeEx+0x695)[0x5636d75] /usr/lib/libpython2.5.so.1.0(PyEval_EvalCode+0x63)[0x5636fd3] /usr/lib/libpython2.5.so.1.0[0x5652542] /usr/lib/libpython2.5.so.1.0(PyRun_FileExFlags+0x92)[0x5652602] /usr/lib/libpython2.5.so.1.0(PyRun_SimpleFileExFlags+0x1bc)[0x5653d8c] /usr/lib/libpython2.5.so.1.0(PyRun_AnyFileExFlags+0x7a)[0x56544fa] /usr/lib/libpython2.5.so.1.0(Py_Main+0xc4f)[0x565e3df] python(main+0x32)[0x80485d2] /lib/libc.so.6(__libc_start_main+0xe6)[0x7595d6] python[0x8048501] ======= Memory map: ======== 00110000-00111000 r-xp 00110000 00:00 0 [vdso] 00111000-00115000 r-xp 00000000 fd:00 1835759 /usr/lib/python2.5/lib-dynload/stropmodule.so 00115000-00117000 rw-p 00004000 fd:00 1835759 /usr/lib/python2.5/lib-dynload/stropmodule.so 00117000-0011a000 r-xp 00000000 fd:00 1835717 /usr/lib/python2.5/lib-dynload/_localemodule.so 0011a000-0011b000 rw-p 00003000 fd:00 1835717 /usr/lib/python2.5/lib-dynload/_localemodule.so 0011b000-00121000 r-xp 00000000 fd:00 1835750 /usr/lib/python2.5/lib-dynload/operator.so 00121000-00122000 rw-p 00006000 fd:00 1835750 /usr/lib/python2.5/lib-dynload/operator.so 00122000-00128000 r-xp 00000000 fd:00 1835727 /usr/lib/python2.5/lib-dynload/_struct.so 00128000-00129000 rw-p 00006000 fd:00 1835727 /usr/lib/python2.5/lib-dynload/_struct.so 00129000-0012c000 r-xp 00000000 fd:00 1835762 /usr/lib/python2.5/lib-dynload/timemodule.so [snip ...] Anyone have some inputs on how to determine the cause\t
VIEWS ON THIS POST

70

Posted on:

Saturday 3rd November 2012
View Replies!

several version of eggs

, I thought that with eggs, I will be able to choose at run time, which version of an egg I would like to use. But after some tests with dummy eggs, I've tried to make it work with SQLAlchemy for example, with no success at all. So does some one know if such feature is available with eggs \t ------------------ the example --------------- easy_install 'SQLAlchemy==0.4.4' .... easy_install 'SQLAlchemy==0.4.6' .... python import pkg_resources >>> pkg_resources.require("SQLAlchemy==0.4.6") [SQLAlchemy 0.4.6 (/home/system/briner/py-lib/SQLAlchemy-0.4.6- py2.5.egg)] >>> pkg_resources.require("SQLAlchemy==0.4.4") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 626, in require needed = self.resolve(parse_requirements(requirements)) File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 528, in resolve raise VersionConflict(dist,req) # XXX put more info here pkg_resources.VersionConflict: (SQLAlchemy 0.4.6 (/home/system/briner/ py-lib/SQLAlchemy-0.4.6-py2.5.egg), Requirement.parse('SQLAlchemy==0.4.4')) Ctrl+D easy_install 'SQLAlchemy==0.4.4' .... python >>> import pkg_resources >>> pkg_resources.require("SQLAlchemy==0.4.4") [SQLAlchemy 0.4.4 (/home/system/briner/py-lib/SQLAlchemy-0.4.4- py2.5.egg)] >>> pkg_resources.require("SQLAlchemy==0.4.6") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 626, in require needed = self.resolve(parse_requirements(requirements)) File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 528, in resolve raise VersionConflict(dist,req) # XXX put more info here pkg_resources.VersionConflict: (SQLAlchemy 0.4.4 (/home/system/briner/ py-lib/SQLAlchemy-0.4.4-py2.5.egg), Requirement.parse('SQLAlchemy==0.4.6')) ------------------------------- so it feels that the only package I can call is the latest one installed !!! cEd
VIEWS ON THIS POST

57

Posted on:

Saturday 3rd November 2012
View Replies!

Re: f2py Error - module crashes after several iterations...

John [H2O] wrote: > , > > I have a module created from a Fortran file to read in unformatted binary > fortran output. It works fine for some datasets, but crashes with others. > The strange thing is it will loop through several files before it crashes, > then suddently giving me this output: Can you run it under gdb to get a more complete backtrace Please join us on numpy-discussion. http://www.scipy.org/Mailing_Lists -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
VIEWS ON THIS POST

116

Posted on:

Saturday 3rd November 2012
View Replies!

Splitting MainWindow Class over several modules.

Until recently almost all my python programs were held 1 file for 1 program. This had grown unwieldy for one of my projects, so i decided to refactor it, and ended up with something like this: --- import wx import options import gui import scf class MainWindow(wx.Frame): def __init__(self): self.title = "SFtools v%s" % VERSION wx.Frame.__init__(self, None, wx.ID_ANY, self.title, size=(800,600)) self.SetMinSize((800,600)) readOptions = options.readOptions writeOptions = options.writeOptions createBindings = gui.createBindings createControls = gui.createControls createMenus = gui.createMenus reportError = gui.reportError loadSCF = scf.loadSCF onOpen = scf.onOpen reloadSCF = scf.reloadSCF setMenuMode = scf.setMenuMode unloadSCF = scf.unloadSCF --- Now, this works fine. I like how it reads and that everything being imported can be clearly seen. I have this funny feeling though, that this isn't the standard way of doing this. What is And is there anything about doing it this way which could be detrimental Iain
VIEWS ON THIS POST

46

Posted on:

Saturday 3rd November 2012
View Replies!

Pickle: several class instance objects in one file?

Hi I've never used the module 'pickle' so far, thus I've got some questions about how to use it: Lets say I have instances of class A and class B: a = A() b = B() Is it possible to pickle both of these instances to the same pkl-file or will that have any bad impact for unpickle (i.e. the instance are 'mixed' or 'destroyed') Or should I rather use a seperate file for every class instance I want to pickle Another very basic question about pickling class instances: To store the value of attributes of an instance is it enough for the pickling-algorithm to use the __dict__ or do I have to implement the _setstate_ and _getstate_ function I didn't really get the meaning of those while reading the python user manual...
VIEWS ON THIS POST

76

Posted on:

Sunday 4th November 2012
View Replies!

raw_input on several lines

Hi everybody, When using raw_input(), the input of the user ends when he types Return on his keyboard. How can I change this behavior, so that another action is needed to stop the input For example, CTRL-G. It would allow the user to input several lines.
VIEWS ON THIS POST

53

Posted on:

Sunday 4th November 2012
View Replies!

Re: Combining several files

En Fri, 02 May 2008 17:45:57 -0300, CRAIG DALTON escribi: > I'm looking to append several text files in one director and out put the > combined files into another director. I'm new to Python and just can't > get it to work. So far I've been able to create a file in the deed > directory but it isn't pulling any of the data in the originating > directory. Could please look at my code and tell me what I'm doing wrong. > > import os,shutil > f=open("c:\\output\\testing1.txt","a+") > for r,d,fi in os.walk("c:\\test"): > for files in fi: > if files.endswith(".txt"): > g=open(os.path.join(r+,files)) > shutil.copyfileobj(g,f) > g.close() > f.close() > > Any help would be great. Except the spurious + in join(r+,files), and the usage of "files" denoting a single file name, the code looks OK to me. Try adding a few print statements, showing the files and directories it is processing. (Note: Next time, if you want to post a NEW question, create a NEW thread instead of replying to any random post...) -- Gabriel Genellina
VIEWS ON THIS POST

57

Posted on:

Sunday 4th November 2012
View Replies!

Is there a way to "link" a python program from several files?

IOW, is there a "linker" for python I've written a program comprised of about five .py files. I'd like to find a way to combine them into a single executable. Obviously, I could hand-edit them into a single .py file, but I'm looking for a way to keep them as seperate files for development but distribute the result as a single file. If this were C, I'd compile and link them and distribute the resulting executable. I'm trying to do that, but for Python. TIA, -- -Ed Falk, falk@despams.r.us.com http://thespamdiaries.blogspot.com/ , "Brian Smith" writes: > So does Haskell. Haskell -In-One handles that by renaming every > top-level artifact. That can't be done reliably in python because namespaces are dynamic. > If it is possible to run an egg as a CGI (without modifying the web > server configuration file), then that would work as well. This would be an interesting enhancement.
VIEWS ON THIS POST

105

Posted on:

Monday 5th November 2012
View Replies!

What is a good way of having several versions of a python moduleinstalled in parallell?

Hi! I write, use and reuse a lot of small python programs for variuos purposes in my work. These use a growing number of utility modules that I'm continuously developing and adding to as new functionality is needed. Sometimes I discover earlier design mistakes in these modules, and rather than keeping old garbage I often rewrite the parts that are unsatisfactory. This often breaks backwards compatibility, and since I don't feel like updating all the code that relies on the old (functional but flawed) modules, I'm left with a hack library that depends on halting versions of my utility modules. The way I do it now is that I update the programs as needed when I need them, but this approach makes me feel a bit queasy. It seems to me like I'm thinking about this in the wrong way. Does anyone else recognize this situation in general How do you handle it I have a feeling it should be possible to have multiple versions of the modules installed simultaneously, and maybe do something like this: mymodule/ + mymodule-1.1.3/ + mymodule-1.1.0/ + mymodule-0.9.5/ - __init__.py and having some kind of magic in __init__.py that let's the programmer choose version after import: import mymodule mymodule.require_version("1.1.3") Is this a good way of thinking about it What would be an efficient way of implementing it Cheers! /Joel Hedlund
VIEWS ON THIS POST

290

Posted on:

Monday 5th November 2012
View Replies!

Split file into several and reformat

I want to take read an input file (sels.txt) that looks like: Begin sels sel1 = {1001, 1002, 1003, ... ... 1099} sel2 = {1001, 1008, 1009 ... ... 1299} End sels And turn it into an output file for each of the "sels" in the input file,i.e sel1.txt: L1001 L1002 L1003 .... L1099 and sel2.txt: L1001 L1008 L1009 .... L1299 And so on. Many thanks, Wayne , On 2007-06-21, bomber71@aapt.net.au wrote: > > > I want to take read an input file (sels.txt) that looks like: > > Begin sels > sel1 = {1001, 1002, 1003, ... > ... > 1099} > > sel2 = {1001, 1008, 1009 ... > ... > 1299} > End sels > > And turn it into an output file for each of the "sels" in the input file, i.e > sel1.txt: > > L1001 > L1002 > L1003 > ... > L1099 > > and sel2.txt: > > L1001 > L1008 > L1009 > ... > L1299 > > And so on. Many thanks, I think I'd put together a simple grammar and then write a recursive descent parser that spit out my output files. But that's just because I find that kind of thing fun. -- Neil Cerutti I'm tired of hearing about money, money, money, money, money. I just want to play the game, drink Pepsi, wear Reebok. --Shaquille O'Neal
VIEWS ON THIS POST

111

Posted on:

Monday 5th November 2012
View Replies!

Re: f2py Error - module crashes after several iterations...

I can try, would you mind giving very brief instructions on how to 'run it under gdb'... thanks! I'll post results over at numpy-discussions. Robert Kern-2 wrote: > > John [H2O] wrote: >> , >> >> I have a module created from a Fortran file to read in unformatted binary >> fortran output. It works fine for some datasets, but crashes with others. >> The strange thing is it will loop through several files before it >> crashes, >> then suddently giving me this output: > > Can you run it under gdb to get a more complete backtrace Please join us > on > numpy-discussion. > > http://www.scipy.org/Mailing_Lists > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless > enigma > that is made terrible by our own mad attempt to interpret it as though > it had > an underlying truth." > -- Umberto Eco > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/f2py-Error---m...p20131768.html Sent from the Python - python-list mailing list archive at Nabble.com.
VIEWS ON THIS POST

105

Posted on:

Wednesday 7th November 2012
View Replies!

cathing uncaught exceptions

how can I catch (globally) exception that were not caught in a try/ catch block in any running thread i had this weird case that an exception was raised in one thread, but nothing was displayed/logged.
VIEWS ON THIS POST

63

Posted on:

Wednesday 7th November 2012
View Replies!

logging.py: mutiple system users writing to same file gettingpermission errors.

An a redhat box I have root, apache and other normal users run code that uses the logging module to write to the same log file. Since umasks are set to 2 or 022 this gets permission errors. I have fixed my issue by patching the logging code everywhere there is an open for write with: try: old_umask = os.umask(0) # open for write here finally: os.umask(old_umask) Is there a better way to solve this issue Are there any security problems with this solution other than the log file not being protected
VIEWS ON THIS POST

114

Posted on:

Wednesday 7th November 2012
View Replies!

Re: Strange set of errors

Sorry, forgot to "Reply to all." On 8/3/07, Stephen Webb wrote: > Greetings all, > Also, I've been having trouble with the plot function in matplotlib. For > example, I enter the following in the terminal: > > >>> from pylab import * > >>> plot([1,2,3]) > [] > I can help you with your second problem: matplotlib is doing what it should, all you need to do is tell it to show() the figure you created (with the plot on it.) Note -- if you call the show() function, you will turn control over to the backend (in my case, TkAgg), and lose the ability to issue interactive commands afterwards. A solution is to use the ion() (stands for "interactive-on") function call before issuing plotting commands: >>> from pylab import * >>> ion() >>> plot([1,2,3]) [] >>> # image is shown here See http://matplotlib.sourceforge.net/interactive.html for an exhaustive explanation. > Every time I run the plot([1,2,3]) I get a different ending number that > seems to vary randomly. The "[]" is what the plot() function returns -- a list of instances of the Line2D class, and it tells you their locations in memory (hence the hex number starting with 0x). The hex number can be used to uniquely identify this object, as in the id(object) call. Hope this helps, Kurt
VIEWS ON THIS POST

118

Posted on:

Wednesday 7th November 2012
View Replies!

Re: How to avoid overflow errors

On Fri, 14 Sep 2007 21:43:38 -0300, Eduardo O. Padoan wrote: >> How do I subclass int and/or long so that my class also auto-converts >> only when needed > > What about just subclassing long - is this not an option Of course it's an option. As it turned out, that was the easiest way for me to proceed. I was a little concerned that the overhead of using longs might have been excessive, but for values close to zero (and by close I mean < millions) there's no significant time difference between arithmetic with ints and longints. -- Steven.
VIEWS ON THIS POST

82

Posted on:

Wednesday 7th November 2012
View Replies!

Weird errors when trying to access a dictionary key

robinsiebler a crit : > I have a data structure that looks like this: > (snip) > > I get the following error: (snip) > AttributeError: 'list' object has no attribute 'keys' Already answered. > Here is where it gets weird: > > type(song) (snip) > TypeError: 'str' object is not callable You code snippet started with: if type == 'artist': which implies you bound the name 'type' to a string. Then you try to use the object bound to name 'type' as a callable. Python's bindings are just name=>object mappings, and nothing prevents you to rebind a builtin name. IOW, avoid using builtins types and functions as identifiers. HTH
VIEWS ON THIS POST

127

Posted on:

Saturday 10th November 2012
View Replies!

How do I trap errors in win32com.client?

How do I trap errors from win32com.client. I have tried the com_error classes from pywintypes and pythoncom sub modules. It is not catching for all cases. Is there any docs available...
VIEWS ON THIS POST

107

Posted on:

Saturday 10th November 2012
View Replies!

getting rid of leading zeros in float expotential

Hi! I'm wondering whether there's an easy way to remove unnecessary leading zeros from my floating point number. realS = float(-1.25e-5) imgS = float(-7.6e4) print complex(realS, imgS) >> (-1.25e-005-76000j) I would like it to look like (-1.25e-5-76000j)...
VIEWS ON THIS POST

84

Posted on:

Saturday 10th November 2012
View Replies!

Preventing 'bad' filenames from raising errors in os.path

Bad file names, i.e. filenames the OS considers illegal, will cause functions in the os.path module to raise an error. Example: import os.path print os.path.getsize( 'c:/pytest/*.py' ) On Windows XP using Python 2.5.2 I get the following traceback: Traceback (most ...
VIEWS ON THIS POST

119

Posted on:

Saturday 10th November 2012
View Replies!

Re: f2py Error - module crashes after several iterations...

John [H2O] wrote: > I can try, would you mind giving very brief instructions on how to 'run it > under gdb'... thanks! Sure. It goes something like this: $ gdb python GNU gdb 6.3.50-20050815 (Apple version gdb-768) (Tue Oct ...
VIEWS ON THIS POST

70

Posted on:

Saturday 10th November 2012
View Replies!