Re: How to run python script in emacs
On 7 oct, 22:07, "Sells, Fred" wrote: > Hitting ctrl-c, twice quickly works for me. > ? what do you mean ? Olivier -- http://mail.python.org/mailman/listinfo/python-list
Re: Neural networks in python
Machine Learning: An Algorithmic Perspective http://www.crcpress.com/product/isbn/9781420067187 Associated python code: http://seat.massey.ac.nz/personal/s.r.marsland/MLBook.html On Wed, Oct 7, 2009 at 11:53 PM, ruchir wrote: > I want to design and train a neural network in python. Can anyone > guide me, from where can I get some useful material/eBook/libraries > etc. for the same. I have no prior experience in neural netwoks and > want to implement it urgently. > Thanks in advance :) > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Neural networks in python
I want to design and train a neural network in python. Can anyone guide me, from where can I get some useful material/eBook/libraries etc. for the same. I have no prior experience in neural netwoks and want to implement it urgently. Thanks in advance :) -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
Carl Banks writes: > On Oct 7, 8:29 pm, Chris Jones wrote: >> Always felt that syntax highlighting for instance is way >> overrated. > > I have all syntax colors turned off except for strings and comments. > I highly recommend this low-key syntax coloring for those who don't > care for the normal psychodelic syntax coloring. > > Bright red comments definitely helps them stand out (the easier to > ignore them with), and cool blue strings provide a subtle syntax clue > while not being too distracting. Rest of the text is black. I quite like a bit of syntax highlighting - it helps to quickly grasp the structure of code. Of course how much is a matter of taste. I also like to highlight things that can creep in accidentally and shouldn't be there - e.g. whitespace at the end of lines, tabs where there should be spaces. -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
Hans Mulder wrote: Errrhm, no. He is not deleting the PyQt4 module from sys.modules; he's only deleting the name QtGui from his own namespace. Next time Python comes across from PyQt4 import QtGui , it finds that the module PyQt4 already exists in sys.modules, so Python does not have to load the module again. All it has to do is bind name QtGui in the importing module to the class with the same name in the PyQt4 module. That does not take many cycles. I recently discovered that when IDLE restarts (as when one runs a file from an edit window), it clears the global namespace but does not clear sys.modules. Hence re-running a script that does time-consuming imports is much faster, as only the global name binding is done after the first run. -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On Oct 7, 8:29 pm, Chris Jones wrote: > Always felt that syntax highlighting for instance is way > overrated. I have all syntax colors turned off except for strings and comments. I highly recommend this low-key syntax coloring for those who don't care for the normal psychodelic syntax coloring. Bright red comments definitely helps them stand out (the easier to ignore them with), and cool blue strings provide a subtle syntax clue while not being too distracting. Rest of the text is black. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On Oct 8, 3:29 am, Chris Jones wrote: > I do have a question: > > You mentioned Vim's clientserver mode. > > What's it good for? It's most valuable for sending data to an existing instance of vim, by name. Both files and keystrokes can be sent fwiw. vim basically organizes it self into buffers, windows, pages, and servers. A buffer is essentially a file, a window a look into a buffer, a page a group of windows, and a server is an instance of vim (group of pages). As a matter of standard operating procedure, I organize tab pages into module or project oriented workspaces; each page usually contains a split window: open to a source file and a corresponding header^* file. It's a work flow I got used to using for dealing with C++ and Perl code, but it is still useful for Python as well. On top of that, I sometimes group instances of vim into 'servers' by type. So for example, I may have a vim servers (instances) each for FooProject, BarPorject, and another for editing personal documents or configuration files. When I have programs that launch vim to handle editing tasks, I'll often make them send the file to an appropriate vim server, so everything is grouped accordingly. Example: when projects require the use of Visual C++, I have the IDE set to open most files with a custom program: which execs gvim --servername MSVC -- remote-tab-silent TheFileNameToOpen.ext. So that every file opened through VC will be in one GVim window. The same could be done with several webbrowsers, mail clients, and newsreaders. It makes using using vim as an external program to something fatter much more convenient. GNU Screen and a decent terminal emulator can be more handy then clientserver, when the work station supports it that is;). As far as I know, both GNU Emacs and XEmacs have client/server system as well. ^* by header, I mean things like C/C++ header files, Perl/Python modules, etc. -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On Wed, 07 Oct 2009 17:32:16 -0700, Carl Banks wrote: >> >> One feature I have that emacs don't is that I'm able to efficiently >> >> edit a file on a remote machine with vim on a terminal (without >> >> graphical interface), and I'm using it. Apart from that, both >> >> solutions are >> >> > emacs has the same efficiency on a terminal. or maybe I don't >> > understand your sentence. >> >> Perhaps this is a reference to the alt/meta/control/buckey/super >> key-chords that emacs is infamous for using > > It's Esc-Meta-Alt-Ctrl-Shift Emacs doesn't use Alt, Super or Hyper for any pre-defined bindings, although you can use them for your own bindings. It does use Meta for pre-defined bindings, and understands Esc, as equivalent to Meta-. The most common terminal-related problems are: 1. Your terminal is configured to treat Meta as Alt (i.e. Meta- sends +128 rather than Esc,. 2. $TERM doesn't accurately reflect your terminal; e.g. $TERM is set to vt100 when the terminal has cursor keys, ANSI colour, or the terminfo entry for $TERM says that Delete sends ESC,[,3,~ when it actually sends DEL (similarly for C-h/DEL for Backspace). 3. Not being able to distinguish between BS, CR, LF from C-h, C-m, C-j, etc. Most bindings which use these keys work with all interpretations (e.g. C-x C-m and C-x return are bound to the same functions for all values of ). The main exception is that C-h maps to BS on a terminal, so you need to use M-? (or Esc,?) or F1 for the help commands. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about RADIXCHAR on Win32
En Wed, 07 Oct 2009 08:16:19 -0300, Stephane Wirtel escribió: I have a problem with locale.RADIXCHAR, it seems this constant isn't defined on the Windows platform. Is there a way to use an equivalent of locale.RADIXCHAR ? You can obtain that info from localeconv, available on Windows too: py> import locale py> locale.localeconv()['decimal_point'] '.' py> locale.setlocale(locale.LC_ALL, '') 'Spanish_Argentina.1252' py> locale.localeconv()['decimal_point'] ',' -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Python + webservice
Fred Chevitarese wrote: Hello all... I'm new here and a search in tis group but unfortunately i didn't find any kind of solution/code/question etc ... I have to made a python script that communicates with an websevice over the web. I tried out use SoapPy, ZSI, BeautifullSoap and others, but get no success... I have to generate a XML file from a XSD file, and them send it to a webservice as i have said before. There's really no need to generate a XML file from a XSD file bu if it's possible it will be very very good... Has anyone made something like this and can share with me a bit of experience? Did you try suds https://fedorahosted.org/suds ? I've got good results with this library. Ralf -- http://mail.python.org/mailman/listinfo/python-list
Re: Rules regarding a post about a commercial product
On Wed, Oct 7, 2009 at 1:59 AM, Ken Elkabany wrote: > Hello, > > I am hoping to get feedback for a new, commercial platform that > targets the python programming language and its users. The product is > currently in a closed-beta and will be free for at least a couple > months. After reviewing the only rules I could find > (http://www.python.org/community/lists/), I wanted to ask one last > time to make sure that such a post would be appropriate. > Commercial/closed-source software is not taboo to the Python community in general. There's a few commercial products which do announcements and such to python-list. If it has to do with Python, it's on-topic. IMHO :) --S -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.6.4rc1
On Wed, 07 Oct 2009 19:45:29 -0700, Carl Banks wrote: > 2.6.3 breaks setuptools: > > http://bugs.python.org/issue7064 > > I might upgrade to 2.6.3 just for that benefit alone. Well, I knew some people disliked setuptools, but I didn't realize the antipathy was so high! -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On Wed, Oct 07, 2009 at 07:06:08PM EDT, TerryP wrote: [..] > I am a freak: I do not use nor want syntax highlighting. I don't want > my editor to understand mail, irc, or the www either, I want it to > edit text efficiently so I can go on with the rest of my life as soon > as possible. Given the choice of using a space cadets editor like > emacs or something primitive one like ed, I would choose *ed* just to > speed things up and save on wrist strain. Before I read a tutorial > about vi, I used XEmacs very happily---vi just lines up better with > how my brain works. > > -- > > It is also general consensus that I am nuts ;) I don't think so. Always felt that syntax highlighting for instance is way overrated. Haven't tried "ed" yet, but since I have already stripped down my everything to what I thought was minimal, now that you mention it, this may be where I'm bound. I do have a question: You mentioned Vim's clientserver mode. What's it good for? Thanks, CJ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.6.4rc1
On Oct 7, 6:28 pm, Robert H wrote: > On Oct 7, 1:18 pm, Barry Warsaw wrote: > > > > > > > Hello everyone. > > > The source tarballs and Windows installers for Python 2.6.4rc1 are now > > available: > > >http://www.python.org/download/releases/2.6.4/ > > > Please download them, install them, and try to use them with your > > projects and environments. Let us know if you encounter any problems > > with them. Hopefully we can avoid the situation with 2.6.3 having > > such critical bugs. > > > 2.6.4 final is planned for 18-October. > > > Cheers, > > -Barry > > > PGP.sig > > < 1KViewDownload > > So I take it builds based on 2.6.3 should be avoided? 2.6.3 breaks setuptools: http://bugs.python.org/issue7064 I might upgrade to 2.6.3 just for that benefit alone. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
On Oct 7, 4:35 pm, Irmen de Jong wrote: > I just got my solution accepted, it ran in 14 seconds though. Hey, that's pretty good. Until n00m instigated the most recent INOUTEST craze, the only accepted answer besides numerix's was one that barely squeaked in at 19.81s, and that result was achieved with the older and apparently much faster (at least on the SPOJ machine) Python 2.5. (I see a lot of people trying to pass INOUTEST with Python these days, many or most of them because they have read this thread.) > Things that eventually made my solution run within the time limit: > - I didn't use int() > - I used Psyco > > Those two resulted in the biggest speed increase. > Tweaking with buffered/unbuffered IO was insignificant. Thank you so much for these tips. I quickly threw something together and now have my very own accepted INOUTEST answer! It's clearly not optimized, and I think a lot of people will soon have solutions much faster than mine and closer to yours, now that they are not wasting their efforts chasing dead ends. John P.S. I hope people realize that the concise, intuitive, readable answers we all tried in our first couple of (failed) attempts are much more Pythonic than the beasts that were created just for SPOJ. -- http://mail.python.org/mailman/listinfo/python-list
Re: WMI remote call in python script to create process on remote windows computer
David Jackson wrote: ok, cut and pasted, but changed the username/password to protect the innocent. this is from interactive prompt. let me know if i am still not doing the slashes correctly please. i doubt authentication is the issue.; i can get pid information using WQL queries. objCreateProc.Create expects 4 strings (not objects?), right? version info: sys.version '2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)]' import win32com.client computer = "servername" strUser = "servername\\my_account" strPassword ="shh_secret" objSWbemLocator = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objSWbemLocator.ConnectServer(computer, r"root\cimv2",strUser,strPassword) objCreateProc = objSWbemServices.Get("Win32_Process") ProcessID = u"200" objCreateProc.Create(u"cmd /c ping 127.0.0.1 >>c:\\temp\\finall.log",u"c:\\temp",u' ',ProcessID ) Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not callable how can i see the method available? help(objCreateProc) just gives me "Help on instance of CDispatch in module win32com.client:" Thanks David Looks to me like objCreateProc.Create has an integer value. You could add a print for that value before the call to objCreateProc.Create(). (Leave off the parentheses on the print statement) My guess is that you've got an address there, but I have no idea how to convert that to a valid Python function pointer. Is there reasonable docs for WMI somewhere? DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.6.4rc1
On Oct 7, 1:18 pm, Barry Warsaw wrote: > Hello everyone. > > The source tarballs and Windows installers for Python 2.6.4rc1 are now > available: > > http://www.python.org/download/releases/2.6.4/ > > Please download them, install them, and try to use them with your > projects and environments. Let us know if you encounter any problems > with them. Hopefully we can avoid the situation with 2.6.3 having > such critical bugs. > > 2.6.4 final is planned for 18-October. > > Cheers, > -Barry > > PGP.sig > < 1KViewDownload So I take it builds based on 2.6.3 should be avoided? Bob -- http://mail.python.org/mailman/listinfo/python-list
Re: SAX: Short tag's ...
Thomas Lehmann wrote: > Hi! > > Is there a way to recognize short tags in a XML? > I'm implementing a SAX handler... > > Problem: storing the XML code I would need this information > in the startElement ... > > How can I handle this? > > > any text So ... are you writing as you read? If so, I'm not sure you can know which form to write out immediately. Best bet would be to delay write until the next SAX event. The next SAX event will tell if the element should be written as or . --David -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
Carl Banks wrote: On Oct 7, 10:29 am, Tim Chase wrote: Perhaps this is a reference to the alt/meta/control/buckey/super key-chords that emacs is infamous for using It's Esc-Meta-Alt-Ctrl-Shift Sure that's not Winkey+Tab+Fn? :-) -tkc :wq! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
On Oct 7, 5:11 pm, Roger Binns wrote: > Curious wrote: > > Did you mean to say that Ubuntu does come pre-installed with 64-bit > > Python? > > I am saying that 64 bit Ubuntu comes with 64 bit Python. (32 bit Ubuntu > comes with 32 bit Python.) > > > When I used the same command as you did, I see a 32-bit > > version there. > > It is most likely that you are running 32 bit Ubuntu (unless you bypassed > Ubuntu's packaging and similar stunts). Run 'uname -a' and look near the > end. For 64 bit you should see something like this: > > $ uname -m > x86_64 > > If you see i686 instead of x86_64 you are on 32 bit. > > > $ file /usr/bin/python2.6 > > /usr/bin/python2.6: ELF 32-bit LSB executable, Intel 80386, version 1 > > (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, > > stripped > > That is definitely a 32 bit binary. Try some others like /bin/ls and > /sbin/init. (A 64 bit kernel can run 32 bit binaries but these core system > files should all match the kernel.) > > > I also tried building Python on this machine by setting following > > configuration option: > > /configure --enable-universalsdk --with-universal-archs="64-bit" > > That is a road you don't want to go down unless you really know what you are > doing and want to bypass the packaging system. As far as I am aware those > options only apply to Macs anyway! > > > Could you please explain how did you get a 64-bit version there? > > When I download Ubuntu I got the 64 bit version. Look at the bottom of the > page: > > http://www.ubuntu.com/getubuntu/download > > You may find various guides on how to convert a 32 bit installation into a > 64 bit one. Do not do any of those (if you do then mention it when asking > for help at which point people will tell you not to have done that!) Make a > backup and do a *fresh* install. > > Roger Thanks Roger. Actually we have one machine at our disposal to try different things out. We installed Linux on it just yesterday and wanted to get Python working so there's nothing important that we fear to loose. We'll probably do the fresh install. Will post on the forum about how it goes and if I get 64-bit Python version. -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On Oct 7, 10:29 am, Tim Chase wrote: > >> One feature I have that emacs don't is that I'm able to efficiently edit > >> a file on a remote machine with vim on a terminal (without graphical > >> interface), and I'm using it. Apart from that, both solutions are > > > emacs has the same efficiency on a terminal. > > or maybe I don't understand your sentence. > > Perhaps this is a reference to the alt/meta/control/buckey/super > key-chords that emacs is infamous for using It's Esc-Meta-Alt-Ctrl-Shift Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
On Oct 7, 4:55 pm, Christian Heimes wrote: > Curious schrieb: > > > > > On Oct 7, 4:07 pm, Roger Binns wrote: > >> Curious wrote: > >>> Ubuntu comes pre-installed with Python2.6 but this python installation > >>> is a 32 bit installation. > >> For 64 bit Ubuntu you are mistaken: > > >> $ file /usr/bin/python2.6 > >> /usr/bin/python2.6: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), > >> dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped > > >>> I do the following to know if the current python installation is 32- > >>> bit or 64-bit: > >> This is what I do: > > > import ctypes > > ctypes.sizeof(ctypes.c_void_p) > >> 8 > > >> Roger > > > Thanks very much for you response, Roger! > > > I am sorry but I am not able to follow what you are saying. I am quite > > new to linux installation world and it's possible that I am missing > > pretty straightforward info. > > > Did you mean to say that Ubuntu does come pre-installed with 64-bit > > Python? When I used the same command as you did, I see a 32-bit > > version there. I am not sure how to get to 64-bit. > > I bet your Ubuntu installation is 32bit, too. You need a 64bit > installation of Ubuntu in order to run a 64bit version of Python. By > default Python is compiled in the same flavor as the OS. What does > "uname -m" show? It should print "x86_64" for a 64bit version of Linux. > > --enable-universalsdk and --with-universal-archs have no function on > Linux. They are Mac OS X only options. > > Christian Thanks for your response Christian! You are right, I have got a wrong Ubuntu installation, installed it by mistake instead of 64-bit. After the re-installation, I will post what Python version I find. Thanks all! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
Curious wrote: > Did you mean to say that Ubuntu does come pre-installed with 64-bit > Python? I am saying that 64 bit Ubuntu comes with 64 bit Python. (32 bit Ubuntu comes with 32 bit Python.) > When I used the same command as you did, I see a 32-bit > version there. It is most likely that you are running 32 bit Ubuntu (unless you bypassed Ubuntu's packaging and similar stunts). Run 'uname -a' and look near the end. For 64 bit you should see something like this: $ uname -m x86_64 If you see i686 instead of x86_64 you are on 32 bit. > $ file /usr/bin/python2.6 > /usr/bin/python2.6: ELF 32-bit LSB executable, Intel 80386, version 1 > (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, > stripped That is definitely a 32 bit binary. Try some others like /bin/ls and /sbin/init. (A 64 bit kernel can run 32 bit binaries but these core system files should all match the kernel.) > I also tried building Python on this machine by setting following > configuration option: > /configure --enable-universalsdk --with-universal-archs="64-bit" That is a road you don't want to go down unless you really know what you are doing and want to bypass the packaging system. As far as I am aware those options only apply to Macs anyway! > Could you please explain how did you get a 64-bit version there? When I download Ubuntu I got the 64 bit version. Look at the bottom of the page: http://www.ubuntu.com/getubuntu/download You may find various guides on how to convert a 32 bit installation into a 64 bit one. Do not do any of those (if you do then mention it when asking for help at which point people will tell you not to have done that!) Make a backup and do a *fresh* install. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
Curious schrieb: > On Oct 7, 4:07 pm, Roger Binns wrote: >> Curious wrote: >>> Ubuntu comes pre-installed with Python2.6 but this python installation >>> is a 32 bit installation. >> For 64 bit Ubuntu you are mistaken: >> >> $ file /usr/bin/python2.6 >> /usr/bin/python2.6: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), >> dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped >> >>> I do the following to know if the current python installation is 32- >>> bit or 64-bit: >> This is what I do: >> > import ctypes > ctypes.sizeof(ctypes.c_void_p) >> 8 >> >> Roger > > Thanks very much for you response, Roger! > > I am sorry but I am not able to follow what you are saying. I am quite > new to linux installation world and it's possible that I am missing > pretty straightforward info. > > Did you mean to say that Ubuntu does come pre-installed with 64-bit > Python? When I used the same command as you did, I see a 32-bit > version there. I am not sure how to get to 64-bit. I bet your Ubuntu installation is 32bit, too. You need a 64bit installation of Ubuntu in order to run a 64bit version of Python. By default Python is compiled in the same flavor as the OS. What does "uname -m" show? It should print "x86_64" for a 64bit version of Linux. --enable-universalsdk and --with-universal-archs have no function on Linux. They are Mac OS X only options. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
On Oct 7, 4:07 pm, Roger Binns wrote: > Curious wrote: > > Ubuntu comes pre-installed with Python2.6 but this python installation > > is a 32 bit installation. > > For 64 bit Ubuntu you are mistaken: > > $ file /usr/bin/python2.6 > /usr/bin/python2.6: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), > dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped > > > I do the following to know if the current python installation is 32- > > bit or 64-bit: > > This is what I do: > > >>> import ctypes > >>> ctypes.sizeof(ctypes.c_void_p) > > 8 > > Roger Thanks very much for you response, Roger! I am sorry but I am not able to follow what you are saying. I am quite new to linux installation world and it's possible that I am missing pretty straightforward info. Did you mean to say that Ubuntu does come pre-installed with 64-bit Python? When I used the same command as you did, I see a 32-bit version there. I am not sure how to get to 64-bit. $ file /usr/bin/python2.6 /usr/bin/python2.6: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes >>> ctypes.sizeof(ctypes.c_void_p) 4 I also tried building Python on this machine by setting following configuration option: /configure --enable-universalsdk --with-universal-archs="64-bit" But no luck. I am definitely missing something here. Could you please explain how did you get a 64-bit version there? I am using ubuntu 9.0.4. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: AES decrypting in Python
Heikki Toivonen wrote: Mike Driscoll wrote: EVP.Cipher(alg="aes_256_ecb", key=SomeKey, iv=SomeIV, op=dec, padding=False) I don't really see where I pass the data that needs the decrypting though. Can someone shed some light on this? Look at test_AES method in http://svn.osafoundation.org/m2crypto/trunk/tests/test_evp.py Basically EVP.Cipher returns the cipher object. You call the update update(data) method on it (you can call this many times if you have lots of data), which returns (possibly partial) result and finally call the final() method to finish, which will return the last piece of the decrypted data. You might also want to take a look at m2secret[1] which is a small library/utility built on top of M2Crypto to encrypt/decrypt stuff. By default it uses AES. [1] http://www.heikkitoivonen.net/m2secret/ thanks Heikki, finally some encryption / decryption tool that can be used by non-crypto-maniaks. cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
I typically use several editors: /bin/ed, nvi, EDIT.COM, and Vi Improved. These are the advantages that I find these various editors give me: ed -- I can quickly edit files without having to wait on an ncurses app to start up. Although I rarely have access to GNU versions of ed, they use readline which is a big perk when you make a typo. nvi -- smaller and faster then vim, works great over slow ssh links or when editing huge files. I like nvi over the original vi, because most of the limitations of the old-school vi are removed; unlimited undo is the best feature added. EDIT.COM -- much faster then notepad over remote connections, and it understands both DOS and UNIX end of lines; meaning I can skip converting formats, the only downside is it's still a 16-bit program. vim -- My favourite and most used editor. I like it because it can be made fairly compatible with vi, but has superior tag stack handling, and the multiple-window, :ex command line history, and completion features leave their nvi equivalents in the dust. (vi had no completion or command history, and lacked split windows.) Vim also has improved register handling, regular expression support, tab pages for organizing workspaces, a client/server mode, and most importantly can be made to adapt itself (e.g. spaces, tabs, eol's) based on file type without much bother. That makes it much easier to use with Python files then most editors in my tool bag. I am a freak: I do not use nor want syntax highlighting. I don't want my editor to understand mail, irc, or the www either, I want it to edit text efficiently so I can go on with the rest of my life as soon as possible. Given the choice of using a space cadets editor like emacs or something primitive one like ed, I would choose *ed* just to speed things up and save on wrist strain. Before I read a tutorial about vi, I used XEmacs very happily---vi just lines up better with how my brain works. -- It is also general consensus that I am nuts ;) TerryP. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to install 64-bit python on Ubuntu
Curious wrote: > Ubuntu comes pre-installed with Python2.6 but this python installation > is a 32 bit installation. For 64 bit Ubuntu you are mistaken: $ file /usr/bin/python2.6 /usr/bin/python2.6: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped > I do the following to know if the current python installation is 32- > bit or 64-bit: This is what I do: >>> import ctypes >>> ctypes.sizeof(ctypes.c_void_p) 8 Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: When ‘super’ is not a good idea
Jean-Michel Pichavant wrote: > alex23 wrote: > > To me, the explicit reference to the base class violates DRY. It also > > means you need to manually change all such references should the base > > class ever change, something that using super() avoids. > > I found the correct answer > (http://www.artima.com/weblogs/viewpost.jsp?thread=236275) I'm not entirely sure how an opinion + explanation of the underlying mechanics is more or less "correct" than a development principle... -- http://mail.python.org/mailman/listinfo/python-list
Tkinter -- the best way to make a realtime loop
What's the best way to make a realtime loop in Tkinter? I know in perl you can use "repeat" and it will call a function every x seconds, in python it seems like "after" may be the equivalent though it doesn't seem to behave like the perl repeat function. Any ideas? Thanks, Jonathan -- http://mail.python.org/mailman/listinfo/python-list
How to install 64-bit python on Ubuntu
Hello All, Ubuntu comes pre-installed with Python2.6 but this python installation is a 32 bit installation. I need to use 64-bit Python on Ubuntu - how do I update the current installation to 64-bit installation? Is there any separate package that I need to apt-get? I do the following to know if the current python installation is 32- bit or 64-bit: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from struct import * >>> calcsize("P") * 8 32 >>> I expect to see the pointer size as 64 there.. If any of you could provide me any info on this matter, it would be a great help Thanks in advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
On Wed, 07 Oct 2009 02:31:00 -0700, Ryan wrote: > Thanks everyone for your insight. I'm going to have to agree with the > paranoid desire to prevent people importing his module and then using > the > classes he imports from elsewhere (I'm not ruling out the lead paint > theory until I can gather more evidence). It does beg the question for > me. No it doesn't, it raises the question. http://en.wikipedia.org/wiki/Begging_the_question > Consider the example from his code below > > from PyQt4 import QtGui > > class LauncherWidget( QtGui.QWidget ): > # A Specialization of QWidget > > del QtGui > > Next time python comes across > > from PyQt4 import QtGui > > it would have to re-import the class, which seems a waste of cycles that > could accumulate. As Hans explained, not quite. When you call "from PyQt4 import QtGui", Python loads the module PyQt4, caches the module in sys.modules, and then adds PyQt4.QtGui into the current namespace (your module). When you delete QtGui, that only removes it from your namespace. The module is still in the cache, so the next time you call the import, it's much, much faster. Multiple imports aren't entirely free, but they're much less expensive than you might think. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining python and sqlite DB into a single, "executeable".
[Please do not email me *and* the list - it is highly annoying] Tom Cumming wrote: > Thanks!, but I already thought of your suggestion. I've already gotten > the clear impression that the amount of work to implement this is more than > the ROI. It isn't anywhere near as hard or as much work as you think! > Having said that, it might work if on exiting the app could re-zip itself. See the atexit module. > One _big_ problem with zip files or compiled python executables is > moving the file > from machine to machine. It wouldn't be platform independent anymore. You are the one who mentioned executables which generally means platform specific binaries (and in the vast majority of cases that platform is Windows) :-) Being an executable means you don't have to care if Python is already installed. If you want it platform independent then you are stuck with Python text scripts. You can put one in a zip file and use PYTHONPATH or you can use the approach I showed at the bottom of my original message. > What I like best so far, is to have something like: You pretty much outlined what I wrote at the bottom of my message. > Convince the python parser not to go here... You can't do that. The entire source file has to be valid Python. You can get Python to not take action on parts by making it a multi-line string you do nothing with (ie surround with """) or by prefixing each line with # to make it a comment. I'd recommend a string at the end with base64 encoded contents. This would be very few lines of code to maintain along with tempfile.NamedTemporaryFile and atexit. My estimate is a total of 10-20 lines of code. > Now the trick is to get the sqlite library to start looking for the > sqlite database at, "offset". You cannot use the standard SQLite API to do that. SQLite does have a way of writing custom file access (known as VFS) that could do it and the APSW SQLite Python wrapper provides that functionality. See http://apsw.googlecode.com/svn/publish/vfs.html (Disclaimer: I am the author of APSW). However writing a VFS is *way* more work than something simple to extract data from the end of a script to a temporary file and put the data back at exit. And you'd have to ensure all machines have both Python and APSW installed. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: Graphical nodes
Sorry for the toppost, I'm on a mobile, but if I'm understanding you then you might want to try graphine- its a graph theory library with experimental dot language support, which you can use to draw your graphs. Give it a try- graphine.org. On Oct 7, 2009 2:12 AM, "Dylan Palmboom" wrote: Hi everyone Please could someone tell me of any libraries that you could use to make use of graphical nodes in python. Each node would hold data and properties. I am trying to achieve a similar effect, as in the application spoken about below. If you have seen an application called Nuke, by the foundry, you will see what I mean. It uses graphical nodes such as rectangles etc (similar to UML) to link operations on images together with arrows etc. I know that Nuke is made using the Qt toolkit, so maybe someone could tell me what classes were probably used to make this node based interface. Maybe the QGraphicsItem and QGraphicsScene classes? It looks cool so if anyone has any ideas on how to do something like this, it would be great. Thanks -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
On Oct 7, 2:31 am, Ryan wrote: > Thanks everyone for your insight. I'm going to have to agree with the > paranoid desire to prevent people importing his module and then using > the > classes he imports from elsewhere (I'm not ruling out the lead paint > theory until I can gather more evidence). It's wasted effort. Python isn't really designed to have totally clean namespaces. A base class can be deleted at the end of a module because it's only used while the module is being imported, but lots of other symbols can't. You can't delete any global that's used in a function, that means most imported modules or functions have to remain in the module's namespace, and usually there are a lot more of them than there are deletable base classes. Given that you can't generally have an externally clean namespace, why put forth such effort just to delete one or two names? The right thing to do is to advertise which symbols are external with __all__ (or, as judgment call, to use leading underscore on all internal symbols). There are some tricks you could use to keep __all__ up-to-date, for instance you can use this idiom to automatically add anything defined between two points to __all__ (though it can be subject to name clashing): ## do all your imports here _internals = set(globals()) ## define all your functions/classes/constants here _allnames = set(globals()) __all__ = list(x for x in _allnames-_internals if not x.startswith('_')) del _internals, _allnames # del ok here because this does free memory Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: WMI remote call in python script to create process on remote windows computer
ok, cut and pasted, but changed the username/password to protect the innocent. this is from interactive prompt. let me know if i am still not doing the slashes correctly please. i doubt authentication is the issue.; i can get pid information using WQL queries. objCreateProc.Create expects 4 strings (not objects?), right? version info: >>> sys.version '2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)]' >>> import win32com.client >>> computer = "servername" >>> strUser = "servername\\my_account" >>> strPassword ="shh_secret" >>> objSWbemLocator = win32com.client.Dispatch("WbemScripting.SWbemLocator") >>> objSWbemServices = objSWbemLocator.ConnectServer(computer, >>> r"root\cimv2",strUser,strPassword) >>> objCreateProc = objSWbemServices.Get("Win32_Process") >>> ProcessID = u"200" >>> objCreateProc.Create(u"cmd /c ping 127.0.0.1 >>> >>c:\\temp\\finall.log",u"c:\\temp",u' ',ProcessID ) Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not callable how can i see the method available? >>> help(objCreateProc) just gives me "Help on instance of CDispatch in module >>> win32com.client:" Thanks David -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 14:05:25 -0700, Victor Subervi wrote: print 'Content-Type: image/jpeg' print 'Content-Encoding: base64' print print content.encode('base64') I did change it to text/plain, but I don't know how I'm supposed to manually decode it. Yes, it printed out a bunch of crap to the screen. I've gotten that far before, and once I read "Adobe" something, so yes, it's an image. TIA, V Hopefully the 'crap' you're getting is the base64-encoded representation of your binary image -- you should be able to use Python to decode that, and then use any image viewer to verify that the JPEG is sound. Can you remind us of the URL where that code (with the text/plain content type) is running? On Wed, Oct 7, 2009 at 3:52 PM, Rami Chowdhury wrote: On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi < victorsube...@gmail.com> wrote: I did that. In fact, just to make things easier, I wrote out exactly what is supposed to be rendered, as below: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = "select pic1 from products where id='1';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg'''# Only print one line Content-Encoding: base64 ''' print print content.encode('base64') Just to reiterate what Gabriel and Carsten have pointed out, I'd suggest changing the last few lines of the script, as the comments below indicate: print '''Content-Type: image/jpeg''' # One header line print '''Content-Encoding: base64''' # Another header line. Note *no* blank line between them print# Blank line signals the end of the headers print content.encode(base64) # Base64-encoded content comes *after* the blank line If you include extra blank lines after the headers, the browser will misunderstand where the binary image data begins, and so will see a malformed JPEG. If this doesn't work, I suggest changing the content-type header to text/plain and trying to manually decode and check the image data to ensure it's valid. On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina >wrote: En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi escribió: > print '''Content-Type: image/jpeg > > ''' > print > print content On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina wrote: > That's still wrong. The output should be: > > - a line containing Content-Type: image/jpeg > - a blank line (no more!) ^ > - the actual image data -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: Combining python and sqlite DB into a single, "executeable".
Thanks!, but I already thought of your suggestion. I've already gotten the clear impression that the amount of work to implement this is more than the ROI. Having said that, it might work if on exiting the app could re-zip itself. One _big_ problem with zip files or compiled python executables is moving the file from machine to machine. It wouldn't be platform independent anymore. What I like best so far, is to have something like: #!/usr/bin/env python """ Here lies python, "boot" code that connects to the sqlite db that pulls from a known sqlite table a blob that is the actual application and executes it. The boot code size must always be less than some size.""" Convince the python parser not to go here... fillter bytes to the sqlite database offset. sqlite database data End of File. Now the trick is to get the sqlite library to start looking for the sqlite database at, "offset". Roger Binns wrote: tcumming...@gmail.com wrote: The problem, is that I need the python app and the sqlite db file to exist in the same disk file. This way the app to access the data and the data are in the same file. For binaries this is possible with a little hackery. Firstly you need make the app be a zip file. The good news is that zip files store their information at the end while executables store their information at the beginning. This is how self extracting zips work - they are the extractor program followed by the zip data. You can store the sqlite database in the zip portion. Copy it out to a tempfile while running and put it back in when done and saving. The tempfile module will help with temporary files. The zipfile module works quite happily with zip files prepended with extra stuff. To get started make a zip file with dummy contents (for example a readme explaining that mail is stored within). Assuming your app is called mail.exe and the zip file is called mail.zip you just concatenate them. py2exe and several other programs can make an executable out of a Python script for you. However in some cases they use this same 'trick' of an appended zip file to store the python code so you could also just modify that. If your app is a python script and you want to distribute it that way then you can make a zip file of the python script and then you have to run it by setting the PYTHONPATH environment variable to point at the zip file. Note that once you try this you may find the operating system and/or python not being too happy about modifying what they are "executing". If you are feeling really adventurous there may even be a way of following the script with the data. This is used in Unix shell scripting but the Unix shell doesn't check the whole file is syntactically correct so you can append any binary junk you want. For Python you could try something like 8< #! python python code python code """ SOMESPECIALMARKER <> """ 8< You'd have to do some escaping of the contents or maybe just base64 encode it. Roger -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
print 'Content-Type: image/jpeg' print 'Content-Encoding: base64' print print content.encode('base64') I did change it to text/plain, but I don't know how I'm supposed to manually decode it. Yes, it printed out a bunch of crap to the screen. I've gotten that far before, and once I read "Adobe" something, so yes, it's an image. TIA, V On Wed, Oct 7, 2009 at 3:52 PM, Rami Chowdhury wrote: > On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi < > victorsube...@gmail.com> wrote: > > I did that. In fact, just to make things easier, I wrote out exactly what >> is >> supposed to be rendered, as below: >> >> #!/usr/local/bin/python >> import cgitb; cgitb.enable() >> import MySQLdb >> import cgi >> import sys,os >> sys.path.append(os.getcwd()) >> from login import login >> user, passwd, db, host = login() >> form = cgi.FieldStorage() >> db = MySQLdb.connect(host, user, passwd, db) >> cursor= db.cursor() >> sql = "select pic1 from products where id='1';" >> cursor.execute(sql) >> content = cursor.fetchall()[0][0].tostring() >> cursor.close() >> print '''Content-Type: image/jpeg'''# Only print one line >> >> Content-Encoding: base64 >> ''' >> print >> print content.encode('base64') >> >> > Just to reiterate what Gabriel and Carsten have pointed out, I'd suggest > changing the last few lines of the script, as the comments below indicate: > > print '''Content-Type: image/jpeg''' # One header line > print '''Content-Encoding: base64''' # Another header line. Note *no* blank > line between them > print# Blank line signals the end of the > headers > print content.encode(base64) # Base64-encoded content comes *after* > the blank line > > If you include extra blank lines after the headers, the browser will > misunderstand where the binary image data begins, and so will see a > malformed JPEG. > > If this doesn't work, I suggest changing the content-type header to > text/plain and trying to manually decode and check the image data to ensure > it's valid. > > > >> On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina > >wrote: >> >> En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi >>> escribió: >>> >>> > print '''Content-Type: image/jpeg >>> > >>> > ''' >>> > print >>> > print content >>> >>> On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina >> p...@yahoo.com.ar>wrote: >>> >>> > That's still wrong. The output should be: >>> > >>> > - a line containing Content-Type: image/jpeg >>> > - a blank line (no more!) >>>^ >>> > - the actual image data >>> >>> -- >>> Gabriel Genellina >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 13:24:28 -0700, Victor Subervi wrote: I did that. In fact, just to make things easier, I wrote out exactly what is supposed to be rendered, as below: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = "select pic1 from products where id='1';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg'''# Only print one line Content-Encoding: base64 ''' print print content.encode('base64') Just to reiterate what Gabriel and Carsten have pointed out, I'd suggest changing the last few lines of the script, as the comments below indicate: print '''Content-Type: image/jpeg''' # One header line print '''Content-Encoding: base64''' # Another header line. Note *no* blank line between them print# Blank line signals the end of the headers print content.encode(base64) # Base64-encoded content comes *after* the blank line If you include extra blank lines after the headers, the browser will misunderstand where the binary image data begins, and so will see a malformed JPEG. If this doesn't work, I suggest changing the content-type header to text/plain and trying to manually decode and check the image data to ensure it's valid. On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina wrote: En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi escribió: > print '''Content-Type: image/jpeg > > ''' > print > print content On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina wrote: > That's still wrong. The output should be: > > - a line containing Content-Type: image/jpeg > - a blank line (no more!) ^ > - the actual image data -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
I tried these combinations: print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print print content.encode('base64') and print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print content.encode('base64') Neither worked :( V On Wed, Oct 7, 2009 at 3:40 PM, Carsten Haese wrote: > Victor Subervi wrote: > > [...] > > print '''Content-Type: image/jpeg > > > > Content-Encoding: base64 > > ''' > > [...] > > You have a spurious blank line between those header lines. > > HTH, > > -- > Carsten Haese > http://informixdb.sourceforge.net > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
RE: How to run python script in emacs
Hitting ctrl-c, twice quickly works for me. > -Original Message- > From: python-list-bounces+frsells=adventistcare@python.org > [mailto:python-list-bounces+frsells=adventistcare@python.org] On > Behalf Of OdarR > Sent: Wednesday, October 07, 2009 12:02 PM > To: python-list@python.org > Subject: Re: How to run python script in emacs > > On 26 sep, 17:54, devilkin wrote: > > I'm just starting learning python, and coding inemacs. I usually > > splitemacswindow into two, coding in one, and run script in the > > other, which is not very convenient. anyone can help me with it? is > > there any tricks likeemacsshort cut? > > > > also please recommand someemacsplug-ins for python programming, i'm > > also beginner inemacs.currently i'm only using python.el. Are any > > plugins supply code folding and autocomplete? > > > > BTW, I'm not a english native speaker, any grammer mistakes, please > > correct them. :) > > hello, > > I was not so long ago in the same situation. > I switch to emacs too, why ? > probably because the movement is more natural than in vi (used for 12+ > years), > python-mode automatically starts on the machines I'm using, this is > very convenient for *re-indentation* . > Python could be difficult to maintain if you don't have a flexible > text editor. > if you want, i can suggest you some lines for the init file .emacs, > in order to keep the text indented with 4 spaces, no tab at all (very > important). > > I also suggest you to have a look on ipython shell, which is a super > shell you keep side the text editor. > once you discover it, you'll understand. > > I didn't hear for an autocompletion in emacs. > but ipython has a autocompletion. It can sound weird to auto-complete > outside your editor, but I like it. > you can test little code snippets in ipython, discover the > documentation and methods, and try them. > I discover this clever advice in http://oreilly.com/catalog/9780596515829/ > > currently I work with Mac (Aquamacs), and I was recently on Solaris or > XP as well. > PS: emacs on Mac Terminal with a french keyboard is a bit of a > nightmare considering the META key...:-( > Aquamacs solves this finally. > > > Olivier > -- > http://mail.python.org/mailman/listinfo/python-list -- [**CONFIDENTIALITY NOTICE**]: The information contained in this message may be privileged and / or confidential and protected from disclosure. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to this message and deleting the material from any computer. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
Victor Subervi wrote: > [...] > print '''Content-Type: image/jpeg > > Content-Encoding: base64 > ''' > [...] You have a spurious blank line between those header lines. HTH, -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Enormous Input and Output Test
n00m wrote: numerix's solution was excelled by Steve C's one (8.78s): http://www.spoj.pl/ranks/INOUTEST/lang=PYTH I don't understand nothing. I just got my solution accepted, it ran in 14 seconds though. I have no idea how to shave more seconds off, so I think 7.5 seconds for the fastest solution is really mindboggling. Things that eventually made my solution run within the time limit: - I didn't use int() - I used Psyco Those two resulted in the biggest speed increase. Tweaking with buffered/unbuffered IO was insignificant. Cheers Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
I did that. In fact, just to make things easier, I wrote out exactly what is supposed to be rendered, as below: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() db = MySQLdb.connect(host, user, passwd, db) cursor= db.cursor() sql = "select pic1 from products where id='1';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print print content.encode('base64') I even changed the "image/jpeg" to "text/html" to see if the image would print out the binary, and it did, so I'm calling the image correctly, just not rendering the binary as an image. V On Wed, Oct 7, 2009 at 2:47 PM, Gabriel Genellina wrote: > En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi > escribió: > > > print '''Content-Type: image/jpeg > > > > ''' > > print > > print content > > On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina p...@yahoo.com.ar>wrote: > > > That's still wrong. The output should be: > > > > - a line containing Content-Type: image/jpeg > > - a blank line (no more!) > ^ > > - the actual image data > > -- > Gabriel Genellina > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
En Wed, 07 Oct 2009 12:00:13 -0300, Victor Subervi escribió: > print '''Content-Type: image/jpeg > > ''' > print > print content On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina wrote: > That's still wrong. The output should be: > > - a line containing Content-Type: image/jpeg > - a blank line (no more!) ^ > - the actual image data -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Python + webservice
Hello all... I'm new here and a search in tis group but unfortunately i didn't find any kind of solution/code/question etc ... I have to made a python script that communicates with an websevice over the web. I tried out use SoapPy, ZSI, BeautifullSoap and others, but get no success... I have to generate a XML file from a XSD file, and them send it to a webservice as i have said before. There's really no need to generate a XML file from a XSD file bu if it's possible it will be very very good... Has anyone made something like this and can share with me a bit of experience? -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 11:51:13 -0700, Victor Subervi wrote: My misunderstanding. Here's the new code: print '''Content-Type: image/jpeg Content-Encoding: base64 ''' Ah, sorry, I wasn't clear -- Content-Encoding is a header, and needs to go with Content-Type, before the newlines. So print '''Content-Type: image/jpeg Content-Encoding: base64 ''' HTH, Rami On Wed, Oct 7, 2009 at 12:56 PM, Rami Chowdhury wrote: On Wed, 07 Oct 2009 10:50:00 -0700, Victor Subervi < victorsube...@gmail.com> wrote: Well, since the code is automatically generated, it printed this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = "select " + pic + " from products where id='" + str(picid) + "';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' Content-Encoding: base64 print print content.encode('base64') which threw this error: [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Traceback (most recent call last): [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch\n result = object(req) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File "/usr/lib64/python2.4/site-packages/mod_python/cgihandler.py", line 96, in handler\n imp.load_module(module_name, fd, path, desc) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File "/var/www/vhosts/ 13gems.com/httpdocs/stxresort/cart/getpic1.py", line 24 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Content-Encoding: base64 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: ^ [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: SyntaxError: invalid syntax Ideas? TIA, V I'm sorry, I don't understand how the code is being auto-generated? Is there no way to place the 'Content-Encoding' header inside the triple-quoted string, where it should go? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
My misunderstanding. Here's the new code: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = "select " + pic + " from products where id='" + str(picid) + "';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print print content.encode('base64') Unfortunately, the same result of printing the url. V On Wed, Oct 7, 2009 at 12:56 PM, Rami Chowdhury wrote: > On Wed, 07 Oct 2009 10:50:00 -0700, Victor Subervi < > victorsube...@gmail.com> wrote: > > Well, since the code is automatically generated, it printed this: >> >> #!/usr/local/bin/python >> import cgitb; cgitb.enable() >> import MySQLdb >> import cgi >> import sys,os >> sys.path.append(os.getcwd()) >> from login import login >> user, passwd, db, host = login() >> form = cgi.FieldStorage() >> picid = int(form['id'].value) >> x = int(form['x'].value) >> pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} >> pic = pics[x] >> db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) >> cursor= db.cursor() >> sql = "select " + pic + " from products where id='" + str(picid) + "';" >> cursor.execute(sql) >> content = cursor.fetchall()[0][0].tostring() >> cursor.close() >> print '''Content-Type: image/jpeg >> >> ''' >> Content-Encoding: base64 >> print >> print content.encode('base64') >> >> which threw this error: >> >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: Traceback (most recent call last): >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: File >> "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in >> HandlerDispatch\n result = object(req) >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: File >> "/usr/lib64/python2.4/site-packages/mod_python/cgihandler.py", line 96, in >> handler\n imp.load_module(module_name, fd, path, desc) >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: File "/var/www/vhosts/ >> 13gems.com/httpdocs/stxresort/cart/getpic1.py", line 24 >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: Content-Encoding: base64 >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: ^ >> [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler >> mod_python.cgihandler: SyntaxError: invalid syntax >> >> Ideas? TIA, >> V >> >> > I'm sorry, I don't understand how the code is being auto-generated? Is > there no way to place the 'Content-Encoding' header inside the triple-quoted > string, where it should go? > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
Ryan wrote: [] It does beg the question for me. Consider the example from his code below from PyQt4 import QtGui class LauncherWidget( QtGui.QWidget ): # A Specialization of QWidget del QtGui Next time python comes across from PyQt4 import QtGui it would have to re-import the class, which seems a waste of cycles that could accumulate. Errrhm, no. He is not deleting the PyQt4 module from sys.modules; he's only deleting the name QtGui from his own namespace. Next time Python comes across from PyQt4 import QtGui , it finds that the module PyQt4 already exists in sys.modules, so Python does not have to load the module again. All it has to do is bind name QtGui in the importing module to the class with the same name in the PyQt4 module. That does not take many cycles. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On 7 oct, 19:29, Tim Chase wrote: > Perhaps this is a reference to the alt/meta/control/buckey/super > key-chords that emacs is infamous for using that don't always get > reliably transmitted by all terminal-emulation programs and > consoles. It was one of my nudging factors towards vi (and later > vim), because I occasionally used some terminal software in which > alt or shift+control+alt (and other such combinations) weren't > detected. Never had that problem with vi/vim. And when all else > fails, I can usually fall back to ed in a pinch ;-) > > -tkc yes, this is true that emacs needs ctrl and meta key. two keys for lots of combinations :-) Like with vi when I began, I need a cheat list of keystrokes for emacs. ctrl is ok. Meta can always be used with ESC. if you really need to stay on a unknown terminal for some weeks, it is not complicated to copy/paste your favorite .emacs file (less than 10 lines is for me sufficient). It's just a matter of organization. Olivier -- http://mail.python.org/mailman/listinfo/python-list
Re: AES decrypting in Python
Mike Driscoll wrote: > EVP.Cipher(alg="aes_256_ecb", key=SomeKey, iv=SomeIV, op=dec, > padding=False) > > I don't really see where I pass the data that needs the decrypting > though. Can someone shed some light on this? Look at test_AES method in http://svn.osafoundation.org/m2crypto/trunk/tests/test_evp.py Basically EVP.Cipher returns the cipher object. You call the update update(data) method on it (you can call this many times if you have lots of data), which returns (possibly partial) result and finally call the final() method to finish, which will return the last piece of the decrypted data. You might also want to take a look at m2secret[1] which is a small library/utility built on top of M2Crypto to encrypt/decrypt stuff. By default it uses AES. [1] http://www.heikkitoivonen.net/m2secret/ -- Heikki Toivonen - http://heikkitoivonen.net -- http://mail.python.org/mailman/listinfo/python-list
Re: ActivePython 3.1.1.2 vs Python 3.1.1 for OSX?
PyPM is now released! http://groups.google.com/group/comp.lang.python/browse_thread/thread/e9efdedf264a3b8a On Oct 1, 4:42 am, flebber wrote: > On Oct 1, 11:28 am, srid wrote: > > > > > > > On Sep 30, 4:51 pm, Robert Hicks wrote: > > > > I am just curious which I should use. I am going to start learning > > > Python soon. Are they comparable and I just do a "eenie meenie minie > > > moe"? > > > ActivePython is essentially same as the installers from python.org - > > but it also comes with additional documentation and tutorials, such > > as: > > > Python FAQs > > A snapshot of the Python Enhancement Proposals (PEPs) (For the most > > recent version, refer to the PEPs on python.org .) > > Dive Into Python (A tutorial for programmers) > > Non-Programmers Tutorial For Python > > >http://docs.activestate.com/activepython/3.1/whatsincluded.html > > > Also note that 2.6.x is probably the best bet if you are going to use > > some 3rd party libraries (after you learn the basics of Python) .. > > because 3.x does not have many of those libraries ported yet. > > > http://www.activestate.com/activepython/ > > > Further, early next week - a new release of ActivePython-2.6 will be > > made available that will include, for the first time, a new Python > > package manager (PyPM) from ActiveState that makes it easier to > > install packages from pypi.python.org(without having to compile them > > yourself). This is similar to PPM from ActivePerl. > > > -srid > > Thats awesome news. -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
Apart of trolling which is also an activity I like, what are the features vim proposes to Python ? Olivier Many, but none that you won't find with emacs, so when I'm stating it is just a matter of personal preference, I mean it :o) "Vi or Emacs" is the same question as "straight or gay" (order matters! :D). No one will come and convince you to use one or the other. Launch both of them, look at the nice and smooth visual of gvim, compare it with the ugly skin of emacs and pick your choice ! Beside from trolling, here are the feature I'm using for python: - syntax highligthts (there are hundreds of different themes, now way you can't find few you like) - auto completion of symbols - code browsing supporting tag files - (almost) smart indentation That's it JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 10:50:00 -0700, Victor Subervi wrote: Well, since the code is automatically generated, it printed this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = "select " + pic + " from products where id='" + str(picid) + "';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' Content-Encoding: base64 print print content.encode('base64') which threw this error: [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Traceback (most recent call last): [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch\n result = object(req) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File "/usr/lib64/python2.4/site-packages/mod_python/cgihandler.py", line 96, in handler\n imp.load_module(module_name, fd, path, desc) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File "/var/www/vhosts/ 13gems.com/httpdocs/stxresort/cart/getpic1.py", line 24 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Content-Encoding: base64 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: ^ [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: SyntaxError: invalid syntax Ideas? TIA, V I'm sorry, I don't understand how the code is being auto-generated? Is there no way to place the 'Content-Encoding' header inside the triple-quoted string, where it should go? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
Well, since the code is automatically generated, it printed this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = "select " + pic + " from products where id='" + str(picid) + "';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' Content-Encoding: base64 print print content.encode('base64') which threw this error: [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Traceback (most recent call last): [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch\n result = object(req) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File "/usr/lib64/python2.4/site-packages/mod_python/cgihandler.py", line 96, in handler\n imp.load_module(module_name, fd, path, desc) [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: File "/var/www/vhosts/ 13gems.com/httpdocs/stxresort/cart/getpic1.py", line 24 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: Content-Encoding: base64 [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: ^ [Wed Oct 07 10:47:42 2009] [error] [client 66.248.168.98] PythonHandler mod_python.cgihandler: SyntaxError: invalid syntax Ideas? TIA, V On Wed, Oct 7, 2009 at 12:00 PM, Rami Chowdhury wrote: > On Wed, 07 Oct 2009 09:38:09 -0700, Victor Subervi < > victorsube...@gmail.com> wrote: > > Yes it is. I have had it print to screen already, and there is data in the >> database. >> V >> > > If you're confident that the data is correct and hasn't been corrupted, > then I'm afraid I'm out of ideas. Perhaps you could try transmitting it as > base64, which might make it more robust in transmission and easier to decode > and find errors locally? You'd just need to change the end of your script to > read: > > print '''Content-Type: image/jpeg > Content-Encoding: base64 > > ''' > print > print content.encode('base64') > > HTH, > Rami > > > >> On Wed, Oct 7, 2009 at 10:03 AM, Rami Chowdhury > >wrote: >> >> On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi < >>> victorsube...@gmail.com> wrote: >>> >>> I took out the line in question (with text/html). Now it prints to >>> screen >>> the url. It did that before. Strange. Any other ideas? TIA, V >>> Looking at the output, it seems the reason for this (for me) is that >>> Firefox can't find the image or any alt text for it, so it's just using >>> the >>> image URL. Are you certain the image data (i.e. the 'content' string) is >>> correct, and being encoded correctly in the output? >>> >>> >>> >>> On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury < rami.chowdh...@gmail.com >wrote: On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi < > victorsube...@gmail.com> wrote: > > The code in question is generated automatically from another script. I > > took >> your idea of the \r\n\r\n and added triple quoting and now it prints >> out >> this: >> >> #!/usr/local/bin/python >> import cgitb; cgitb.enable() >> import MySQLdb >> import cgi >> import sys,os >> sys.path.append(os.getcwd()) >> from login import login >> user, passwd, db, host = login() >> form = cgi.FieldStorage() >> picid = int(form['id'].value) >> x = int(form['x'].value) >> pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} >> pic = pics[x] >> print '''Content-Type: text/html >> >> ''' >> db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) >> cursor= db.cursor() >> sql = "select " + pic + " from products where id='" + str(picid) + >> "';" >> cursor.execute(sql) >> content = cursor.fetchall()[0][0].tostring() >> cursor.close() >> print '''Content-Type: image/jpeg >> >> ''' >> print >> print content >> >> >> To answer your questions, I have no idea what eNom has done to their >> servers, which is where the other site was hosted (never went live), >> but >> am >> in the process of building on DreamHost, who seems to be a FAR better >> service than eNom, whom I actually had to report to the BBB and they >> never >> fixed or acknowledged very obvious problems. At any rate, the above >> code >> gets the browser to print out all the binary "garbage" that should
Re: best vi / emacs python features
One feature I have that emacs don't is that I'm able to efficiently edit a file on a remote machine with vim on a terminal (without graphical interface), and I'm using it. Apart from that, both solutions are emacs has the same efficiency on a terminal. or maybe I don't understand your sentence. Perhaps this is a reference to the alt/meta/control/buckey/super key-chords that emacs is infamous for using that don't always get reliably transmitted by all terminal-emulation programs and consoles. It was one of my nudging factors towards vi (and later vim), because I occasionally used some terminal software in which alt or shift+control+alt (and other such combinations) weren't detected. Never had that problem with vi/vim. And when all else fails, I can usually fall back to ed in a pinch ;-) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Queue deadlock
On Oct 7, 12:16 pm, MRAB wrote: > Felix wrote: > > Hello, > > > I keep running into a deadlock in a fairly simple parallel script > > using Multiprocessing.Queue for sending tasks and receiving results. > > It seems to be the workers cannot finish pusing buffered results into > > the output queue when calling 'results.join_thread' while terminating, > > but why is that? I tried calling 'results.close()' before joining the > > workers in the main process, but it does not make a difference. > > > Is there something I am understanding wrong about the interface? Is > > there a much better way to do what I am trying to do above? > You can therefore get into a deadlock where: > > * Process A won't read from the queue until it has joined process B. > * The join won't succeed until process B has terminated. > * Process B won't terminate until it has finished writing to the queue. > * Process B can't finish writing to the queue because it's full. > * The queue is full because process A isn't reading from it. I thought about that, but it seemed unlikely since I am not generating too many results (a few thousand small touples of int). Also I tried to deal with it by reading as many results form the queue as were available, then joining the workers, then reading again. This did not work reliably, maybe because the queue would fill up again while I start joining the individual workers. In any case the core of the problem is the following: A bunch of workers push an unknown number of results into a queue. The main process needs to collect all those results. What is the right way to implement that with multiprocessing? I tried joining the workers and then reading everything available, but obviously (see above) that does not seem to work. A dirty trick that works would be reading all results slowly and assuming no more results are comming after the queue is empty, but this is obviously unstable: while 1: try: res.append(results.get(True,LONG_TIMEOUT)) except Empty: break It could be made somewhat better by joining the workers afterwards and reading again, but another deadlock might happen. What I am doing now is having the workers push a "DONE" flag on the result queue when they end and reading results until all DONE flags have arrived: def work(tasks, results): for task in iter(tasks.get, 'STOP'): res = calc(*task) if res: results.put(res) tasks.put((task[0], res[1])) tasks.put((res[0],task[1])) queue.task_done() results.put('DONE') And in main: res = [] for i in range(opts.nprocs): res += list(iter(results.get,'DONE')) for p in procs: p.join() This seems to work, and as long as workers push data to the results queue in the same order as the puts happen in each process (is this guaranteed?) it should be stable. But is it the best/easiest way to do this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
[Hrvoje Niksic] > Note that stable sort has additional memory requirements. In situations > where you don't need stability, but do need memory-efficient in-place > sorting, an unstable sort might well be preferred. This is why > libraries such as C++'s STL offer both. FWIW, the "additional memory requirements" are typically a set of pointers to the objects being sorted, so the memory overhead is typically very small relative to the size of the objects being sorted. IOW, this isn't much of a consideration in most Python apps. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Python 2.6.4rc1
Hello everyone. The source tarballs and Windows installers for Python 2.6.4rc1 are now available: http://www.python.org/download/releases/2.6.4/ Please download them, install them, and try to use them with your projects and environments. Let us know if you encounter any problems with them. Hopefully we can avoid the situation with 2.6.3 having such critical bugs. 2.6.4 final is planned for 18-October. Cheers, -Barry PGP.sig Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 09:38:09 -0700, Victor Subervi wrote: Yes it is. I have had it print to screen already, and there is data in the database. V If you're confident that the data is correct and hasn't been corrupted, then I'm afraid I'm out of ideas. Perhaps you could try transmitting it as base64, which might make it more robust in transmission and easier to decode and find errors locally? You'd just need to change the end of your script to read: print '''Content-Type: image/jpeg Content-Encoding: base64 ''' print print content.encode('base64') HTH, Rami On Wed, Oct 7, 2009 at 10:03 AM, Rami Chowdhury wrote: On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi < victorsube...@gmail.com> wrote: I took out the line in question (with text/html). Now it prints to screen the url. It did that before. Strange. Any other ideas? TIA, V Looking at the output, it seems the reason for this (for me) is that Firefox can't find the image or any alt text for it, so it's just using the image URL. Are you certain the image data (i.e. the 'content' string) is correct, and being encoded correctly in the output? On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury >wrote: On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi < victorsube...@gmail.com> wrote: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] print '''Content-Type: text/html ''' db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = "select " + pic + " from products where id='" + str(picid) + "';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content To answer your questions, I have no idea what eNom has done to their servers, which is where the other site was hosted (never went live), but am in the process of building on DreamHost, who seems to be a FAR better service than eNom, whom I actually had to report to the BBB and they never fixed or acknowledged very obvious problems. At any rate, the above code gets the browser to print out all the binary "garbage" that should translate into an image (you can look: http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1 ). Any more ideas would be helpful. Going to that URL, my browser now tries to render an HTML page, and I can now see the 'Content-Type: image/jpeg' string being printed into the HTML source. Have you tried removing the 'Content-Type: text/html' header, with the new triple-quoted syntax? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On 7 oct, 18:44, Jean-Michel Pichavant wrote: > Being a vi fan, I can just tell you that emacs is for loosers, and no > one will dare to challenge this. vi is very good for newbees, I recommend it. > vi/emacs is like choosing between the Celtics or the Lakers, there is no > reason for that, the fun part resides in being totally devoted to your > choice :o) > For my part I never switched to emacs cause I was tired of getting > syntax error with ':w' inserted everywhere in my code. Bad habits are > sticky. just use the other symetric part of your brain. > One feature I have that emacs don't is that I'm able to efficiently edit > a file on a remote machine with vim on a terminal (without graphical > interface), and I'm using it. Apart from that, both solutions are emacs has the same efficiency on a terminal. or maybe I don't understand your sentence. > efficient. I would add that inside a company, it is a good idea to use > the same editor as you can share knowledge, macro, plugins and so on. I never used macro with vi or emacs. I shared know-how for vi or emacs. I worked in companies full of talented people, open to new technologies, no issues mixing both editors. and don't speak of UltraEdit yet :) Apart of trolling which is also an activity I like, what are the features vim proposes to Python ? Olivier -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
On Oct 7, 10:44 am, Jean-Michel Pichavant wrote: > OdarR wrote: > > hello, > > > * this is not a troll * > > > which kind of help you have with your favorite editor ? > > > personnally, I find emacs very nice, in the current state of my > > knowledge, when I need to reindent the code. > > you know how this is critical in python...:-) > > > I don't use other python-mode features for the moment, maybe you have > > some advices. > > I used with success an Xemacs on Solaris, as well as a Aquamacs on > > Mac. > > > For the vi/vim guys, explain us the best features this editor give you > > in your py files ! > > > thanks, > > > Olivier > > Being a vi fan, I can just tell you that emacs is for loosers, and no > one will dare to challenge this. I concur 100% with this statement. That said, I like how my install of VIM 'just works' with Python files, doing a good job of coloring and auto indentation. I don't like, however, how an arbitrary colon will trigger auto indentation on the next line. I'm guessing, though, that this is just an issue with my particular syntax file. Garrick -- http://mail.python.org/mailman/listinfo/python-list
Re: best vi / emacs python features
OdarR wrote: hello, * this is not a troll * which kind of help you have with your favorite editor ? personnally, I find emacs very nice, in the current state of my knowledge, when I need to reindent the code. you know how this is critical in python...:-) I don't use other python-mode features for the moment, maybe you have some advices. I used with success an Xemacs on Solaris, as well as a Aquamacs on Mac. For the vi/vim guys, explain us the best features this editor give you in your py files ! thanks, Olivier When opposing vi to emacs, there's is no possibility you get constructive and objective answer, because basically, what can do with one, you can also do it with the other. Being a vi fan, I can just tell you that emacs is for loosers, and no one will dare to challenge this. vi/emacs is like choosing between the Celtics or the Lakers, there is no reason for that, the fun part resides in being totally devoted to your choice :o) For my part I never switched to emacs cause I was tired of getting syntax error with ':w' inserted everywhere in my code. Bad habits are sticky. One feature I have that emacs don't is that I'm able to efficiently edit a file on a remote machine with vim on a terminal (without graphical interface), and I'm using it. Apart from that, both solutions are efficient. I would add that inside a company, it is a good idea to use the same editor as you can share knowledge, macro, plugins and so on. JM -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
Yes it is. I have had it print to screen already, and there is data in the database. V On Wed, Oct 7, 2009 at 10:03 AM, Rami Chowdhury wrote: > On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi < > victorsube...@gmail.com> wrote: > > I took out the line in question (with text/html). Now it prints to screen >> the url. It did that before. Strange. Any other ideas? >> TIA, >> V >> > > Looking at the output, it seems the reason for this (for me) is that > Firefox can't find the image or any alt text for it, so it's just using the > image URL. Are you certain the image data (i.e. the 'content' string) is > correct, and being encoded correctly in the output? > > > >> On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury > >wrote: >> >> On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi < >>> victorsube...@gmail.com> wrote: >>> >>> The code in question is generated automatically from another script. I >>> took your idea of the \r\n\r\n and added triple quoting and now it prints out this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] print '''Content-Type: text/html ''' db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = "select " + pic + " from products where id='" + str(picid) + "';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content To answer your questions, I have no idea what eNom has done to their servers, which is where the other site was hosted (never went live), but am in the process of building on DreamHost, who seems to be a FAR better service than eNom, whom I actually had to report to the BBB and they never fixed or acknowledged very obvious problems. At any rate, the above code gets the browser to print out all the binary "garbage" that should translate into an image (you can look: http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1 ). Any more ideas would be helpful. >>> Going to that URL, my browser now tries to render an HTML page, and I can >>> now see the 'Content-Type: image/jpeg' string being printed into the HTML >>> source. Have you tried removing the 'Content-Type: text/html' header, >>> with >>> the new triple-quoted syntax? >>> >>> >>> -- >>> Rami Chowdhury >>> "Never attribute to malice that which can be attributed to stupidity" -- >>> Hanlon's Razor >>> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) >>> >>> > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing.Queue deadlock
Felix wrote: Hello, I keep running into a deadlock in a fairly simple parallel script using Multiprocessing.Queue for sending tasks and receiving results. From the documentation I cannot figure out what is happening and none of the examples seem to cover quite what I am doing. The main code is results = mp.Queue() tasks = mp.JoinableQueue() tasks.put( (0,0) ) procs = [ mp.Process(target=work, args=(tasks, results)) for i in range (nprocs)] for p in procs: p.daemon = True p.start() tasks.join() for i in range(nprocs): tasks.put('STOP') for p in procs: p.join() res=[] while 1: try: res.append(res.get(False)) except Empty: break The function 'work' both consumes tasks adding the results to the output queue and adds new tasks to the input queue based on its result. def work(tasks, results): for task in iter(tasks.get, 'STOP'): res = calc(*task) if res: results.put(res) tasks.put((task[0], res[1])) tasks.put((res[0],task[1])) queue.task_done() This program will hang while the main process joins the workers (after all results are computed, i.e. after tasks.join() ). The workers have finished function 'work', but have not terminated yet. Calling results.cancel_join_thread as a last line in 'work' prevents the deadlocks, as does terminating the workers directly. However I am not sure why that would be needed and if it might not make me loose results. It seems to be the workers cannot finish pusing buffered results into the output queue when calling 'results.join_thread' while terminating, but why is that? I tried calling 'results.close()' before joining the workers in the main process, but it does not make a difference. Is there something I am understanding wrong about the interface? Is there a much better way to do what I am trying to do above? It think it's down to the difference between multithreading and multiprocessing. When multithreading, the threads share the same address space, so items can be passed between the threads directly. However, when multiprocessing, the processes don't share the same address space, so items need to be passed from process to process via a pipe. Unfortunately, the pipe has a limited capacity, so if a process doesn't read from one end then the pipe will eventually fill up and the sender will block. Also, a process won't terminate until it has finished writing to the pipe, and it can't be joined until it has terminated. You can therefore get into a deadlock where: * Process A won't read from the queue until it has joined process B. * The join won't succeed until process B has terminated. * Process B won't terminate until it has finished writing to the queue. * Process B can't finish writing to the queue because it's full. * The queue is full because process A isn't reading from it. -- http://mail.python.org/mailman/listinfo/python-list
best vi / emacs python features
hello, * this is not a troll * which kind of help you have with your favorite editor ? personnally, I find emacs very nice, in the current state of my knowledge, when I need to reindent the code. you know how this is critical in python...:-) I don't use other python-mode features for the moment, maybe you have some advices. I used with success an Xemacs on Solaris, as well as a Aquamacs on Mac. For the vi/vim guys, explain us the best features this editor give you in your py files ! thanks, Olivier -- http://mail.python.org/mailman/listinfo/python-list
ElementTree ; change namespace
Hello the list, I have question about ElementTree module, I didn't find a specific list so I post here. I hope I'm not wrong. I would like to know how to change the namespace URI of all the Element of my XML tree without changing anything else. I want that because I have to compare 2 XML trees, so I walk trought the first tree, and each time I found an element, I delete it (with the Element.remove() function) on the second tree. This way, I can see if there is remaining or lacking elements in my second tree. The problem is that my two trees may not have the same namespace, so the Element.remove() function doesn't work. That's why I want to change the namespace. Also, The Element.remove() documentation says it compares element with their identity ; what is exactly an element identity ? Thank you, Ben -- http://mail.python.org/mailman/listinfo/python-list
Re: How to run python script in emacs
On 26 sep, 17:54, devilkin wrote: > I'm just starting learning python, and coding inemacs. I usually > splitemacswindow into two, coding in one, and run script in the > other, which is not very convenient. anyone can help me with it? is > there any tricks likeemacsshort cut? > > also please recommand someemacsplug-ins for python programming, i'm > also beginner inemacs.currently i'm only using python.el. Are any > plugins supply code folding and autocomplete? > > BTW, I'm not a english native speaker, any grammer mistakes, please > correct them. :) hello, I was not so long ago in the same situation. I switch to emacs too, why ? probably because the movement is more natural than in vi (used for 12+ years), python-mode automatically starts on the machines I'm using, this is very convenient for *re-indentation* . Python could be difficult to maintain if you don't have a flexible text editor. if you want, i can suggest you some lines for the init file .emacs, in order to keep the text indented with 4 spaces, no tab at all (very important). I also suggest you to have a look on ipython shell, which is a super shell you keep side the text editor. once you discover it, you'll understand. I didn't hear for an autocompletion in emacs. but ipython has a autocompletion. It can sound weird to auto-complete outside your editor, but I like it. you can test little code snippets in ipython, discover the documentation and methods, and try them. I discover this clever advice in http://oreilly.com/catalog/9780596515829/ currently I work with Mac (Aquamacs), and I was recently on Solaris or XP as well. PS: emacs on Mac Terminal with a french keyboard is a bit of a nightmare considering the META key...:-( Aquamacs solves this finally. Olivier -- http://mail.python.org/mailman/listinfo/python-list
Re: AES decrypting in Python
On Oct 7, 10:04 am, "M.-A. Lemburg" wrote: > Mike Driscoll wrote: > > Hi, > > > I am working on a project where I need to decrypt some data that has > > been encrypted with AES. It looks like M2Crypto is the module of > > choice for these sorts of things, but I cannot figure out how to do > > this stuff from the docs. I have the following PHP code that needs to > > be translated into Python: > > > $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); > > $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); > > return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, > > $data,MCRYPT_MODE_ECB, $iv),"\0"); > > > I can't find a method in M2Crypto that gets the "initialization > > vector" size. I found the right method in the tests, which appears to > > be EVP.Cipher. So I would assume, I would need to do something like: > > > EVP.Cipher(alg="aes_256_ecb", key=SomeKey, iv=SomeIV, op=dec, > > padding=False) > > > I don't really see where I pass the data that needs the decrypting > > though. Can someone shed some light on this? > > If you just need AES, you're probably better of with pycrypto: > > http://www.amk.ca/python/code/crypto > > Still, to answer your question: AES uses blocks of 16 bytes (256 bits) > each, so the IV-size is always 16 bytes. > > BTW: I'm not sure what the PHP code is trying to do ... ECB mode > doesn't use the IV at all. It's only used for chained modes and > there you include the IV in the encrypted data (usually at the > beginning), since you need it for decryption. The PHP code > apparently generates a random IV block for decryption. This > would never work in e.g. CBC mode. > > -- > Marc-Andre Lemburg > eGenix.com > That's good to know. I had originally started with PyCrypto by following the example here: http://www.codekoala.com/blog/2009/aes-encryption-python-using-pycrypto/ Unfortunately, no matter which base64 decoding method I use, I get a padding error or in the case of b16decode, I get "TypeError: Non- base16 digit found". AES decoding is something I've never done before, so I apologize for my greenness. I'll bug the guys on the pycrypto list as well. Thanks, Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
On Tuesday 06 October 2009 02:40:46 pm Paul Rubin wrote: > > The problem is that if you allow to use the cmp, lot of programmers > > will use it straight away, not even bothering to know what that > > strange 'key' argument may be useful for. And they miss the how much > > handy 'key' is. > > Given how often we hear "consenting adults" as justification for any > number of gaps in Python error checking, the argument above is > singularly unpersuasive. Well, as long as you consider them "gaps" in need of a "justification", of course that argument (and the one about the "gaps" themselves) will of course seem singularly unpersuasive. But if you see them as a "feature" (that may sometimes, albeit rarely, missfire), then you would have no problem with /either/ argument. -- Luis Zarrabeitia (aka Kyrie) Fac. de Matemática y Computación, UH. http://profesores.matcom.uh.cu/~kyrie -- http://mail.python.org/mailman/listinfo/python-list
Re: data matrix python
On 2009-10-07 05:46 AM, bbarb...@inescporto.pt wrote: Good morning all! I am trying to build a data matrix, but I am not able either to write to file with a proper structure nor to get the data from the matrix. I want to sort some music by similarity content, and I just have the indexes of the playlist like this: dm = numpy.array(songs) [0 4 2 1 3] [1 2 0 4 3] [2 1 0 4 3] [3 2 1 0 4] [4 0 1 2 3] Now, I want to keep the same format but with the names of the songs, something like this: Sort_dm.append(songlist(dm)) ['100.mp3\n' '10008.mp3' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n' '10001.mp3\n' '10005.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n' '10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3' '10008.mp3' '100.mp3\n' '10001.mp3\n' '10005.mp3\n' '10006.mp3\n'] But there is no way either I can access to the data... because there are strings, or save them in matrix format! I could not find anything in the documentation about this! any hint would be very welcome! thank you for your time! You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists However, you will need to show a little more code for us to understand what you are trying to do. Show us the code that you have, show us what results you get (copy-and-paste, please), and tell us what results you expect to get. -- 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
Re: Rules regarding a post about a commercial product
On 2009-10-07 03:59 AM, Ken Elkabany wrote: Hello, I am hoping to get feedback for a new, commercial platform that targets the python programming language and its users. The product is currently in a closed-beta and will be free for at least a couple months. After reviewing the only rules I could find (http://www.python.org/community/lists/), I wanted to ask one last time to make sure that such a post would be appropriate. Yes, announcements involving relevant commercial products are welcome within limits. For example, one announcement per release is perfectly acceptable. Multiple announcements per release are spam (e.g. "Only five more days left for our special promotion!!!" "Only four more days ...!!!", etc.). I suspect what you have in mind is fine. -- 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
Re: Rules regarding a post about a commercial product
Ken Elkabany wrote: I am hoping to get feedback for a new, commercial platform that targets the python programming language and its users. The product is currently in a closed-beta and will be free for at least a couple months. After reviewing the only rules I could find (http://www.python.org/community/lists/), I wanted to ask one last time to make sure that such a post would be appropriate. You might want to go for comp.lang.python.announce I am certain you are welcome if you don't spray the area with ads, see, for example, ActiveState's behavior. I trust that if you so start making real money from it, like ActiveState you'll help out the community that is giving you its support. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: When ‘super’ is not a good idea
Ben Finney wrote: Scott David Daniels wrote: ... class Initialized(ClassBase): @classmethod def _init_class(class_): class_.a, class_.b = 1, 2 super(Initialized, class_)._init_class() Mea culpa: Here super is _not_ a good idea, […] Why is ‘super’ not a good idea here? class Initialized(ClassBase): @classmethod def _init_class(class_): class_.a, class_.b = 1, 2 ClassBase._init_class() What makes this implementation better than the one using ‘super’? Well, it doesn't end with an error message :-) The reason for the error message is that super is built for instance methods, not class methods. You'd need a class method style super to get to "the next superclass in the __mro__ with an '_init_class' method." Personally I don't see the need. You could of course do it like this: class MyOtherType(type): def __new__(class_, name, bases, dct): result = type.__new__(class_, name, bases, dct) result()._init_class() return result class OtherClassBase(object): __metaclass__ = MyOtherType def _init_class(self): print 'initializing class' class Initialized(OtherClassBase): def _init_class(self): self.__class__.a, self.__class__.b = 1, 2 super(Initialized, self)._init_class() This code is a problem because the point of this exercise is to do initialization _before_ building an instance (think of building tables used in __init__). Before you decide that super should simply check if the second arg to super is a subclass of the first arg, and operate differently in that case (as my first code naively did), realize there is a problem. I saw the problem in trying the code, and simply tacked in the proper parent call and ran off to work. Think about the fact that classes are now objects as well; a class itself has a class (type or in these classes MyType or MyOtherType) with its own needs for super, and the combination would be a mess. I'm certain you'd get inadvertent switches across the two subtype hierarchies, but that belief may just be my fear of the inevitable testing and debugging issues such an implementation would require. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: AES decrypting in Python
Mike Driscoll wrote: > Hi, > > I am working on a project where I need to decrypt some data that has > been encrypted with AES. It looks like M2Crypto is the module of > choice for these sorts of things, but I cannot figure out how to do > this stuff from the docs. I have the following PHP code that needs to > be translated into Python: > > $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); > $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); > return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, > $data,MCRYPT_MODE_ECB, $iv),"\0"); > > I can't find a method in M2Crypto that gets the "initialization > vector" size. I found the right method in the tests, which appears to > be EVP.Cipher. So I would assume, I would need to do something like: > > EVP.Cipher(alg="aes_256_ecb", key=SomeKey, iv=SomeIV, op=dec, > padding=False) > > I don't really see where I pass the data that needs the decrypting > though. Can someone shed some light on this? If you just need AES, you're probably better of with pycrypto: http://www.amk.ca/python/code/crypto Still, to answer your question: AES uses blocks of 16 bytes (256 bits) each, so the IV-size is always 16 bytes. BTW: I'm not sure what the PHP code is trying to do ... ECB mode doesn't use the IV at all. It's only used for chained modes and there you include the IV in the encrypted data (usually at the beginning), since you need it for decryption. The PHP code apparently generates a random IV block for decryption. This would never work in e.g. CBC mode. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 07 2009) >>> Python/Zope Consulting and Support ...http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
On Wed, 07 Oct 2009 06:37:08 -0700, Victor Subervi wrote: I took out the line in question (with text/html). Now it prints to screen the url. It did that before. Strange. Any other ideas? TIA, V Looking at the output, it seems the reason for this (for me) is that Firefox can't find the image or any alt text for it, so it's just using the image URL. Are you certain the image data (i.e. the 'content' string) is correct, and being encoded correctly in the output? On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury wrote: On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi < victorsube...@gmail.com> wrote: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] print '''Content-Type: text/html ''' db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = "select " + pic + " from products where id='" + str(picid) + "';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content To answer your questions, I have no idea what eNom has done to their servers, which is where the other site was hosted (never went live), but am in the process of building on DreamHost, who seems to be a FAR better service than eNom, whom I actually had to report to the BBB and they never fixed or acknowledged very obvious problems. At any rate, the above code gets the browser to print out all the binary "garbage" that should translate into an image (you can look: http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1 ). Any more ideas would be helpful. Going to that URL, my browser now tries to render an HTML page, and I can now see the 'Content-Type: image/jpeg' string being printed into the HTML source. Have you tried removing the 'Content-Type: text/html' header, with the new triple-quoted syntax? -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- Rami Chowdhury "Never attribute to malice that which can be attributed to stupidity" -- Hanlon's Razor 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
Gabriel, don't you remember fighting this through with me a year or two ago? It worked just fine back then, but now the same code doesn't work! Go figure! We've tweaked it to this point: #!/usr/local/bin/python import cgitb; cgitb.enable() import MySQLdb import cgi import sys,os sys.path.append(os.getcwd()) from login import login user, passwd, db, host = login() form = cgi.FieldStorage() picid = int(form['id'].value) x = int(form['x'].value) pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} pic = pics[x] db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) cursor= db.cursor() sql = "select " + pic + " from products where id='" + str(picid) + "';" cursor.execute(sql) content = cursor.fetchall()[0][0].tostring() cursor.close() print '''Content-Type: image/jpeg ''' print print content Your comments are very much appreciated. TIA, V On Wed, Oct 7, 2009 at 9:51 AM, Gabriel Genellina wrote: > En Tue, 06 Oct 2009 17:26:19 -0300, Victor Subervi > escribió: > > The code in question is generated automatically from another script. I >> took >> your idea of the \r\n\r\n and added triple quoting and now it prints out >> this: >> > > That's still wrong. The output should be: > > - a line containing Content-Type: image/jpeg > - a blank line (no more!) > - the actual image data > > A Content-Type of text/html is just *wrong* for an image... > > -- > Gabriel Genellina > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
En Tue, 06 Oct 2009 17:26:19 -0300, Victor Subervi escribió: The code in question is generated automatically from another script. I took your idea of the \r\n\r\n and added triple quoting and now it prints out this: That's still wrong. The output should be: - a line containing Content-Type: image/jpeg - a blank line (no more!) - the actual image data A Content-Type of text/html is just *wrong* for an image... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Re: unittest.TestCase and functools.partial don't seem to mix
En Tue, 06 Oct 2009 18:01:34 -0300, Joel Smith escribió: Gabriel Genellina wrote: Note that you don't *have* to use partial in this case, as you're building the suite yourself. Just create the TestCase instances manually: suite = unittest.TestSuite([ TestGenericWindow('testit', 'brown'), TestGenericWindow('testit', 'blue'), TestGenericWindow('testit', 'green') ]) unittest.TextTestRunner().run(suite) Perfect! This is exactly what I needed. For some reason, I didn't understand that I could construct my TestCase objects directly... I thought that I had to allow the unittest framework to construct them for me. This is straightforward, and does exactly what I need. You're not alone :) The unittest design is rather convoluted, probably because it aims to mimic the jUnit design as closely as possible, with all its javaism and unpythonicity. I don't think one could understand how to use the framework just by reading the package documentation; more background info is needed. The "Dive into Python" book contains a chapter on this topic. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: mktime, how to handle dates before 01-01-1970 ?
Christian Heimes wrote: > M.-A. Lemburg schrieb: >> Christian Heimes wrote: >>> Ben Finney wrote: If you're committed to changing the epoch anyway, I would recommend using http://en.wikipedia.org/wiki/Astronomical_year_numbering> (epoch at 4004 BCE) since it is widely used to unify dates referring to human history. >>> I prefer JDN or MJD (http://en.wikipedia.org/wiki/JDN) for dates long >>> before or after the unix epoch. The conversion from JDN as float to a >>> datetime object is trivial. >> >> FWIW, mxDateTime can help you with all of those: >> > import mx.DateTime > mx.DateTime.DateTimeFrom('1.1.4004 BCE') >> > mx.DateTime.DateTimeFrom('1.1.4004 BCE').jdn >> 258994.5 > mx.DateTime.DateTimeFromJDN(258994.5) >> > mx.DateTime.DateTimeFrom('1.1.4004 BCE').mjd >> -2141006.0 > mx.DateTime.DateTimeFromMJD(-2141006.0) >> >> >> The supported date range is limited by the number of days >> that fit into a C long. Should be enough for most use cases :-) > > Nice ... :) I didn't know that mxDateTime has support for Julian Date. It also implements the TJD that's sometimes used in the US (the NIST definition of it): >>> mx.DateTime.DateTimeFrom('1.1.4004 BCE').tjd -1006.0 >>> mx.DateTime.DateTimeFrom('1.1.4004 BCE').tjd_myriad 26 >>> mx.DateTime.DateTimeFromTJD(-1006.0, 26) And has support for the Julian calendar: >>> mx.DateTime.JulianDateTime(1752, 9, 2).Gregorian() which is sometimes handy for historical dates: http://en.wikipedia.org/wiki/Julian_calendar -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 07 2009) >>> Python/Zope Consulting and Support ...http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
Hrvoje Niksic: > Note that stable sort has additional memory requirements. In situations > where you don't need stability, but do need memory-efficient in-place > sorting, an unstable sort might well be preferred. This is why > libraries such as C++'s STL offer both. There are stable sorts that need no additional memory. In a largish program written in a general-purpose multi-level language, like D (this is probably true for C++ too), often 80% of the code takes a very little time to run. Such code may need to process few small arrays, or small data sets, or to manage the GUI, etc. So optimizing those parts of the code for performance (both in memory used and CPU cycles used) is stupid. What you want in such large parts of the code is: - to write code quickly - to have code that's short, readable, easy to fix, and most important of all that is the less bug-prone as possible. So what you need in such large parts of the code is something that's very flexible and safe, even if it's not top performance (both in memory and CPU). This is why for example in D there are built-in associative arrays, that have a handy syntax, built-in methods, and they are never O(n^2), even if they are not the most efficient ones where you need max performance, or where you need minimal memory used, or where you need to perform unusual operations. Such built-ins are useful to reduce both code length and bug count, because they are quite safe and easy to use. Stable sorts are a little safer, because they don't scramble your data in certain ways, so they can be used in more situations. This is why having the Timsort in Python is good. When you run profile the D code and you see your program uses too much RAM or wastes too much time in the built-in sort, then you can switch to using special sorts from the std lib. You can even write your own hash or sort for special situations (and you don't have to drop down to use another language for that, you keep using the same, even if you may want to change your programming stile, and use a more C-like style, with no dynamic allocations, some bit twidding, pointers, more structs, 16 bit integers, unsigned integers, unions, compiler intrinsics, even inlined assembly that uses SSE3, etc). In normal code you may want to adopt a more Java-like programming style, or templates, or even using a large library I have written, you may program it almost as a curious Python-like, with lazyness too. This is why I think the built-in sort has to be flexible, because you are supposed to use it most of the times, and most of the times you don't need top performance. Different parts of a program have to be optimized for different things, computer performance, or programmer performance. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
AES decrypting in Python
Hi, I am working on a project where I need to decrypt some data that has been encrypted with AES. It looks like M2Crypto is the module of choice for these sorts of things, but I cannot figure out how to do this stuff from the docs. I have the following PHP code that needs to be translated into Python: $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data,MCRYPT_MODE_ECB, $iv),"\0"); I can't find a method in M2Crypto that gets the "initialization vector" size. I found the right method in the tests, which appears to be EVP.Cipher. So I would assume, I would need to do something like: EVP.Cipher(alg="aes_256_ecb", key=SomeKey, iv=SomeIV, op=dec, padding=False) I don't really see where I pass the data that needs the decrypting though. Can someone shed some light on this? Thanks, Mike -- http://mail.python.org/mailman/listinfo/python-list
Rules regarding a post about a commercial product
Hello, I am hoping to get feedback for a new, commercial platform that targets the python programming language and its users. The product is currently in a closed-beta and will be free for at least a couple months. After reviewing the only rules I could find (http://www.python.org/community/lists/), I wanted to ask one last time to make sure that such a post would be appropriate. Thanks, Ken -- http://mail.python.org/mailman/listinfo/python-list
Re: When ‘super’ is not a good id ea
alex23 wrote: Jean-Michel Pichavant wrote: a possible answer: - explicit >> implicit I'm not sure this is the correct one though :) To me, the explicit reference to the base class violates DRY. It also means you need to manually change all such references should the base class ever change, something that using super() avoids. I found the correct answer (http://www.artima.com/weblogs/viewpost.jsp?thread=236275) " super is perhaps the trickiest Python construct: this series aims to unveil its secrets" "Having established that super cannot return the mythical superclass, we may ask ourselves what the hell it is returning ;) The truth is that super returns proxy objects.Informally speaking, a proxy is an object with the ability to dispatch to methods of other objects via delegation. Technically, super is a class overriding the __getattribute__ method. Instances of super are proxy objects providing access to the methods in the MRO." Jean-Michel -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Displaying Pics
I took out the line in question (with text/html). Now it prints to screen the url. It did that before. Strange. Any other ideas? TIA, V On Tue, Oct 6, 2009 at 3:40 PM, Rami Chowdhury wrote: > On Tue, 06 Oct 2009 13:26:19 -0700, Victor Subervi < > victorsube...@gmail.com> wrote: > > The code in question is generated automatically from another script. I >> took >> your idea of the \r\n\r\n and added triple quoting and now it prints out >> this: >> >> #!/usr/local/bin/python >> import cgitb; cgitb.enable() >> import MySQLdb >> import cgi >> import sys,os >> sys.path.append(os.getcwd()) >> from login import login >> user, passwd, db, host = login() >> form = cgi.FieldStorage() >> picid = int(form['id'].value) >> x = int(form['x'].value) >> pics = {1:'pic1',2:'pic2',3:'pic3',4:'pic4',5:'pic5',6:'pic6'} >> pic = pics[x] >> print '''Content-Type: text/html >> >> ''' >> db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) >> cursor= db.cursor() >> sql = "select " + pic + " from products where id='" + str(picid) + "';" >> cursor.execute(sql) >> content = cursor.fetchall()[0][0].tostring() >> cursor.close() >> print '''Content-Type: image/jpeg >> >> ''' >> print >> print content >> >> >> To answer your questions, I have no idea what eNom has done to their >> servers, which is where the other site was hosted (never went live), but >> am >> in the process of building on DreamHost, who seems to be a FAR better >> service than eNom, whom I actually had to report to the BBB and they never >> fixed or acknowledged very obvious problems. At any rate, the above code >> gets the browser to print out all the binary "garbage" that should >> translate >> into an image (you can look: >> http://13gems.com/stxresort/cart/getpic1.py?id=1&x=1 ). Any more ideas >> would >> be helpful. >> > > Going to that URL, my browser now tries to render an HTML page, and I can > now see the 'Content-Type: image/jpeg' string being printed into the HTML > source. Have you tried removing the 'Content-Type: text/html' header, with > the new triple-quoted syntax? > > > -- > Rami Chowdhury > "Never attribute to malice that which can be attributed to stupidity" -- > Hanlon's Razor > 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD) > -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
Bearophile writes: > What I meant is that a general sorting routine, even in D, is better > to be first of all flexible. So I think it's better for the D built-in > sort to be stable, because such extra invariant allows you to use the > sort in more situations. Note that stable sort has additional memory requirements. In situations where you don't need stability, but do need memory-efficient in-place sorting, an unstable sort might well be preferred. This is why libraries such as C++'s STL offer both. -- http://mail.python.org/mailman/listinfo/python-list
Python book similar to Enterprise Recipes with Ruby and Rails
Hi Is there a python book that resemble this http://www.amazon.com/Enterprise-Recipes-Ruby-Rails-Schmidt/dp/1934356239/ref=sr_1_1?ie=UTF8&s=books&qid=1254914183&sr=8-1-spell Also is there a active record version or port of Python ? regards -- http://mail.python.org/mailman/listinfo/python-list
data matrix python
Good morning all! I am trying to build a data matrix, but I am not able either to write to file with a proper structure nor to get the data from the matrix. I want to sort some music by similarity content, and I just have the indexes of the playlist like this: dm = numpy.array(songs) [0 4 2 1 3] [1 2 0 4 3] [2 1 0 4 3] [3 2 1 0 4] [4 0 1 2 3] Now, I want to keep the same format but with the names of the songs, something like this: Sort_dm.append(songlist(dm)) ['100.mp3\n' '10008.mp3' '10005.mp3\n' '10001.mp3\n' '10006.mp3\n' '10001.mp3\n' '10005.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3' '10006.mp3\n' '10006.mp3\n' '10005.mp3\n' '10001.mp3\n' '100.mp3\n' '10008.mp3' '10008.mp3' '100.mp3\n' '10001.mp3\n' '10005.mp3\n' '10006.mp3\n'] But there is no way either I can access to the data... because there are strings, or save them in matrix format! I could not find anything in the documentation about this! any hint would be very welcome! thank you for your time! Best regards, Bea Mora This message was sent using IMP, the Internet Messaging Program. -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
On Wed, Oct 7, 2009 at 2:31 AM, Ryan wrote: > Next time python comes across > > from PyQt4 import QtGui > > it would have to re-import the class, which seems a waste of cycles > that could accumulate. Python only imports modules once. The next time Python comes across that, it looks in sys.modules, sees a copy of PyQt4, and just adds a reference to the class in the existing already-loaded module. All 'del PyQt4' does is deletes a reference to that module from the local namespace. It doesn't actually delete the module or cause it to be destroyed or cleaned up, as there's always at least one additional reference to all modules in the sys.modules dictionary. There's no re-importing. > In this situation, the use of __all__ is > better. Plus, by using __all__ instead of del you do not have to worry > about forgetting to del a class. > IMHO, __all__ is almost always better because of its explicitness if you care about the API/modules/classes exposed from this module. "del PyQt4" at the end of the file is completely harmless, though. It won't actually affect anything. --S -- http://mail.python.org/mailman/listinfo/python-list
Re: mktime, how to handle dates before 01-01-1970 ?
M.-A. Lemburg schrieb: > Christian Heimes wrote: >> Ben Finney wrote: >>> If you're committed to changing the epoch anyway, I would recommend >>> using http://en.wikipedia.org/wiki/Astronomical_year_numbering> >>> (epoch at 4004 BCE) since it is widely used to unify dates referring to >>> human history. >> I prefer JDN or MJD (http://en.wikipedia.org/wiki/JDN) for dates long >> before or after the unix epoch. The conversion from JDN as float to a >> datetime object is trivial. > > FWIW, mxDateTime can help you with all of those: > import mx.DateTime mx.DateTime.DateTimeFrom('1.1.4004 BCE') > mx.DateTime.DateTimeFrom('1.1.4004 BCE').jdn > 258994.5 mx.DateTime.DateTimeFromJDN(258994.5) > mx.DateTime.DateTimeFrom('1.1.4004 BCE').mjd > -2141006.0 mx.DateTime.DateTimeFromMJD(-2141006.0) > > > The supported date range is limited by the number of days > that fit into a C long. Should be enough for most use cases :-) Nice ... :) I didn't know that mxDateTime has support for Julian Date. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: mktime, how to handle dates before 01-01-1970 ?
Christian Heimes wrote: > Ben Finney wrote: >> If you're committed to changing the epoch anyway, I would recommend >> using http://en.wikipedia.org/wiki/Astronomical_year_numbering> >> (epoch at 4004 BCE) since it is widely used to unify dates referring to >> human history. > > I prefer JDN or MJD (http://en.wikipedia.org/wiki/JDN) for dates long > before or after the unix epoch. The conversion from JDN as float to a > datetime object is trivial. FWIW, mxDateTime can help you with all of those: >>> import mx.DateTime >>> mx.DateTime.DateTimeFrom('1.1.4004 BCE') >>> mx.DateTime.DateTimeFrom('1.1.4004 BCE').jdn 258994.5 >>> mx.DateTime.DateTimeFromJDN(258994.5) >>> mx.DateTime.DateTimeFrom('1.1.4004 BCE').mjd -2141006.0 >>> mx.DateTime.DateTimeFromMJD(-2141006.0) The supported date range is limited by the number of days that fit into a C long. Should be enough for most use cases :-) -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 07 2009) >>> Python/Zope Consulting and Support ...http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: When ‘super’ is not a good idea
Jean-Michel Pichavant wrote: > a possible answer: > - explicit >> implicit > > I'm not sure this is the correct one though :) To me, the explicit reference to the base class violates DRY. It also means you need to manually change all such references should the base class ever change, something that using super() avoids. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python: Text file insert to MySQL
On Wed, Oct 7, 2009 at 1:32 PM, Schedule wrote: > That was great ! Now I am able to insert the values from the file. > > Somehow I am not able to update a specific field with all the vaues in the > file. For eg: > [...] > c.execute("UPDATE a SET last = %s", row) The database does what you say, not what you mean ;-) SQL commands like SELECT, UPDATE, DELETE work on sets. If you don't qualify the set any further, you always operate on the whole set. To restrict the set, apply a WHERE clause. I. e. Perhaps you should try a SQL tutorial before jumping into SQL + Python. Here's one: http://sqlzoo.net/ -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: sort's key and cmp parameters
Paul Rubin: > Bearophile: > > sorting, and something that's surely not bug-prone. In such situation > > having a 'key' argument is *better*. Such sort can be stable. > > Nothing stops comparison sorting from being stable. Since the rest of > your post seems premised on the opposite, I hope that clears things up > for you. When I have written that post I was partially unfocused, I am sorry. What I meant is that a general sorting routine, even in D, is better to be first of all flexible. So I think it's better for the D built-in sort to be stable, because such extra invariant allows you to use the sort in more situations. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Question about RADIXCHAR on Win32
Hi all, I have a problem with locale.RADIXCHAR, it seems this constant isn't defined on the Windows platform. Is there a way to use an equivalent of locale.RADIXCHAR ? Thank you Stephane -- Stephane Wirtel - "As OpenERP is OpenSource, please feel free to contribute." Developper - Technical Lecturer OpenERP OpenERP - Tiny SPRL Chaussee de Namur, 40 B-1367 Gerompont Tel: +32.81.81.37.00 Web: http://www.tiny.be Web: http://www.openerp.com Planet: http://www.openerp.com/planet/ Blog: http://stephane-wirtel-at-tiny.blogspot.com <>-- http://mail.python.org/mailman/listinfo/python-list
Re: Python: Text file insert to MySQL
That was great ! Now I am able to insert the values from the file. Somehow I am not able to update a specific field with all the vaues in the file. For eg: Before the update my table contents are: +---+---+ | first | last | +---+---+ | Sara | Jones | | Terry | Burns | | Filiz | Khan | +---+---+ When I do the update using the following code, --- import MySQLdb, csv, sys conn = MySQLdb.connect (host = "localhost",user = "usr", passwd = "pass",db = "db") c = conn.cursor() csv_data=csv.reader(file("b.txt")) for row in csv_data: print row c.execute("UPDATE a SET last = %s", row) #c.commit() c.close() - The table contents get updated with the last content of the input file . for eg +---+--+ | first | last | +---+--+ | Sara | c| | Terry | c| | Filiz | c| +---+--+ the contents of the b.txt file: a b c Any kind of help would be greatly appreciated. James On Tue, Oct 6, 2009 at 9:33 PM, Gerhard Häring wrote: > Schedule wrote: > > Hello, > > > > I am currenty using MySQL 5.1 community server and trying to import the > > data of the comma delimited text file into the table using python 2.6 > > scripts. I have installed Mysqldb 1.2.2. > > > > follwoing is my script: > > [...] > >7. > > c.execute("INSERT INTO a (first, last) VALUES (%s, %s), row") > > [...] > > When I execute the statement I get the following error: > > > > > [...] > > _mysql_exceptions.ProgrammingError: (1064, "You have an error in your > > SQL syntax; check the manual tha > > t corresponds to your MySQL server version for the right syntax to use > > near '%s, %s), row' at line 1") > > You misplaced the closing quote. > > wrong: c.execute("INSERT INTO a (first, last) VALUES (%s, %s), row") > correct: c.execute("INSERT INTO a (first, last) VALUES (%s, %s)", row) > > > -- Gerhard > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: When ‘super’ is not a good idea
Ben Finney wrote: Scott David Daniels writes: Scott David Daniels wrote: class Initialized(ClassBase): @classmethod def _init_class(class_): class_.a, class_.b = 1, 2 super(Initialized, class_)._init_class() Mea culpa: Here super is _not_ a good idea, […] Why is ‘super’ not a good idea here? class Initialized(ClassBase): @classmethod def _init_class(class_): class_.a, class_.b = 1, 2 ClassBase._init_class() What makes this implementation better than the one using ‘super’? a possible answer: - explicit >> implicit I'm not sure this is the correct one though :) JM -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use WSGI applications with apache
Chris Colbert wrote: > if you want to use it with apapache, you need mod_wsgi. Or you can use mod_proxy alone or with mod_rewrite if you want to stick to the builtin webserver of cherrypy. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: del an imported Class at EOF... why?
Thanks everyone for your insight. I'm going to have to agree with the paranoid desire to prevent people importing his module and then using the classes he imports from elsewhere (I'm not ruling out the lead paint theory until I can gather more evidence). It does beg the question for me. Consider the example from his code below from PyQt4 import QtGui class LauncherWidget( QtGui.QWidget ): # A Specialization of QWidget del QtGui Next time python comes across from PyQt4 import QtGui it would have to re-import the class, which seems a waste of cycles that could accumulate. In this situation, the use of __all__ is better. Plus, by using __all__ instead of del you do not have to worry about forgetting to del a class. Ryan -- http://mail.python.org/mailman/listinfo/python-list