Psyco 64 bits
Hi, I used Psyco to speed up my Python code. Due to the great amount of data I have to proccess, I moved my Linux system to a 64 bits version with more RAM. It seems that Psyco cannot be used in such platforms. Or is there another version of Psyco for 64 bits platform? I googled and arrived to PyPy. But I don't know how to use it. With psyco, I used to include two statements roughly at the beginning of the script: import psyco psyco.full() With PyPy, is there a similar way to try to speed up my script? Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: MemoryError c/vcompiler.h:745: Fatal Python error (Psycopg2)
Sun, 21 Jun 2009 13:04:59 +, Lie Ryan escreveu: > Luis P. Mendes wrote: >> Hi, >> >> I have a program that uses a lot of resources: memory and cpu but it >> never returned this error before with other loads: >> >> """ >> MemoryError >> c/vcompiler.h:745: Fatal Python error: psyco cannot recover from the >> error above >> Aborted >> """ >> The last time I checked physical RAM while the script was running, it >> was used in about 75% and there is no reason (based in other runs of >> the program) for it to surpass 80% (maximum). >> >> $ python -V >> Python 2.5.2 >> >> Pyscopg2 is version 2.0.8 >> >> I use Linux, Kernel 2.6.24.5-smp #2 SMP with a Core2 CPU T5500 @ >> 1.66GHz and 3GB of RAM >> >> I could not find this error. What does this mean? >> >> Is this a bug of Python? of Psycopg2? >> >> Luis > > Have you tried running without psyco? Psyco increases memory usage quite > significantly. > > If it runs well without psyco, you can try looking at your code and > selectively psyco parts that need the speed boost the most. I really need Psyco (use version 1.6 - forgot to mention earlier) to speed up the code. The part that consumes more memory is the one that needs Psyco the most. Luis -- http://mail.python.org/mailman/listinfo/python-list
MemoryError c/vcompiler.h:745: Fatal Python error (Psycopg2)
Hi, I have a program that uses a lot of resources: memory and cpu but it never returned this error before with other loads: """ MemoryError c/vcompiler.h:745: Fatal Python error: psyco cannot recover from the error above Aborted """ The last time I checked physical RAM while the script was running, it was used in about 75% and there is no reason (based in other runs of the program) for it to surpass 80% (maximum). $ python -V Python 2.5.2 Pyscopg2 is version 2.0.8 I use Linux, Kernel 2.6.24.5-smp #2 SMP with a Core2 CPU T5500 @ 1.66GHz and 3GB of RAM I could not find this error. What does this mean? Is this a bug of Python? of Psycopg2? Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 error
Hello Martin, Em Wed, 09 May 2007 06:17:09 +0200, Martin v. Löwis escreveu: >> ImportError: libpq.so.5: cannot open shared object file: No such file or >> directory >> >> libpq files are readable by the world: [EMAIL PROTECTED] pgsql # ll lib/ -d >> drwxr-xr-x 3 postgres postgres 1528 2007-05-07 23:25 lib/ > > Don't try this as the root user, but as the one for whom it is failing: > What does "file /usr/local/psql/lib/libpq.so.5" say? The problem was that I couldn't issue this command. Permissions were set incorrectly: $ ll /usr/local/pg* -d drwxr-x--- 10 postgres postgres 712 2007-05-08 20:43 /usr/local/pgsql Once corrected to: $ ll /usr/local/pg* -d drwxr-xr-x 10 postgres postgres 712 2007-05-08 20:43 /usr/local/pgsql I can import psycopg2 fine. Thank you for your help! Best regards, Luis -- http://mail.python.org/mailman/listinfo/python-list
psycopg2 error
Hi, I've installed psycopg2 under Slacware 11.0 along with PostgreSQL 8.2.4. When I run the python shell I get the following error: [EMAIL PROTECTED] ~$ python Python 2.4.3 (#1, Jul 26 2006, 20:13:39) [GCC 3.4.6] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import psycopg2 Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/site-packages/psycopg2/__init__.py", line 60, in ? from _psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID ImportError: libpq.so.5: cannot open shared object file: No such file or directory The strange thing is that under root and postgres users, there is no error. [EMAIL PROTECTED] ~$ python Python 2.4.3 (#1, Jul 26 2006, 20:13:39) [GCC 3.4.6] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import psycopg2 >>> >>> libpq files are readable by the world: [EMAIL PROTECTED] pgsql # ll lib/ -d drwxr-xr-x 3 postgres postgres 1528 2007-05-07 23:25 lib/ [EMAIL PROTECTED] lib # ll libpq* -rw-r--r-- 1 postgres postgres 155858 2007-05-07 23:25 libpq.a lrwxrwxrwx 1 postgres postgres 12 2007-05-07 23:25 libpq.so -> libpq.so.5.0 lrwxrwxrwx 1 postgres postgres 12 2007-05-07 23:25 libpq.so.5 -> libpq.so.5.0 -rwxr-xr-x 1 postgres postgres 126496 2007-05-07 23:25 libpq.so.5.0 The postgreSQL lib is in ld.so.conf and ldconfig has been run: # cat /etc/ld.so.conf /usr/local/lib /usr/X11R6/lib /usr/i486-slackware-linux/lib /opt/kde/lib /usr/lib/qt/lib /usr/local/pgsql/lib What is wrong? Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 faster way to retrieve last x records
Em Tue, 07 Nov 2006 17:03:17 -0800, Stuart Bishop escreveu: > > The following SQL statement will return the last 200 rows in reverse order: > > SELECT * FROM seconds ORDER BY tempounix DESC LIMIT 200 > > This will only send 200 rows from the server to the client (your existing > approach will send all of the rows). Also, if you have an index on tempounix > it will be really fast. > > > If you really need the results in tempounix order, then: > > SELECT * FROM ( > SELECT * FROM seconds ORDER BY tempounix DESC LIMIT 200 > ) AS whatever > ORDER BY tempounix; Thank you Stuart, I'll try it. Luis P. Mendes -- http://mail.python.org/mailman/listinfo/python-list
psycopg2 faster way to retrieve last x records
Hi, I would like to know if there is a better way to do what I'm already doing as stated in the following example, when using psycopg2 with PostgresQL. ... nr_bars_before = 200 tabela = 'seconds' sqlString = "SELECT * FROM " + tabela + " ORDER BY tempounix;" curs = self.conn.cursor() curs.execute(sqlString) try: while 1: curs.scroll(1,mode='relative') except: pass curs.scroll(-int(math.fabs(nr_bars_before)),mode='relative') row = curs.fetchone() curs.close() ... What I need is to get the last 200 records from the table, each couple minutes. As stated, what I do is to go all the way through the table records until the end, then going back 200 in order to select all of them (those 200) forward down to the last one. But it takes a lot of time to do it. I mean some seconds. And it brings some 'heavy' work on disk. The table 'seconds' has 54+ lines right now. Can I do something different in order to have a lighter load on the system and a quicker response? Luis P. Mendes -- http://mail.python.org/mailman/listinfo/python-list
Re: ancestor class' __init__ doesn't call other methods
Rob De Almeida escreveu: > Luis P. Mendes wrote: >> Method a() is not called. Why is this? What is the best option to >> solve this? Have Cotacoes returning values and not to be an ancestor >> class of CruzaEmas? > > It works for me, after rearranging your code a little bit: > Ok, thanks. I already know where the problem was. The a() method was just an example. The real problem was elsewhere. I had two methods with the same name, one at Cotacoes (the ancestor), another one at CruzaEmas. The method called at the __init__ of the ancestor was the one of the daughter class, and not the one of the ancestor's, as I was expecting. After changing the name of the latter, everything seems to be fine. Luis P. Mendes -- http://mail.python.org/mailman/listinfo/python-list
ancestor class' __init__ doesn't call other methods
Hi, I have the following problem: I instantiate class Sistema from another class. The result is the same if I import it to interactive shell. s = Sistema("par") class Sistema: def __init__(self, par): cruza_ema = CruzaEmas(par) class CruzaEmas(Ema, Cotacoes): def __init__(self, par): Cotacoes.__init__(self, par) <- calls ancestor class' __init__ class Cotacoes: def __init__(self, par): print "par: ", par self.a() def a(self):<- just as an example print "ff" Method a() is not called. Why is this? What is the best option to solve this? Have Cotacoes returning values and not to be an ancestor class of CruzaEmas? -- http://mail.python.org/mailman/listinfo/python-list
Re: pyXLWriter - grid lines and if formula
Waldemar Osuch escreveu: > Luis P. Mendes wrote: >> Gregory Piñero escreveu: >>> On 7/7/06, Luis P. Mendes <[EMAIL PROTECTED]> wrote: >>>> Hi, >>>> >>>> I know that pyExelerator is the supported project now, but I can't use >>>> it because I'd need it to generate files from a web platform. Since I >>>> can not save a file to a file-like object, I have to use pyXLWriter. > >> So, perhaps you could show me how to generate an excel file as a http >> response in django? > > If it is a simple one sheet Workbook you can produce HTML document with > a table and set the headers to indicate it is Excel. > > Content-Type: application/vnd.ms-excel > Content-Disposition: attachment;filename=report.xls > > Lookup documentation on how to generate formula: > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoffxml/html/ofxml2k.asp > > Waldemar > Thanks, but it's a workbook with several sheets. Luis P. Mendes -- http://mail.python.org/mailman/listinfo/python-list
Re: pyXLWriter - grid lines and if formula
Gregory Piñero escreveu: > On 7/7/06, Luis P. Mendes <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I know that pyExelerator is the supported project now, but I can't use >> it because I'd need it to generate files from a web platform. Since I >> can not save a file to a file-like object, I have to use pyXLWriter. > > I don't really know what I'm talking about, but maybe have a Python > script that uses pyExelerator and saves the file to Sdout, name that > script with an .xls extension and the browser will present it to the > user as an Excel file? > > Maybe, maybe?? > > -Greg pinero I'll try that option and see what I can get. Still, there's an open patch at http://sourceforge.net/tracker/index.php?func=detail&aid=1481069&group_id=134081&atid=730645 that says: """ Summary: (?) pass file-like objects to write In a cgi script you use mosty sys.stdout to write to the client with this little patch this is possible. """ but it has not been submitted yet. So, perhaps you could show me how to generate an excel file as a http response in django? Luis P. Mendes -- http://mail.python.org/mailman/listinfo/python-list
pyXLWriter - grid lines and if formula
Hi, I know that pyExelerator is the supported project now, but I can't use it because I'd need it to generate files from a web platform. Since I can not save a file to a file-like object, I have to use pyXLWriter. The problems are: 1- how to turn off/on the grid lines of each sheet? 2- I tried to build a simple 'if' formula but couldn't. Is it my problem or pyXLWriter's problem? If the former, is it possible to post an example? TIA Luis P. Mendes -- http://mail.python.org/mailman/listinfo/python-list
download file from intranet linux server to windows clients
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I'm building an intranet web server in Linux for around 40 windows clients with Django. The problem is that I want to build an excel file based on criteria entered by the client, that the client must be able do download to his personal work space. I use pyExcelerator to create the Excel files. How can I do it? Do I need another excel generator? Client's information about its working directory should be read, but how? I could only find the way to read the server environment variables, where data is processed. Luis P. Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEkuY9Hn4UHCY8rB8RAvjYAJ9RSp1llMo6GPJIYAicm8gRSQJ/AwCgrN5Y 3EzU+SGn3Uk/1j1gwl4uBik= =3330 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: ascii to latin1
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > > With regards to º, Richie already gave you food for thoughts, if you > want "1 DE MO" to match "1º DE MO" remove that symbol from the key > (linha_key = linha_key.translate({u"º": None}), if you don't want such > a fuzzy matching, keep it. > Thank you all for your help. That was what I did. That symbol 'º' is not needded for the field. It's working fine, now. Luis P. Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEYdUGHn4UHCY8rB8RAhWgAKCNqUaknEmiNlA050u5G+p4cTPGHwCgs7fu 7/5HMYDDo+sOP2QDexIELn8= =XiPL -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: ascii to latin1
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 >> When I used the "NFD" option, I came across many errors on these and >> possibly other codes: \xba, \xc9, \xcd. > > What errors? normalize method is not supposed to give any errors. You > mean it doesn't work as expected? Well, I have to admit that using > normalize is a far from perfect way to implement search. The most > advanced algorithm is published by Unicode guys: > <http://www.unicode.org/reports/tr10/> If you read it you'll understand > it's not so easy. > >> I tried to use "NFKD" instead, and the number of errors was only about >> half a dozen, for a universe of 60+ names, on code \xbf. >> It looks like I have to do a search and substitute using regular >> expressions for these cases. Or is there a better way to do it? > > Perhaps you can use unicode translate method to map the characters that > still give you problems to whatever you want. > Errors occur when I assign the result of ''.join(cp for cp in de_str if not unicodedata.category(cp).startswith('M')) to a variable. The same happens with de_str. When I print the strings everything is ok. Here's a short example of data: 115448,DAÇÃO 117788,DA 1º DE MO Nº 2 I used the following script to convert the data: # -*- coding: iso8859-15 -*- class Latin1ToAscii: def abreFicheiro(self): import csv self.reader = csv.reader(open(self.input_file, "rb")) def converter(self): import unicodedata self.lista_csv = [] for row in self.reader: s = unicode(row[1],"latin-1") de_str = unicodedata.normalize("NFD", s) nome = ''.join(cp for cp in de_str if not \ unicodedata.category(cp).startswith('M')) linha_ascii = row[0] + "," + nome # * print linha_ascii.encode("ascii") self.lista_csv.append(linha_ascii) def __init__(self): self.input_file = 'nome_latin1.csv' self.output_file = 'nome_ascii.csv' if __name__ == "__main__": f = Latin1ToAscii() f.abreFicheiro() f.converter() And I got the following result: $ python latin1_to_ascii.py 115448,DACAO Traceback (most recent call last): File "latin1_to_ascii.py", line 44, in ? f.converter() File "latin1_to_ascii.py", line 22, in converter print linha_ascii.encode("ascii") UnicodeEncodeError: 'ascii' codec can't encode character u'\xba' in position 11: ordinal not in range(128) The script converted the ÇÃ from the first line, but not the º from the second one. Still in *, I also don't get a list as [115448,DAÇÃO] but a [u'115448,DAÇÃO'] element, which doesn't suit my needs. Would you mind telling me what should I change? Luis P. Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEYN7+Hn4UHCY8rB8RAjcTAKCgEkZwCURgp/VrtthM1MBba+d7KACfY9dj xcHVL1BuhyrPV8+9Z5Q2AJQ= =+AO0 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: ascii to latin1
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Richie Hindle escreveu: > [Serge] >> def search_key(s): >> de_str = unicodedata.normalize("NFD", s) >> return ''.join(cp for cp in de_str if not >>unicodedata.category(cp).startswith('M')) > > Lovely bit of code - thanks for posting it! > > You might want to use "NFKD" to normalize things like LATIN SMALL > LIGATURE FI and subscript/superscript characters as well as diacritics. > Thank you very much for your info. It's a very good aproach. When I used the "NFD" option, I came across many errors on these and possibly other codes: \xba, \xc9, \xcd. I tried to use "NFKD" instead, and the number of errors was only about half a dozen, for a universe of 60+ names, on code \xbf. It looks like I have to do a search and substitute using regular expressions for these cases. Or is there a better way to do it? Luis P. Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEYINaHn4UHCY8rB8RAqLKAJ0cN7yRlzJSpmH7jlrWoyhUH1990wCgkxCW 9d7f/FyHXoSfRUrbES0XKvU= =eAuO -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
ascii to latin1
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I'm developing a django based intranet web server that has a search page. Data contained in the database is mixed. Some of the words are accented, some are not but they should be. This is because the collection of data began a long time ago when ascii was the only way to go. The problem is users have to search more than once for some word, because the searched word can be or not be accented. If we consider that some expressions can have several letters that can be accented, the search effort is too much. I've searched the net for some kind of solution but couldn't find. I've just found for the opposite. example: if the word searched is 'televisão', I want that a search by either 'televisao', 'televisão' or even 'télévisao' (this last one doesn't exist in Portuguese) is successful. So, instead of only one search, there will be several used. Is there anything already coded, or will I have to try to do it all by myself? Luis P. Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEX9yqHn4UHCY8rB8RAovDAJ90vllWjxfXN5bnNvg0OCKadbrfnwCfb4Hp 2jmRFyNYySukPwYACJ1TdM8= =hTr3 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket freezes
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Thank you all for your suggestions. Luis P. Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFECb5AHn4UHCY8rB8RAmeLAKCmSVfTvgQ94NPnJlD2QqdbMwVFXACdGFAh 8GL/9zxwXCYcmWxpyDweggE= =9U0o -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: socket freezes
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 | Try setting a default timeout on the socket, and if it times out | recontact the other system on a new socket. See socket.setdefaultimeout() | | regards | Steve Thank you for your answers. I'm beggining to suspect that the problem has to do with a discontinual of service of the ISP. It provides me a dynamic IP address not a static one. I say this because after some hours, I returned to the computer and could not acess the internet for surfing port 80 and the socket was also down again - it just uses another port. After unplugging the power cord of the cable modem from the internet and pluging it in after a while, I could already access sites (http). But the socket was still down, still with no error raised. Based on this hypothesis, is there any way for my python program to deal with this? Any thoughts? Thanks again. Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFECKMmHn4UHCY8rB8RAoeAAJ92sEUsFk2bsXcCX77cDyHY2jOogwCgnGKZ xStEmoEDTDrhVE7+aIAxSbI= =qzed -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
socket freezes
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I've developed a program that uses a socket to receive information 24h a ~ day. The problem is that the socket seems to freeze. By that I mean the program stops getting information but doesn't raise any error. I tried to solve this by writing the following functions, in order to try to start the socket connection again: def keepAlive(self): ~self.alive = 0 ~tnow = time.time() ~if tnow - self.lastTime > 90: # last time got from last string received from the socket ~self.alive = 1 def reSocket(): ~print "socket has failed", time.strftime('%X', time.localtime()) ~time.sleep(60) ~l=GServer()# new instance that contains the socket reSocket is triggered when self.alive is 1. But it hasn't solved my problem. These functions have effect only after I do a ^C, and even then, the socket doesn't start to acquire new input. Any clues you can give me about this? Luis P. Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFECEF8Hn4UHCY8rB8RAtaaAKCnFb2O28AE4uRTK0sPSpnOifaDzACdG2EA imVqvzcRX4qGWqMzLRUcyao= =Cqkb -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 rounds unix time [solved]
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 |> example: |> unix time inserted at first row: 1138839839.64456 |> unix time as retrieved in psql: 1.13884e+09 |> unix time retrieved by psycopg2: 113884.0 | Note: When timestamp values are stored as double precision | floating-point numbers (currently the default), the effective limit of | precision may be less than 6. timestamp values are stored as seconds | before or after midnight 2000-01-01. Microsecond precision is achieved | for dates within a few years of 2000-01-01, but the precision degrades | for dates further away. When timestamp values are stored as eight-byte | integers (a compile-time option), microsecond precision is available | over the full range of values. However eight-byte integer timestamps | have a more limited range of dates than shown above: from 4713 BC up to | 294276 AD. The same compile-time option also determines whether time and | interval values are stored as floating-point or eight-byte integers. In | the floating-point case, large interval values degrade in precision as | the size of the interval increases. | """ | | Otherwise, what data type *are* you using to store the Unix time? Thank you for your answer. In python, I use float data type to deal with time values (from time.time()), for example. In Postgresql, the unix time field was set up as real. I've changed it to double precision and it runs fine, now. Luis P. Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD50nTHn4UHCY8rB8RAkUUAJ9Pby8S5do7c7qMYjC6t222eDyG8wCfTJOR aGMlkq86dN1juXUjBMgRuGQ= =nnGl -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
psycopg2 rounds unix time
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I've inserted a couple hundred rows in a table in Postgres via psycopg2. The first field of each row is a certain unix time (since epoch) when an event occured. When I try to access that database with psycopg2, I get rounded values for the unix time field. example: unix time inserted at first row: 1138839839.64456 unix time as retrieved in psql: 1.13884e+09 unix time retrieved by psycopg2: 113884.0 Is this a bug? I'm using: Python 2.3.5 in a Debian Sarge box PostgreSQL 7.4.7 psycopg2-2.0b6 Luis P. Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFD5q7kHn4UHCY8rB8RAvh0AJ4nr6239OT6vweUVEF3Htq8smaCJQCgoVnY NZXZdAyq9UmNXdlOxtwN2y8= =ZawE -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: nested tuples
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 | | Why? What is it about the list of tuples that you don't like? | Philosophically, it's more in line with Guido's separation of list and | tuple. I'm not saying that I don't like, I was just curious to know if there was a way to do it using exclusively tuples. Regards, Luis Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDIqgSHn4UHCY8rB8RAps/AJ905JXc5naxJYWLA0JLd0ZaJfQQWACeLXHJ pLE9nmMH+k81ybbB1Otj0hg= =2/LC -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
nested tuples
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I'm trying to solve this problem: suppose I'm reading a csv file and want to create a tuple of all those rows and values, like ((row1value1, row1value2, row1value3),(row2value1, row2value2, row2value3),..., (rowNvalue1, rowNvalue2, rowNvalue3)) I haven't found the way to do it just using tuples. How can I do it? Nevertheless, I can solve it like this: a=[] for row in reader: ~ elem = (row[0],row[1],row[2]) ~ a.append(elem) which will result in a list of tuples: [(row1value1, row1value2, row1value3),(row2value1, row2value2, row2value3),..., (rowNvalue1, rowNvalue2, rowNvalue3)] Then, I get what I want with tuple(a). Luis P. Mendes -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDIdcvHn4UHCY8rB8RAjBnAJ9hLzbMZVZf3vLZ0iCs2ptK0v6RPwCfRr1S GHdoy/APTZSWy+rLBA+i0KE= =vyR6 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: PostgreSQL & Python vs PHP
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I would like to thank all of you. For what I've read, I'll be using python instead of Php. Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFC5RQ5Hn4UHCY8rB8RAi3QAKCuU3tgluOZXktbseUmq5d6WpyGCgCfWTCK hKweHnSkvEm/QLKwMw4uP2A= =6asH -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: PostgreSQL & Python vs PHP
gene tani wrote: > ok, to make this less open-ended, you should mention what O/S and web > server you have in mind, whether the web and DB servers will be under > your admin (big diff betw python and PHP, as far as finding shared > server accounts at web hosts), what kinds of queries, concurrent > read/write volumes, transactions, dirtiness, etc. etc Also if you > build your questions to this newsgroup on past threads you've read, you > will get absolute superb information, I guarantee it. I'll be using Apache, under Linux. The db server will be under my admin. A dozen clients acessing the db. For the first project: Three or four of them will be using queries mainly from three tables with: table 1: 350 lines x 20 cols table 2: 350 lines x 6 cols table 3: 4200 lines x 5 cols as an estimate. Other clients will be very light users but need easy web interface for mouse clicks only. Thank you for your support and excuse me for my ignorance, but I'm starting the project and would like to start it in the right direction. Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: PostgreSQL & Python vs PHP
gene tani wrote: > To be honest, this is a pretty open-ended question. Are there specific > issues (SQL injection/security, minimizing db connections, simplest > code, etc, your'e concerned with?) Simplest code with be an important factor, since the db will be used far from max capabilities. Ease of use of the web page by clients is also a main factor. I need to build it from the server and also client side. For the client side I'll be using Python. But for the server side, I would like to hear some opinions. Is it worth learning Php? > > To be more honest, googline "Python vs. PHP" raises lots of hits > http://wiki.w4py.org/pythonvsphp.html nice link :-) Thank you, Luis -- http://mail.python.org/mailman/listinfo/python-list
PostgreSQL & Python vs PHP
Hi, I don't know anything about PHP and I'm initiating right now with PostgreSQL. Could someone tell me the pros and cons of assessing the PostgreSQL databases with Python vs. PHP? I will need to build a database that has to be assessed by a dozen clients via a web page in an intranet (possibly from outside, too). Is Python more used on the client side and PHP on the server side? I now Python, although I'm far from being an expert. Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyrex: step in for loop
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 | so it's | | for i in range(8, 14, 1): ... | | http://enigmail.mozdev.org iD8DBQFClkmlHn4UHCY8rB8RAlUqAKCxSEkEKVIcoshTwmL7GQNK6d/j0wCgoC67 jOhuXQpnDt23SEAM9huKTQA= =8XO0 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Pyrex: step in for loop
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I'm trying to improve speed in a module and substituted the pythonic 'for in range()' for 'for i from min < i < max:' But, I need to define a step for the i variable. How can I do it? for example, how do I iterate through 8 to 14 with step 1? Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFClkGTHn4UHCY8rB8RAgZXAJ0XPg9IH0OU329FVX3o14QjNFXuXgCgm+UR O0GpXmDpQr7Y7TgMsmVvZ6s= =zZnm -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Pyrex: TypeError: unsubscriptable object
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I'm just transforming a Python module into Pyrex, and I get the following error: File "indicadorPyrex.pyx", line 37, in indicadorPyrex.volatilidade ~h1 = precoMax[barra] I made no changes to this module except including 'int' for two variables in the def argument of the function. I also tried to declare cdef float h1, but I get the same error. What can be wrong? Thanks, Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCkz6MHn4UHCY8rB8RAlTZAJ0ZXfdmkZuXFLPrhGvaYUBoS7YTVQCZAZhp Fc65UgWF+rCkilTs0BAmNSU= =PZpG -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: speeding up Python script
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I appreciate everyone's help! I got some ideas that I'll try to put into practice. Regards, Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCi7QQHn4UHCY8rB8RAkpWAJsGezFRCjDpVvbDiuEN8a2lPY41AgCgm6w4 3hgtkw5NkxZ6GuzC1k2dIYo= =Epti -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: speeding up Python script
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 The reason why I'm using six nested for loops is because I need to find the best output using those six variables as input. Here's the simplified code: for per in range(): ~for s in range(): ~for t in range(): for v in range(): ~for n in range(): ~for l in range(): var a, \ var b, \ ... var 15 = function1(arg1, \ ... arg20) ~ var a, \ var d, \ var a, \ ... var 14 = function2(arg1, \ ... arg25) var c, \ ... var 18 = function3(arg1, \ ... arg20) ia = var1*var2-numPerdidos*sl result.insert(index, [per,s,t,v,n,l,ia]) index = index + 1 thanks for the replies -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCiy2CHn4UHCY8rB8RAlafAJ4wQ8mSCGFwTTt9EH1bn54tTuI40wCfSrn8 KDSrHnsIV2cY/PKmL3ZwLdI= =39Cm -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
speeding up Python script
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I have a 1000 line python script that takes many hours to finish. It is running with six inside 'for' loops. I've searched the net for ways to speed up the proccess. Psyco improves performance around 3% in this case which is not good enough. How can I dramatically improve speed? I tried to find some tool that converts Python to C automatically but couldn't. As I don't know C, I think that weave and PyInline for example are out of the solution. I'm using Linux. Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCio0YHn4UHCY8rB8RAoe0AKC4rj/dxE2HGw4xtCMEmVGDgrGEEwCghO1r +Rkgx8j1BzD0Lxq/iPey23s= =xv4O -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
speeding up Python
Hi, I have a 1000 line python script that takes many hours to finish. It is running with six inside 'for' loops. I've searched the net for ways to speed up the proccess. Psyco improves performance around 3% in this case which is not good enough. How can I dramatically improve speed? I tried to find some tool that converts Python to C automatically but couldn't. As I don't know C, I think that weave and PyInline for example are out of the solution. I'm using Linux. Luis -- http://mail.python.org/mailman/listinfo/python-list
Dive into Python java equivalent
Hi, do you know if is there any 'Dive into Python' equivalent for the java language? DiP is the best I've seen and I would need to learn some basics of Java and also ways to interact between the two languages. (I'm already aware of Jpype and Jython) Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: xml parsing escape characters
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 ~From your experience, do you think that if this wrong XML code could be meant to be read only by somekind of Microsoft parser, the error will not occur? I'll try to explain: xml producer writes the code in Windows platform and 'thinks' that every client will read/parse the code with a specific Windows parser. Could that (wrong) XML code parse correctly in that kind of specific Windows client? Or in other words: Do you know any windows parser that could turn that erroneous encoding to a xml tree, with four or five inner levels of tags? I'd like to thank everyone for taking the time to answer me. Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFB8UIOHn4UHCY8rB8RAgK4AKCiHjPdkCKnirX4gEIawT9hBp3HmQCdGoFK 3IEMLLXwMZKvNoqA4tISVnI= =jvOU -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: xml parsing escape characters
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 ~From your experience, do you think that if this wrong XML code could be meant to be read only by somekind of Microsoft parser, the error will not occur? I'll try to explain: xml producer writes the code in Windows platform and 'thinks' that every client will read/parse the code with a specific Windows parser. Could that (wrong) XML code parse correctly in that kind of specific Windows client? Or in other words: Do you know any windows parser that could turn that erroneous encoding to a xml tree, with four or five inner levels of tags? I'd like to thank everyone for taking the time to answer me. Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFB8UIOHn4UHCY8rB8RAgK4AKCiHjPdkCKnirX4gEIawT9hBp3HmQCdGoFK 3IEMLLXwMZKvNoqA4tISVnI= =jvOU -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: xml parsing escape characters
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I would like to thank everyone for your answers, but I'm not seeing the light yet! When I access the url via the Firefox browser and look into the source code, I also get:~ should I take the contents of the string tag that is text and replace all '<' with '<' and '>' with '>' and then read it with xml.minidom? how to do it? or should I use another parser that accomplishes the task with no need to replace the escaped characters? -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFB8AIQHn4UHCY8rB8RAuw8AJ9ZMQ8P3c7wXD1zVLd2fe7MktMQwwCfXAND EPpY1w2a3ix2s2vWRlzZ43U= =bJQV -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list~ 439 ~
Re: xml parsing escape characters
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 this is the xml document: http://www..";>~ When I do: print xmldoc.toxml() it prints: http://www...";>~ 439 (... others ...) ~~ __ with: stringNode = xmldoc.childNodes[0] print stringNode.toxml() I get: http://www...";>~ 439 ~~ __ with: DataSetNode = stringNode.childNodes[0] print DataSetNode.toxml() I get:~ 439 ~~ ___- so far so good, but when I issue the command: print DataSetNode.childNodes[0] I get: IndexError: tuple index out of range Why the error, and why does it return a tuple? Why doesn't it return:~ 439 ~?? -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFB76y3Hn4UHCY8rB8RAvQsAKCFD/hps8ybQli8HAs3iSCvRjwqjACfS/12 5gctpB91S5cy299e/TVLGQk= =XR2a -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list 439
xml parsing escape characters
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I only know a little bit of xml and I'm trying to parse a xml document in order to save its elements in a file (dictionaries inside a list). When I access a url from python 2.3.3 running in Linux with the following lines: resposta = urllib.urlopen(url) xmldoc = minidom.parse(resposta) resposta.close() I get the following result: http://www..";>~ _ In the lines below, I try to get all the child nodes from string, first by counting them, and then ignoring the /n ones: stringNode = xmldoc.childNodes[0] print stringNode.toxml() dataSetNode = stringNode.childNodes[0] numNos = len(dataSetNode.childNodes) todosNos={} for no in range(numNos): todosNos[no] = dataSetNode.childNodes[no].toxml() posicaoXml = [no for no in todosNos.keys() if len(todosNos[no])>4] print posicaoXml (I'm almost sure there's a simpler way to do this...) _ I don't get any elements. But, if I access the same url via a browser, the result in the browser window is something like: http://www..";> ~ ~ ~ 439 (... others ...) ~ ~ and the lines I posted work as intended. I already browsed the web, I know it's about the escape characters, but I didn't find a simple solution for this. I tried to use LL2XML.py and unescape function with a simple replace text = text.replace("<", "<") but I had to convert the xml document to string and then I could not (or don't know) how to convert it back to xml object. How can I solve this? Please, explain it having in mind that I'm just beggining with Xml and I'm not very experienced in Python, too. Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFB7rzKHn4UHCY8rB8RAhnlAKCYA6t0gd8rRDhIvZ5sdmNJlEPSeQCgteB3 XUtZ0JoHeTavBOCYi6YYnNo= =VORM -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list~ 439 (... others ...) ~