KeyError in pickle
Hi, I am using pickle/unpickle to let my program save its documents to disk. While this it worked stable for a long time, one of my users now complained, that he had a file which can't be loaded. The traceback is: File "pickle.pyo", line 1374, in loads File "pickle.pyo", line 858, in load KeyError: 'A' Does anybody know this problem. How this can happen and how can I avoid it? Thanks, Christof -- http://mail.python.org/mailman/listinfo/python-list
Re: KeyError in pickle
On 23 Mai, 10:48, Peter Otten <[EMAIL PROTECTED]> wrote: > christof wrote: > > I am using pickle/unpickle to let my program save its documents to > > disk. While this it worked stable for a long time, one of my users now > > complained, that he had a file which can't be loaded. > > > The traceback is: > > > File "pickle.pyo", line 1374, in loads > > File "pickle.pyo", line 858, in load > > KeyError: 'A' > > > Does anybody know this problem. How this can happen and how can I > > avoid it? > > Is this reproducible? How? If not I would guess that the file is corrupted. > > Peter I found the problem: the user did a text export and gave the exported file the wrong extension. So: the file was not valid python pickle. I should add a type signature to fhe file format to avoid this. Thanks anyway, Christof -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Help!!!
Elfine Peterson Tjio wrote: > I'm trying to make a program that reads Fasta file and print it out. I used > the SeqIO module and the results is: > > 'ATGGTCATSingleAlphabet()' > > For this purpose, should I use SeqIO or Fasta? > > for example: > > from Bio import SeqIO > > or > > from Bio import Fasta > > I want it to print every letter. Can anyone point me to the right direction. > The newest biopython tutorial or book recommendation will be appreciated, > too. Dear Elfine: The correct place for such a question is the BioPython discussion list at [EMAIL PROTECTED] You can subscribe to it here: http://lists.open-bio.org/mailman/listinfo/biopython/ The newest BioPython tutorial (last updated 16 March 2007) can be found at http://biopython.org/DIST/docs/tutorial/Tutorial.pdf SeqIO and Fasta should both work fine. You could also try >>> help(SeqIO) >>> help(Fasta) after your import for some further information. Cheers, Christof -- http://mail.python.org/mailman/listinfo/python-list
Re: Method much slower than function?
Gabriel Genellina wrote:
[...]
> py> import timeit
> py>
> py> def f1():
> ... a=""
> ... for i in xrange(10):
> ... a+=str(i)*20
> ...
> py> def f2():
> ... a=[]
> ... for i in xrange(10):
> ... a.append(str(i)*20)
> ... a="".join(a)
> ...
> py> print timeit.Timer("f2()", "from __main__ import f2").repeat(number=1)
> [0.42673663831576358, 0.42807591467630662, 0.44401481193838876]
> py> print timeit.Timer("f1()", "from __main__ import f1").repeat(number=1)
>
> ...after a few minutes I aborted the process...
>
Using
Python 2.4.4 (#2, Jan 13 2007, 17:50:26)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
f1() and f2() also virtually take the same amount of time, although I must
admit
that this is quite different from what I expected.
Cheers,
Christof
--
http://mail.python.org/mailman/listinfo/python-list
Re: Want to learn Python
Amol wrote: > Hi, I want to learn Python in less than a month which resources should > I use. I prefer to read books . Please give me a list of *recognized* > resources. Thank You all This is an excellent resource: http://rgruet.free.fr/PQR24/PQR2.4.html Although it's quite different from a book, I must admit. Cheers, Christof -- http://mail.python.org/mailman/listinfo/python-list
Re: How to optimise this code?
David N Montgomery wrote:
> class testCase:
> def __init__(self, tc):
> if tc == 1:self.testCase1()
> if tc == 2:self.testCase2()
> if tc == 3:self.testCase3()
> if tc == 4:self.testCase4()
> if tc == 5:self.testCase5()
> if tc == 6:self.testCase6()
>
> def testCase1(self):
> print "tc1"
>
> def testCase2(self):
> print "tc2"
>
> def testCase3(self):
> print "tc3"
>
> def testCase4(self):
> print "tc4"
>
> def testCase5(self):
> print "tc5"
>
> def testCase6(self):
> print "tc6"
>
>
> def testCaseX(self):
> print "tcX"
>
> totalNumberOfTestCases = 6
> x = 0
> while x <= totalNumberOfTestCases:
> x += 1
> testCase(x)
>
>
> This template code is working, but I envisage having 100+ test cases and
> am concerned about my useage of if statements. I would be grateful for
> any pointers as to how I can run all tests cases, regardless of how
> many, in a more efficient manner.
>
> Thank you in advance.
To get rid of the if statements, replace __init__ function with:
def __init__(self, tc):
functionToCall = eval("self.testCase%s" % tc)
functionToCall()
HTH,
Chris
--
http://mail.python.org/mailman/listinfo/python-list
Re: 2 python questions!
[EMAIL PROTECTED] wrote: [...] > Now the second question has to do with images retrieval and > manipulation. Which libraries do you propose to work with to > retrieve and resize images from the web? urllib.urlretrieve() and Python Imaging Library (PIL) -- http://mail.python.org/mailman/listinfo/python-list
Re: list (range) syntax
Ryan Ginstrom wrote: >> On Behalf Of Steven D'Aprano >> Because in common English, counting starts at 1 and ranges >> normally include both end points (that is, it is a "closed" >> interval). If you say "I'll be away from the 4th to the 7th" >> and then turn up on the 7th, nearly everyone will wonder why >> you're back a day early. > > Actually, I think this illustrates the point about confusion, because in the > United States at least, "the 4th to the 7th" will not necessarily include > the 7th. That's why it's common to use circumlocutions like "the 4th through > the 7th" and "the 4th to the 7th, inclusive" when one wants to be sure. [slightly OT] A better example would be "10 to 12 people", which translates to "10, 11, or 12 people" and hardly ever "10 or 11 people". -- http://mail.python.org/mailman/listinfo/python-list
state of XSLT2/XPath2 or XQuery in CPython
hi, I was wondering if there is any way to use XSLT2 or maybe even XQuery with "normal" CPython. Using Saxon/XSLT2 with Jython is no problem (I have not tried Saxon.NET with IronPython but suspect no problem?) but I could not find any way to use XSLT2 or XPath Features with CPython. All the usual suspects 4suite or libxslt (via lxml) seem to have no support yet. Is there any hope I oversaw something? Would be especially interesting for a WSGI application, so a more or less complicated hack via CPython->Jython->Saxon and back would probably not be very useful (if that is possible at all). thanks! Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: state of XSLT2/XPath2 or XQuery in CPython
Stefan Behnel wrote: > Christof Hoeke wrote: >> I was wondering if there is any way to use XSLT2 or maybe even XQuery >> with "normal" CPython. Using Saxon/XSLT2 with Jython is no problem (I >> have not tried Saxon.NET with IronPython but suspect no problem?) but I >> could not find any way to use XSLT2 or XPath Features with CPython. All >> the usual suspects 4suite or libxslt (via lxml) seem to have no support >> yet. Is there any hope I oversaw something? > > I wouldn't know any implementation. Are you looking for a specific feature? > Using Python functions in XPath/XSLT might get you pretty close to XPath2. Almost full XSLT2 Support (minus XML Schema support, IMHO not too useful part of XSLT2) would be the best as writing templates in a general templating lang as XSLT is great if you use the same ones in cross-lang systems which are e.g. usable in Java or Python environment. Especially XPath Support with temporary trees (and not just fragments) is very useful (I know EXSLT is an option, but still not quite as good as XSLT2). Or stuff like sequences in XPAth2 simplifies development quite a bit (I think the following is possible, have not used it in the last weeks though): (a, b, c)[EMAIL PROTECTED]'123'] Or using sequences for ordering stuff like e.g.: in XSLT1: which in XSLT2 simply is: I used the Python extension functions some years ago in Pyana and later in LXML which is great but these naturally very much depend on Python then... I know XML and therefor also XSLT seem not the most favourite of tools in the Python community but for e.g. document based systems like CMS systems XML and XSLT is at least in my experience a great combination. thanks Christof -- http://mail.python.org/mailman/listinfo/python-list
Javascript parser
hello, is there any Javascript (not just JSON) parser for Python? I saw http://wwwsearch.sourceforge.net/python-spidermonkey/ which seems to be from 2003 and unmaintained and seems to be quite complicated to get to work anyway :( Using Rhino from Jython is not really an option as I'd like to work in (C)Python only. thanks for any hint Christof -- http://mail.python.org/mailman/listinfo/python-list
SimpleHTTPServer send wrong Content-Length for text/* on Windows?
hi, I noticed while trying a simple (but still very useful) server based on SimpleHTTP that it does report a wrong "Content-Length" for "text/*" files if Windows line-end "\r\n" is used. Most clients (e.g. browsers) do simply ignore a wrong Content-Length but there are programs that do care and simply abort handling a file given with a wrong Content-Length and not sending enough content afterwards. I had this problem specifically with Prince-XML but that seems to be based on curl which therefor might also be affect other products/libs. I found this via Google: http://mail.python.org/pipermail/python-bugs-list/2005-January/027157.html It seems this is not a new bug and I somehow recall that in an older version of Python (2.4?) it did work. But in 2.5 (also 2.5.1 and 2.5.2) this is not working anymore. Does anyone know if this is maybe being looked into already? I could not find anything in the Python Bug tracker but wanted to ask here first (I actually am not sure if I can add a bug report anyway). Thanks! Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: what IDE is the best to write python?
Hi, >> IMHO, scripting languages like Python are generally better suited to >> working with a text editor than an IDE. >> > I don't understand that, because in my opinion yields > IDE = texteditor + (much) more > please could you explain (as I'm very interested in user interfaces in > general ) Try to think of the operating system as the IDE. At least with Unix and similar systems that is a really powerfull solution. It includes not only vim, bash and make, but also stuff like e.g. ctags, awk, sed, etc. Even python itsself is part of the system and can be used for special purpous utilities like e.g. code generators. If you need User Interface Design, there are quite powerful stand alone tools, like e.g. the QtDesigner which can be used with that "OS IDE". Christof -- http://mail.python.org/mailman/listinfo/python-list
Re: what IDE is the best to write python?
Hi, >> > Just to register a contrary opinion: I *hate* syntax highlighting >> >> With vim you simply don't turn it on. Would that be OK for you? > > No. Even the /possibility/ of having syntax highlighting would indicate > wimpness and thus humiliate me. Ah, I guess you are using butterflies then: http://xkcd.com/378/ Christof -- http://mail.python.org/mailman/listinfo/python-list
Re: what IDE is the best to write python?
Hi, > Just to register a contrary opinion: I *hate* syntax highlighting With vim you simply don't turn it on. Would that be OK for you? Christof -- http://mail.python.org/mailman/listinfo/python-list
Re: Bitwise 2009 ($5000 prize money)
Hi, > http://www.bitwise.iitkgp.ernet.in/ I'm having quite some fun reading the questions since I got this Post in comp.lang.c++ before. Here it is of topic and this crosspostings will definatelly not be a good advertisement for your contest. Christof -- http://mail.python.org/mailman/listinfo/python-list
Re: Will multithreading make python less popular?
Hi, > But there is > something interesting, something like multi processing. But is it a > real alternative for multi threading. As i searched it is not, it > requires heavy hardware requirements (lots of memory, lots of cpu > power). Not necessarily. For the memory, modern operating Systems can ustilize a copy on write semantics in their Applications virtual memory space. That means that after starting a new process with fork(), the new Process shares all physical Memory Pages with the original one as long a none of them writes to wome Memory. The first write is cought by the OS. Then the Page will be copied and the writing process will in future use the new copy of that page while the other one (or eventually many) stay with the original. Multiprocessing needs more Memory than well optimized Multithreading, but it is not as bad as it is often said. For the CPU: There are two things that make the difference here. One ist Context Switching. When the OS switches between two threads of the same Process, it does not need to change the memory lookup table. When switching between Processes that is always necessary. Switching from a Thread of Process A to a Thread of Process B is just like switching from A to B. Using Threads just increases the probability that the OS can do a faster Context Switch. So Threads are faster here, but it is not a too big issue as well. The Second Thing is Communication. With Threds you can simply use variables to communicate between Threads. To Prevent conflicting access to those Variables you will use e.g. mutexes. That can be done with Shared Memory as well. Shared Memory is a bit more difficult to handle than simply using the heap, but again the impact is not really so big. Google uses Processes for the Tabs in Chrome, because that way they get around many Memory Management Problems they would have with Threads or with a singlethreaded reactor. Using Processes is not per se a bad Idea. You pay a bit with Memory and CPU but in many situations you get a much simpler programming model. Christof -- http://mail.python.org/mailman/listinfo/python-list
SOAPpy WSDL problem: namespace of schema and import match error
I am trying to use a webservice with SOAPpy: import SOAPpy intact_wsdl = "http://www.ebi.ac.uk/intact/binary-search-ws/binarysearch?wsdl"; intact_serv = SOAPpy.WSDL.Proxy(intact_wsdl) The resulting error message is posted below. If I understand it right, XMLSchema.py complains about the imported XSD namespace being the same as the existing targetNamespace. Perl and Java have no problems with the WSDL document (see sample code at http://www.ebi.ac.uk/~intact/devsite/remote/binarysearch_ws.html) My question: - Is there a problem with the WSDL file being not valid? - Is there a problem with the Python SOAP/WSDL implementation? Any suggestions? Christof Traceback (most recent call last): File "testEBIIntactWebservice.py", line 3, in intact_serv = SOAPpy.WSDL.Proxy(intact_wsdl) File "/var/lib/python-support/python2.5/SOAPpy/WSDL.py", line 62, in __init__ self.wsdl = reader.loadFromStream(stream, wsdlsource) File "/var/lib/python-support/python2.5/SOAPpy/wstools/WSDLTools.py", line 34, in loadFromStream wsdl.load(document) File "/var/lib/python-support/python2.5/SOAPpy/wstools/WSDLTools.py", line 260, in load schema = reader.loadFromNode(WSDLToolsAdapter(self), item) File "/var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py", line 80, in loadFromNode schema.load(reader) File "/var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py", line 1076, in load tp.fromDom(node) File "/var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py", line 1177, in fromDom raise SchemaError, 'namespace of schema and import match' SOAPpy.wstools.XMLSchema.SchemaError: namespace of schema and import match -- http://mail.python.org/mailman/listinfo/python-list
Re: SOAPpy WSDL problem: namespace of schema and import match error
Christof Winter wrote, On 28.07.2008 12:32: I am trying to use a webservice with SOAPpy: import SOAPpy intact_wsdl = "http://www.ebi.ac.uk/intact/binary-search-ws/binarysearch?wsdl"; intact_serv = SOAPpy.WSDL.Proxy(intact_wsdl) [...] My question: - Is there a problem with the WSDL file being not valid? I just figured out that this could indeed be true. The WSDL document contains an XML Schema import that probably should be an XML Schema include: "The import element is used to add multiple schemas with different target namespace to a document." http://www.w3schools.com/schema/el_import.asp "The include element is used to add multiple schemas with the same target namespace to a document." http://www.w3schools.com/schema/el_include.asp Maybe I should post this to comp.text.xml Christof -- http://mail.python.org/mailman/listinfo/python-list
Re: Good books in computer science?
Hi, > Which are the classic books in computer science which one should > peruse? >From having read this discussion up to now I'd recomend you to read code written by good programmers. Christof -- http://mail.python.org/mailman/listinfo/python-list
