Re: collecting results in threading app
John Nagle wrote: >Gerardo Herzig wrote: > > >>Hi all. [EMAIL PROTECTED] over here. Im missing some point here, but cant >>figure out which one. >> >>This little peace of code executes a 'select count(*)' over every table >>in a database, one thread per table: >> >>class TableCounter(threading.Thread): >> def __init__(self, conn, table): >> self.connection = connection.Connection(host=conn.host, >>port=conn.port, user=conn.user, password='', base=conn.base) >> threading.Thread.__init__(self) >> self.table = table >> >> def run(self): >> result = self.connection.doQuery("select count(*) from %s" % >>self.table, [])[0][0] >> print result >> return result >> >> >>class DataChecker(metadata.Database): >> >> def countAll(self): >> for table in self.tables: >> t = TableCounter(self.connection, table.name) >> t.start() >> return >> >> >>It works fine, in the sense that every run() method prints the correct >>value. >>But...I would like to store the result of t.start() in, say, a list. The >>thing is, t.start() returns None, so...what im i missing here? >>Its the desing wrong? >> >> > > 1. What interface to MySQL are you using? That's not MySQLdb. > 2. If SELECT COUNT(*) is slow, check your table definitions. > For MyISAM, it's a fixed-time operation, and even for InnoDB, > it shouldn't take that long if you have an INDEX. > 3. Threads don't return "results" as such; they're not functions. > > >As for the code, you need something like this: > >class TableCounter(threading.Thread): >def __init__(self, conn, table): > self.result = None > ... > > def run(self): > self.result = self.connection.doQuery("select count(*) from %s" % > self.table, [])[0][0] > > > def countAll(self): > mythreads = [] # list of TableCounter objects > # Start all threads > for table in self.tables: > t = TableCounter(self.connection, table.name) > mythreads.append(t) # list of counter threads > t.start() > # Wait for all threads to finish > totalcount = 0 > for mythread in mythreads:# for all threads > mythread.join() # wait for thread to finish > totalcount += mythread.result # add to result > print "Total size of all tables is:", totalcount > > > > John Nagle > > Thanks John, that certanly works. According to George's suggestion, i will take a look to the Queue module. One question about for mythread in mythreads: # for all threads mythread.join() # wait for thread to finish That code will wait for the first count(*) to finish and then continues to the next count(*). Because if is that so, it will be some kind of 'use threads, but execute one at the time'. I mean, if mytreads[0] is a very longer one, all the others will be waiting...rigth? There is an approach in which i can 'sum' after *any* thread finish? Could a Queue help me there? Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
collecting results in threading app
Hi all. [EMAIL PROTECTED] over here. Im missing some point here, but cant figure out which one. This little peace of code executes a 'select count(*)' over every table in a database, one thread per table: class TableCounter(threading.Thread): def __init__(self, conn, table): self.connection = connection.Connection(host=conn.host, port=conn.port, user=conn.user, password='', base=conn.base) threading.Thread.__init__(self) self.table = table def run(self): result = self.connection.doQuery("select count(*) from %s" % self.table, [])[0][0] print result return result class DataChecker(metadata.Database): def countAll(self): for table in self.tables: t = TableCounter(self.connection, table.name) t.start() return It works fine, in the sense that every run() method prints the correct value. But...I would like to store the result of t.start() in, say, a list. The thing is, t.start() returns None, so...what im i missing here? Its the desing wrong? thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: request for Details about Dictionaries in Python
Saideep A V S wrote: >Hello Sir, > > Thank You a ton. I was looking for this function. As far what I've >understood from the "Shelve" module is that, there would be no memory >wastage and the whole transactions would be done from and to the file we >specify. Am I right?. > > My actual task is to build a basic dictionary for two languages and store >word and its meaning in another language in a file and must be able to >access it through on-disk Hash tables. as these would be saving memory space >for a huge data. > >so, I hope shelve is the right one, I am searching for., I shall try out >with the function. > > >Thank You once again. > >Cheers, >Saideep > > > Plz remember allways reply to the python group also. They are many many many ones to know more than i do! Well, i dont quite think that it would be "no memory wastage", since when you read/write from disk, there is memory involved in the process. I *really* believe that, when data goes huge, a *real* database (like postgres, and others) has to come and play the game. Hope that helps Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: request for Details about Dictionaries in Python
Saideep A V S wrote: >Hello Sir, > > I am a beginner level programmer in Python. I am in search of a >function for 'On-Disk' Dictionaries which is similar to On-Disk Hash tables >in Perl (i.e., tie function in Perl). > > > Could anyone help me with the concept. I have also searched the net, but >was not successful in finding any related. > >Awaiting your Solutions. > >Thanks in Advance. > >Saideep > > > I guess you are looking for shelve http://docs.python.org/lib/module-shelve.html Gerardo -- http://mail.python.org/mailman/listinfo/python-list
compiling plpython compilation error
Hi all. Im having a hard time trying to compile the plpython package. This is the error make gives me: [EMAIL PROTECTED]:/usr/local/src/postgresql-8.2.5/src/pl/plpython> make gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -fpic -shared -Wl,-soname,libplpython.so.0 plpython.o -L/usr/lib/python2.5/config -L../../../src/port -lpython2.5 -lpthread -ldl -lutil -lm -Wl,-rpath,'/usr/lib/python2.5/config' -o libplpython.so.0.0 /usr/lib64/gcc/x86_64-suse-linux/4.2.1/../../../../x86_64-suse-linux/bin/ld: /usr/lib/python2.5/config/libpython2.5.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC /usr/lib/python2.5/config/libpython2.5.a: could not read symbols: Bad value collect2: ld returned 1 exit status make: *** [libplpython.so.0.0] Error 1 This runs on OpenSuse 10.3. python 2.5 postgres 8.2.5 ( and 8.3.0) Any clues? Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: How to pass shell variable to shell script from python
Rockins Chen wrote: >Hi all, > >I encountered a problem: I have a python script, let's just name it >caller.py, It calls a shell script, which is named callee.sh. In callee.sh, >it need a shell variable $target, which should be supplied by caller.py(cannot >pass by argument). I try to use os.environ to do this, as follows: > >caller.py >-- >#/usr/bin/python > >import os > >os.environ["target"] = "localhost.localdomain.org" >os.putenv("target", "localhost.localdomain.org") >os.system("./callee.sh") >--- > >callee.sh >--- >#!/bin/bash > >echo $target >exit 0 > > >But, unluckily, it didn't work. What can I do? > >TIA, > > > > Well, if you have to use os.system, that could be os.system("export target=localhost.localdomain.org; ./callee.sh") Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Weird cgi error
Jesse Aldridge wrote: >I uploaded the following script, called "test.py", to my webhost. >It works find except when I input the string "python ". Note that's >the word "python" followed by a space. If I submit that I get a 403 >error. It seems to work fine with any other string. >What's going on here? > >Here's the script in action: http://crookedgames.com/cgi-bin/test.py > >Here's the code: > >#!/usr/bin/python >print "Content-Type: text/html\n" >print """ > > > > > > > > > >""" > > If you cant have access to the apache (?) error_log, you can put this in your code: import cgitb cgitb.enable() Which should trap what is being writed on the error stream and put it on the cgi output. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: standardization allows?
[EMAIL PROTECTED] wrote: >Standardization allows RCA cables, bumpers, and 115V plugs. The Bill >of Rights allows Huckleberry Finn. What is the analogue of the Bill >of Rights for programmers and users, whether of programming languages >or latter-generation software? > > I want that drogues, man -- http://mail.python.org/mailman/listinfo/python-list
Re: Removing Pubic Hair Methods
Sion Arrowsmith wrote: >Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > >>On Tue, 29 Jan 2008 11:48:38 -0800, Tobiah wrote: >> >> >>>class genital: >>> def pubic_hair(self): >>> pass >>> def remove(self): >>> del(self.pubic_hair) >>> >>> >>I think `pubic_hair` is an attribute instead of a method. >> >>Oh, and ``del`` is a statement and not a function. So the way you wrote >>it with parentheses is a bit misleading. >> >> > >And who's going to want to call genital().remove() anyway? > > > I will use genital().extend(), thats for shure ^^ -- http://mail.python.org/mailman/listinfo/python-list
sharing objects between classes
Hi all. Im wondering the way to share a database connection between some classes: So far, i came up with a simple class schema, where each class means each different relation, i mean i have the follow classes class Database(object): ## make the connection self.conn = make_conn() class Table(object): def get_fields: And at this point i dont know how to use the Database.conn attribute, since the get_fields method will perform a query over the given database. At first, i just define the Table class as a inner class of Database, but if i try a class Database(object): ## make the connection def __init__(self): self.conn = sql_connect() self.table = Table('foo') class Table(object): ## inner class def get_fields(self, name): I get a "NameError: global name 'Table' is not defined". So, which would the right pattern to use here? Using a global module? I dont know why, but i dont like that idea too much. Any comments will be appreciated! Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: *** AMERICAN BASTARDS DESERVE TO BE RAPED ***
James Matthews wrote: >When did this list become a politics dialog? Please keep on topic "Python"! > >Thanks >James > >On Jan 12, 2008 8:07 PM, Joe Riopel <[EMAIL PROTECTED]> wrote: > > >>On Jan 12, 2008 2:00 PM, radiosrfun <[EMAIL PROTECTED]> wrote: >> >> >>>Whether we agree on "tactics" or not - if it come to a battlefield with the >>>two of us - or any Americans there - we're still going to fight the same >>>enemy - not each other. >>> >>> >>This is a good resource for starting Python >>http://diveintopython.org/ >> >>-- >>http://mail.python.org/mailman/listinfo/python-lis >> >> >> >> indian = CreeIndian() indian.setVoice("lugubrious") indian.says("When the last tree is cut down, the last fish eaten and the last stream poisoned, you will realize that you cannot eat money.") :) -- http://mail.python.org/mailman/listinfo/python-list
Re: dealing with binary files
Tom Brown wrote: >On Mon, 2008-01-07 at 11:57 -0200, Guilherme Polo wrote: > > >>2008/1/7, Gerardo Herzig <[EMAIL PROTECTED]>: >> >> >>>Hi all. Im trying to read a binary data from an postgres WAL archive. >>>If i make a >>>xfile = open('filename', 'rb').xreadlines() >>>line = xfile.next() >>> >>>i see this sort of thing: >>>']\xd0\x03\x00\x01\x00\x00\x00\r\x00\x00\x00\x00\x00\x00JM//DI+,D\x00\x00\x00\x01$\x00\x00\x00\x7f\x06\x00\x00y\r\t\x00\x02\x0f\t\x00\x00\x00\x10\x00)\x00\x01\x00\x12\x08 >>>\x00^\xc2\x0c\x00\x08\x00\x00\x003001([EMAIL PROTECTED]' >>> >>>This file suppose to have some information about database activity, but >>>at this point i cant do more than this, because i cant figure out what >>>to do in order to have some 'readable' text. >>> >>>Im guessing is some C code, im reading the struct module to see if it >>>helps, but im not into C programming, and im lost at the start of my >>>problem. >>> >>> >>You are looking at the correct module, struct. But in order to >>understand or even correctly extract data from a binary file, you need >>to know its structure. There should be some document describing the >>Postgre WAL file format. >> >> >> > >"The log record headers are described in access/xlog.h" > >http://www.postgresql.org/docs/8.2/interactive/wal-internals.html > > > Yes Tom, my 'C' comes that far, cant do more, i get quickly overwelmed...Guess i will have to spend some time reading about it. Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
dealing with binary files
Hi all. Im trying to read a binary data from an postgres WAL archive. If i make a xfile = open('filename', 'rb').xreadlines() line = xfile.next() i see this sort of thing: ']\xd0\x03\x00\x01\x00\x00\x00\r\x00\x00\x00\x00\x00\x00JM//DI+,D\x00\x00\x00\x01$\x00\x00\x00\x7f\x06\x00\x00y\r\t\x00\x02\x0f\t\x00\x00\x00\x10\x00)\x00\x01\x00\x12\x08 \x00^\xc2\x0c\x00\x08\x00\x00\x003001([EMAIL PROTECTED]' This file suppose to have some information about database activity, but at this point i cant do more than this, because i cant figure out what to do in order to have some 'readable' text. Im guessing is some C code, im reading the struct module to see if it helps, but im not into C programming, and im lost at the start of my problem. Can someone point me out some advice? Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: How to delete this file ???
hank/ann wrote: >pop up that says: error loading c:/progra~1\mywebs~1bar\2bin\mwsbar.dll the >specified module could not be found > >this pop up appeares on desktop each time we log on cannot get rid off it >can you help Ann > > import os.Linux :P -- http://mail.python.org/mailman/listinfo/python-list
Re: Extract a number from a complicated string
Horacius ReX wrote: >Hi, > >I have to read some data from a file, and on each block it always >appears the followng string; xyz.vs.1-81_1 . It appears a lot of time >with different numbers like; > >xyz.vs.1-81_1 >xyz.vs.1-1234_1 >xyz.vs.1-56431_1 > >and so on > >My problem is that I need to extract from this string the number. For >instance in xyz.vs.1-81_1 I have to extract the number 81, and in >xyz.vs.1-1234_1 I need to get the number 1234. > >What is the easiest way of doing this ? > >Thanks > > If the strings looks *allways* that way, so its not to complicated: >>> number_regex = re.compile('-(\d+)_') >>> print number_regex.search('xyz.vs.1-1234_1').group(1) 1234 >>> print number_regex.search('xyz.vs.1-56431_1').group(1) 56431 -- http://mail.python.org/mailman/listinfo/python-list
plpythonu and "hello concurrent world"
Hi all. Im having some "problems" with a small concurrent plpython function. Based on a small example [1] about concurrent programming, there is some code which works fine under python: #! /usr/bin/python import threading, random import time def myPrint(str): print 'searching...', str time.sleep(random.randint(10, 1) / 1000.0) print str, 'OK!' myThreads = (threading.Timer(random.random(), myPrint, ["hello"]), \ threading.Timer(random.random(), myPrint, ["concurrent"]), \ threading.Timer(random.random(), myPrint, ["world"])) for thr in myThreads: thr.start() [EMAIL PROTECTED]: python pp.py searching... concurrent searching... world searching... hello hello OK! concurrent OK! world OK! So far, so good. Almost the same example in plpythonu: CREATE OR REPLACE FUNCTION search_t() returns bigint security definer as $$ import threading, random import time def myPrint(str): plpy.notice ('searching...', str) time.sleep(random.randint(10, 1) / 1000.0) plpy.notice(str, 'OK!') myThreads = (threading.Timer(random.random(), myPrint, ["hello"]), \ threading.Timer(random.random(), myPrint, ["concurrent"]), \ threading.Timer(random.random(), myPrint, ["world"])) for thr in myThreads: thr.start() return 1 $$ language plpythonu; gse_new_version=# select * From search_t(); search_t -- 1 (1 row) Looks like myPrint() is not executing at all!! Have no idea why, so i decided writing both on python and postgres forums. Any ideas?? Postgres 8.1.3 python 2.5.1 Thanks!! Gerardo [1] http://forums.hostrocket.com/showthread.php?t=13325 -- http://mail.python.org/mailman/listinfo/python-list
Re: "Python" is not a good name, should rename to "Athon"
[EMAIL PROTECTED] wrote: >Python is a good programming language, but "Python" is not a good >name. > >First, python also means snake, Monty Python. If we search "python" in >google, emule, many results are not programming resource. If we search >PHP, all results are programming resource. > >Second, python also means snake, snake is not a good thing in western >culture. Many people dislike any things relevant to snake. We must >have high regard for the custom. > >Now, python3000 is coming. It's the best time to rename! > >Athon is a good candidate, you could provide better names. > >In Athon, the first letter "A" could pronounce as [ e ] . > > You will be eaten by the Snake-Ra god tonight! -- http://mail.python.org/mailman/listinfo/python-list
Re: i want to know what is the problem in this code
nani wrote: >i am getting the following error for below code > > Python 2.5.1: C:\Python25\python.exe >Mon Nov 26 10:13:17 2007 > >A problem occurred in a Python script. Here is the sequence of >function calls leading up to the error, in the order they occurred. > C:\Program Files\Apache Group\Apache2\cgi-bin\hello.py in () >7 >8 val = cgi.FieldStorage() >9 name = val["name"].value > 10 time_from = val["time_from"].value > 11 time_to = val["time_to"].value >name undefined, val = FieldStorage(None, None, []), ].value = [] > C:\Python25\lib\cgi.py in __getitem__(self=FieldStorage(None, None, >[]), key='name') > 565 if item.name == key: found.append(item) > 566 if not found: > 567 raise KeyError, key > 568 if len(found) == 1: > 569 return found[0] >builtin KeyError = , key = 'name' > >: 'name' > > > >#!C:/Python25/python.exe >import cgi >import cgitb; cgitb.enable() > >print "Content-Type: text/html" >print > >val = cgi.FieldStorage() >name = val["name"].value >time_from = val["time_from"].value >time_to = val["time_to"].value >html = """ > > > > Hello %s from %s to %s > > > >""" >print html%(name, time_from, time_to) > > > > > > >html page is... > > > > > > > > > > > Enter your name: > > > > Time from: > td> > > > Time to: > td> > > > value="Click Here" /> > > > > > > > > > > > Looks like the text field "name" is empty when "submitin" the form, and cgi.FieldStorage() -no args- does not build the key/pair for empty textfields. You can use the keep_blank_values=1 arg in FieldStorage() if you want force the key/pair to be generated anyway. Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary and list
Beema shafreen wrote: >hi everbody, > I have a file, > a b c d e > 2722316 2722360A_16_P03641972150-44 > 2722510 2722554A_16_P2136023916-44 > 2722570 2722614A_16_P0364197344-44 > 2722658 2722702A_16_P415636692187-44 > 2724889 2724948A_16_P03641974738-59 > 2725686 2725745A_16_P03641975422-59 > 2726167 2726219A_16_P0364197688-52 > 2726307 2726366A_16_P415636772167-59 > 2728533 2728589A_16_P213602495819-56 > 2734408 2734467A_16_P21360257-14-59 > 2734453 2734509A_16_P03641977376-56 > 2734885 2734929A_16_P213602591987-44 > > > This intro looks exactly like the 10 previous post from you. You will have to leave some money here, man! Try posting the result you get, and the result you want for a start. Dont make others do what you already did. Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Which index can i use ?
Abandoned wrote: >Hi.. >I want to do index in postgresql & python. >My table: >id(int) | id2(int) | w(int) | d(int) > >My query: >select id, w where id=x and id2=y (sometimes and d=z) > >I have too many insert and select operation on this table. >And which index type can i use ? Btree, Rtree, Gist or Hash ? >Also I want to unique (id, id2).. >Now this is my index. is it give me good performance ? >CREATE UNIQUE INDEX ind1 ON test USING btree (id, id2) >CREATE INDEX ind2 ON test USING btree (id) >CREATE INDEX ind3 ON test USING btree (id2) >CREATE INDEX ind4 ON test USING btree (w) >CREATE INDEX ind5 ON test USING btree (d) > >I'm too sorry my bad english. >King regards.. > > > Well, this is no python-related at all. But, for a start, if you are not using the 'w' field in the WHERE clause, the ind4 index is not necesary at all. Having more indexes that you need is a waste of space and perfomance. It also depends on the amount of records your table has. -Hash indexes are discouraged -GiST indexes are for more advanced uses than equality comparisons -Rtree are used in multidimentional indexing So, keep the default btree. Do the test with the diff indexes if you want. You may use EXPLAIN for viewing the index usage. And dont forget about VACUUM too! Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple HTML template engine?
allen.fowler wrote: >Hello, > >Can anyone recommend a simple python template engine for generating >HTML that relies only on the Pyhon Core modules? > >No need for caching, template compilation, etc. > >Speed is not a major issue. > >I just need looping and conditionals. Template inheritance would be a >bonus. > >I've seen Genshi and Cheetah, but they seem way too complex. > >Any ideas? > >I'm sure I could build something myself, but I'm sure this has already >been done quite a few times. Why re-invent the wheel, right? > > >Thank you, >Allen > > > http://htmltmpl.sourceforge.net/ It has loops and conditionals, simple to use. Very simple. Kind of old program (dont seems to have suffer modifications since 2001) Try it. Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: multimethods decorator
Bruno Desthuilliers wrote: >[EMAIL PROTECTED] a écrit : > > >>>Gerardo Herzig a écrit : >>> >>> >>>>Hi all. Im reading the Gido's aproach using decorators at >>>>http://www.artima.com/weblogs/viewpost.jsp?thread=101605 >>>> >>>>It looks good to me, but the examples shows the functionality using >>>>functions. >>>>Now, when i try to give this decorator into a method, if i try the >>>> >>>>class test(object): >>>> @multimethod(...) >>>> def met(self, ...): >>>> >>>>The multimethod decorator needs the types of the arguments, and, if the >>>>met method requires self as the first argument, the multimethod should >>>>look like >>>>@multimethod(self.__class__, bla, ble) or some like that... >>>> >>>>Now i know that im wrong, because i have this error >>>> >@multimethod(self.__class__) >>>> >NameError: name 'self' is not defined >>>> >>>> >>>Indeed. Neither self (which will only be known at method call time) nor >>>even the 'test' class (which is not yet defined when the decorator is >>>executed) are availables. >>> >>> > > > >>Doh! >> >> > >If you're surprised, then you'd better learn way more about Python's >internal (execution model && object model mostly) before continuing with >multimethods. > > Is not that, is just...it allways make sense to me AFTER someone tells me!! :) > > >>>>So what would be the first argument to @multimethod?? >>>> >>>> >>>A string ?-) >>> >>> > > > >>Ah? And what will that string contains? >> >> > >What makes sens for you. Don't forget that Python has very strong >introspection features. Also note that it's not uncommon to use a 2-pass >approach : marking some methods with the decorator, then doing the real >processing in the metaclass (which of course implies a custom metaclass) >or in the __new__ method (in which case this processing will happen on >*each* instanciation). > > Oh well, now you kill me with that one. > > >>>FWIW, there's already an implementation of multiple dispacth by Mr. Eby... >>> >>> >>Oh yes, i found the dispatch version of multimethods, but i have not tried >>it yet. Do you think is better this version than Guido's? >> >> > >I think that dispatch is actually used in a few packages, frameworks or >applications. Is it the case of Guido's stuff ? > >Also, IIRC, Guido's snippet is quite less generic than dispatch (which >is based on expression rules, not only on types). > > Ok. So im giving dispatch version a chance. Its working nice so far. Thanks Man! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
multimethods decorator
Hi all. Im reading the Gido's aproach using decorators at http://www.artima.com/weblogs/viewpost.jsp?thread=101605 It looks good to me, but the examples shows the functionality using functions. Now, when i try to give this decorator into a method, if i try the class test(object): @multimethod(...) def met(self, ...): The multimethod decorator needs the types of the arguments, and, if the met method requires self as the first argument, the multimethod should look like @multimethod(self.__class__, bla, ble) or some like that... Now i know that im wrong, because i have this error >@multimethod(self.__class__) >NameError: name 'self' is not defined So what would be the first argument to @multimethod?? Thanks!! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: migrating to packages
Bruno Desthuilliers wrote: >Gerardo Herzig a écrit : > > >>Carl Bank a écrit : >> >> >>>Add these lines in __init__.py: >>> >>>from MYCLASSES.A import A >>>from MYCLASSES.B import B >>> >>> >>> >>> >>Ummm, that works indeed, but forces me to import all (more than A and B) >>classes, rigth? >> >> > >Why so ? > > > If the original MYCLASSES.py has 5 different classes ,say A,B,C,D,E , each one has to be imported (as A and B) in order to be used for the client code. The thing is, there are more than 5 classes, and looks like a lot of unnecesary work to me, since a particular program can use 1,2, or 3 classes at the timeThats why im watching the way to override the `import statement'... Damn client code!!! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: List of objects X Database
MindMaster32 wrote: >I am writing a script that has to read data from an ASCII file of >about 50 Mb and do a lot of searches and calculations with that data. >That would be a classic problem solved by the use of a database >(SQLite would suit just fine), but that would require the user to >install more packages other than python itself, and that I am trying >to avoid. >Since the data is not too large, I wonder if there is another way to >store all data in memory and work with it more or less like a >database, doing searches and working with datafields. > >This is not clear to me how can be implemented. I thought of creating >a class with the data structure, and creating a list of objects of >that class, each one containing one line of data from the "database". > >Any thoughts or suggestions? > >Thanks! >Eduardo > > > What about shelve? It Requires some db support, yesAnd what about just reading the file and making a dict? It is a `csv' like file, so you can just read it and generate a dict? Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: migrating to packages
> > > >>>On Oct 3, 2007, at 11:42 AM, Gerardo Herzig wrote: >>> >>> >>> >>>>Hi all. I have a single file with several classes, wich i want to >>>>separate into several packages. >>>>The big file is named, say MYCLASES, and contains a class named >>>>A(object), and B(A). >>>> >>>>We have been using this MYCLASES in the from MYCLASES import B syntax, >>>>but i cant reproduce this syntax using packages. Im forced to write >>>>from PACKAGE.B import *, and if that means >>>>i have to touch so many files, that would really be a problem to me. >>>>There is (i cant find it yet) a place where i can read about that kind >>>>of package 'migration' situation? >>>> >>>>Because i *really* want to keep the FROM PACKAGE import B syntax. >>>> >>>> >>>http://www.python.org/doc/current/tut/ >>>node8.html#SECTION00840 >>> >>> >>I have already read those files (and i just read it again), but still >>cant find the solution. Maybe i just do not explain myself in the >>correct way (or i am very very stupid :) >>I will expose my case quicly. >>The MYCLASES.py file contains the A class, so i can use from MYCLASES >>import A >>a = () >> >>Using the "package mode" (wich looks fine BTW), having the simple >>MYCLASES/ >> __init__.py >> A.py >> >>forces my (i guess) to use the >>from MYCLASES.A import A >> >>which is not what i want, because the big amount of files i will have to >>modify (and im not alones, there is a group of dudes who use this >>MYCLASES) >> >>Im i missing something in that docs you post? Thanks!! >> >> > >Add these lines in __init__.py: > >from MYCLASSES.A import A >from MYCLASSES.B import B > > Ummm, that works indeed, but forces me to import all (more than A and B) classes, rigth? Gerardo. -- http://mail.python.org/mailman/listinfo/python-list
migrating to packages
Hi all. I have a single file with several classes, wich i want to separate into several packages. The big file is named, say MYCLASES, and contains a class named A(object), and B(A). We have been using this MYCLASES in the from MYCLASES import B syntax, but i cant reproduce this syntax using packages. Im forced to write from PACKAGE.B import *, and if that means i have to touch so many files, that would really be a problem to me. There is (i cant find it yet) a place where i can read about that kind of package 'migration' situation? Because i *really* want to keep the FROM PACKAGE import B syntax. Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: database persistence with mysql, sqlite
coldpizza wrote: >Hi, > >I want to run a database query and then display the first 10 records >on a web page. Then I want to be able to click the 'Next' link on the >page to show the next 10 records, and so on. > >My question is how to implement paging, i.e. the 'Next/Prev' NN >records without reestablishing a database connection every time I >click Next/Prev? Is it at all possible with cgi/mod_python? > >For example, in a NON-web environment, with sqlite3 and most other >modules, I can establish a database connection once, get a cursor >object on which I run a single 'SELECT * FROM TABLE' statement and >then use cursor.fetchmany(NN) as many times as there are still results >left from the initial query. > >How do I do the same for the web? I am not using any high-level >framework. I am looking for a solution at the level of cgi or >mod_python (Python Server Pages under Apache). To call >cursor.fetchmany(NN) over and over I need to pass a handle to the >database connection but how do I keep a reference to the cursor object >across pages? I use mysql and sqlite3 as databases, and I am looking >for an approach that would work with both database types (one at a >time). So far I have successfully used the following modules for >database access: sqlite3, mysqld, and pyodbc. > > Apache/cgi just dont work this way. When apache receives a new request (a cgi being called), it starts a new thread, it execute him, and gives the client some result. AND THEN KILL THE THREAD. Altough i never used it, what i think you need is fast cgi (fcgi), wich takes care of persistent connections to a web server. Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
executing list of methods (and collecting results)
Hi all. Im in this situation: I want to perform several kind of (validating) methods to a given value. Lets say i have a class named Number, and the following methods: is_really_a_number(), is_even(), is_greater_than_zero(), and so on. All of them returning booleans. I want the collect_validators() method is to execute any of the above methods, and collect their names as items of a list (wich will be the collect_validators() return value). My first approach is: [code] def collect_validators(self): v_dict = { 'is_really_a_number': is_really_a_number, 'is_even': is_even, 'is_greater_than_zero', is_greater_than_zero } for name, meth in v_dict.items(): result = meth() if result: yield name [/code] I wondering if is this a good pattern to apply, i like the way it looks like, at least to me it looks `natural', but...im calling every method twice here? One in v_dict and again on the dict iteration? Any suggestion will be great! Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Regex Question
[EMAIL PROTECTED] wrote: >I need to extract the number on each >i.e 49.950 from the following: > > 49.950 > >The actual number between: 49.950 can be any number of >digits before decimal and after decimal. > > ##. > >How can I just extract the real/integer number using regex? > > > If all the td's content has the [value_to_extract] pattern, things goes simplest [untested] /http://mail.python.org/mailman/listinfo/python-list
Re: parsing long `To' and 'Cc' from email
Steve Holden wrote: >Gerardo Herzig wrote: > > >>Hi all. Im trying to develop yet another email filter. Just for fun for >>now. Im having a little trouble parsing long 'To' and 'Cc' headers. >>Sometimes p.e. the 'To' header comes like >> >>'[EMAIL PROTECTED], [EMAIL PROTECTED]' >>others comes like >>'"My self" <[EMAIL PROTECTED]>, "My brother" <[EMAIL PROTECTED]>', >>other times a \r\t comes inside the `To' header. And any combination of >>the above mentioned (and shurely more) can ocur. >> >>the email.* package dont seems to parse that kind of headers >>`correctly'. What i want is to get a list with all the email address in >>the `To' header. >> >>Someone know if there is a more sofisticated parser for doing this? >> >> >> >Have you tried using email.utils.getaddresses()? > >regards > Steve > > No, i was not. And it works just perfect! One day i will make a hard question!! I wonder why this getaddresess() function is not a method into the HeaderParser class. Ok, so my content-filter can continue now. Thanks Steve! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
parsing long `To' and 'Cc' from email
Hi all. Im trying to develop yet another email filter. Just for fun for now. Im having a little trouble parsing long 'To' and 'Cc' headers. Sometimes p.e. the 'To' header comes like '[EMAIL PROTECTED], [EMAIL PROTECTED]' others comes like '"My self" <[EMAIL PROTECTED]>, "My brother" <[EMAIL PROTECTED]>', other times a \r\t comes inside the `To' header. And any combination of the above mentioned (and shurely more) can ocur. the email.* package dont seems to parse that kind of headers `correctly'. What i want is to get a list with all the email address in the `To' header. Someone know if there is a more sofisticated parser for doing this? Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me understand this script
Ryan J Nauman wrote: >Can someone help me understand this script please? >I understand everything except for the anagram function. Could you break >it down into more than 1 line of code for me or explain it? (I understand >WHAT it does but HOW?) Thanks. > >Script >> > >### ># SCRABBLE.PY ># ># purpose: ># find usable "bingos" based on your rack ># ># usage: ># python scrabble.py eilsnsy ># ># output: ># Straight anagrams: ># linseys ># lysines ># Possible other words: ># + B ># sensibly >#+ K ># skylines >#+ V ># sylvines >### ># Scrabble is a registered trademark of J. W. Spear & Son PLC and ># Hasbro Inc. Any and all uses of the word "Scrabble" in this code ># refers to this trademark. ># ># This code is not affiliated with any company. >### > >import sys > >WORDS = [ i.rstrip ().lower() for i in file ('c:\python25\TWL06.txt') ] ># you can download the current TWL and/or SOWPODS dictionaries from ># http://67.19.18.90/twl.zip and http://67.19.18.90/sowpods.zip . ># Update the file name above as appropriate if you want to use a "proper" ># Scrabble dictionary. > > > >def alphabetise(word): >x = [i for i in word] >x.sort() > >return "".join(x) > >def anagram(word): >wordLength = len(word) >sortedWord = alphabetise(word.lower()) >return [i for i in WORDS if len(i) == wordLength and alphabetise(i) == >sortedWord] > >for word in sys.argv[1:]: >print "Straight anagrams: " >for i in anagram(word): >print " " + i >print "Possible other words: " >for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": >a = anagram(i + word) >if a: >print "+", i >for h in a: >print " ", h > ><< End script > > I guess the difficult part remains in the last line. (Untested code bellow) [code] def anagram(word): resultValue = [] wordLength = len(word) sortedWord = alphabetise(word.lower()) #not much to change until here for WORD in WORDS: if wordLength == len(WORD) and alphabetise(WORD) == sortedWord: resultValue.append(WORD) return resultValue [/code] Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: How does super() work?
Lamonte Harris wrote: >I've searched Google, and other search engines to try to find out how >super() works. Can someone explain in short detail how super() works? I >may and may not need to know this information, but it is good to know. > > > There is at least one explanation in the python.org site, among other topics related to super() usage: http://www.python.org/download/releases/2.2.3/descrintro/#cooperation Cheers, Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: pure python for sms
Neil Hodgson wrote: >Gerardo Herzig: > > > >>Hi dudes. Im looking for a python implementation for sending sms to a >>cell phone. I was try using some free pages, but i want to use a python. >>Do i need a cellphone conected to my machine? Or can i send sms to some >>cell via some python library? >> >> > >This is likely to cost some money similar to sending an SMS from a >'phone. There are several companies that provide SMS sending services >that can be accessed through HTTP. Have a look at www.clickatell.com and >www.aql.com . Here is a library based on Clickatell: >http://www.powertrip.co.za/code/python/clickatell.py > >Neil > > Well, im not triyng to send a SMS `FROM' a cellphone, im trying to send a SMS `TO' a cellphone. Here (in Argentina) are several sites who lets you send a sms for free. You also can receive SMS responses via this page http://sms.personal.com.ar/Mensajes/msn.htm While my tries using this page via urllib failed, i dont want to depend on an external page anyway. The python class you send to me looks like a pay site (if not, i dont see why the tokenpay() and getbalance() methods :) I was also avaiable to send a sms in the form of an plain email [EMAIL PROTECTED], but it not seems to work this way no longer. Again, i dont want to do it that way anyway. Thats why im looking for a python implementation of that funcionality. Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Setting a read-only attribute
[EMAIL PROTECTED] wrote: >I have an object and wish to set an attribute on it which, >unfortunately for me, is read-only. > >How can I go about this? > >Cheers. >-T > > > I guess we all need an code example to show us the way 'read only' is implemented. If you cant access to the class wich you are instantiated from, well, maybe you can just post the error or exception you get. Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
pure python for sms
Hi dudes. Im looking for a python implementation for sending sms to a cell phone. I was try using some free pages, but i want to use a python. Do i need a cellphone conected to my machine? Or can i send sms to some cell via some python library? Waiting for advice. Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it reasonably easy easy to something like this with python?
walterbyrd wrote: >On Aug 28, 1:31 pm, Gerardo Herzig <[EMAIL PROTECTED]> wrote: > > >>walterbyrd wrote: >> >> > > > >>The one who make that table sorteable is AJAX. Not php. The php part is >>kind of trivial (so it would be `trivial' in python too). It just reads >>some data and format it in an html table. >> >> > > >Thank you, that is great to know. What if there were 1000 records, and >the table was paginated? I suppose, ajax would sort the front end, and >backend language, and database, would soft behind the scene, or >something? > > > Im not an AJAX expert (not even close actually. In fact i just used it once), but seems like you will have to reload all the page (all the table at least). Because now is a different scenario. If the table is paginated, it looks like you will send, say 50 results at one time, then (when pressing 'next 50'), anhoter 50, and so on. So AJAX only will have THOSE 50 for ordering. Another approach would be returning de entire recordset, and implement all the 'next' and 'previous' links via AJAX. And i dont think you will like to send the entire result. I dont. What will i do (at least from WIK for now), is having a set of `hrefs' (maybe with some nice arrows) in all of the table headers, to indicate the desired order you want to get. And, if you have a column table named 'age', you will make those href like '' then your cgi python script will take that mess after the ? sign, parse it (via cgi module perhaps), and make a new query, with the 'order by age asc' clause, wich are the 'arguments' in the url. There is allways a lot of ways to do some stuff. I will check into de AJAX list too! Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Is it reasonably easy easy to something like this with python?
walterbyrd wrote: >This is made with a php5 framework called qcodo. > >http://examples.qcodo.com/examples/dynamic/inline_editing.php > >With qcodo it's easy to make grids that are sortable and inline >editable. Qcodo grids work from the database - not an xml table or >array. Qcodo handles complex data relations, and fairly large >datadabes. > >I like python better than php, but I don't know of any python tools to >create these sorts of grids. > > > The one who make that table sorteable is AJAX. Not php. The php part is kind of trivial (so it would be `trivial' in python too). It just reads some data and format it in an html table. Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
extending of adding method?
Hi all. I have a question about design. The general question would be: Where is the line beteween extending a class and adding new methods to that class? And the particular case im involved is: I have a class (say USERCLASS) who implements a user interface. One of his methods is called `login'. Later on i got the order of implementing a `single login', which off course means a single user cant login if a session is already started for that user. Extending comes to my mind at first (it works good, actually). But now im thinikng if there some problem in adding a method to the USERCLASS class named single_login(), who will take care of applying the rules of single sign on. Which one you guys will pick up? USERCLASS().single_login() or SINGLELOGINUSERCLASS().login() Thanks for your oppinions! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: advice about `correct' use of decorator
BJörn Lindqvist wrote: >On 8/22/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > > >>On 22 ago, 10:00, "BJörn Lindqvist" <[EMAIL PROTECTED]> wrote: >> >> >>>As I said, you can accomplish the exact same thing by calling a >>>function from within the function that requires the user to be logged >>>in. >>> >>>def change_pass(): >>>check_user_logged_in() >>>... more stuff here... >>> >>>is less complex (and therefore preferable) than: >>> >>>@check_user_logged_in >>>def change_pass(): >>>... more stuff here... >>> >>>An important principle in engineering is that you should always strive >>>to make your design as simple as possible. If you have two equal >>>designs, you should always choose the one that is simpler because >>>simple things are easier to understand than complex things. >>> >>> >>I don't see the complexity in this case - both are a single line of >>code. Any internal complexity is hidden by the language. In fact, I >> >> > >"Hiding" doesn't reduce complexity, quite the opposite. > > > >>consider the decorated function simpler than the other: its body >>represents exactly what the function does, without any distracting >>precondition calls. >> >> > >Think about how the decorator is implemented. It is a high order >function, taking a function and returning a new function. Something >like this: > >def check_user_logged_in(func): >def f(*args, **kwargs): >if global_state.the_user.is_logged_in: >return func(*args, **kwargs) >return show_login_page() >return f > >@check_user_logged_in >def change_pass(): >... more stuff here... > >or: > >def check_user_logged_in(): >return global_state.the_user.is_logged_in > >def change_pass(): >if not check_user_logged_in(): >return show_login_page() >... more stuff here ... > >or even: > >def change_pass(): >if not global_state.the_user.is_logged_in: >return show_login_page() >... more stuff here ... > > > >>The decorator has some advantages: can have syntax support on your >>editor, can perform some registering/logging, it's even easier to >>quickly check visually if it's here. >> >> > >The decorator has just as many disadvantages. For example, what if you >want to redirect back to the change_pass page once the user has >pressed the Login button on the login_page? Or if you want to show >different login pages depending on user properties? How much control >flow do you really want to "hide" in your decorator? > > > Thanks Björn. Maybe im blind here in my intent to use decorators somewhere, but even re-checking you samples (pretty much the kind of example i show to my boss), it looks nicer (to me) when using a decorator!! I guess im becoming a `deco junky' :) Later you expose some interesing points about that login page and redirecting stuff...well, im my case, the login page does depends on user properties, wich (at this point) are stored in a `session data variable' (actually a table row), so the login pages take care about user properties, not the decorator itself, but the other part of the page. I guess decorators has is own public, well, im one of that public. Let my be with my deco-junk alone, you bastard :) Thanks a lot for your opinnions, guys! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: advice about `correct' use of decorator
BJörn Lindqvist wrote: >On 8/16/07, Gerardo Herzig <[EMAIL PROTECTED]> wrote: > > >>@is_logued_in >>def change_pass(): >>bla >>bla >> >>And so on for all the other functions who needs that the user is still >>loged in. >> >>where obviosly the is_logued_in() function will determine if the dude is >>still loged in, and THEN execute change_pass(). If the dude is not loged >>in, change_pass() is NOT executed at all. Instead, it will be redirected >>to the `login' screen. >> >> > >I think this is redundant use of a decorator. You can achieve the >exact same effect by writing: > >def is_logued_in(): >if not user.is_logged_in(): >raise NotLoggedInError > >It costs you one more line, but reduces complexity. And if you are >worried about that extra line you can put it in a function. > > > As far as i know (by the way, AFAK is the shortcut?, and BTW means `by the way'? ), decorators are not indispensable. I mean, all that you can do with python, you can doit without decorators. And from my point of view, this hides the complexity for the other developers of my group, since all they have to do is add the @is_logged_in line at the top of the cgi script, and not to worrie about exceptions, not even how the decorator is implemented (i may log the error in some file). All they have to know is that any abnormal situation will redirect to the `login' screen. Thank you for your comments! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: advice about `correct' use of decorator
Laszlo Nagy wrote: > >>> >>> Are you developing a website or a GUI program? >>> >>> >> It will be used in a web development. It is an important point? > > Yes, I think. Unless you use AJAX. :-) Most web sites work this way: > > user clicks -> request to server -> process on server -> response > > I would rather enclose the whole handler in try/except and raise a > custom PermissionDenied exception when the user has inscuficient > permissions. There are problems with a decorator used for > authorization. The context needs to be determined. E.g. which user is > accessing the method? (It can be hard to tell if the method is part of > a thread object that lies in a thread pool and is shared between > simultaneous clients...) Also it might be that the method's purpose is > to change objects of the same class, and the user has permission to > modify one object but not the other. In this case, authorization must > be done inside the function call... How do you express this with a > decorator? > > These are just ideas. You should analyze your problem and make your > decision. If you only want to restrict access to functions, then > probably using decorators is perfect. > > Best, > > Laszlo > > I post the change_pass() function as an example, there is a buch of other functions (the whole site actually) that will require a logged user. May the change_pass() function have additional control, shure, but it will be not part of the `global' requirement. Thank you very much for your time, Laszlo Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: advice about `correct' use of decorator
Steven Bethard wrote: >Gerardo Herzig wrote: > > >>Hi all. I guess i have a conceptual question: >>Im planing using a quite simple decorator to be used as a conditional >>for the execution of the function. I mean something like that: >> >>@is_logued_in >>def change_pass(): >> bla >> bla >> >>And so on for all the other functions who needs that the user is still >>loged in. >> >>where obviosly the is_logued_in() function will determine if the dude is >>still loged in, and THEN execute change_pass(). If the dude is not loged >>in, change_pass() is NOT executed at all. Instead, it will be redirected >>to the `login' screen. >> >>Something in my mind tells me that this is not the pythonic way...But i >>like the idea, so please tell me that im in the right way :) >> >> > >Django does it almost exactly this way: > >http://www.djangoproject.com/documentation/authentication/#the-login-required-decorator > >STeVe > > Great! So from now on, my idea is labeled as `djangothic' :) Thanks a lot! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: advice about `correct' use of decorator
Gerardo Herzig wrote: >> Hi all. I guess i have a conceptual question: >> Im planing using a quite simple decorator to be used as a conditional >> for the execution of the function. I mean something like that: >> >> @is_logued_in >> def change_pass(): >> bla >> bla >> >> And so on for all the other functions who needs that the user is >> still loged in. >> >> where obviosly the is_logued_in() function will determine if the dude >> is still loged in, and THEN execute change_pass(). If the dude is not >> loged in, change_pass() is NOT executed at all. Instead, it will be >> redirected to the `login' screen. >> > > Are you developing a website or a GUI program? > > Laszlo > > It will be used in a web development. It is an important point? Gerardo -- http://mail.python.org/mailman/listinfo/python-list
advice about `correct' use of decorator
Hi all. I guess i have a conceptual question: Im planing using a quite simple decorator to be used as a conditional for the execution of the function. I mean something like that: @is_logued_in def change_pass(): bla bla And so on for all the other functions who needs that the user is still loged in. where obviosly the is_logued_in() function will determine if the dude is still loged in, and THEN execute change_pass(). If the dude is not loged in, change_pass() is NOT executed at all. Instead, it will be redirected to the `login' screen. Something in my mind tells me that this is not the pythonic way...But i like the idea, so please tell me that im in the right way :) Cheers. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me!!
Anhoter HURRA for list comprehensions: >>> a = ['a', 'b', 'c', 'd'] >>> b = ['a','c'] >>> [x in b and x.upper() or x for x in a] ['A', 'b', 'C', 'd'] Is what you want? Cheers Gerardo >I'm trying to compare the list with another list and if it is there in >both I'm changing it to upper case and adding to another list and if >its not there in both I just want to add it to the global list (ie >files). >I'm able to do the first part but when I'm doing the second part the >files which are not there in both are getting repeatedly into the >global file. Some one help me so that >If ab = [a,b,c,d] >and cd = [a,c] >my global list file should be [A,b,C,d] > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about properties.
king kikapu wrote: >On Aug 10, 1:33 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > >>On Fri, 10 Aug 2007 03:21:29 -0700, king kikapu wrote: >> >> >>>Hi, >>> >>> >>>i read in a book the following code snippet that is dealing with >>>properties: >>> >>> >>>class ProtectAndHideX(object): >>>def __init__(self, x): >>>assert isinstance(x, int), '"x" must be an integer!"' >>>self.__x = ~x >>> >>> >>>def get_x(self): >>>return ~self.__x >>> >>> >>>x = property(get_x) >>> >>> >>>Can anyone please help me understand what the symbol "~" does here ?? >>> >>> >>This has nothing to do with properties. For integer objects ``~`` is the >>bitwise negation or invertion operator. >> >>Ciao, >>Marc 'BlackJack' Rintsch >> >> > >Xmmm...ok then but what is actually doing there ?? I removed it and >things seems to work the same way... > > > I guess it is the `Hide' part of the Protectand*Hide* class. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
(May be OT) developing in jython, using in java?
Hi all. I dont know if this is the right place for asking this, but maybe some of you know where i must go. The thing is: Im writing a very simple class (in python) to access some LDAP server. A companion will access to the same LDAP server too, but his developing in java. So i said "ok, wait, i dont think we have to make the exact same thing twice! Let me see if jython can help us"I can find (after a quick review) an answer to this: "Can i, using jython, make a package so my companion can import that package as a webservice??" As im farly new in python, *very* new at Java, and *even newer* at jython, my brain just said to me "ok, i dont know, i want a beer", so maybe some of you can gide me to where i must go in order to clarify my ideas. Thanks!!! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: SQLObject 0.9.1
Oleg Broytmann wrote: >Hello! > >I'm pleased to announce the 0.9.1 release of SQLObject. > > >What is SQLObject >= > >SQLObject is an object-relational mapper. Your database tables are described >as classes, and rows are instances of those classes. SQLObject is meant to be >easy to use and quick to get started with. > >SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and >Firebird. It also has newly added support for Sybase, MSSQL and MaxDB (also >known as SAPDB). > > > > So..at 11:23 we got version 0.7.8...at 11:30 was version 0.8.5...now there is a 0.9.1 version?? Have a coffe dude, stop programming a little :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Delete a file from a CGI
When you execute a cgi, the program runs under the "apache user" (ussualy www or wwwrun or so), so THAT user needs permissions for deleting the file. Other approach could be suid'ing the cgi program. Gerardo >HI! > >I want to delete a file from a CGI, but I always get a Permission denied >error. > >I've tryed this after creating the file (from a normal script): > >os.chmod(".lock",stat.S_IMODE(stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG)) >os.chown(".lock",pwd.getpwnam("nobody")[2],pwd.getpwnam("nobody")[3]) > >but the CGI still can't delete the file. > >I will appreciate very much your help. > >Thanks a lot. > > > > -- http://mail.python.org/mailman/listinfo/python-list
using google search api for python
Hi all. Im looking for the pyGoogle for making google searchs y a python script. The thing is, all im founding is an AJAX api, but the application ill use is NOT a web app. So, someone know if there is a pure python api that i can download and use? Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
I25 barcode generator?
Hi. Im looking for an I25 barcode generator. I found a couple of nice EAN barcode generators, but this application needs an I25 barcode. Since this will be an web application, i need to do it in the server side. In python, off course :) Anybody knows one? Thanks! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
getting user id (from an arbitrary sys user)
hi all. What i need to know is if there is some function like os.getuid(), but taking an argument (the username, off course), so i can do getuid('myuser') Thanks you dudes! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
Re: list comprehension (searching for onliners)
You are the man, you are the man!! Yes, i need those dicts in order to assign them to a nested for the htmltmpl templating engine. Thats why i cant use the solution provided by Max, and thanks to Jon too!! Thanks a lot dudes, i hope someday ill turn myself into some of you guys who can actually answer questions ;) Gerardo >> result = [{'service_id' : 1, 'value': 10}, >> {'service_id': 2, 'value': 5}, >> {'service_id': 1, 'value': 15}, >> {'service_id': 2, 'value': 15}, >> ] >> >> and so on...what i need to do is some list comprehension that returns >> me something like >> >> result = [ >> { >> 'service_id' : 1, 'values': [ {'value': 10}, >> {'value': 15}] >> }, >> { >> 'service_id' : 2, 'values': [ {'value': 5}, {'value': 15}] >> } >> >> My problem now is i cant avoid have "repeteated" entries, lets say, >> in this particular case, 2 entries for "service_id = 1", and other 2 >> for "service_id =2". > > > Okay...while I'm not sure the opacity of a one-liner is actually > productive, it *can* be done. Whether it should, I leave that to your > discernment. :) > > >>> [{'service_id': i, 'values':[{'value':d2['value']} for d2 in > result if d2['service_id'] == i ]} for i in set(d['service_id'] for d > in result)] > > [{'service_id': 1, 'values': [{'value': 10}, {'value': 15}]}, > {'service_id': 2, 'values': [{'value': 5}, {'value': 15}]}] > > > There's no claiming it's efficient, as it looks like there may be some > O(N^2) logic going on under the hood (or possibly O(N*M) where N is > the size of the result-set and M is the count of unique service_id > values), as it's iterating over the result-set in two > dimensions...once to create the set of top-level indices, and once for > each result. > > If you didn't have to have all those dictionaries around, it might > come out more cleanly to just have some result-set that came out to be > > {1: [10,15], 2: [5,15]} > > Just a few thoughts... > > -tkc > > > > -- http://mail.python.org/mailman/listinfo/python-list
list comprehension (searching for onliners)
Hi all: I have this list thing as a result of a db.query: (short version) result = [{'service_id' : 1, 'value': 10}, {'service_id': 2, 'value': 5}, {'service_id': 1, 'value': 15}, {'service_id': 2, 'value': 15}, ] and so on...what i need to do is some list comprehension that returns me something like result = [ { 'service_id' : 1, 'values': [ {'value': 10}, {'value': 15}] }, { 'service_id' : 2, 'values': [ {'value': 5}, {'value': 15}] } My problem now is i cant avoid have "repeteated" entries, lets say, in this particular case, 2 entries for "service_id = 1", and other 2 for "service_id =2". Ill keeping blew off my hair and drinking more cofee while searching for this damn onliner im looking for. Thanks dudes. Gerardo -- http://mail.python.org/mailman/listinfo/python-list
plpython and pickle
Hi all, sory if this is kind of [OT], but cannot find the answer for this behaviour Im programming a db function using plpython...i have a db called 'sessions', and a postgres 8.1.2 database called 'test'. In 'sessions', i store several values in a `pickled' way so If a do """ You are now connected to database "sessions". sessions=# select * from getsessiondata('QQtEpLoKHnvbKGSpgJgYMPyCdHgXSi'); getsessiondata (dp0--ENTER--S---alucod-ENTER--p1--ENTER--S---32009436-ENTER--p2--ENTER--sS---respuestas_1-ENTER--p3--ENTER--S---3-ENTER--p4--ENTER--sS---respuestas_2-ENTER--p5--ENTER--S---2-ENTER--p6--ENTER--sS---respuestas_3-ENTER--p7--ENTER--S---4-ENTER--p8--ENTER--sS---submit-ENTER--p9--ENTER--S---Responder-ENTER--p10--ENTER--s. (1 row) """ Perfect. Thats what i spect to see. Now, if i do (in 'test' database) """ data = plpy.execute("SELECT * from dblink('dbname=sessions', 'select * from getsessiondata(\'\'%s\'\')') as t1(session_data name); " % session_id)[0]["session_data"]; plpy.notice(data) """ i got this NOTICE: ("'(dp0--ENTER--S---alucod-ENTER--p1--ENTER--S---32009436-'",) The pickled string as been truncated at some point, and when i try to unpickle it, i got error. Now, the question: What da hell can i do? -Postgresql 8.1.2 -Python 2.4.2 Im not even sure if this is a pickle, plpython nor postgresql issue, so im sory if this is [OT] here. Thanks!! Gerardo -- http://mail.python.org/mailman/listinfo/python-list
operator creation?
Hi all. Ill try to explain mi situation: Lets say i have an DB object, who implements the querys to the database trough a method called DBObject.doQuery. On the other hand, i have 50 sql functions stored in the database. So i can call DBObject.doQuery('select * from my_sql_function()')...Ok, what do i want to achieve, is some mecanism to be able to call DBObject.my_sql_function(), but without actually having to declare the method called "my_sql_function". May be with creating a `->' operator... maybe overrwriting the '.' operator... Im not shure. If someone understand my problem (and my poor english), please help :) Gerardo -- http://mail.python.org/mailman/listinfo/python-list