right curly quote and unicode
Hi all,I am trying to compare my Itunes Library xml to the actual files on my computer.As the xml file is in UTF-8 encoding, I decided to do the comparison of the filenames in that encoding.It all works, except with one file. It is named 'The Chemical Brothers-Elektrobank-04 - Don't Stop the Rock (Electronic Battle Weapon Version).mp3'. It goes wrong with the apostrophe in Don't. That is actually not an apostrophe, but ASCII char 180: ´ In the Itunes library it is encoded as: Don%E2%80%99tI do some some conversions with both the library path names and the folder path names. Here is the code:(in the comment I dispay how the Don't part looks. I got this using print repr(filename)) -#Once I have the filenames from the library I clean them using the following code (as filenames are in the format ' file://localhost/m:/music/track%20name.mp3')filename = urlparse.urlparse(filename)[2][1:] # u'Don%E2%80%99t' ; side question, anybody who nows a way to do this in a more fashionable way?filename = urllib.unquote (filename) # u'Don\xe2\x80\x99t'filename = os.path.normpath(filename) # u'Don\xe2\x80\x99t'I get the files in my music folder with the os.walk method and thenI do:filename = os.path.normpath(os.path.join (root,name)) # 'Don\x92t'filename = unicode(filename,'latin1') # u'Don\x92t'filename = filename.encode('utf-8') # 'Don\xc2\x92t'filename = unicode(filename,'latin1') # u'Don\xc2\x92t'- I think the folder part is a bit weird with the unicode, encode, unicode conversions, but it works for all the other songs. Of which some contain latin1 characters like accented e and a, and c's with an s underneath them. Only this wierd quote apostrophe thingy is not working. What am I doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: right curly quote and unicode
That is actually> not an apostrophe, but ASCII char 180: ´It's actually Unicode char #180, not ASCII. ASCII characters are in 0..127 range.Yep, that's what I ment... :D > In the Itunes library it is encoded as: Don%E2%80%99t Looks like a utf-8 encoded string, then encoded like an url.It is. I just found out it is unicode character 2019. So in the Itunes library it is not unicode char 180, but it looks exactly the same... > I do some some conversions with both the library path names and the folder > path names. Here is the code:> (in the comment I dispay how the Don't part looks. I got this using print> repr(filename))> -> #Once I have the filenames from the library I clean them using the following > code (as filenames are in the format '> file://localhost/m:/music/track%20name.mp3')>> filename = urlparse.urlparse(filename)[2][1:] # u'Don%E2%80%99t' ; side > question, anybody who nows a way to do this in a more fashionable way?> filename = urllib.unquote (filename) # u'Don\xe2\x80\x99t'This doesn't work for me in python 2.4, unquote expects str type, not unicode. So it should be:filename = urllib.unquote(filename.encode('ascii')).decode('utf-8') It works for me with python 2.4.3. It returns a unicode string. > filename = os.path.normpath(filename) # u'Don\xe2\x80\x99t'>> I get the files in my music folder with the os.walk method and then> I do:>> filename = os.path.normpath(os.path.join (root,name)) # 'Don\x92t' > filename = unicode(filename,'latin1') # u'Don\x92t'> filename = filename.encode('utf-8') # 'Don\xc2\x92t'> filename = unicode(filename,'latin1') # u'Don\xc2\x92t'This looks like calling random methods with random parameters :) It is... Well, not totally random. I figured I needed a unicode string to be able to encode it to utf-8 (otherwise it gives an error). After that is appears not to be a unicode string anymore(no u in front of it), so I decided to unicode it again It worked, but I now accomplish the same by just the encode line and the following: Python is able to return you unicode file names right away, you justneed to pass input parameters as unicode strings:>>> os.listdir(u"/")[u'alarm', u'ARCSOFT' ...]So in your case you need to make sure the start directory parameter for walk function is unicode.That does not matter much for me. Then I will have to convert the path name to unicode, as it is user input. (ok, it still saves me converting a string to unicode a thousand times, so I'll do it :) Now I know where the problem lies. The character in the actual file path is u+00B4 (Acute accent) and in the Itunes library it is u+2019 (a right curly quote). Somehow Itunes manages to make these two the same...? As it is the only file that gave me trouble, I changed the accent in the file to an apostrophe and re-imported it in Itunes. But I would like to hear if there is a solution for this problem? -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a lot of SPAM from this list
How do you send and receive this email?24 Oct 2006 22:12:35 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid>: I've given up on email pretty much. I no longer have a public emailaddress of any type. I just give out a URL (including on my resume,business cards, etc), which leads to a HTTPS contact form. It's been quite reliable and I get very little spam that way.--http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python for me?
> > At least: i use the dutch portal http://python.startpagina.nl/ to start > with. Can you advice me a good Python interpreter, or a good startpage > (as in Python for dummys)? > > Lennart > > -- > http://mail.python.org/mailman/listinfo/python-list > check http://www.diveintopython.org/ pretty good book on all the basics, and it's freely available online. for interpreters, try out SPE http://stani.be/python/spe/blog/ , it is free, and has some nice features. And see: http://spyced.blogspot.com/2006/02/pycon-python-ide-review.html for a comparison of 4 ide's (including SPE) -- http://mail.python.org/mailman/listinfo/python-list
bad marshal data in site.py in fresh 2.5 install win
Hi, I have installed python two days ago on a USB memory stick (I am on the move and have no laptop.) I am on windows computers, mostly XP, all the time. Now, after pluging it in to a different computer, I get the following message when I run pyhthon: 'import site' failed; use -v for traceback python -v gives: G:\Python25>python -v # installing zipimport hook import zipimport # builtin # installed zipimport hook # G:\Python25\lib\site.pyc matches G:\Python25\lib\site.py import site # precompiled from G:\Python25\lib\site.pyc # G:\Python25\lib\os.pyc matches G:\Python25\lib\os.py import os # precompiled from G:\Python25\lib\os.pyc import nt # builtin # G:\Python25\lib\ntpath.pyc matches G:\Python25\lib\ntpath.py import ntpath # precompiled from G:\Python25\lib\ntpath.pyc # G:\Python25\lib\stat.pyc matches G:\Python25\lib\stat.py import stat # precompiled from G:\Python25\lib\stat.pyc # G:\Python25\lib\UserDict.pyc matches G:\Python25\lib\UserDict.py import UserDict # precompiled from G:\Python25\lib\UserDict.pyc # G:\Python25\lib\copy_reg.pyc matches G:\Python25\lib\copy_reg.py import copy_reg # precompiled from G:\Python25\lib\copy_reg.pyc # G:\Python25\lib\types.pyc matches G:\Python25\lib\types.py import types # precompiled from G:\Python25\lib\types.pyc import _types # builtin # zipimport: found 74 names in G:\Python25\lib\site-packages\setuptools-0.6c3-py 2.5.egg # G:\Python25\lib\locale.pyc matches G:\Python25\lib\locale.py import locale # precompiled from G:\Python25\lib\locale.pyc import encodings # directory G:\Python25\lib\encodings # G:\Python25\lib\encodings\__init__.pyc matches G:\Python25\lib\encodings\__ini t__.py import encodings # precompiled from G:\Python25\lib\encodings\__init__.pyc # G:\Python25\lib\codecs.pyc matches G:\Python25\lib\codecs.py import codecs # precompiled from G:\Python25\lib\codecs.pyc import _codecs # builtin # G:\Python25\lib\encodings\aliases.pyc matches G:\Python25\lib\encodings\aliase s.py 'import site' failed; traceback: Traceback (most recent call last): File "G:\Python25\lib\site.py", line 415, in main() File "G:\Python25\lib\site.py", line 406, in main aliasmbcs() File "G:\Python25\lib\site.py", line 356, in aliasmbcs import locale, codecs File "G:\Python25\lib\locale.py", line 14, in import sys, encodings, encodings.aliases File "F:\Python25\lib\encodings\__init__.py", line 32, in ValueError: bad marshal data # G:\Python25\lib\warnings.pyc matches G:\Python25\lib\warnings.py import warnings # precompiled from G:\Python25\lib\warnings.pyc # G:\Python25\lib\linecache.pyc matches G:\Python25\lib\linecache.py import linecache # precompiled from G:\Python25\lib\linecache.pyc Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> - What can I do about this? Thanks, TiNo -- http://mail.python.org/mailman/listinfo/python-list
Help on installing Easy_Install
Hi, I'm having problems installing easy_install. When I run python ez_setup.py I get: G:\python>python ez_setup.py 'import site' failed; use -v for traceback Downloading http://cheeseshop.python.org/packages/2.5/s/setuptools/setuptools-0. 6c3-py2.5.egg Processing setuptools-0.6c3-py2.5.egg Copying setuptools-0.6c3-py2.5.egg to g:\python25\lib\site-packages Adding setuptools 0.6c3 to easy-install.pth file Traceback (most recent call last): File "ez_setup.py", line 217, in main(sys.argv[1:]) File "ez_setup.py", line 152, in main return main(list(argv)+[egg]) # we're done here File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 1588, in main File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 1577, in with_ei_usage File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 1592, in File "F:\Python25\lib\distutils\core.py", line 151, in setup File "F:\Python25\lib\distutils\dist.py", line 974, in run_commands File "F:\Python25\lib\distutils\dist.py", line 994, in run_command File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 211, in run File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 427, in easy_install File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 473, in install_item File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 497, in process_distribution File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 373, in install_egg_scripts File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 569, in install_wrapper_scripts File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 1480, in get_script_args File "G:\python\setuptools-0.6c3-py2.5.egg\setuptools\command\easy_install.py" , line 1412, in get_script_header LookupError: no codec search functions registered: can't find encoding ?? What to do? thanks, TiNo -- http://mail.python.org/mailman/listinfo/python-list
Re: bad marshal data in site.py in fresh 2.5 install win
Good question... I am now on a different computer, one that has never heard of Python, so no env vars are set. Again, this gives (my memory stick is now F:\): -- F:\Python25>python -v # installing zipimport hook import zipimport # builtin # installed zipimport hook # F:\Python25\lib\site.pyc matches F:\Python25\lib\site.py import site # precompiled from F:\Python25\lib\site.pyc # F:\Python25\lib\os.pyc matches F:\Python25\lib\os.py import os # precompiled from F:\Python25\lib\os.pyc import nt # builtin # F:\Python25\lib\ntpath.pyc matches F:\Python25\lib\ntpath.py import ntpath # precompiled from F:\Python25\lib\ntpath.pyc # F:\Python25\lib\stat.pyc matches F:\Python25\lib\stat.py import stat # precompiled from F:\Python25\lib\stat.pyc # F:\Python25\lib\UserDict.pyc matches F:\Python25\lib\UserDict.py import UserDict # precompiled from F:\Python25\lib\UserDict.pyc # F:\Python25\lib\copy_reg.pyc matches F:\Python25\lib\copy_reg.py import copy_reg # precompiled from F:\Python25\lib\copy_reg.pyc # F:\Python25\lib\types.pyc matches F:\Python25\lib\types.py import types # precompiled from F:\Python25\lib\types.pyc import _types # builtin # zipimport: found 74 names in F:\Python25\lib\site-packages\setuptools-0.6c3-py 2.5.egg # F:\Python25\lib\locale.pyc matches F:\Python25\lib\locale.py import locale # precompiled from F:\Python25\lib\locale.pyc import encodings # directory F:\Python25\lib\encodings # F:\Python25\lib\encodings\__init__.pyc matches F:\Python25\lib\encodings\__ini t__.py import encodings # precompiled from F:\Python25\lib\encodings\__init__.pyc # F:\Python25\lib\codecs.pyc matches F:\Python25\lib\codecs.py import codecs # precompiled from F:\Python25\lib\codecs.pyc import _codecs # builtin # F:\Python25\lib\encodings\aliases.pyc matches F:\Python25\lib\encodings\aliase s.py 'import site' failed; traceback: Traceback (most recent call last): File "F:\Python25\lib\site.py", line 415, in main() File "F:\Python25\lib\site.py", line 406, in main aliasmbcs() File "F:\Python25\lib\site.py", line 356, in aliasmbcs import locale, codecs File "F:\Python25\lib\locale.py", line 14, in import sys, encodings, encodings.aliases File "F:\Python25\lib\encodings\__init__.py", line 32, in from encodings import aliases ValueError: bad marshal data # F:\Python25\lib\warnings.pyc matches F:\Python25\lib\warnings.py import warnings # precompiled from F:\Python25\lib\warnings.pyc # F:\Python25\lib\linecache.pyc matches F:\Python25\lib\linecache.py import linecache # precompiled from F:\Python25\lib\linecache.pyc Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> --- ?? also removed site.pyc, and run it again, but with the same result. 2006/12/29, "Martin v. Löwis" <[EMAIL PROTECTED]>: > TiNo schrieb: > > # G:\Python25\lib\encodings\aliases.pyc matches > [...] > > File "F:\Python25\lib\encodings\__init__.py", line 32, in > > > > What can I do about this? > > Where does F:\Python25 come from? > > If you have set any PYTHON* environment variables (e.g. PYTHONPATH), > unset them. > > Regards, > Martin > -- http://mail.python.org/mailman/listinfo/python-list
Re: bad marshal data in site.py in fresh 2.5 install win
Removing aliases.pyc solved it. Thank you. 2007/1/3, "Martin v. Löwis" <[EMAIL PROTECTED]>: > TiNo schrieb: > > File "F:\Python25\lib\encodings\__init__.py", line 32, in > >from encodings import aliases > > ValueError: bad marshal data > > > > also removed site.pyc, and run it again, but with the same result. > > It's likely rather aliases.pyc which is bad, so try removing that. > If in doubt, remove all .pyc files. > > If one of them is bad, it's either because the stick wasn't ejected > properly at some point, or it suffers from data loss. > > Regards, > Martin > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: pdb.py - why is this debugger different from all other debuggers?
R. Bernstein wrote: Hi! To summarize, I think most of us readers here like your changes or at least didn't shout loud enough against it ;-) As I also would like to have a more powerful and gdb-like debugging facility in out-of-the-box python, I think it would be the best strategy to make a consolidated patch now, send it to sf and to post a note about that on python-dev@python.org to get the "board's approval" :-) "idle" also changed dramatically during the last versions - why shouldn't pdb also become better ... a volunteer seems to be there ;-) Thanks for your effort and cheers, Tino (who is really +1 for your changes!) -- http://mail.python.org/mailman/listinfo/python-list
CSV Parser and unusual (?) linesterminator - misunderstanding?
Hi! I'm trying to use the csv Parser included with Python. Field Delimiter is "|", Line Delimiter is "#". Unfortunately it doesn't work as expected. The parser seems to just ignore the 'lineterminator'? Here's some example: > $ cat test.py > #! /usr/bin/env python > > import sys, csv, cStringIO > > class SpecialCSVDialect(csv.Dialect): > delimiter = '|' > lineterminator = '#' > quotechar = '"' > doublequote = True > skipinitialspace = False > quoting = csv.QUOTE_MINIMAL > > csv.register_dialect("SpecialCSV", SpecialCSVDialect) > > memfile = cStringIO.StringIO("1a|1b|1c|1d#2a|2b|2c|2d#3a|3b|3c|3d#") > cfile = csv.reader(memfile, dialect="SpecialCSV") > > while 1: > try: > data = cfile.next() > except csv.Error, (errmsg): > print >> sys.stderr, "SpecialCSVError '%s' - aborting...!" % (errmsg) > sys.exit() > except StopIteration: > break > print data > $ ./test.py > ['1a', '1b', '1c', '1d#2a', '2b', '2c', '2d#3a', '3b', '3c', '3d#'] > $ I would have been expecting that the parser returns three lines, i. e. > ['1a', '1b', '1c', '1d'] > ['2a', '2b', '2c', '2d'] > ['3a', '3b', '3c', '3d'] Any hints what I'm doing wrong here? Thanks Tino -- http://mail.python.org/mailman/listinfo/python-list
Re: CSV Parser and unusual (?) linesterminator - misunderstanding?
Peter Otten wrote: > Tino Lange wrote: > >> I'm trying to use the csv Parser included with Python. Field Delimiter is >> "|", Line Delimiter is "#". Unfortunately it doesn't work as expected. >> The parser seems to just ignore the 'lineterminator'? > > The csv reader accepts '\r' '\r\n' or '\n' as line endings, even mixed in > the same file. This behaviour is hardcoded. Only the writer uses the > lineterminator specified in the dialect. Boah ... Really? a) this is not in the documentation ... or did I oversee something? b) this is really unacceptable, or? At least we here have many CSV's with other lineterminators than '\n'. Is this going to be changed? Is someone working on it? Or are patches for SF wanted? Cheers, Tino -- http://mail.python.org/mailman/listinfo/python-list
Re: reading file to list
Xah Lee wrote: comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby ... OK, I want to create a nested list in Lisp (always of only integers) from a text file, such that each line in the text file would be represented as a sublist in the 'imported' list. example of a file's content 3 10 2 4 1 11 18 example of programing behavior (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) In a show-off context, it can be reduced to by about 50%, but still far verbose than ruby or say perl (which is 1 or 2 lines. (python would be 3 or 5)). So? Please count the lines: [line.strip().split() for line in file("blob.txt")] HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: reading file to list
MRAB wrote: Tino Wildenhain wrote: Xah Lee wrote: comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby ... OK, I want to create a nested list in Lisp (always of only integers) from a text file, such that each line in the text file would be represented as a sublist in the 'imported' list. example of a file's content 3 10 2 4 1 11 18 example of programing behavior (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18)) In a show-off context, it can be reduced to by about 50%, but still far verbose than ruby or say perl (which is 1 or 2 lines. (python would be 3 or 5)). So? Please count the lines: [line.strip().split() for line in file("blob.txt")] The original requirement was for a list of lists of integers: Actually I read: "Note that the result element is string, not numbers. There's no easy way to convert them on the fly. 3 or so more lines will be needed to do that." So I felt that requirement was dropped, but otherwise, you are right :-) [[int(x) for x in line.split()] for line in open("blob.txt")] Still only 1 line, though. Yep. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 weirdness
Neha Gupta wrote: Hey, ... crs_dep_hour, origin from flightdata where date = '" + date + "' group ^^^ never ever do that! Even more when input comes from user. The correct form is cur.exec("... date = %s group by ...",(date,)) please see dbapi2 documentation or examples which come with psycopg2. ... You can see above that I even ignored the date passed from the form and I have hardcoded '01-05-2007'. The message "About to issue query" gets printed as well as the right date chosen from the date picker but then I see the following: Assertion failed: (str != NULL), function PyString_FromString, file Objects/stringobject.c, line 107. Abort trap with a pop that says: "The application Python quit unexpectedly. The problem may have been caused by the _psycopg.so plug-in". -- I don't understand the error message above. The date did get passed correctly and am now not even using it, I use the hard coded date. So what is going on? Do other querys work within your application? Looks like the components of the db layer are not correctly found. This can happen if the environment of the web server differs from your personal user when you are testing your scripts. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print lambda result ?
Hi, Barak, Ron wrote: Hi, Wanting to print the correct plural after numbers, I did the following: for num in range(1,4): string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") print string_ However, instead of getting the expected output: 1 event 2 events 3 events I get: 1 event at 0x00AFE670> 2 event at 0x00AFE670> 3 event at 0x00AFE6B0> lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. (num,(lambda n: n >1 and "s" or "")(num)) which is just a quite useless application of lambda :-) (num,num >1 and "s" or "") or even (num,"s" if num >1 else "") in python > 2.5 or in python <3.0: (num,"s"*(num >1)) :-) HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print lambda result ?
Barak, Ron wrote: Thanks Tino: your solutions without the lambda work nicely. What I still don't understand is why the print does not execute the lambda and prints the result, instead of printing the lambda's object description. Bye, Ron. Well its up to the implemention what a class is supposed to return when its __str__() is called. Default is what you see. (this is actually __str__() returning __repr__() which is at its default) Regards Tino -Original Message----- From: Tino Wildenhain [mailto:t...@wildenhain.de] Sent: Tuesday, January 20, 2009 14:22 To: Barak, Ron Cc: python-list@python.org Subject: Re: How to print lambda result ? Hi, Barak, Ron wrote: Hi, Wanting to print the correct plural after numbers, I did the following: for num in range(1,4): string_ = "%d event%s" % (num,lambda num: num > 1 and "s" or "") print string_ However, instead of getting the expected output: 1 event 2 events 3 events I get: 1 event at 0x00AFE670> 2 event at 0x00AFE670> 3 event at 0x00AFE6B0> lambda creates a function so this is the result you are seeing. You would need to call the function to get your result. (num,(lambda n: n >1 and "s" or "")(num)) which is just a quite useless application of lambda :-) (num,num >1 and "s" or "") or even (num,"s" if num >1 else "") in python > 2.5 or in python <3.0: (num,"s"*(num >1)) :-) HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: USB in python
Astan Chee wrote: Hi, Im trying to write a program for my USB device and I'm thinking of using python to do this. The USB device is of my own making and it is activated when one of the two data pins of the USB is given about 5V (or similar to whatever the power pin is getting). Now I'm confused to if the software to activate this can actually be written and how do I do it? Any examples? I've seen pyUSB but it doesn't give me control over the hardware and how much power is going through the data pins. Thanks for any help. Your approach doesn't sound right to me. I don't believe you can control the PINs of the USB host interface directly. You need to configure the host controller - OS is giving you interfaces and abstration for the different device types. All you need to do is to implement the end points as per spec in your hardware and write handler for your hardware's USB ids. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: USB in python
Hi, Astan Chee wrote: Diez B. Roggisch wrote: If all you need is on-off - why can't you just use a switch? Because I want to control the on-off the device using a computer and write software for it (which I am confident I can do if I had references to how the wrappers to said interface). What I'm using is dallas 1wire stuff to do such things. The dongle (which is available as USB too) connects to the host and you have a lib with bindings even to python for it: http://www.owfs.org/ The other end is just a bus with a telephone wire... The most interesting part might be temperature sensors but there are a lot of GPIO chips, electronic resistors, A/D converters etc. available. Most of the stuff can be even ordered as sample from dallas/maxim. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Results of executing hyperlink in script
Tim Chase wrote: 1. This method was suggested by Cameron Laird: os.system("start %s" % URL) It works. But, if the URL contains character &, it will fail. For As an aside, the START command is a bit picky regarding quotes. You have to use this horrible contortion os.system('start "title" "%s"' % URL) The "title" is optional content-wise, but required positionally if there's a quoted resource, so you can just use start "" "%s" a pain, but that's CMD.EXE for you. :) ah, and just for the records, at least os.popen2,os.popen3 support tuple as argument: i,o=os.popen2((cmd,arg1,arg2)) and quotes them correctly. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
Muriel de Souza Godoi wrote: Python offers support for object orientation, but it's not an object-oriented language. I mean, you can code a entire program in Python with no classes. So you use it if you want to. It's not like java, which you must use a class to code a Hello World, but Java isn't fully object-oriented, because it doesn't provide support for multiple inheritance and it has primitive types (multiple interfaces and wrappers to primitive types doesn't count :) ) AFAIK, the unique fully object oriented languagem is Smaltalk. (maybe Simula?), where everything is a class, even the primitive types. well actually except keywords, everything is an object in python too, including of course primitive types (if you say so - practically python does not have them). Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: key capture
Hi, swamynathan wrote: hello, im making a virtual piano in python where on key stroke a wav is played from a location now to implement a fully functional piano i need to have multiple key stroke captures ie if 2 or 3 keys pressed then the function which playes the wav is called with 3 parameters how to implement this or any other suggestion(i was asked to try multi threading which dint seem optimal) Are you trying to do this with a computer keyboard or with an attached midi or usb music keybord? If the former, you are probably w/o luck because afaik there is no way to track the event of having random keys pressed the same time. (Last time I did it was with a real C=64 where you have access to the key matrix) If you manage to receive the keypress events, multithreading is probably easiest to do but it really depends on the way you play the sounds - at least the playback needs to be asynchronously so you can catch note-on, note-off events during playback. Good luck Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Unzipping a .zip properly, and from a remote URL
Hi, Christopher Culver wrote: Returning to Python after several years away, I'm working on a little script that will download a ZIP archive from a website and unzip it to a mounted filesystem. The code is below, and it works so far, but I'm unsure of a couple of things. The first is, is there a way to read the .zip into memory without the use of a temporary file? If I do archive = zipfile.ZipFile(remotedata.read()) directly without creating a temporary file, the zipfile module complains that the data is in the wrong string type. Which makes sense given the documentation (note you can either browse the HTML online/offline or just use help() within the interpreter/ide: Help on class ZipFile in module zipfile: class ZipFile | Class with methods to open, read, write, close, list zip files. | | z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True) | | file: Either the path to the file, or a file-like object. |If it is a path, the file will be opened and closed by ZipFile. | mode: The mode can be either read "r", write "w" or append "a". | compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). | allowZip64: if True ZipFile will create files with ZIP64 extensions when | needed, otherwise it will raise an exception when this would | be necessary. | ... so instead you would use archive = zipfile.ZipFile(remotedata) The second issue is that I don't know if this is the correct way to unpack a file onto the filesystem. It's strange that the zipfile module has no one simple function to unpack a zip onto the disk. Does this code seem especially liable to break? try: remotedata = urllib2.urlopen(theurl) except IOError: print("Network down.") sys.exit() data = os.tmpfile() data.write(remotedata.read()) archive = zipfile.ZipFile(data) if archive.testzip() != None: print "Invalid zipfile" sys.exit() contents = archive.namelist() for item in contents: ... here you should check the zipinfo entry and normalize and clean the path just in case to avoid unpacking a zipfile with special crafted paths (like /etc/passwd and such) Maybe also checking for the various encodings (like utf8) in pathnames makes sense. The dir-creation could be put into a class with caching of already existing subdirectories created and recursive creation of missing subdirectories as well es to make sure you do not ascend out of your target directory by accident (or crafted zip, see above). Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Unzipping a .zip properly, and from a remote URL
Christopher Culver wrote: Tino Wildenhain writes: so instead you would use archive = zipfile.ZipFile(remotedata) That produces the following error if I try that in the Python interpreter (URL edited for privacy): import zipfile import urllib2 remotedata = urllib2.urlopen("http://...file.zip";) archive = zipfile.ZipFile(remotedata) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.5/zipfile.py", line 346, in __init__ self._GetContents() File "/usr/lib/python2.5/zipfile.py", line 366, in _GetContents self._RealGetContents() File "/usr/lib/python2.5/zipfile.py", line 376, in _RealGetContents endrec = _EndRecData(fp) File "/usr/lib/python2.5/zipfile.py", line 133, in _EndRecData fpin.seek(-22, 2) # Assume no archive comment. AttributeError: addinfourl instance has no attribute 'seek' Oh thats annoying. In this case short of providing a buffered wrapper (which is possible) you would stick to the temp file for an easy solution. Sorry about that. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Python ssh with SSH Tectia server
Hi, loial wrote: Has anyone any experiencing with ssh between a python client and the SSH Tectia server from SSH (ssh.com) ? this might well be. ;) Does it work? Did you try? (It should however since at least openssh client worked) Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Locating python
andrew cooke wrote: On Feb 3, 7:35 pm, David Sevilla wrote: I am quite new to Linux, and thought that by using yast2 there would be no user problems (I am asked for the root password). I will sudo it to see if it solves the problem. yast asked you for the password so that easy_install could be installed correctly. you are now using "sudo easy_install" to install mnemosyne and sudo is asking for the root password. each time you install something you need to change public files on the system, and so each time you need to use root in some way. yast does this by logging in as root for you, but needs the password to do it. sudo does the same thing, but again needs the password to do it. hope that makes senses (and that this worked). actually "su" needs the root (or the target users') password and sudo needs _your_ (the current users) password. HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Locating python
andrew cooke wrote: On Feb 4, 9:16 am, andrew cooke wrote: actually "su" needs the root (or the target users') password and sudo needs _your_ (the current users) password. argh, sorry for the confusion. actually, no. sudo requires the root password. at least on opensuse 11.1 default config. i just tried it: argh. This Nürnberg Windows ;-) But this shows that a sensible configuration of the system is usefull before you start installing services on it :-) Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: len()
Marco Mariani wrote: Pat wrote: Why didn't you answer the len() question? It's a bit of a FAQ: len() cannot be a method of list objects because it works on any sequence or iterable. Thats only half of the truth :-) len() can use some internal optimizations on certain objects where sequences indeed have a len() method called __len__() Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Use list name as string
Hi, Vincent Davis wrote: Sorry for not being clear I would have something like this x = [1, 2, 3,5 ,6 ,9,234] Then def savedata(dataname): .. savedata(x) this would save a to a file called x.csv This is my problem, getting the name to be x.csv which is the same as the name of the list. and the data in the file would be 1,2,3,5,6,9,234 this parts works the problem you are facing comes from a little misunderstanding. To clarify: python objects are nameless. You can bind them to any number of names (aka variables) >>> 1 # unnamed integer object with value 1 1 >>> a=1 # bind the integer object to name 'a' >>> b=a # bind the same integer object referred to by name a to name b therefore in your above example, which "name" should your savedata pick up for the filename? the 'x' of the first assignment or the 'dataname' of the assignment in the function call? The only solution I see would be to add a property to your datastore to give it its own unique name. (By subclassing and providing a name attribute or property) - and while you are at it, maybe you want to put the 'write to file' part into the class as well. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Use list name as string
Hendrik van Rooyen wrote: > "MRAB" wrote: > >> The actual names of the variables and functions shouldn't matter to the >> outside world; the name of an output file shouldn't depend on the name >> of a variable. > > That is a matter of opinion. > It is however, an interesting problem, namely: > > How does one get hold of the actual name by which some parameter > is passed? > > you may want to print, as a debug thingy: > > print "the name passed in was: ", ImpossibleThingYieldingName > print "and it evaluates to:" , ArgumentPassed This is possible to some degree: import inspect def F(a): frame_obj,filename,line_no, func_name,contextlines, contextindex=(inspect.getouterframes(inspect.currentframe()))[1] print "F(%s) called from '%s' within '%s' line %d" % (repr(a),filename,func_name,line_no) for ln,srcline in enumerate(contextlines or []): print "%3s : %s" % ('*>' if ln==contextindex else '',srcline) just play around calling the above function from different places and you should see what I mean :-) Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Comparing two book chapters (text files)
andrew cooke wrote: On Feb 4, 10:20 pm, Nick Matzke wrote: So I have an interesting challenge. I want to compare two book chapters, which I have in plain text format, and find out (a) percentage similarity and (b) what has changed. no idea if it will help, but i found this yesterday - http://www.nltk.org/ it's a python toolkit for natural language processing. there's a book at http://www.nltk.org/book with much more info. Also there is difflib in the standard package which can be used depending on exact definition of "similarity". Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Fastest database solution
Hi Curt, Curt Hash wrote: I'm writing a small application for detecting source code plagiarism that currently relies on a database to store lines of code. The application has two primary functions: adding a new file to the database and comparing a file to those that are already stored in the database. I started out using sqlite3, but was not satisfied with the performance results. I then tried using psycopg2 with a local postgresql server, and the performance got even worse. My simple benchmarks show that sqlite3 is an average of 3.5 times faster at inserting a file, and on average less than a tenth of a second slower than psycopg2 at matching a file. I expected postgresql to be a lot faster ... is there some peculiarity in psycopg2 that could be causing slowdown? Are these performance results typical? Any suggestions on what to try from here? I don't think my code/queries are inherently slow, but I'm not a DBA or a very accomplished Python developer, so I could be wrong. Off hand thats hard to tell w/o any details on what you are actually doing. At least an outline what kind of data you are storing and of course details of your database configuration would be helpful. Please note that postgres is quite good at handling concurrent load - this does not mean its best or every desk top database application. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Strings
Hi, Kalyankumar Ramaseshan wrote: Hi, Excuse me if this is a repeat question! I just wanted to know how are strings represented in python? It depents on if you mean python2.x or python3.x - the model changed. Python 2.x knows str and unicode - the former a sequence of single byte characters and unicode depending on configure options either 16 or 32 bit per character. str in python3.x replaces unicode and what formerly used to be like str is now bytes (iirc). I need to know in terms of: a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? It uses an internal fixed length encoding for unicode, not UTF b) They are converted to utf-8 format when it is needed for e.g. when storing the string to disk or sending it through a socket (tcp/ip)? Nope. You need to do this explicitely. Default encoding for python2.x implicit conversion is ascii. In python2.x you would use unicodestr.encode('utf-8') and simplestr.decode('utf-8') to convert an utf-8 encoded string back to internal unicode. There are many encodings available to select from. Any help in this regard is appreciated. Please see also pythons documentation which is very good and just try it out in the interactive interpreter Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: convert the ip packet to and from RS-232 packet
Hi, Li Han wrote: Hi, I need to use radio to connect two local ip network, each local network has a server computer which connects to a radio with RS-232 interface. I need to write a program to convert the local ip packet into RS-232 packet, so the radio can send packetes to the remote radio. I don't want to reinvent the wheel, is there anyone could give me some suggestions? You might want to check: http://en.wikipedia.org/wiki/Packet_radio some free OS already come with an interface implemention so all you need would be configuring that interface and routing appropriately. As such, not really a python topic. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: python ssh and Tetia SSH server
loial wrote: Anyone out there any experience of using python ssh modules to connect to the Tetia SSH server from SSH (ssh.com)? Did you call their support? Personally I see no reason why paramiko http://www.lag.net/paramiko/ should not work, given that openssh ssh client also worked in the past with ssh.com ssh. Maybe you can get a test version and just try it out. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Using paramiko rsa key
loial wrote: I want to connect via ssh from a python script on windows to an AIX server running openSSH using rsa keys rather than a password. Can anyone provide me with /point me at a simple tutuorial on the steps I need to go though in terms of geneerating the key, installing on the server and connecting in my python code? Sure, where can we send the invoice too? Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2.Request:: http Request sending successfully, but Response contains in valid data.
Hi, nRk wrote: Hi I am trying to send Data to a website through "http" using "urllib.request" library using the bellow code. Response status code contains. 200 (OK) but Response contains nothing... With same data When I test using C# it working fine.. Response having.. some data in xml format. But I am using below python code i am getting response only "". This does not mean you are doing it identical to C# here, doesn't it? Also you might be looking at the defaults in the calls within C# and some weird expectations on server side. Also you are requesting XML by sending a payload of XML data, so you need to make sure you actually use POST and not GET. I'd start by watching your working application with strace or wireshark and compare with the data to and fro from your python application. Also I believe there should be example code for reading RSS feeds from python. Is there any in my code.. req = urllib2.Request(url) // url is valid url req.add_header('Authorization','AuthSub token="x"') req.add_header('Content-Type','application/atom+xml') req.data=data // data is having valid xml data r = urllib2.urlopen(req) print(r.code) // output 200 print(r.msg) // output OK print(r.read()) // Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: PySerial "write" should accept "bytearray"
John Nagle wrote: PySerial, which is basically a binary input/output system, is still requiring "str" instead of "bytearray", even under Python 2.6. For "file-like objects", "write" functions are supposed to accept "bytearray" now, and "read" functions should return a "bytearray". I'm sure patches are welcome. And did you copy the pyserial author? Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Python interface to ODF documents?
Hi, Dotan Cohen wrote: Is there a Python interface to ODF documents? I'm thinking of something that will import, for example, an ADS spreadsheet into a multidimensional array (including formulas and formatting) and let me manipulate it, then save it back. Yes, you have zipfile and a host of xml parsers included in the standard lib. This works very well to my experience. Not sure if an abstraction layer on top of that exists. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: hist without plotting
Nick Matzke wrote: Hi, Is there a way to run the numpy hist function or something similar and get the outputs (bins, bar heights) without actually producing the plot on the screen? (R has a plot = false option, something like this is what I'm looking for...) something like scipy.histogram(a) ? Actually I don't see many plotting functions beside plot() anyway... Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to determine if a string is a number
Python Nutter wrote: Type casting seems to be the wrong way to go about this. teststring = '15719' teststring.isdigit() returns True Actually its instantiating not type casting and it works by using the type's actual description of the data it accepts. This looks pretty good approach instead of trying to copy (incomplete as it has been shown not only digits and . constitute a float) already implemented code. Of course if you want to limit the range of accepted data even more, then isdigit and friends can be used - maybe you could time both approaches with a set of data. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic way to determine if a string is a number
Roy Smith wrote: In article , Mel wrote: Christian Heimes wrote: Roy Smith wrote: They make sense when you need to recover from any error that may occur, possibly as the last resort after catching and dealing with more specific exceptions. In an unattended embedded system (think Mars Rover), the top-level code might well be: while 1: try: main() except: reset() Do you really want to except SystemExit, KeyboardInterrupt, MemoryError and SyntaxError? Absolutely. Let's take my example -- you're writing software for a Mars Rover. I have no idea how you might get a MemoryError, but let's say you do. Which would you rather do, perform a system reset, or print a stack trace and wait for a friendly Martian to come along and reboot you? You may think I'm being silly, but I'm dead serious. The many layers of "It's impossible for this to happen, but if it does let's do something to try and recover" processing saved that mission several times over. In some applications, there's no such thing as "halt". Yeah, having your mars rower forever running in a loop to try to convert some random string to a number is sure something you want to achieve. Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: print string as raw string
Mirko Dziadzka wrote: Hi all I'm trying to find a way to output strings in the raw-string format, e.g. print_as_raw_string(r"\.") should output r"\." instead of "\\." Is there a better way than writing your own print function? Some magic encoding? Thats nonsense. print r"\." or in python3.0 print(r"\.") will just print: \. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Python dictionary size/entry limit?
intellimi...@gmail.com wrote: I wrote a script to process textual data and extract phrases from them, storing these phrases in a dictionary. It encounters a MemoryError when there are about 11.18M keys in the dictionary, and the size is about 1.5GB. I tried multiple times, and the error occurs everytime at exactly the same place (with the same number of keys in the dict). I then split the dictionary into two using a simple algorithm: if str[0]<='m': dict=dict1 else: dict=dict2 #use dict... And it worked fine. The total size of the two dictionaries well exceeded 2GB yet no MemoryError occured. I have 1GB of pysical memory and 3GB in pagefile. Is there a limit to the size or number of entries that a single dictionary can possess? By searching on the web I can't find a clue why this problem occurs. From what can be deducted from the headers of your message: X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1;... you are using windows? It seems either python or windows memory management somehow prevent the use of continuous memory areas that large. We've got such an example somewhere down the list which was similar (iirc it was a large string in memory) which runned perfectly with linux. You can try yourself maybe by installing ubuntu on the same host. (If you feel fit you can even skip the install and run it off life CD but then you need to fiddle a little to get swap space on disk) Regards Tino -- http://mail.python.org/mailman/listinfo/python-list smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: finding the difference between the two version of the python program...
Hi, Piyush Anonymous wrote: is there a tool which, given two version of programs, finds the difference like set of classes added, deleted and modified? assuming the python program is written in oops way. diff for example can do this. There is also an difflib in python which you can use to roll your own diff. Regards TIno smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a .xls file to .html
Hi, tarun wrote: Hello All, I've a .xml file (saved as .xls) that can be opened in Microsoft excel. Well if its an xml file then just attach a style to it and you can just view it in a browser w/o involving excel in the first place. Also there are lots of xml libraries coming with python so you can translate it directly into HTML of your choice. I want to write python code that converts this excel file into .html (so that it can be viewed as is in an explorer). Whats an Explorer? I guess you mean Webbrowser here? Now if you manage to have it in Excel, then you could just save it as HTML (or whatever Microsoft believes is HTML). If the file is stored elsewhere in Excel-Format, then you could script that using xlrd (google for it) Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: python to parse excel file csv format
MRAB wrote: Jay Jesus Amorin wrote: This is how i do it, but it runs with error. Kindly help #!/usr/bin/env python import csv, sys, os filename = (sys.argv[1]) reader = csv.reader(open(filename, "rb"), delimiter=',', quoting=csv.QUOTE_NONE) try: for row in reader: os.popen("chown row[0] row[1]") This should be: os.popen("chown %s %s" % (row[0], row[1])) or: os.popen("chown %s %s" % tuple(row)) No, it should really be os.popen(("chown",row[0],row[1])) or better yet, for fmodes,fname in reader: os.popen(("chown",fmodes,fname)) or even plus better: for fmodes,fname in reader: os.chmod(fname,fmodes) (Both my examples avoid problems with unquoted filenames) Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: zip a created file
frendy zhang wrote: > if form.accepts(request.vars,session): > for table in db.tables: > rows=db(db[table].id).select() > print rows > open(str(os.sep).join([os.getcwd(), 'applications', > request.application, 'databases', > table+'.csv']),'w').write(str(db(db[table].id).select ())) > > > where and what should i put the zip code to zip the file created above? > thanks in advance You don't? ;) The code is very -crappy- suboptimal... - can you reformulate the problem first? Where is request, session coming from? If its a web application, what are you doing with open() and why this complicated code instead of just os.path.join() ? In short, creating a file and zipping and sending to the browser should not need to create an intermediate file in the file system. (This also avoids a lot of problems with your approach above - for example if the same query is put twice the same time...) Just have a look at the examples in the documentation which come with the zipfile module. Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: regex problem ..
Analog Kid wrote: Hi All: I am new to regular expressions in general, and not just re in python. So, apologies if you find my question stupid :) I need some help with forming a regex. Here is my scenario ... I have strings coming in from a list, each of which I want to check against a regular expression and see whether or not it "qualifies". By that I mean I have a certain set of characters that are permissible and if the string has characters which are not permissible, I need to flag that string ... here is a snip ... flagged = list() strs = ['HELLO', 'Hi%20There', '123...@#@'] p = re.compile(r"""[^a-zA-Z0-9]""", re.UNICODE) for s in strs: if len(p.findall(s)) > 0: flagged.append(s) print flagged my question is ... if I wanted to allow '%20' but not '%', how would my current regex (r"""[^a-zA-Z0-9]""") be modified? You might want to normalize before checking, e.g. from urllib import unquote p=re.compile("[^a-zA-Z0-9 ]") flagged=[] for s in strs: if p.search(unquote(s)): flagged.append(s) be carefull however if you want to show the flagged ones back to the user. Best is always quote/unquote at the boundaries as appropriate. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Neal Becker wrote: Reading some FAQ, I see that __str__ is "meant for human eyes". But it seems that: class X(object): def __str__(self): return "str" def __repr__(self): return "repr" x = X() d = {0 : x} print d {0: repr} So if __str__ is "meant for human eyes", then why isn't print using it! it is: > print x str but dict just uses repr() for all its childs to print. T. smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Neal Becker wrote: ... So if __str__ is "meant for human eyes", then why isn't print using it! it is: > print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Every class is free on how to best implement __str__, you will find the same behavior on tuple and list as well. Maybe its discussable to change the implementation sensibly, best if you would come with a proposal? Perhaps pprint.pprint is a starting point? Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Are Django/Turbogears too specific?
Philip Semanchuk wrote: ... I prefer Mako over the other template languages I've seen. From what I can tell Mako is nearly identical to all other template languages you might have seen (e.g. PHP style tags). Thats why I personally would not consider it. Its just much of a hassle to mix code and design this way. I prefer TAL (template attribute language, ZPT) [1] much over the other attempts I've seen ( and I've seen a lot) Cheers Tino [1] http://en.wikipedia.org/wiki/Template_Attribute_Language smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to represent a sequence of raw bytes
Steven Woody wrote: On Mon, Dec 22, 2008 at 10:27 AM, Michiel Overtoom wrote: On Monday 22 December 2008 03:23:03 Steven Woody wrote: 2. char buf[] = {0x11, 0x22, 0x33, ... } What's the equivalent representation for above in Python? buf="\x11\x22\33" ... I thing "\x11\x22\x33" in python is not the {0x11, 0x22, 0x33} in C. Since, a string in python is immutable, I can _not_ do something like: b[1] = "\x55". And, how about char buf[200] in my original question? The intension is to allocate 200 undefined bytes in memory. Thanks. Well in most cases you don't need to do that, instead you could assemble your stream on the way out based on sequences, generators etc. Please note that char in your example is just a bit inapropriate (but common in C) shorthand for unsigned short int. There is no such type in python so you could use int() if you want to operate on the numeric value. Depending on your use case a big integer could also serve well and you can convert it into a byte string. If you want random access to the bytes, you can use list or array (see array module) or, if you want it with much more performance resort to numpy, scipy, they have arrays similar to C and also much more numeric datatypes. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Can´t Surf Python Pages in Windoz e
hi, Victor Subervi wrote: Hi; I try to surf to this code in Windoze and it doesn't work...just posts a small, black screen for a split second. Why? I don't know what "surf this code" means (or what Windoze should be) print "Content-Type: text/html" print print """ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";> http://www.w3.org/1999/xhtml"; xml:lang="en"> Yeah """ this could be fine if called in CGI context. Also, Zope is installed, but when I go to: localhost:8080/manage_main or local:8080/Zope-Instance/manage_main I get a 404, after having started the service and everything is go. I have Python up. What gives? Don't know what "gives" but how did you make sure Zope could really start and bind the port? There are a lot things which could go wrong: Applications using this port already, firewall in your way... a 404 however indicates the service is there but you are not authorized. Please read "User and Permission" chapter in the zope book. Please note the above code you cited is not useable (or sensible) in a zope environment. Happy coding Tino Victor -- http://mail.python.org/mailman/listinfo/python-list smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows SSH (remote execution of commands) - Python Automation
Hi, Narasimhan Raghu-RBQG84 wrote: Hi experts, I am looking for some information on how to automate remote login to a UNIX machine using ssh from a windows XP box. Possible way: 1. Use putty (or any other ssh client from windows XP). -- Can be automated with command line parameters. The problem is that I am able to login - Putty window opens up as well. But obviously I am unable to run any commands in that. I need to find something like a handle to that Putty window so that I can execute commands there. Obviously putty is one (of several) terminal emulators (or in short gui clients) for ssh protocol. This means they are made for interactive work with mouse and keyboard rather then for command automation. Its easy if you just use one of the many command line ssh clients. You can use os.popen() and friends or the command module to work with them. There is also another solution: http://www.lag.net/paramiko/ which implements the ssh protocol in python so you can do more and have finer control over the processes and channels (for example file transfer and command control w/o resort to multiple connections) This is a little bit harder of course. Also, sometimes its more easy and relieable to just use cron on unix side. This works much much better then Task scheduler on windows btw. Regards Tino Can anyone provide me some help in achieving this ? Thanks, -- *Raghu* -- http://mail.python.org/mailman/listinfo/python-list smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: math module for Decimals
jerry.carl...@gmail.com wrote: ... It's really just the goniometric functions that I am missing most at the moment, so maybe I can figure it out with help of what you said plus the already existing imperfect modules. Meantime maybe this discussion will caught Guido's eye... ;-) And btw I do expect that Python becomes better than Mathematica one day because it's free and open :-) Maybe when Wolfram retires ;-) Thanks again! I agree having full support for all math.* functions for all builtin types would be nice. However if you are more looking for replacement of mathematica and friends with python you might check scipy/numpy. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing Excel spreadsheets
r wrote: On Dec 30, 10:07 am, "andyh...@gmail.com" wrote: Hi, Can anybody recommend an approach for loading and parsing Excel spreadsheets in Python. Any well known/recommended libraries for this? The only thing I found in a brief search washttp://www.lexicon.net/sjmachin/xlrd.htm, but I'd rather get some more input before going with something I don't know. Thanks, Andy. xlrd(read only) also see pyExcelerator which is now replaced by xlwt :-) Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Switching user in a SSH connection
Shah Sultan Alam wrote: Hi Group, I am trying to connect to a Linux maching using paramiko. and able to run a command like "ls -l" Now I want to switch user being in the connection ( eg running something like "su -" ) Will you please let me know how to do that. You would for example run su - in that connection? Or sudo if installed and configured. What else would you need? Tino. smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: ACL in python
John Boloshevich wrote: Hello, does anybody know about an ACL implementation for python, which is not tied to the filesystem? I would like to use ACL on different objects not on files, so the POSIX file access solution is not the one I am looking for. You mean something like the restricted environment you find within zope for all the TTW-stuff? Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Ideas to optimize this getitem/eval call?
mario wrote: On Jan 3, 7:16 am, Steven D'Aprano wrote: I was about to make a comment about this being a security hole, Strange that you say this, as you are also implying that *all* the widely-used templating systems for python are security holes... Well, you would be right to say that of course ;-) Infact, evoque is really one of the few (or even the only one?) that was conceived from the start to support restricted evaluation. Thats is definitively not the case. There are at least 2 quite old template systems on top of a quite good restricted environment. Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: image recogniton?
Hi, Furkan Kuru wrote: start with Python Image Library: http://www.pythonware.com/products/pil/ I think this is more a job for OpenCV and its python bindings. http://opencv.willowgarage.com/wiki/PythonInterface On Tue, Jan 6, 2009 at 4:28 PM, Li Han <mailto:lihang9...@gmail.com>> wrote: Hi! I know little about the computer image processing, and now I have a fancy problem which is how to read the time from the picture of a clock by programming ? Is there anyone who can give me some suggestions? Thank! Li Han Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Pure Python interface to MySQL?
Hi, Roy Smith wrote: In article <[EMAIL PROTECTED]>, Carsten Haese <[EMAIL PROTECTED]> wrote: Roy Smith wrote: Does there exist a pure Python version of a MySQL module? A quick google search turns up this: http://github.com/mopemope/pure-python-mysql/tree/master/pymysql Awesome, thanks! You have better searching skills than I do, apparently :-) Will you be asking for a pure python implementation of mysql in the next question? ;) Why not use the proxy approach (for example via xmlrpc) as suggested by James or just spill to a file? :-) Just wondering... Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: SMTPlib inside function, extra tab
Hunter wrote: I am writing a script that needs to send some emails. And I've used smtplib in the past and it is pretty easy. But I thought, gee it would be easier if I could just call it as a function, passing the from, to, subject, and message text. So I wrote it up as a function and it sort of works, but I get a weird error. When it runs it inserts a "\t" tab character before each item during the send portion (which I can see when I turn on debug). The end result is that I don't get any body or subject in my emails. It works fine when I copy the inside of the function and run it directly. It isn't a dealbreaker, I can certainly just call it direct, but from a learning Python perspective I'm wondering if anyone knows what exactly is happening.I'm more interested in the why this is happening than a solution (though that would be great too). Oh and if you could explain it to me, with no CS background, that would be even better. I am working on Windows Vista with Python 2.5.2 (activestate). Thanks --Joshua Snip of script (more or less a copy/paste from effbot): fromaddress = '[EMAIL PROTECTED]' tolist = ['[EMAIL PROTECTED]','[EMAIL PROTECTED]'] msgsubj = "Hello!" messagebody = "This message was sent with Python's smtplib." def send_mail(fromaddress,tolist,msgsubj,messagebody): import smtplib SERVER = "mymailserver.mydomain.com" message = """\ From: %s To: %s Subject: %s %s """ % (fromaddress, ", ".join(tolist),msgsubj, messagebody) ^ The tabs are exactly here. best is to use the mail package to generate mime compliant emails and use simple templates - which could in the easiest form just module level constants like: stdform=""" Hello %(greeting)s, this automated email is about %(subject)s ... """ and so on and then you use it with stdform % dict(greeting='Mr Ed',subject='writing emails') ... HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Builing Python 2.6 on AIX 5.2
brasse wrote: Hello! I am having some trouble building Python 2.6 on AIX. The steps I have taken are: ... a funny side note: I was originally drawn to python because perl wouldn't build on my particular installation of AIX but python did :-) But this was 1.4 or so back then :-) Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: template strings for matching?
Joe Strout wrote: Catching up on what's new in Python since I last used it a decade ago, I've just been reading up on template strings. These are pretty cool! However, just as a template string has some advantages over % substitution for building a string, it seems like it would have advantages over manually constructing a regex for string matching. So... is there any way to use a template string for matching? I expected something like: templ = Template("The $object in $location falls mainly in the $subloc.") d = templ.match(s) and then d would either by None (if s doesn't match), or a dictionary with values for 'object', 'location', and 'subloc'. But I couldn't find anything like that in the docs. Am I overlooking something? Yeah, its a bit hard to spot: http://docs.python.org/library/stdtypes.html#string-formatting-operations HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Efficient Bit addressing in Python.
Hi, Hendrik van Rooyen wrote: Is there a canonical way to address the bits in a structure like an array or string or struct? Or alternatively, is there a good way to combine eight ints that represent bits into one of the bytes in some array or string or whatever? It seems to me that there is a dilemma here : if you can write: bit3 = 1 Then you have to jump through hoops to get bit0 through bit7 into some byte that you can send to an i/o routine. On the other hand, if you keep the bits "in" the byte, then you can write: byte[3] = '\x7e' but you have to jump through hoops to get at the individual bits. Is there a "best" way? It would be nice to be able to write: if io.byte2.bit3: do_something() if io.byte2 == alarm_value: do_something_else() where: io.byte2 & 8 "is" io.byte2.bit3 byte1 byte2? this does not look very practical to me. In the simplest form of storing your values in a text string, you could just use ord() to get the byte value and operate on it with 1<<0 1<<1 1<<3 and so on. If you want, put a module in which defines the constants bit1=1<<0 bit2=1<<1 and so on and use it via if byte & bit1: ... more efficiently for operations on really big bit strings is probably just using integers. HTH Tino Is this possible? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: template strings for matching?
[EMAIL PROTECTED] wrote: Tino> Yeah, its a bit hard to spot: Tino> http://docs.python.org/library/stdtypes.html#string-formatting-operations That shows how to use the template formatting as it currently exists. To my knowledge there is no support for the inverse operation, which is what Joe asked about. Given a string and a format string assign the elements of the string which correspond to the template elements to key/value pairs in a dictionary. ??? can you elaborate? I don't see the problem. "%(foo)s" % mapping just calls get("foo") on mapping so if you have a dictionary with all possible values it just works. If you want to do some fancy stuff just subclass and change the method call appropriately. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: FLexible formatted text involving nested lists?
Hi, RossRGK wrote: Kerri Reno wrote: Ross, I'm no expert in python, so excuse me if this is inane. What I would do is have fmts be a dictionary where fmts = { 3 = 'oats %0d kilos over %0d days with %0d workers', 2 = 'barley %0d lbs for %0d hours', 1 = 'apples %0d baskets'} then something like for x in bigList: print fmts[len(x)] % x I didn't test this, but in theory it should work. Hope this helps, Kerri Thx for the suggestion - i think that would match the number of fields to the number of parameters in the specific example but not the general case. ie fmts[3] could have 3fields this time, but might be 2 another time or something else. Maybe you want to reconsider your approach and instead of use "lists" just a dict or class with the correct naming? If you use a class you could also attach all the meta information for formatting. Dicts are easily aliased to your formats using named arguments: 'oats %(weight)0d kilos over %(days)0d days with %(workers)0d workers' % dict(weight=5,days=3,workers=10) which would make more sense when you read it and/or edit the sentence sometime later. You could also consider extending the attributes to have the unit (e.g. kg, pound, days, ...) attached to it and decide to add a clever get() method to your container class (which replaces the list) and use it like this: 'oats %(weight.kg)s ...' % yourinstance ... where instance.get() would be called with 'weight.kg', splits on the . for the attribute: weight, calls self.weight.format(unit='kg') to retrieve "5 kilos" or something :-) Just some random thoughts. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Efficient Bit addressing in Python.
Hendrik van Rooyen wrote: "Tino Wildenhain" wrote: byte1 byte2? this does not look very practical to me. In the simplest form of storing your values in a text string, you could just use ord() to get the byte value and operate on it with 1<<0 1<<1 1<<3 and so on. If you want, put a module in which defines the constants bit1=1<<0 bit2=1<<1 and so on and use it via if byte & bit1: ... This is what I meant by "jumping through hoops". more efficiently for operations on really big bit strings is probably just using integers. Sure, one could for instance make a list of eight-entry lists: io = [[b0,b1,b2,b3,b4,b5,b6,b7],] what should that represent? Which byte order do you have in mind etc? Then the hoop jumping goes in the opposite direction - to get hold of an actual byte, you have to rotate the bits into some byte one at a time. Well, thats one would expect by your proposed interface. Can you perhaps outline what kind of application you have in mind and which operations look meaningfull to that? I'm familar with embedded hardware where you would have a couple of registers where you usually only have the distinction between 8-bit or 16 bit flag registers where it makes sense to individually influence bits. Personally I can't follow you on the path to have arbitrary lengthy bitfields - even nore to have artifically attributes (like bit5) on them. Just using a big integer to represent your bitfield and using binary operators on it does not sound so wrong to me in this case. Of course one could create a type which derives from sequence types and implement something like bitfieldinstance[bitindex] (where 0 is LSB) would you like fries... err slices with that? e.g. >>> bf=BitField(10) >>> int(bf[1:]) 5 ? This approach has the advantage that you can add a ninth "dirty" bit to indicate that the "byte" in question needs to be written out. What do you mean by "written out" to where? Is there not some OO way of hiding this bit banging complexity? foo & bar is complex? So you want to replace foo + bar as well with something? ;) Using getters and setters? - I tend to go "tilt" like a cheap slot machine when I read that stuff. Getters setters? Where would that improve the situation beside having to write lots of unneccessary code? Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating single .exe file without py2exe and pyinstaller
Hi, Abah Joseph wrote: I have written a small application of about 40-45 lines which is about 4KB, so I want to create a single .exe file from it, using py2exe it created unnecessary files, that just increase the size of the program and also less portable to me. What else can I use? the "unneccessary files" you say, are what your 40-45 lines bring to life. 1) just distribute the 40-45 lines - but this requires python installation on users end 2) use a python to C(++) compiler and compile the result to .exe, works pretty well for simple applications: http://shed-skin.blogspot.com/ Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: keyword in package name.
Abhishek Mishra wrote: Hello Everyone, I have the habit of using domain names (of either the application or company) in reverse in package names. for e.g. com.spam.app1 While this seemed a good idea for java, I don't think it makes sense for python - the reason: in python you have an import mechanism, where in java you just have namespaces. Therefore you can always avoid namespace clashes at import time. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: [APSW] SELECT COUNT(*) not succesfull?
Gilles Ganault wrote: Hello I'm trying to use the APSW package to access a SQLite database, but can't find how to check if a row exists. I just to read a tab-separated file, extract a key/value from each line, run "SELECT COUNT(*)" to check whether this tuple exists in the SQLite database, and if not, run an INSERT. The problem is that "if not row" isn't run: == import apsw connection=apsw.Connection("test.sqlite") cursor=connection.cursor() data = {} f = open("data.tsv", "r") textlines = f.readlines() f.close() p = re.compile('^(\d+)\t(\d+)$') for line in textlines: m = p.search(line) if m: data[m.group(1)] = m.group(2) for (key,value) in data.items(): sql = "SELECT COUNT(*) FROM mytable WHERE key='%s'" % key row=cursor.execute(sql) #Why not run? if not row: print "Row doesn't exist : %s" % key sql = "INSERT INTO mytable (key,value) VALUES ('%s',%u)" % key,value cursor.execute(sql) connection.close(True) sys.exit() == Any idea what's wrong with the above? Apart from the other comments, what is obviously wrong is the way you aliased the variables into SQL. Please read on parametrized queries, e.g. the following should work: sql = "SELECT COUNT(*) FROM mytable WHERE key=%s" cursor.execute(sql,(key,)) (see also SQL injection) Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: FTP via web browser
rodmc wrote: Hi, I have posted elsewhere about a related topic. But I an curious is it possible to set up a web form which people select a file for upload which is then upload it via FTP protocol to the web server - the entire process must be web based and not require an external FTP client. The reason for asking is that uploading large files via HTTP form post is very unreliable beyond say 20MB. No its not - see for example rapidshare. You are asking for web browser - so to do anything here you would have a web server anyway - and the file upload via form post. No matter if its using ftp or some local store underneath. What about Webdav? Most OS have support for it nowadays. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: xchat
Hi, luca72 wrote: Hello i have installed xchat on suse11 i see that there is the possibility to use python for make some script, i see also that the python interface is loaded, but when in python i type import xchat i get that the module don't exist. where is the module? I try also to ask in the xchat forum but i get no reply so i try here try it again from within xchat. See the documentation for the python console (like a chat to python interpreter) Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: mySQL problems
Hi, Alfons Nonell-Canals wrote: Hello, I've developed a program using python that have to connect to a mysql server several times. In a local machine (running the program in the same machine where the mysql server is) I have no problems. I can run several instances of the program at the same time with no problem. Them problem arrives when I try to distribute the tasks to different machines, for example, in a cluster. In this situation, the machine that runs the python program is different than the machine that hosts the database. If I run the python program only an other machine, only one run of the program, there is no problem. But, If I run the program in different machines, all of them connecting to the same database server, randomly, it crash. Crash all running programs! at the same time. The output is clear: _mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'HOST' (110)") It is clearly related with the connection to the mySQL server. As I said, it only happens when there are more than one programs running in different machines (or in the same) but conecting to a mysql server that is in an other machine. And... it is random, sometimes happens and sometimes no... Maybe there is a certain connection limit which hits if your client programms reconnect in random order? I saw this on some PHP web sites. Probably some configuration adjustments and persistent connections could help you in this situation. Also, was the choice of MySQL a conscious one? Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Sorting a list
RC wrote: unsortedList = list(["XYZ","ABC"]) sortedList = unsortedList.sort() print sortedList Why this return None? Because you did not read the documentation. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: mySQL problems
Alfons Nonell-Canals wrote: Hi, Maybe there is a certain connection limit which hits if your client programms reconnect in random order? I saw this on some PHP web sites. Probably some configuration adjustments and persistent connections could help you in this situation. I know I can check it but I am not the admin of the server where the mySQL server is and before to check it with the sysadmin I would like to discard other possibilities (they ask me to do this before) :-( Well in this case just open as many connections in a loop as you can and watch for the outcome. Also, was the choice of MySQL a conscious one? Yes, the choice of MySQL is conscious because I have to manage huge amounts of data and I already have some experience in mySQL which makes it easier. But with no other open source database I presume? Watch out! There are lots of diamonds beside your way :-) Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to open a shell prompt from an existing shell prompt
gaurav kashyap wrote: reply please try to invest some time in your question, it might be a cultural thing and from my observations common in questions from the indian area... So "give me that." "I require..." might syntactically be correct, but the sound to other people on mailinglists is not so nice. Better try to describe what your problem is - and not only the immediate one but an overall picture of what you want to achive and then put your question. That was people can better understand what you want to do and help you. Ah and btw, sentence with questions are better ended with question marks -> ? This makes it easier to parse. Back to your problem: its not clear what you mean by "open a shell prompt (window)" You can execute a script via subprocess module and get all the input and output in separate file handles you could use to interact with the script. Open a new window would mean a new terminal and is very os specific. Usually you don't have control over such a spawned terminal window. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to open a shell prompt from an existing shell prompt
gaurav kashyap wrote: Dear Tino, I am using python 2.3.5. on POSIX system,I have the simple query as: I log into the shell as root.Can i issue some command that will open another terminal?(i.e I get a duplicate copy of the shell prompt already opened) I'd say so but what would that have to do with python? What is the goal you really want to achive? What will you do with the "shell prompt" once you have it? Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: modifying locals
Hi John, John [H2O] wrote: Steven D'Aprano-7 wrote: What you are actually trying to do is unclear to me. Perhaps you could try explaining better with a more concrete example? -- Steven -- Actually, maybe a LACK of an example would make it simpler. What I'm after is a function, to which I can pass a dictionary defined from locals(), then in the function I would modify some of the variables from the dictionary. But I want the modifications to be 'seen' by the method that called the function without passing them back via return. Well a method belongs to a class, so the most cleanest way would be to store the values in the respective instance. If you want to modify just arbitrary callers objects, just hand them to your method our function as argument and modify them there (e.g. dicts can be modified in place for example) Also, locals() already returns a dict, no need for the exec trickery. You can just modify it: >>> locals()["foo"]="bar" >>> foo 'bar' Ideally, I would prefer not to use global, as I think (due to other problem in my scripting) this might cause problems. I strongly suspect that you are doing something much too complicated. the "modify a few of the elements..." is where it gets interesting. What are you doing? Is it just that you try to emulate a switch statement to save some typing? Currently I these two possibilities: def myFunction(D): for key,item in D.iteritems(): exec "%s = %s" % (key, item) modify a few of the elements... return locals() locals().update(D) would have done the same :) ... Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: modifying locals
Hi, Steven D'Aprano wrote: On Fri, 31 Oct 2008 07:10:05 +0100, Tino Wildenhain wrote: Also, locals() already returns a dict, no need for the exec trickery. You can just modify it: >>> locals()["foo"]="bar" >>> foo 'bar' That is incorrect. People often try modifying locals() in the global scope, and then get bitten when it doesn't work in a function or class. def foo(): ... x = 1 ... locals()['y'] = 2 ... y ... foo() Traceback (most recent call last): File "", line 1, in File "", line 4, in foo NameError: global name 'y' is not defined You cannot modify locals() and have it work. The fact that it happens to work when locals() == globals() is probably an accident. Ah thats interesting. I would not know because I usually avoid such ugly hacks :-) Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to open a shell prompt from an existing shell prompt
Hi, gaurav kashyap wrote: Dear Tino, There is no subprocess module in python 2.3.5. My goal is: 1.Open a terminal window and login as root. 2.Issue some command in the terminal window that will open another terminal,similar to the onealready opened. Am i clear now. Not at all. All you told us so far has not the faintest relation to python in any way. I'd suggest reading a book on unix, command line, x windows system etc. And better yet, do this before becoming root next time. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: open a new terminal window from another terminal window in linux/unix system
Hi, gaurav kashyap wrote: Dear all, I am using Microsoft Windows XP.Using putty.exe,I connected to LINUX server and a terminal window gets opened.Here i logeed in as root. What i want to do is open another terminal window from already opened terminal window. Ugh. As others said and I already guessed, this has nothing to do with python. While this is totally unrelated to this list I'll help you going into the right direction (but you need to walk yourself): http://x.cygwin.com/ Basically you would install the x window system and some shell tools (including openssh client) and then log into the remote box and start any x window application, also as many terminals as you can carry. (especially look out for x-session forwarding etc.) Can this be achieved.If yes,please provide a tested solution Ah tested. Haha. Yes many people have done it, so its tested. If you provide a contract and pay money you should also be able to get someone to configure the system in the way you want it :-) Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: modifying locals
M.-A. Lemburg wrote: On 2008-10-31 09:08, Tino Wildenhain wrote: ... Ah thats interesting. I would not know because I usually avoid such ugly hacks :-) It doesn't even work for already defined local variables: def foo(): ... x = 1 ... locals()['x'] = 2 ... print x ... foo() 1 The reason is that locals are copied in to a C array when entering a function. Manipulations are then done using the LOAD_FAST, STORE_FAST VM opcodes. The locals() dictionary only shadows these locals: it copies the current values from the C array into the frame's f_locals dictionary and then returns the dictionary. This also works the other way around, but only in very cases: * when running "from xyz import *" * when running code using "exec" globals() on the other hand usually refers to a module namespace dictionary, for which there are no such optimizations.. I don't know of any way to insert locals modified in a calling stack frame... but then again: why would you want to do this anyway ? Yes, thats what I'm saying. Unless you are writing a debugger or something you better don't mess with the internals. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: push-style templating - an xml-like way to process xhtml
Terrence Brannon wrote: Hello, The most common way of dynamically producing HTML is via template engines like genshi, cheetah, makotemplates, etc. These engines are 'inline' --- they intersperse programming constructs with the HTML document itself. An opposite approach to this form of dynamic HTML production is called push-style templating, as coined by Terence Parr: Hm. "$attr.title$ $if(attr.active)$ $attr.submenu:menuItem()$ $endif$" This looks ugly to me. Why not just using well tested TAL, which is also available for a number of languages? http://en.wikipedia.org/wiki/Template_Attribute_Language In contrast there would be something like TSSL, which unfortunately never saw the light of the day yet :-) http://mail.zope.org/pipermail/zpt/2002-May/003304.html (This solution would not even touch the HTML directly) Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: push-style templating - an xml-like way to process xhtml
Terrence Brannon wrote: Tino Wildenhain wrote: An opposite approach to this form of dynamic HTML production is called push-style templating, as coined by Terence Parr: Hm. "$attr.title$ $if(attr.active)$ $attr.submenu:menuItem()$ $endif$" This looks ugly to me. It looks ugly to me too. Why not just using well tested TAL, which is also available for a number of languages? well, to me, TAL has to be learned. It is a language. Why is this an issue? Let me answer: I already know Python. I already know the XHTML standard. I do not wish to learn TAL. If you know Python, and can read the API to a high-quality XML processing toolkit, then you are done. TAL introduces another language and I have to learn its conventions and idiosyncrasies. Your templating engine you have in your paper has yet another language. So where is the difference? Now, the same would be true of Terence Parr's StringTemplate engine. It is small, only 4 commands, but it litters the template with too much if you ask me. TAL's core has also only a few "commands". So not much to learn. If thats to much, development is not for you I fear ;) I like the approach of my own HTML::Seamstress --- object-oriented Perl and knowledge of an object-oriented tree-rewriting library is all you need: http://search.cpan.org/~tbone/HTML-Seamstress-5.0b/lib/HTML/Seamstress.pod#Text_substitution_via_replace_content()_API_call. Still you need to learn. There is no way out. http://en.wikipedia.org/wiki/Template_Attribute_Language In contrast there would be something like TSSL, which unfortunately never saw the light of the day yet :-) http://mail.zope.org/pipermail/zpt/2002-May/003304.html (This solution would not even touch the HTML directly) just remember: XHTML is a subset of XML and no one ever touches XML directly. There really is no reason for HTML to be handled any differently than XML. That TSSL is a nightmare. It's trying to be a programming language. And again, we already have Perl/Python, so why bother? You can avoid touching HTML by using Python. Mini languages is the correct term. And yes they have their purpose. (Think of SQL for example). Thank you for writing. I enjoyed the discussion. Yeah :-) Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Efficient way to remove objects from a list
一首诗 wrote: Hi all, Today I wrote some code like this: for m in self.messages: if not m.finished: continue #process the message fini = [m for m in self.messages if m.finished] for m in fini: self.messages.remove(m) As you can, I want to find these finished messages in "self.messages", process them, and then remove them from the list. Because a list can not be modified while iterating it, I have to use a list "fini" to accomplish the target. I found a smell of bad performance here. Is there any faster ways? I'm not getting what your code really wants to do - you are iterating over messages, and if its "not" finished, skip over it and process all which are finished. (If they are finished, why process them?) Wouln't it make more sense to call the process where you process the messages? And you could just pop() the list or use some of the queue implementations for better performance. e.g. def enqueue_messages(self,msg): self.messages.append(msg) def process_messages(self): if self.messages: msg=self.messages.pop(0) process(msg) if you want some post processing, its really like you are acting in different stages, so you could just have two lists for your messages: one for the messages in phase1, one for the messages passed phase1 and now in phase2 and work over them in the way shown above. Regards Tino -- http://mail.python.org/mailman/listinfo/python-list smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Workflow engine?
Grzegorz Staniak wrote: Hi, In a couple of weeks I'm starting a medium-size project (using a web framework) involving a workflow implementation. Are you aware of any open source workflow engines/libraries that I could base the project on? Google returns hist for GoFlow (Django only, from what I can tell), itools.workflow, spiff (AFAIK tied to a CMS), but not much else. I don't think I'll have enough time to get acquinted with Plone and its offer of products. Has anyone here tried any such code? What would you recommend? I would recommend to start with a problem, rather then with a solution. There is not so much magic in workflows as you might seem to think. After all its "just" maintaining a state and rules for possible transitions. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Insert data into MySQL from HTML Form using .psp script
brianrpsgt1 wrote: I am attempting to insert data from a HTML form using a .psp script. I can not find how to link the data that is inserted into the form to the variables in the .psp script to then insert into the MySQL Insert statement. I am familiar with PHP, where you would write $_POST(['field']), however I can not find the equivalent in PSP. I believe that this is the my missing piece. Technically, what is occurring that that when I click the 'Submit' button, it is inserting NULL field values into the db. wht is a PSP script? If you have that and good reason to use it you should have documentation, no? If not, just use something else you know or which comes with documentation. Sample code is below :: HTML FORM CODE PAGE Date: Time: Activity: Next Steps: Below is the psp script <% import MySQLdb host = 'localhost' user = 'user' passwd = 'somepass' db = 'MyDB' conn = MySQLdb.connect(host, user, passwd, db) mysql = conn.cursor() sql = ("""INSERT INTO activity VALUES (date,time,activity,notes);"""); mysql.execute(sql) conn.commit() mysql.close() conn.close() %> Sucess! I would not recommend this, no matter what PSP is. You are not only mixing code with HTML, you even mix HTML, code and SQL. This is strongly discouraged. Try to split your application into templating and core application and let the application deal with whatever your data storage is. Note there are plenty really good web frameworks with python which save you a great deal of the housekeeping, giving your more time to construct your application. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Workflow engine?
Hi, Grzegorz Staniak wrote: On 08.11.2008, Eric Wertman <[EMAIL PROTECTED]> wroted: To be exact, I used the words "engine/library", not "a whole framework". Thanks for the link, I've googled for articles and recipes myself and as I said, I more or less know what to do - I just thought it might be a good idea to ask whether perhaps the wheel has already been invented. Apparently I was wrong. I think that was part of the problem.. you asked if the wheel had already been invented, rather than tell us about the stones you have to haul up a mountain, and whether a wheel is what you need. It's difficult to answer your original question.. someone could have just as easily said that you should consider Sharepoint and not bother writing any code. Aw, come on. The problem was only mentioned, but the question was pretty specific: could you comment on/recommend an open source python workflow engine/module (implied: to go with a web app). Sharepoint doesn't match the description. I think one could assume that if I'm asking about wheels, I need a pointer to a wheel shop, and I'm not instead making a disguised request for people to analyze my problem for me. Well if we can see you are asking for "what is the best wheel ..." and we can deduct from your mail that you are tying to build a sleigh, the recomendation to expand on the original problem first would not seem to sound so silly, wouldn't it? And so if you are asking about the "best workflow engine to base the work on" you are obviously in a similar situation. This question implies that you are maybe not really aware of what a workflow engine is and does apart from the nice word. The common denonimator of a workflow (state engine) is so simple, the only complexity comes from the environment it needs to drive. So in short: I doubt there is a general solution to the problem. Regards Tino GS smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.stdout, urllib and unicode... I don't understand.
Thierry wrote: Hello fellow pythonists, I'm a relatively new python developer, and I try to adjust my understanding about "how things works" to python, but I have hit a block, that I cannot understand. I needed to output unicode datas back from a web service, and could not get back unicode/multibyte text before applying an hack that I don't understand (thank you google) I have realized an wxPython simple application, that takes the input of a user, send it to a web service, and get back translations in several languages. The service itself is fully UTF-8. The "source" string is first encoded to "latin1" after a passage into unicode.normalize(), as urllib.quote() cannot work on unicode srcText=unicodedata.normalize('NFKD',srcText).encode('latin1','ignore') urllib.quote() operates on byte streams. If your web service is UTF-8 it would make sense to use UTF-8 as input encoding not latin1, wouldn't it? unicodeinput.encode("utf-8") After that, an urllib request is sent with this encoded string to the web service con=urllib2.Request(self.url, headers={'User-Agent':'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11'}, origin_req_host='http://translate.google.com') req=urllib2.urlopen(con) First problem, how to determine the encoding of the return ? It is sent as part of the headers. e.g. content-type: text/html; charset=utf-8 If I inspect a request from firefox, I see that the server return header specify UTF-8 But if I use this code: ret=U'' for line in req: ret=ret+string.replace(line.strip(),'\n',chr(10)) I end up with an UnicodeDecodeError. I tried various line.decode(), line.normalize and such, but could not make this error disapear. I, until now, avoided that problem as the service always seems to return 1 line, but I am wondering. web server answer is encoded byte stream too (usually utf-8 but you can check the headers) so line.decoce("utf-8") should give you unicode to operate on (always do string operations on canonized form) Second problem, if I try an print line into the loop, I too get the same error. I though that unicode() would force python to consider the given text as unicode, not to try to convert it to unicode. But it is what it does. Basically unicode() is a constructor for unicode objects. Here again, trying several normalize/decode combination did not helped at all. Its not too complicated, you just need to keep unicode and byte strings separate and draw a clean line between the two. (the line is decode() and encode() ) Then, looking for help through google, I have found this post: http://mail.python.org/pipermail/python-list/2007-October/462977.html and I gave it a try. What I did, though, was not to override sys.stdout, but to declare a new writer stream as a property of my main class: self.out=OutStreamEncoder(sys.stdout, 'utf-8') This is fancy but not needed if you take care like above. HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Little direction please Python MySQL
Bruno Desthuilliers wrote: len a écrit : Hi all; I am looking for a little direction in moving from novice python MySQL to real world processing. I can connect to MySQL databases and have performed most of the various select, create, update, insert, etc given the examples in the various books and internet tutorials not to many problems. ... You may want to have a look at SQLAlchemy. It will require some additional learning, but chances are you'll waste less time than trying to roll your own half-backed ORM-like system. And it has the additonally benefit to be able to change the database later on more easy then with hand crafted queries when you find out the initial choice of mysql (for whatever reason) was inapropriate. Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Win 98 with Python 2.5--matplotlib and Numpy problem
W. eWatson wrote: I'm trying to figure out why an application that both myself and a colleague use gives errors when he uses it under W98. I'm using XP. Py 2.5 is installed on each of our machines. His first problem came with ... Clearly things have gone astray. Is numpy somehow not compatible with PY 2.5? numpy when compiled against python2.5 is perfectly compatible with python2.5. However this does not tell you anything if you run an application compiled on recent windows on a very old one. I guess this could be worked out but I don't know if the user base with win98 is large enough to justify this. If you feel desperate, you could always get the compiler and try your luck. Otoh you collegue could just abhore the windows and use something different on his hardware :-) With fvwm98 it would even look like :-) HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Will MySQLdb, the Python shim, be supported for Python 2.6 or 3.x?
Hi, Dennis Lee Bieber wrote: ... I'm not any heavy user -- but if it means anything... I finally converted my home machine from 2.4 to 2.5 only a few months ago! (My work machine is still running 2.4). Converted? You can install and run more then one Python version in parallel. (Of course only one is "the default" but you can use as many as you want explicitely) ... smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: compressed serialization module
Hi, greg wrote: Mark wrote: Thanks guys. This is for serializing to disk. I was hoping to not have to use too many intermediate steps You should be able to use a gzip.GzipFile or bz2.BZ2File and pickle straight into it. also: import codecs out=codecs.open("picklefile.bz2",mode="wb",encoding="bz2") pickle.dump(obj,out,pickle.pickle.HIGHEST_PROTOCOL) out.close() should work (and has far less code :-) Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting fractional part from a float without using string operations
srinivasan srinivas wrote: Yes. But it didn't give only the expected decimals. For ex: >>> a = 1.23 >>> abs(int(a) -a) 0.22998 I would like to get the result '0.23' only. well, thats what get stored internally - there is no way around it if you are using floating point numbers: >>> 0.23 0.23001 but str() handles the rounding correctly: >>> print 0.23 0.23 >>> print abs(int(a) -a) 0.23 See also http://en.wikipedia.org/wiki/Floating_point for the problems with FP figures. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Program
J wrote: Is it possible to make a GUI email program in Python that stores emails, composes, ect? Yes this is possible. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Program
Hi, Dennis Lee Bieber wrote: On Sat, 28 Feb 2009 17:50:35 -0800 (PST), J declaimed the following in gmane.comp.python.general: Is it possible to make a GUI email program in Python that stores emails, composes, ect? What is "ect"? The latin phrase is "et cetera" -- roughly translated: and so forth -- and commonly abbreviated as "etc." (with the common period denoting an abbreviation ) As for a GUI email program... Define the requirements in more detail... But it is possible... Though I've never needed to -- my email client programs have always been acceptable, whereas the mail transfer agents have sometimes been a flop. Oh I personally think even existing MUAs could be improved. I even pondered writing a own version in python (If I only could settle on a GUI lib ;) Of course, one has to go back to the early days of public Internet access... When a mail client only read mail from a LOCAL (ie, on the same machine) mailbox; and spooled mail into a local spool directory. Mail transfer agents were responsible for pulling mail down from POP3 ISP mailboxes, and for sending via SMTP. Not necessarily - python has everything (SMTP, IMAP(S), even POP) included as well and with the help of pgcrypto even smime and friends should be doable. My first real Python program -- written with the Amiga version of Python 1.4 -- was a rudimentary Sendmail daemon, which would take messages from a local spool directory, connect to my ISPs SMTPd, relay all the address, then send the body of the message. I wrote this within a week of discovering Python via the first books available. And I wrote this as my previous, downloaded, MTAs had severe faults -- the first properly handled TO, CC, and BCC, but relied upon connecting directly to the destination address for each recipient, and would hang up the entire spool if given an address that could not be connected; the second worked as most current clients, by relaying via one's own ISP... but it totally ignored BCC and CC addresses! Ha! I did something the other way round but not with python but with AREXX those days. It was an SMTPD to accept forwarded mail and spool directly into YAM (that if someone on the other end of the world has hit "send" it was immediately rattling in my inbox :-) Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl-python regex-performance comparison
Ivan wrote: Hello everyone, ... 1. Although it is all relatively similar, there are differences between regexes of these two. Which do you believe is the more powerful variant (maybe an example) ? 2. They are both interpreted languages, and I can't really be sure how they measure in speed. In your opinion, for handling large files, which is better ? (I'm processing files of numerical data of several hundred mb - let's say 200mb - how would python handle file of such size ? As compared to perl ?) 3. This last one is somewhat subjective, but what do you think, in the future, which will be more useful. Which, in your (humble) opinion "has a future" ? I guess both languages have their use and future. You should come to your own conclusion when you work with both languages for a while. I can only say for myself, I know both and prefer python for its nice straight forward way. And you don't need the hammer (aka regex) for everything. Several hundred megabytes is not much, you would work thru them sequentially, that is with python you would almost exclusively work with generators. HTH Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: String Identity Test
Avetis KAZARIAN wrote: Gary Herron wrote: The question now is: Why do you care? The properties of strings do not depend on the implementation's choice, so you shouldn't care because of programming considerations. Perhaps it's just a matter of curiosity on your part. Gary Herron Well, it's not about curiosity, it's more about performance. I will make a PHP example (a really quite simple ) PHP : Stat 1 : $aVeryLongString == $anOtherVeryLongString Stat 2 : $aVeryLongString === $anOtherVeryLongString Stat 2 is really faster than Stat 1 (due to the binary comparison) As I said, I'm coming from PHP, so I was wondering if there was such a difference in Python. Please keep in mind in both cases there is nothing "for free". To have identity, you would need to have the same object - which in case of a string means the interpreter has to find out about existing string with exactly the same contents and reference it instead of creating a new object in memory. This takes about at least the same time (if not more) then just run the compare with both strings when you need (aka == ). If you only have a few strings but compare them often, you could profit from identity and the overhead of installing it would be neglectable (and you can force this in python with "internal") but in this case I'd think calculating and working with a hash instead should be preferred. Regards Tino Wildenhain smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Inverse of dict(zip(x,y))
lone_eagle wrote: Hi all, This might be trivial ... Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two lists x and y? So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1, x2:y2, ...}, what is there any trick to get lists x = [x1, x2, ...] and y = [y1, y2, ...] x,y=zip(d.items()) Cheers Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list