Twisted 100% event driven or hybrid?
I am diving into Twisted and Perspective Broker (PB) in particular. I am designing a system having several models running on different machines, they need to be recalculated periodically, I have to collect the results, process them and start again from the beginning. It is not clear to me if I can blend some event driven programming with a more traditional one where the flow would be deterministic. In my case I have to iterate on a list of models and send the request of recalculation to the specific machine where the model resides. I don’t want to wait for each single result but I want to sent all the requests in one go. In this phase I am happy to have an event driven framework with callbacks. Then I have to stop and wait for all the results to be ready, I collect and process them. From now on I don’t need a the system to be event drive any more, the processing should occur only on the master machine, following a deterministic flow. As soon as finished I am ready to start again to resubmit the models for recalculation and so on. This should go on forever. Is it possible to have an hybrid system like this? If I call reactor.spot() at the certain point of the execution where does the execution continue from? Would this be a good design or in general is better to keep a 100% event drive system even if I don’t actually need to handle asynchronicity for big chunks of the code. I would appreciate any suggestion and for the time being I recommend this doc, one of the clearest i have read so far. http://www.artima.com/weblogs/viewpost.jsp?thread=230001 Grazie, Jacopo -- http://mail.python.org/mailman/listinfo/python-list
Twisted: 1 thread in the reactor pattern
I am diving into Twisted and Perspective Broker (PB) in particular and I would like to understand more about what happens behind the curtains. Say I have a client and a server on two different machines, the server gets callRemote()’s in an asynchronous way, these requests are parked in a queue and then served sequentially (not in parallel – correct me if I am wrong). If everything is implemented in a single thread, how is it possible that while the processor is engaged in the processing triggered by callRemote()’s at the same time the reactor is ready to listen/accept new events and put them in a queue? To me it looks like there should be at least 2 processes, one for the reactor and on for the rest. In the documentation they keep stressing how one of the peculiarity of the reactor pattern is the single thread, but I can not figure out how. Any suggestion would be welcome. For the time being I recommend this doc which has been the most useful to me so far. http://www.artima.com/weblogs/viewpost.jsp?thread=230001 Thanks, Jacopo -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging question
Gabor Urban schrieb: Hi guys, I have embarassing problem using the logging module. I would like to encapsulate the creation and setting up of the logger in a class, but it does not seem working. Here are my relevant parts of the code: -- import sys import logging class LogClass: def __init__(self, fileName, loggerName = 'classLog'): self.Logger = logging.getLogger(loggerName) self.traceName = fileName handler = logging.FileHandler(self.traceName,'a') formatter = logging.Formatter(%(name)s %(asctime)s %(filename)s %(lineno)d %(levelname)s %(message)s) handler.setFormatter(formatter) self.Logger.addHandler(handler) self.Handler = handler def closeLog(self): self.Handler.flush() self.Handler.close() def fetchLogger(self): return self.Logger if __name__ == __main__: name = 'testlog.trc' classLog = LogClass(name) logger = classLog.fetchLogger() logger.info(Created) logger.debug(Test) logger.info(Created .. ) logger.debug(Test data) classLog.closeLog() -- The trace file is created properly but contains no lines at all. If I put the code directly in __main__, it works fine. What did I miss? Any ideas are wellcome. That the default level is less than INFO - if you set that to e.g. logging.DEBUG. However, I think there are a few problems here beside that. For once, reading PEP8 might be worth considering. And the logging-module is written so that setting it up using it are de-coupled. Which you foil here somewhat. What is the above supposed to do? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Very simple finite automaton (?)
On Tue, 22 Sep 2009 22:24:28 -0700, kpp9c wrote: I am trying to use a table (called a transition table? i dunno) to define a bunch of moves like so: 1 -- 2 5 2 -- 1 4 3 -- 3 4 -- 1 5 -- 4 3 so that i can generate a sequence that, given an initial value, will continue to grow according to these rules. ... First, I would like to know what, precisely, this kind of process is called so that i can look it up. Many names are suggested but when googling more names and acronyms show up, maybe there are many names used for a variety of related things, but I could be curious to know exactly what this is an instance of. No idea, sorry :) Second, I am not sure how to get started with the loop (is this an example of recursion?) and how best to represent the table (dictionary)? If anyone has an example of how to do this or a suggestion on where to start poking around, that would be great. Start with a set of rules: rules = {1: (2, 5), 2: (1, 4), 3: (3,), 4: (1,), 5: (4, 3)} There are lots of ways to go from here, possibly including recursion, but this is the way that feels most natural to me. Create a generator that applies the rules from some input sequence: def apply_rules(sequence): for element in sequence: # look it up in the global rules values = rules[element] # yield each of those in turn for value in values: yield value And now use it to build new lists, replacing the old list each time. Here it is in use: data = [1] for i in range(5): ... print data ... gen = apply_rules(data) ... data = list(gen) ... [1] [2, 5] [1, 4, 4, 3] [2, 5, 1, 1, 3] [1, 4, 4, 3, 2, 5, 2, 5, 3] print data # one more to get the final result [2, 5, 1, 1, 3, 1, 4, 4, 3, 1, 4, 4, 3, 3] -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Very simple finite automaton (?)
kpp9c schrieb: Very simple finite automaton (?) I am not sure if this is and example of Finite Automaton or a Finite State Machine or perhaps it is related to a transition table or markov process. I am not a math person so i am not sure what it is called. I googled around and got lots of super complicated gobbledegoo all with knotty regex stuff, but what i want to do is much more simple. I am trying to use a table (called a transition table? i dunno) to define a bunch of moves like so: 1 -- 2 5 2 -- 1 4 3 -- 3 4 -- 1 5 -- 4 3 so that i can generate a sequence that, given an initial value, will continue to grow according to these rules. So starting with 1, we get: 1 2 5 1 4 4 3 2 5 1 1 3 1 4 4 3 2 5 2 5 3 . etc. Essentially, iterating over the last added items to the list, applying the table, adding those new items to the list, applying the table again... etc, until the sequence reaches some predetermined number of iterations and quits. What you show as example and what you describe here differ - the above example shows replacements, while you *talk* about adding. [ [1], [2, 5], [1, 4] , [4, 3], [2, 5], [1], [1], [3], [1, 4], [4, 3], [2, 5], [2, 5], [3] ] First, I would like to know what, precisely, this kind of process is called so that i can look it up. Many names are suggested but when googling more names and acronyms show up, maybe there are many names used for a variety of related things, but I could be curious to know exactly what this is an instance of. Second, I am not sure how to get started with the loop (is this an example of recursion?) and how best to represent the table (dictionary)? If anyone has an example of how to do this or a suggestion on where to start poking around, that would be great. It sure isn't a finite automaton. The things it reminds me of are these: http://en.wikipedia.org/wiki/Context-sensitive_grammar http://en.wikipedia.org/wiki/L-system This is under the assumption you mean replacment, not adding. Diez -- http://mail.python.org/mailman/listinfo/python-list
Looking for Python Developers in Jakarta, Indonesia
Responsibilities: You will be part of a team responsible for implementing and supporting a Google App Engine based application. Requirements: Professional: University bachelor's degree in computer science or related discipline (web development, design, relevant computer languages and software applications) Python - Experience working in a web framework: Django or GAE (Google App Engine) preferred. Source Control Experience (Branching, merging, conflict resolution). - Knowledge and experience with unit testing and testing concepts. Other Skills: * Able to work in a fast paced environment, and quickly produce deliverables. * Able to communicate effectively with both technical and non- technical staff. * Able to work independently with minimal supervision. If you have a blog, bitbucket, github or google code repository/ opensource or other interesting projects that you feel may be relevant to you application, please provide links for review. We thank all candidates for their interest however only those selected for an interview will be contacted. Contact: kugutsumen+j...@gmail.com -- http://mail.python.org/mailman/listinfo/python-list
ARP Request/reply in Python
Hello all. I want check Mac Address Client on network which alive help me please. Thanks. _ ด้วย Windows Live คุณสามารถจัดการ แก้ไข และแบ่งปันภาพถ่ายของคุณ http://www.microsoft.com/thailand/windows/windowslive/products/photo-gallery-edit.aspx-- http://mail.python.org/mailman/listinfo/python-list
Re: easy question, how to double a variable
On Mon, 21 Sep 2009 21:49:50 +0100, daggerdvm dagger...@yahoo.com wrote: you brain needs error checking! Your post, by contrast, needs grammar checking. -- Rhodri James *-* Wildebeest Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list
Read header and data from a binary file [LONG]
Hello, I want to read from a binary file called myaudio.dat Then I've tried the next code: import struct name = myaudio.dat f = open(name,'rb') f.seek(0) chain = 4s 4s I 4s I 20s I I i 4s I 67s s 4s I s = f.read(4*1+4*1+4*1+4*1+4*1+20*1+4*1+4*1+4*1+4*1+4*1+67*1+1+4*1+4*1) a = struct.unpack(chain, s) header = {'identifier' : a[0], 'cid' : a[1], 'clength' : a[2], 'hident' : a[3], 'hcid32' : a[4], 'hdate' : a[5], 'sampling' : a[6], 'length_B' : a[7], 'max_cA' : a[8], 'max_cA1' : a[9], 'identNOTE' : a[10], 'c2len' : a[11],} It produces: {'length_B': 150001, 'sampling': 5, 'max_cA1': 'NOTE', 'hident': 'HEDR', 'c2len': Normal Sustained Vowel 'A', Voice and Speech Lab., MEEI, Boston, MA, 'hdate': 'Jul 13 11:57:41 1994', 'identNOTE': 68, 'max_cA': -44076, 'cid': 'DS16', 'hcid32': 32, 'identifier': 'FORM', 'clength': 300126} So far when I run f.tell() f.tell() 136L The audio data length is 300126, now I need a clue to build an array with the audio data (The Chunk SDA_), would it possible with struct?, any help ? Thanks The file format is: Offset | Length | Type |Contents 0 4character Identifier: FORM 4 4character Chunk identifier: DS16 8 4integer Chunk length 12 - - Chunk data Header 2 Offset Length Type Contents 0 4 character Identifier: HEDR or HDR8 4 4 integer Chunk length (32) 8 20 character Date, e.g. May 26 23:57:43 1995 28 4 integer Sampling rate 32 4 integer Data length (bytes) 36 2 unsigned integer Maximum absolute value for channel A: 0x if not defined 38 2 unsigned integer Maximum absolute value for channel A: 0x if not defined NOTE Chunk Offset Length Type Contents 0 4 character Identifier: NOTE 4 4 integer Chunk length 8 - character Comment string SDA_, SD_A or SDAB Chunk Offset Length Type Contents 0 4 character Identifier: SDA_, SD_B, or SDAB 4 4 integer Chunk length 8 - - Data -- http://mail.python.org/mailman/listinfo/python-list
Re: custom data warehouse in python vs. out-of-the-box ETL tool
snfctech wrote: Does anyone have experience building a data warehouse in python? Any thoughts on custom vs using an out-of-the-box product like Talend or Informatica? I have an integrated system Dashboard project that I was going to build using cross-vendor joins on existing DBs, but I keep hearing that a data warehouse is the way to go. e.g. I want to create orders and order_items with relations to members (MS Access DB), products (flat file) and employees (MySQL). Thanks in advance for any tips. My experience is that if you enjoy hacking around databases and are proficient in Python, than for small scale solutions it is preferable to do it yourself. If you need a large scale solutions with advanced requirements, building it yourself is mostly the only way. I have build a rather complex datawarehouse system in the past (well actually more like a centralised synchronisation hub, having input and reporting databases as satellite clients), shoving data from around 500 databases (typically 5 Gb in size each) spread over the world. The only commercial solutions I reviewed was Business Objects Data Integrator and Oracle Warehouse Builder. These tools where quite flexible and if you already have a license deal which includes these tools I would definitely recommend to have more than just a look at it. If not and you are comfortably with using python to shovel data from A to B and transform it at the same time (moving relational data automatically into a EAV model and back again, for example) than building your own solution will probably save you money and time (as opposed to learn how to use that ETL tool). This will require you to have at least interest in the following subjects: - Authorization, may everybody use all data or should it be limited to a subset on the data depending on the data? (My solution was one centralised hub which contains all data but is only accessible to special 'client' servers strictly maintained by me which only sync the data relevant to them). - Authenticity, if you have different values for the same thing, which one should be considered authoritative and if yes may it be pushed back to the un-authoritative? -Synchronisation, you really don't want to push/pull all of the database content over every x times, so how can you delta it and is there a way to do this only when the data changes (push vs pull)? -ATOMIC, how long may the data be out of date and is it allowed to partially update -Using and maintaining multiple databases, hopefully spread over multiple systems. I had a server for each production DB, a server that mirrored that production DB with some added columns per table for external synchronization purposes and a master synchronisation server (so in essence all data was copied three times, not very efficient but good if you like to play it on the safe side). -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
Re: difficulty in understanding rsplit(None,1)[1]
On Sep 22, 7:10 pm, hrishy hris...@yahoo.co.uk wrote: Hi Martin Many thanks And by the way great way to explain that thing great way to find out for yourself faster than waiting for a response from the internet ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: easy question, how to double a variable
On Tue, 22 Sep 2009 07:41:11 -0700, Hyuga wrote: Forget ethical. We can do his homework for him, we can perhaps pass exams for him, maybe graduate for him, and then with our luck, he'll get a job in our office and we get to do his work for him. No, no, no. The plan is to do his homework for him so that he's incompetent when he graduates and won't be competition for the rest of us who did do our homework. Well, while they may not be as much competition come promotion time, I think Mr. Finney had it right that these people *do* still somehow get hired ... It was Mel Wilson, not Ben Finney, who write the paragraph starting with Forget ethical. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
delete items from list by indices
Hi, I have some list: x = [8, 9, 1, 7] and list of indices I want to delete from x: indices_to_delete = [0, 3], so after deletion x must be equal to [9, 1]. What is the fastest way to do this? Is there any builtin? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: delete items from list by indices
On Wed, Sep 23, 2009 at 1:25 AM, blumenkraft vohs...@gmail.com wrote: Hi, I have some list: x = [8, 9, 1, 7] and list of indices I want to delete from x: indices_to_delete = [0, 3], so after deletion x must be equal to [9, 1]. What is the fastest way to do this? Is there any builtin? #untested unbenchmarked since it's 1am offset = 0 for index in indices_to_delete: del x[index-offset] offset += 1 Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: delete items from list by indices
blumenkraft wrote: I have some list: x = [8, 9, 1, 7] and list of indices I want to delete from x: indices_to_delete = [0, 3], so after deletion x must be equal to [9, 1]. What is the fastest way to do this? Is there any builtin? Why's that obsession with speed? items = [a, b, c, d] delenda = [0, 3] for i in sorted(delenda, reverse=True): ... del items[i] ... items ['b', 'c'] items = [a, b, c, d] delenda = set([0, 3]) items = [item for index, item in enumerate(items) if index not in delenda] items ['b', 'c'] If you really need to modify the list in place change items = [item for ...] to items[:] = [item for ...] Try these and come back to complain if any of the above slows down your script significantly... Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: custom data warehouse in python vs. out-of-the-box ETL tool
snfctech wrote: Does anyone have experience building a data warehouse in python? Any thoughts on custom vs using an out-of-the-box product like Talend or Informatica? I have an integrated system Dashboard project that I was going to build using cross-vendor joins on existing DBs, but I keep hearing that a data warehouse is the way to go. e.g. I want to create orders and order_items with relations to members (MS Access DB), products (flat file) and employees (MySQL). Thanks in advance for any tips. You might want to look at this solution for doing cross-database JOINs: EasySoft ODBC Join-Engine: http://www.easysoft.com/products/data_access/odbc_odbc_join_engine/index.html and then use our mxODBC to access EasySoft's Engine: http://www.egenix.com/products/python/mxODBC/ or mxODBC Connect, if you have a client-server setup: http://www.egenix.com/products/python/mxODBCConnect/ Some database engines also allow integrating external ODBC data sources - the external tables then look like normal database tables and can be used in JOINs as well. I know that DB2 and Oracle support this kind of setup. You can access those using mxODBC as well. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 23 2009) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: delete items from list by indices
Hi 2009/9/23 blumenkraft vohs...@gmail.com: Hi, I have some list: x = [8, 9, 1, 7] and list of indices I want to delete from x: indices_to_delete = [0, 3], so after deletion x must be equal to [9, 1]. What is the fastest way to do this? Is there any builtin? Try this- x = [8, 9, 1, 7] [x.pop(i) for i in sorted(indices_to_delete,reverse=True)] [7, 8] x [9, 1] Built-in used here is `sorted' and method on list used here is `pop'. With regards to efficiency you may want to use the methods of list which is more intuitive afaik and useful as its more reflective of effect on the type list. It's a trivial choice here but later it might help. -- Regards, Ishwor Gurung -- http://mail.python.org/mailman/listinfo/python-list
Re: delete items from list by indices
On 23 сен, 12:48, Peter Otten __pete...@web.de wrote: blumenkraft wrote: I have some list: x = [8, 9, 1, 7] and list of indices I want to delete from x: indices_to_delete = [0, 3], so after deletion x must be equal to [9, 1]. What is the fastest way to do this? Is there any builtin? Why's that obsession with speed? items = [a, b, c, d] delenda = [0, 3] for i in sorted(delenda, reverse=True): ... del items[i] ... items ['b', 'c'] items = [a, b, c, d] delenda = set([0, 3]) items = [item for index, item in enumerate(items) if index not in delenda] items ['b', 'c'] If you really need to modify the list in place change items = [item for ...] to items[:] = [item for ...] Try these and come back to complain if any of the above slows down your script significantly... Peter Thanks, it helped (I didn't know about keyword argument reverse in sorted function) -- http://mail.python.org/mailman/listinfo/python-list
Re: custom data warehouse in python vs. out-of-the-box ETL tool
snfctech wrote: Thanks for your replies, Sean and Martin. I agree that the ETL tools are complex in themselves, and I may as well spend that learning curve on a lower-level tool-set that has the added value of greater flexibility. Can you suggest a good book or tutorial to help me build a data warehouse in python? Bill Inmon's Building the Data Warehouse is 17 years old, and I've been cautioned against Kimball. Thanks. cut Data warehouse isn't something magical, it is just another database, albeit containing multiple datasets gathered from foreign resources in possibly multiple formats. Depending on your purpose of what you want, you design your tables the way you usually do. For example if you only want reporting, you might want to build your tables in such a way so it makes your life easier to build the actual report. Now you have an empty database containing the fields you wish for the report and have filled database(s) containing data from the user application. Now you use Python to fill the empty database, tada, you have a Data warehouse and used Python for ETL processing. So if you already have some insights in creating tables in a database, you are all set. Most likely you will go through a number of iterations before you are happy with the result though. There is no book substitute for applying theory, experience and common sense to a problem you want to solve, unless you write it yourself for that specific situation. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
Re: Q on explicitly calling file.close
except: return 0 So wrong on so many levels... -- http://mail.python.org/mailman/listinfo/python-list
TestFixtures 1.6.2 released!
Hi All, I'm pleased to announce a new release of TestFixtures. This package is a collection of helpers and mock objects that are useful when writing unit tests or doc tests. This release fixes problems when using Comparison objects with instances of Django models, so tests like the following will now work as expected: from testfixtures import Comparison as C,compare class TestUser(TestCase): def test_create(self): u = User(name='Test') u.save() t = User.objects.get(name='Test') compare([C(User,name='Test',strict=False)], list(User.objects.all())) To find out more, please read here: http://pypi.python.org/pypi/testfixtures cheers, Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: DBHandler class for logging?
See my answer to a question on Stack Overflow, which has the source code for a simple handler which writes to a database using the Python DB-API 2.0: http://stackoverflow.com/questions/935930/creating-a-logging-handler-to-connect-to-oracle/1014450#1014450 Although the question relates to Oracle, my answer is not so specific. It's not production quality code but it should get you started. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging question
On Sep 23, 6:36 am, Gabor Urban urbang...@gmail.com wrote: Hi guys, I have embarassing problem using theloggingmodule. I would like to encapsulate the creation and setting up of the logger in a class, but it does not seem working. Here are my relevant parts of the code: -- [snip] I'm not sure why you need to do this. Diez's reply tells you why you don't see any output, but your code may also lead to other problems. For example, if you create two LogClass instances with loggerName values of A and A.B, then any call to logger A.B will lead to two messages in the log. That's because when a call to A.B is handled, then it is passed to all handlers associated not only with logger A.B but also A (its parent logger) and the root logger (its grandparent). Since you have two FileHandlers configured (one for A.B and one for A), the message will end up appearing in two files (or the same file, if you used the same filename for both ClassLog instantiations). It's generally suspicious when you see someone trying to instantiate a logger and adding a handler at the same time, as you're doing. The reason this is a potential anti-pattern is that, other than for trivial scripts, there isn't a natural one-to-one mapping between loggers and handlers. Loggers (defined by their names, as in A.B) define areas of an application organized hierarchically (and answer the question about a logging event, Where did it happen?) whereas handlers are about who's interested in those events, i.e. potential log readers - they are generally organized according to the answer to the question about a logging event, Who wants to know?. In trivial or command-line scripts, there's often just a one-to-one mapping (root logger - console) or one-to-two (root logger - console and file) but once your application gets more complex, then you usually have a good few loggers (based on application areas) but just a few handlers (e.g. one log file for everything, one log file for errors, console, and one or two email handlers). Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: easy question, how to double a variable
On Sep 22, 9:57 am, Grant Edwards inva...@invalid.invalid wrote: No, no, no. The plan is to do his homework for him so that he's incompetent when he graduates and won't be competition for the rest of us who did do our homework. Don't forget the Peter principal --- we might end up working for him! Btw, I can't believe nobody provided the simplest literal solution: def twice(i): return i, i -- http://mail.python.org/mailman/listinfo/python-list
Re: Very simple finite automaton (?)
It seems to that you have a transformational grammar. Gerry On Sep 23, 3:18 am, Diez B. Roggisch de...@nospam.web.de wrote: kpp9c schrieb: Very simple finite automaton (?) I am not sure if this is and example of Finite Automaton or a Finite State Machine or perhaps it is related to a transition table or markov process. I am not a math person so i am not sure what it is called. I googled around and got lots of super complicated gobbledegoo all with knotty regex stuff, but what i want to do is much more simple. I am trying to use a table (called a transition table? i dunno) to define a bunch of moves like so: 1 -- 2 5 2 -- 1 4 3 -- 3 4 -- 1 5 -- 4 3 so that i can generate a sequence that, given an initial value, will continue to grow according to these rules. So starting with 1, we get: 1 2 5 1 4 4 3 2 5 1 1 3 1 4 4 3 2 5 2 5 3 . etc. Essentially, iterating over the last added items to the list, applying the table, adding those new items to the list, applying the table again... etc, until the sequence reaches some predetermined number of iterations and quits. What you show as example and what you describe here differ - the above example shows replacements, while you *talk* about adding. [ [1], [2, 5], [1, 4] , [4, 3], [2, 5], [1], [1], [3], [1, 4], [4, 3], [2, 5], [2, 5], [3] ] First, I would like to know what, precisely, this kind of process is called so that i can look it up. Many names are suggested but when googling more names and acronyms show up, maybe there are many names used for a variety of related things, but I could be curious to know exactly what this is an instance of. Second, I am not sure how to get started with the loop (is this an example of recursion?) and how best to represent the table (dictionary)? If anyone has an example of how to do this or a suggestion on where to start poking around, that would be great. It sure isn't a finite automaton. The things it reminds me of are these: http://en.wikipedia.org/wiki/Context-sensitive_grammar http://en.wikipedia.org/wiki/L-system This is under the assumption you mean replacment, not adding. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging question
Gabor Urban wrote: Hi guys, I have embarassing problem using the logging module. I would like to encapsulate the creation and setting up of the logger in a class, but it does not seem working. Here are my relevant parts of the code: -- import sys import logging class LogClass: def __init__(self, fileName, loggerName = 'classLog'): self.Logger = logging.getLogger(loggerName) self.traceName = fileName handler = logging.FileHandler(self.traceName,'a') formatter = logging.Formatter(%(name)s %(asctime)s %(filename)s %(lineno)d %(levelname)s %(message)s) handler.setFormatter(formatter) self.Logger.addHandler(handler) self.Handler = handler def closeLog(self): self.Handler.flush() self.Handler.close() def fetchLogger(self): return self.Logger if __name__ == __main__: name = 'testlog.trc' classLog = LogClass(name) logger = classLog.fetchLogger() logger.info(Created) logger.debug(Test) logger.info(Created .. ) logger.debug(Test data) classLog.closeLog() -- The trace file is created properly but contains no lines at all. If I put the code directly in __main__, it works fine. What did I miss? Any ideas are wellcome. Gabor As pointed out you should definitely split the logger creation from its configuration, here are my 2 cents: import logging _LOGGER_NAME = 'foo' class MyFileHandler(logging.FileHandler): FORMAT = '%(name)s %(asctime)s %(filename)s %(lineno)d %(levelname)s %(message)s' def __init__(self, fileName): logging.FileHandler.__init__(self, fileName, 'a') self.setFormatter(logging.Formatter(self.FORMAT)) if __name__ == '__main__': # split creation from configuration # creation logger = logging.getLogger(_LOGGER_NAME) # configuration logger.addHandler(MyFileHandler('anyfile.tmp')) logger.setLevel(logging.DEBUG) logger.info('bar') I personally use the following pattern: In any submodule moduleA.py of an application: import MyApp _logger = logging.getLogger(MyApp.logger.name + '.moduleA') # attach my logger to MyApp logger # Configuration : nothing to be done, relies on MyApp configuration logger # You can add code in case you are executing your module in standalone mode (for unit testing for instance) if __name__ == '__main__': _logger = logging.getLogger('moduleA') _logger.addHandler(logging.FileHandler('moduleA.test','a')) # here is some unit tests Jean-Michel -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging question
On Sep 23, 2:46 pm, Jean-Michel Pichavant jeanmic...@sequans.com wrote: I personally use the following pattern: In any submodule moduleA.py of an application: import MyApp _logger =logging.getLogger(MyApp.logger.name + '.moduleA') # attach my logger to MyApp logger It's also common to use the pattern logger = logging.getLogger(__name__) which will use the name of the module for a logger name, correctly getting the name of subpackages and submodules when used therein. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Read header and data from a binary file [LONG]
Jose, Hi Note: I've worked with struct but a while ago so might be rusty a bit. Also, this sounds a bit like a homework. If it is a homework please do it yourself(or at least try) as you'd otherwise never know the knowledge behind it on real-world scenario :-) Having said that I am giving you below an example on top of my reply. import struct name = myaudio.dat f = open(name,'rb') f.seek(0) f.seek(0) line is not explicitly needed afaik but you can if you want to. chain = 4s 4s I 4s I 20s I I i 4s I 67s s 4s I s = f.read(4*1+4*1+4*1+4*1+4*1+20* 1+4*1+4*1+4*1+4*1+4*1+67*1+1+4*1+4*1) which is 136 bytes. a = struct.unpack(chain, s) Yep. little-endian ordering pack 136 bytes of `s' in `a' according to chain. header = {'identifier' : a[0], 'cid' : a[1], 'clength' : a[2], 'hident' : a[3], 'hcid32' : a[4], 'hdate' : a[5], 'sampling' : a[6], 'length_B' : a[7], 'max_cA' : a[8], 'max_cA1' : a[9], 'identNOTE' : a[10], 'c2len' : a[11],} It produces: {'length_B': 150001, 'sampling': 5, 'max_cA1': 'NOTE', 'hident': 'HEDR', 'c2len': Normal Sustained Vowel 'A', Voice and Speech Lab., MEEI, Boston, MA, 'hdate': 'Jul 13 11:57:41 1994', 'identNOTE': 68, 'max_cA': -44076, 'cid': 'DS16', 'hcid32': 32, 'identifier': 'FORM', 'clength': 300126} So far when I run f.tell() f.tell() 136L tell( ) gives you current position of the file descriptor (you read 136 bytes so tell( ) says that you read in 136 so far as the position of the current file descriptor or position in the binary file). The audio data length is 300126, now I need a clue to build an array with the audio data (The Chunk SDA_), would it possible with struct?, any help ? clength above is 300126. Maybe you can use that to get Data? :-) SDA_'s format: does it mean it starts at offset 8 bytes-EOF? If it starts at 8 bytes after the header then what is stored in between the lengthOf(header)+8? In anycase, as I understand, to get all the values from the offset 8(called `Data' as per your protocol spec), you can do: reading_after_136_file_pos_to_eof = f.read(); #continue from 136L above. clen_fs = '%ds' % clength; # I assume here that is a character x = struct.unpack(clen_fs, reading_after_136_file_pos_to_eof [8:]); #start at index 8 onwards Now, `x' will have stored unpacked value of the reading_after_136_file_pos_to_eof starting from 8'th byte and wil only store 300126 bytes of characters (1 byte each so 300136 bytes long) i.e., starting from 8'th byte file descriptor position assuming each char is 1 bytes long on Python (as per struct modules' definition) [ ... ] -- Regards, Ishwor Gurung -- http://mail.python.org/mailman/listinfo/python-list
Re: easy question, how to double a variable
On Sep 23, 2009, at 8:15 , Casey Webster wrote: Btw, I can't believe nobody provided the simplest literal solution: def twice(i): return i, i -- or this one, which is possibly even more literal: def twice(p): return an int that is twice the value of the parameter twice(an int parameter) -- Brian Blais bbl...@bryant.edu http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
Re: Read header and data from a binary file [LONG]
char is 1 bytes long on Python (as per struct modules' definition) Also, this is also another option for you to use instead of built-in struct. http://www.sis.nl/python/xstruct/xstruct.shtml -- Regards, Ishwor Gurung -- http://mail.python.org/mailman/listinfo/python-list
Re: Twisted 100% event driven or hybrid?
On 05:55 am, jacopo.pe...@gmail.com wrote: I am diving into Twisted and Perspective Broker (PB) in particular. I am designing a system having several models running on different machines, they need to be recalculated periodically, I have to collect the results, process them and start again from the beginning. It is not clear to me if I can blend some event driven programming with a more traditional one where the flow would be deterministic. In my case I have to iterate on a list of models and send the request of recalculation to the specific machine where the model resides. I don 19t want to wait for each single result but I want to sent all the requests in one go. In this phase I am happy to have an event driven framework with callbacks. Then I have to stop and wait for all the results to be ready, I collect and process them. From now on I don 19t need a the system to be event drive any more, the processing should occur only on the master machine, following a deterministic flow. As soon as finished I am ready to start again to resubmit the models for recalculation and so on. This should go on forever. Is it possible to have an hybrid system like this? If I call reactor.spot() at the certain point of the execution where does the execution continue from? Would this be a good design or in general is better to keep a 100% event drive system even if I don 19t actually need to handle asynchronicity for big chunks of the code. If you're happy to block event processing, then there's no reason you can't do just that - once you have your results, start processing them in a blocking manner. Twisted will not service events while you're doing this, but as long as you're happy with that, it doesn't really matter to Twisted. You might not be as happy with this later on if your requirements change, but you can always worry about that later. In particular, though, there's no reason or need to call reactor.stop() in order to switch to your non-event driven code. Wherever you were thinking of putting that call, just put your non-event driven code there instead. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Solved - Python: automate input to MySQL query
On Tue, 22 Sep 2009 22:36:15 -0700 Dennis Lee Bieber wlfr...@ix.netcom.com wrote: I wasn't really referring to the table used as a qualifier (in front of the .). But in your sample statement, every /field/ name seemed to contain the table name too... traveler.travelerFirstName rather than being just traveler.FirstName I do that all the time. Many of my tables have an ID, an active flag and other fields such as first name like this example. Putting the table name into the field name simplifies joins. Consider the following (untested) code. from pg import DB # PyGreSQL db = DB() # uses my default PostgeSQL database res = db.query( SELECT * FROM employee, manager WHERE manager.id = employee.id).dictresult() print res[0]['id'] # is this the employee's ID or the manager's? print res[0]['firstname'] # same question Of course you can get around this by specifying every field and using AS to change the names to manager_id and employee_firstname, etc. but if you are going to do that anyway, why not just do it once in the database instead of littering the code? In my databases I make sure that every field name is unique across all tables unless the field actually refers the the same item (i.e. joining field) so that I never have an accident. My manager table would have a manager_id and the employee table would have an employee_id. The employee table would also have a manager_id but it is not a different field. It's the same field as in the manager table. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: Twisted: 1 thread in the reactor pattern
On 06:08 am, jacopo.pe...@gmail.com wrote: I am diving into Twisted and Perspective Broker (PB) in particular and I would like to understand more about what happens behind the curtains. Say I have a client and a server on two different machines, the server gets callRemote() 19s in an asynchronous way, these requests are parked in a queue and then served sequentially (not in parallel 13 correct me if I am wrong). Since, as you point out below, there is only one thread, the remote methods can only be invoked one at a time. However, rather central to the asynchronous operation of Twisted libraries and applications, the remote method itself may return before the remote call has been completely serviced. So while only one remote method will run at a time, each of the two remote calls may run concurrently at some point before they are responded to. If everything is implemented in a single thread, how is it possible that while the processor is engaged in the processing triggered by callRemote() 19s at the same time the reactor is ready to listen/accept new events and put them in a queue? To me it looks like there should be at least 2 processes, one for the reactor and on for the rest. It isn't possible. While the remote methods are running, other events are not being serviced. This is what is meant when people describe Twisted as a *cooperative* multitasking system. Event handlers (such as remote methods) run for a short enough period of time that it doesn't matter that the reactor is prevented from accepting new connections (or what have you) for the duration of their execution. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Copy directory tree without copying files
I am trying to copy a folder hierarchy from one location to another. I can use the shutil.copytree function to copy the folder tree, but I don't want the files copied, just the folders. What is a good way to approach this? Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy directory tree without copying files
Jeremy Conlin wrote: I am trying to copy a folder hierarchy from one location to another. I can use the shutil.copytree function to copy the folder tree, but I don't want the files copied, just the folders. What is a good way to approach this? Thanks, Jeremy Use os.walk and create the directories as they appear? TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy directory tree without copying files
Have you considered using os.walk? http://docs.python.org/library/os.html#os.walk It won't be completely automated, but I think it should allow you to easily walk the directory structure to reproduce it in another location. If the file names/extensions are predictable you might also be able to use the ignore attribute in the shutil.copytree function to prevent copying files: http://docs.python.org/library/shutil.html#shutil.copytree Daniel On Sep 23, 9:04 am, Jeremy Conlin jlcon...@gmail.com wrote: I am trying to copy a folder hierarchy from one location to another. I can use the shutil.copytree function to copy the folder tree, but I don't want the files copied, just the folders. What is a good way to approach this? Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy directory tree without copying files
On Sep 23, 9:15 am, Tim Golden m...@timgolden.me.uk wrote: Jeremy Conlin wrote: I am trying to copy a folder hierarchy from one location to another. I can use the shutil.copytree function to copy the folder tree, but I don't want the files copied, just the folders. What is a good way to approach this? Thanks, Jeremy Use os.walk and create the directories as they appear? TJG I was hoping to use os.walk, but this doesn't work because I wont know when os.walk descends into a new directory or which directory it descends into. Perhaps I don't understand everything about it. Thanks, Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy directory tree without copying files
Jeremy Conlin wrote: On Sep 23, 9:15 am, Tim Golden m...@timgolden.me.uk wrote: Jeremy Conlin wrote: I am trying to copy a folder hierarchy from one location to another. I can use the shutil.copytree function to copy the folder tree, but I don't want the files copied, just the folders. What is a good way to approach this? Thanks, Jeremy Use os.walk and create the directories as they appear? TJG I was hoping to use os.walk, but this doesn't work because I wont know when os.walk descends into a new directory or which directory it descends into. Perhaps I don't understand everything about it. Some rough but working code might help you out here: code import os source_dir = c:/temp/oldtree target_dir = c:/temp/newtree # should not exist yet for dirpath, dirnames, filenames in os.walk (source_dir): os.mkdir (os.path.join (target_dir, dirpath[1+len (source_dir):])) os.startfile (target_dir) /code TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy directory tree without copying files
Jeremy Conlin wrote: I am trying to copy a folder hierarchy from one location to another. I can use the shutil.copytree function to copy the folder tree, but I don't want the files copied, just the folders. What is a good way to approach this? The easiest is def ignore(folder, names): return set(n for n in names if not os.path.isdir(os.path.join(folder, n))) shutil.copytree(source, dest, ignore=ignore) Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy directory tree without copying files
On Sep 23, 9:15 am, dwatrous daniel.watr...@gmail.com wrote: Have you considered using os.walk?http://docs.python.org/library/os.html#os.walk It won't be completely automated, but I think it should allow you to easily walk the directory structure to reproduce it in another location. If the file names/extensions are predictable you might also be able to use the ignore attribute in the shutil.copytree function to prevent copying files:http://docs.python.org/library/shutil.html#shutil.copytree Daniel Thanks, that helps. I could write a function like def ignore_files(dirpath): ignore = [] for f in os.listdir(dirpath) if os.path.isfile(f): ignore.append(f) return ignore That seems like it will work (haven't tested yet). Thanks for the help. Jeremy -- http://mail.python.org/mailman/listinfo/python-list
cleanup in sys.excepthook?
hello, my script creates files that i need to delete if an exception is thrown. is this a good pythonic style to do this kind of cleanup in sys.excepthook instead of inside except clause of a try block? konstantin -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy directory tree without copying files
On Sep 23, 9:31 am, Tim Golden m...@timgolden.me.uk wrote: Jeremy Conlin wrote: On Sep 23, 9:15 am, Tim Golden m...@timgolden.me.uk wrote: Jeremy Conlin wrote: I am trying to copy a folder hierarchy from one location to another. I can use the shutil.copytree function to copy the folder tree, but I don't want the files copied, just the folders. What is a good way to approach this? Thanks, Jeremy Use os.walk and create the directories as they appear? TJG I was hoping to use os.walk, but this doesn't work because I wont know when os.walk descends into a new directory or which directory it descends into. Perhaps I don't understand everything about it. Some rough but working code might help you out here: code import os source_dir = c:/temp/oldtree target_dir = c:/temp/newtree # should not exist yet for dirpath, dirnames, filenames in os.walk (source_dir): os.mkdir (os.path.join (target_dir, dirpath[1+len (source_dir):])) os.startfile (target_dir) /code TJG Perfect. That's exactly what I needed. Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy directory tree without copying files
On 2009-09-23, Jeremy Conlin jlcon...@gmail.com wrote: I am trying to copy a folder hierarchy from one location to another. I can use the shutil.copytree function to copy the folder tree, but I don't want the files copied, just the folders. What is a good way to approach this? Just in case there's no real requirement to use Python... $ (cd srcdir; find . -type d) | (cd dstdir; xargs mkdir) -- Grant Edwards grante Yow! ... My pants just went at on a wild rampage through a visi.comLong Island Bowling Alley!! -- http://mail.python.org/mailman/listinfo/python-list
Re: custom data warehouse in python vs. out-of-the-box ETL tool
On Sep 22, 4:00 pm, snfctech tschm...@sacfoodcoop.com wrote: Does anyone have experience building a data warehouse in python? Any thoughts on custom vs using an out-of-the-box product like Talend or Informatica? I have an integrated system Dashboard project that I was going to build using cross-vendor joins on existing DBs, but I keep hearing that a data warehouse is the way to go. e.g. I want to create orders and order_items with relations to members (MS Access DB), products (flat file) and employees (MySQL). Thanks in advance for any tips. I use both Python and a Data-warehouse tool (Datastage) from IBM that is similar to Informatica. The main difference with Python is throughput. The tool has good sort and join routines of multithreaded C code that handles data bigger than what fits in RAM. It also has good native drivers for the DB2 database. For data conversions and other transformations every row gets processed on a different CPU. You can really put a 16 core machine to good use with this thing. In your case you probably won't have enough data to justify the cost of buying a tool. They are quite expensive. -- http://mail.python.org/mailman/listinfo/python-list
Re: Very simple finite automaton (?)
On Sep 23, 1:24 am, kpp9c k...@mac.com wrote: Very simple finite automaton (?) 1 -- 2 5 2 -- 1 4 3 -- 3 4 -- 1 5 -- 4 3 hello, this is a graph and you are doing depth first search. konstantin -- http://mail.python.org/mailman/listinfo/python-list
Re: cleanup in sys.excepthook?
akonsu wrote: hello, my script creates files that i need to delete if an exception is thrown. is this a good pythonic style to do this kind of cleanup in sys.excepthook instead of inside except clause of a try block? Speaking personally, I'd do the cleanup in the except clause if they needed to be deleted only if there was an exception; I'd use a finally clause or a 'with' context if they always had to be deleted, whether there was an exception or not. -- http://mail.python.org/mailman/listinfo/python-list
Re: Very simple finite automaton (?)
On Sep 23, 11:49 am, akonsu ako...@gmail.com wrote: On Sep 23, 1:24 am, kpp9c k...@mac.com wrote: Very simple finite automaton (?) 1 -- 2 5 2 -- 1 4 3 -- 3 4 -- 1 5 -- 4 3 hello, this is a graph and you are doing depth first search. konstantin BREADTH first. sorry :) -- http://mail.python.org/mailman/listinfo/python-list
Re: cleanup in sys.excepthook?
akonsu wrote: hello, my script creates files that i need to delete if an exception is thrown. is this a good pythonic style to do this kind of cleanup in sys.excepthook instead of inside except clause of a try block? konstantin def doIt(): pass try: doIt() except Exception, exc: #cleaning up files I mean, what is the problem with try except ? It's pythonic. If you tell us what wrong with it in your case, we may spend time on hacking sys.excepthook. Jean-Michel -- http://mail.python.org/mailman/listinfo/python-list
Re: Very simple finite automaton (?)
kpp9c wrote: Very simple finite automaton (?) I am not sure if this is and example of Finite Automaton or a Finite State Machine or perhaps it is related to a transition table or markov process. I am not a math person so i am not sure what it is called. I googled around and got lots of super complicated gobbledegoo all with knotty regex stuff, but what i want to do is much more simple. I am trying to use a table (called a transition table? i dunno) to define a bunch of moves like so: 1 -- 2 5 2 -- 1 4 3 -- 3 4 -- 1 5 -- 4 3 so that i can generate a sequence that, given an initial value, will continue to grow according to these rules. So starting with 1, we get: 1 2 5 1 4 4 3 2 5 1 1 3 1 4 4 3 2 5 2 5 3 . etc. Essentially, iterating over the last added items to the list, applying the table, adding those new items to the list, applying the table again... etc, until the sequence reaches some predetermined number of iterations and quits. [ [1], [2, 5], [1, 4] , [4, 3], [2, 5], [1], [1], [3], [1, 4], [4, 3], [2, 5], [2, 5], [3] ] [snip] I'm interested to know what you're then doing with the list. Depending on that you might want to view it (or implement it) in terms of a matrix, graph ... Duncan -- http://mail.python.org/mailman/listinfo/python-list
Re: Most active coroutine library project?
On Aug 25, 12:51 am, Denis denis.bile...@gmail.com wrote: You can also at gevent http://pypi.python.org/pypi/gevent Please, please document this! There are a lot of people who would love to use this but give up when they don't find a guide or something similar. -- http://mail.python.org/mailman/listinfo/python-list
Re: cleanup in sys.excepthook?
On Sep 23, 11:57 am, Jean-Michel Pichavant jeanmic...@sequans.com wrote: akonsu wrote: hello, my script creates files that i need to delete if an exception is thrown. is this a good pythonic style to do this kind of cleanup in sys.excepthook instead of inside except clause of a try block? konstantin def doIt(): pass try: doIt() except Exception, exc: #cleaning up files I mean, what is the problem with try except ? It's pythonic. If you tell us what wrong with it in your case, we may spend time on hacking sys.excepthook. Jean-Michel thanks. nothing is wrong with try/except. i just already have an excepthook handler that uses logger to send emails if a critical error occurs, so i was just thinking that maybe i can add cleanup there. i agree, try/except makes more sense. konstantin -- http://mail.python.org/mailman/listinfo/python-list
Re: Copy directory tree without copying files
On Sep 23, 9:44 am, Grant Edwards inva...@invalid.invalid wrote: On 2009-09-23, Jeremy Conlin jlcon...@gmail.com wrote: I am trying to copy a folder hierarchy from one location to another. I can use the shutil.copytree function to copy the folder tree, but I don't want the files copied, just the folders. What is a good way to approach this? Just in case there's no real requirement to use Python... $ (cd srcdir; find . -type d) | (cd dstdir; xargs mkdir) Thanks, but this has to be platform independent so Python seemed like a good choice. Jeremy -- http://mail.python.org/mailman/listinfo/python-list
Unable to import package over NFS in solaris
Hi, I have sqlalchemy package installed on the server. However I want to run a script on the client that uses the sqlalchemy package. Hence I shared the directory containing the sqlalchemy unsing NFS. Then I added the NFS pathname to the sqlalchemy packege in the client program. Now when I import sqlalchemy in the client program it throws the following error. Traceback (most recent call last): File /net/sqlhost/ashok/send.py, line 9, in ? from sqlalchemy import * ImportError: No module named sqlalchemy I have added the NFS path to the PYTHONPATH as folllows in my program. #!/usr/bin/python import os,commands,sys os.environ['PYTHONPATH']='/net/sqlhost/usr/lib/python2.4/site-packages/ SQLAlchemy-0.5.6-py2.4.egg/sqlalchemy' sys.path.append('/net/sqlhost/usr/lib/python2.4/site-packages/ SQLAlchemy-0.5.6-py2.4.egg/sqlalchemy') from sqlalchemy import * Contents of the directory shared under NFS in Solaris. bash-3.00# ls /usr/lib/python2.4/site-packages/SQLAlchemy-0.5.6- py2.4.egg/sqlalchemy/ __init__.py engine ext log.py pool.py queue.pycsql topological.pyc util.py __init__.pyc exc.py interfaces.pylog.pyc pool.pyc schema.pytest types.py util.pyc databasesexc.pyc interfaces.pyc orm queue.py schema.pyc topological.py types.pyc Please let me know what went wrong? thx, ~Ashok. -- http://mail.python.org/mailman/listinfo/python-list
Re: custom data warehouse in python vs. out-of-the-box ETL tool
@Martin: I originally thought that there was nothing magical about building a data warehouse, but then I did a little research and received all sorts of feedback about how data warehouse projects have notorious failure rates, that data warehouse design IS different than normal RDBMS - and then there's the whole thing about data marts vs. warehouses, Kimball vs. Inmon, star schemas, EAV tables, and so on. So I started to think that maybe I needed to get a little better read on the subject. On Sep 23, 3:15 am, Martin P. Hellwig martin.hell...@dcuktec.org wrote: snfctech wrote: Thanks for your replies, Sean and Martin. I agree that the ETL tools are complex in themselves, and I may as well spend that learning curve on a lower-level tool-set that has the added value of greater flexibility. Can you suggest a good book or tutorial to help me build a data warehouse in python? Bill Inmon's Building the Data Warehouse is 17 years old, and I've been cautioned against Kimball. Thanks. cut Data warehouse isn't something magical, it is just another database, albeit containing multiple datasets gathered from foreign resources in possibly multiple formats. Depending on your purpose of what you want, you design your tables the way you usually do. For example if you only want reporting, you might want to build your tables in such a way so it makes your life easier to build the actual report. Now you have an empty database containing the fields you wish for the report and have filled database(s) containing data from the user application. Now you use Python to fill the empty database, tada, you have a Data warehouse and used Python for ETL processing. So if you already have some insights in creating tables in a database, you are all set. Most likely you will go through a number of iterations before you are happy with the result though. There is no book substitute for applying theory, experience and common sense to a problem you want to solve, unless you write it yourself for that specific situation. -- MPHhttp://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
Re: custom data warehouse in python vs. out-of-the-box ETL tool
@Lemburg: Thanks for the suggestion. I'm sure you make a fine product, but my development platform is Linux, and I don't want any additional Windows servers to deal with (than the ones I'm already stuck with.) On Sep 23, 2:02 am, M.-A. Lemburg m...@egenix.com wrote: snfctech wrote: Does anyone have experience building a data warehouse in python? Any thoughts on custom vs using an out-of-the-box product like Talend or Informatica? I have an integrated system Dashboard project that I was going to build using cross-vendor joins on existing DBs, but I keep hearing that a data warehouse is the way to go. e.g. I want to create orders and order_items with relations to members (MS Access DB), products (flat file) and employees (MySQL). Thanks in advance for any tips. You might want to look at this solution for doing cross-database JOINs: EasySoft ODBC Join-Engine: http://www.easysoft.com/products/data_access/odbc_odbc_join_engine/in... and then use our mxODBC to access EasySoft's Engine: http://www.egenix.com/products/python/mxODBC/ or mxODBC Connect, if you have a client-server setup: http://www.egenix.com/products/python/mxODBCConnect/ Some database engines also allow integrating external ODBC data sources - the external tables then look like normal database tables and can be used in JOINs as well. I know that DB2 and Oracle support this kind of setup. You can access those using mxODBC as well. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Sep 23 2009) Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic Form
I've been trying the hidden field, but the problem is that when I set the variable flag, it stays in memory. I would rather just pass a var like I've been trying, but I don't think it's possible. Any ideas? Is a session cookie the only way? Here's more simplified code: #!/usr/bin/python import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) import MySQLdb import string, re def client(): form = cgi.FieldStorage() client = string.replace(string.replace(form.getfirst('client', ''), ', '#39;'), '', '#34;') flag = form.getfirst('flag', '') print Content-Type: text/html print print !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Frameset//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd; head xmlns=http://www.w3.org/1999/xhtml; body if flag == '': print form method=post action=client.py Company Name: input type='text' value='' size='20' maxlength='100' name='client' /br / input type='hidden' name='flag' value='y' / div align='center' input type='submit' value=' Send ' / /div /form /body/html else: host = 'h' db = 'db' user = 'u' passwd = '1' database = MySQLdb.connect(host, user, passwd, db) cursor = database.cursor() cursor.execute('insert into companies (client);' % (client)) cursor.close() print '/body/html' client() TIA, V On Tue, Sep 22, 2009 at 1:43 PM, Dennis Lee Bieber wlfr...@ix.netcom.comwrote: On Tue, 22 Sep 2009 12:50:31 -0400, Victor Subervi victorsube...@gmail.com declaimed the following in gmane.comp.python.general: Well it's Web stuff, sure, but it's written in python :) The code follows. The problem is that I haven't figured out how to tell the program that the user has entered data and to clear the cache of that data so that it's not re-entered. How do I do that? Remember, HTTP is a stateless protocol. EACH submission is considered a totally new transaction with no memory of the previous processing. Possible solutions... * Use a session cookie that identifies what phase in the multistep processing you are in... * Use a hidden field in the form that defaults to, say False, when you first display the form, but then gets set to True during the first response process (and is then sent back out with True so the second response takes a different branch). -- Wulfraed Dennis Lee Bieber KD6MOG wlfr...@ix.netcom.com HTTP://wlfraed.home.netcom.com/ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to import package over NFS in solaris
On Sep 23, 12:15 pm, Ashok asho...@gmail.com wrote: Hi, I have sqlalchemy package installed on the server. However I want to run a script on the client that uses the sqlalchemy package. Hence I shared the directory containing the sqlalchemy unsing NFS. Then I added the NFS pathname to the sqlalchemy packege in the client program. Now when I import sqlalchemy in the client program it throws the following error. Traceback (most recent call last): File /net/sqlhost/ashok/send.py, line 9, in ? from sqlalchemy import * ImportError: No module named sqlalchemy I have added the NFS path to the PYTHONPATH as folllows in my program. #!/usr/bin/python import os,commands,sys os.environ['PYTHONPATH']='/net/sqlhost/usr/lib/python2.4/site-packages/ SQLAlchemy-0.5.6-py2.4.egg/sqlalchemy' sys.path.append('/net/sqlhost/usr/lib/python2.4/site-packages/ SQLAlchemy-0.5.6-py2.4.egg/sqlalchemy') from sqlalchemy import * Contents of the directory shared under NFS in Solaris. bash-3.00# ls /usr/lib/python2.4/site-packages/SQLAlchemy-0.5.6- py2.4.egg/sqlalchemy/ __init__.py engine ext log.py pool.py queue.pyc sql topological.pyc util.py __init__.pyc exc.py interfaces.py log.pyc pool.pyc schema.py test types.py util.pyc databases exc.pyc interfaces.pyc orm queue.py schema.pyc topological.py types.pyc Please let me know what went wrong? thx, ~Ashok. You don't need the additional 'sqlalchemy' after the '/net/sqlhost/usr/ lib/python2.4/site-packages/ SQLAlchemy-0.5.6-py2.4.egg/' path. Using your configuration, Python is looking for: /net/sqlhost/usr/lib/python2.4/site-packages/ SQLAlchemy-0.5.6-py2.4.egg/sqlalchemy/sqlalchemy/ As an example, see below. Note that this is in a virtual environment that is not part of sys.path by default (I didn't run bin/activate). [j...@marvin ~]$ export PYTHONPATH=/home/jeff/Work/hostapi/lib/ python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/sqlalchemy/ [j...@marvin ~]$ python -c 'import sqlalchemy' Traceback (most recent call last): File string, line 1, in module ImportError: No module named sqlalchemy [j...@marvin ~]$ export PYTHONPATH=/home/jeff/Work/hostapi/lib/ python2.6/site-packages/SQLAlchemy-0.5.5-py2.6.egg/ [j...@marvin ~]$ python -c 'import sqlalchemy' [j...@marvin ~]$ -- Thanks, Jeff mcjeff.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Getting return code for a Python script invoked from a Linux shell script
Hi, folks, I have a Python script that is invoked by a shell script. I uses sys.exit() with a parameter within python. The calling script is using this line to get the return code: exit_code = !$ but it fails to get it. What's wrong here? (I am no Linux guru) Thanks in advance Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting return code for a Python script invoked from a Linux shell script
On Wed, 23 Sep 2009 09:51:29 -0700, volcano wrote: The calling script is using this line to get the return code: exit_code = !$ but it fails to get it. What's wrong here? (I am no Linux guru) Exit code is obtained with $?, not with !$ -- Igor Pozgaj | ipozgaj at gmail.com (GTalk / MSN) ICQ: 126002505 | http://fly.srk.fer.hr/~ipozgaj PGP: 0xEF36A092 | http://ipozgaj.blogspot.com fb, lfm, li, dA | http://twitter.com/ipozgaj -- http://mail.python.org/mailman/listinfo/python-list
Re: Most active coroutine library project?
On Sun, Aug 23, 2009 at 11:02 AM, Phillip B Oldham phillip.old...@gmail.com wrote: I've been taking a look at the multitude of coroutine libraries available for Python, but from the looks of the projects they all seem to be rather quiet. I'd like to pick one up to use on a current project but can't deduce which is the most popular/has the largest community. Libraries I looked at include: cogen, weightless, eventlet and circuits (which isn't exactly coroutine-based but it's event-driven model was intriguing). Firstly, are there any others I've missed? And what would the consensus be on the which has the most active community behind it? -- http://mail.python.org/mailman/listinfo/python-list Coroutines are built into the language. There's a good talk about them here: http://www.dabeaz.com/coroutines/ HTH, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting return code for a Python script invoked from a Linux shell script
On Wednesday 23 September 2009 18:51:29 volcano wrote: exit_code = !$ I think it's $? to get the code. \d -- home: http://otherwise.relics.co.za/ 2D vector animation : https://savannah.nongnu.org/projects/things/ Font manager : https://savannah.nongnu.org/projects/fontypython/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting return code for a Python script invoked from a Linux shell script
On Sep 23, 12:51 pm, volcano mark.gey...@gmail.com wrote: Hi, folks, I have a Python script that is invoked by a shell script. I uses sys.exit() with a parameter within python. The calling script is using this line to get the return code: exit_code = !$ but it fails to get it. What's wrong here? (I am no Linux guru) Thanks in advance Mark Assuming Bash, you'll want $? instead. The '!$' construct is used to pull the last argument of the previous command. Also, if I remember correctly, the history mechanism is disabled within shell scripts. -- Thanks, Jeff mcjeff.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
arrays in python
Can someone tell me how to allocate single and multidimensional arrays in python. I looked online and it says to do the following x = ['1','2','3','4'] However, I want a much larger array like a 100 elements, so I cant possibly do that. I want to allocate an array and then populate it using a for loop. Thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list
tool per conversione e trasformazione dati
Salve, lavoro in una ditta dove effettuiamo intensamente conversioni di database, trasformazione dei dati e raccolta da sorgenti diverse, successive query per fare dei fix eccetera... insomma, un lavoro bello complesso. Mi domandavo, insieme ai miei colleghi, se esistono dei tool/framework per effetturare operazioni di questo tipo e, allargando il discorso al di la di python, se esiste una disciplina teorica da dove possiamo attingere informazioni per riorganizzare i nostri programmi e script. ringrazio per l'attenzione, Francesco Stablum -- The generation of random numbers is too important to be left to chance - Robert R. Coveyou -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in python
On Wednesday 23 September 2009 19:14:20 Rudolf wrote: I want to allocate an array and then populate it using a for loop. You don't need to allocate anything, just use the list or dictionary types. l=[] #empty list for x in range(1,500): l.append(x) \d -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in python
On Sep 23, 2009, at 1:16 PM, Rudolf yellowblueyel...@gmail.com wrote: Can someone tell me how to allocate single and multidimensional arrays in python. I looked online and it says to do the following x = ['1','2','3','4'] However, I want a much larger array like a 100 elements, so I cant possibly do that. I want to allocate an array and then populate it using a for loop. Thanks for your help. Python lists have a dynamic size so you don't usually do that. Instead, we use list comprehensions to stick the for loop inside the list declaration. [str(x) for x in xrange(100)] -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: tool per conversione e trasformazione dati
I am sorry, the previous mail was intended to be published to the italian python mailing list, but... whoops, autocomplete tricked me... I will translate it in English: Hello, I work in a company where we do intensively database conversions, data transformations from different sources, queries of fixes... a very complex job. I was wondering if there are any tool/frameworks to do such operations and if there exist a theoretical scientific branch where we can get some more informations to reorganize our scripts and programs. thanks for the attention, Francesco Stablum 2009/9/23 Francesco Stablum stab...@gmail.com: Salve, lavoro in una ditta dove effettuiamo intensamente conversioni di database, trasformazione dei dati e raccolta da sorgenti diverse, successive query per fare dei fix eccetera... insomma, un lavoro bello complesso. Mi domandavo, insieme ai miei colleghi, se esistono dei tool/framework per effetturare operazioni di questo tipo e, allargando il discorso al di la di python, se esiste una disciplina teorica da dove possiamo attingere informazioni per riorganizzare i nostri programmi e script. ringrazio per l'attenzione, Francesco Stablum -- The generation of random numbers is too important to be left to chance - Robert R. Coveyou -- The generation of random numbers is too important to be left to chance - Robert R. Coveyou -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in python
Hi! See: http://docs.python.org/tutorial (section 5) @+ -- MCI -- http://mail.python.org/mailman/listinfo/python-list
Re: Twisted 100% event driven or hybrid?
exar...@twistedmatrix.com wrote: On 05:55 am, jacopo.pe...@gmail.com wrote: ... results to be ready, I collect and process them. From now on I don 19t need a the system to be event drive any more, the processing should occur only on the master machine, following a deterministic flow. As soon as finished I am ready to start again to resubmit the models for recalculation and so on. This should go on forever. Jean-Paul is obviously far more authoritative on the twisted way than I am, so if he says you can just run your synchronous operation in-situ, that's probably the way to go, but IIRC there's a reactor.deferToThread() function which can run your synchronous code off to the side, while allowing the twisted code to continue to process incoming operations. Thus you'd do something like: def process( dataset ): dl = [ remote_call( x ) for x in dataset] dl = defer.DeferredList( dl ) def on_all_results( results ): reactor.deferToThread( sync_process, (results,)).addCallback( process ) return dl.addCallback( on_all_results ) (I'm typing all of that from the distance of a few years of memory decay, so take it as loosely this, with the proper function names and the like). Threads aren't really part of the twisted way in my understanding, but they can be used if necessary AFAIK, and they will let your application remain responsive to network events during the processing. HTH, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-list
Get error message from FTPLib
I am using ftplib for a project, using a try/except loop. I would like to find out the exception, but I am a python newbie and do not know how. How, in a try/except loop would I find the ftplib exception? -- http://mail.python.org/mailman/listinfo/python-list
Re: [SQL] Pick random rows from SELECT?
On Mon, 21 Sep 2009 21:40:02 -0700, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: I'd suggest either a pool of threads -- 5-10, each reading company names from a shared QUEUE, which is populated by the main thread (remember to commit() so that you don't block on database updates by the threads). OR... determine how many companies there are, and start threads feeding them start and length (length being #names / #threads, round up -- start then being 0*length+1, 1*length+1, etc...) and use those in thread specific selects using ... limit length offset start... This way each thread retrieves its own limited set of companies (make sure to use the same sorting criteria). Thanks for the help :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Most active coroutine library project?
On 05:00 pm, sajmik...@gmail.com wrote: On Sun, Aug 23, 2009 at 11:02 AM, Phillip B Oldham phillip.old...@gmail.com wrote: I've been taking a look at the multitude of coroutine libraries available for Python, but from the looks of the projects they all seem to be rather quiet. I'd like to pick one up to use on a current project but can't deduce which is the most popular/has the largest community. Libraries I looked at include: cogen, weightless, eventlet and circuits (which isn't exactly coroutine-based but it's event-driven model was intriguing). Firstly, are there any others I've missed? And what would the consensus be on the which has the most active community behind it? -- http://mail.python.org/mailman/listinfo/python-list Coroutines are built into the language. There's a good talk about them here: http://www.dabeaz.com/coroutines/ But what some Python programmers call coroutines aren't really the same as what the programming community at large would call a coroutine. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Twisted 100% event driven or hybrid?
On 05:48 pm, mcfle...@vrplumber.com wrote: exar...@twistedmatrix.com wrote: On 05:55 am, jacopo.pe...@gmail.com wrote: ... results to be ready, I collect and process them. From now on I don 19t need a the system to be event drive any more, the processing should occur only on the master machine, following a deterministic flow. As soon as finished I am ready to start again to resubmit the models for recalculation and so on. This should go on forever. Jean-Paul is obviously far more authoritative on the twisted way than I am, so if he says you can just run your synchronous operation in- situ, that's probably the way to go, but IIRC there's a reactor.deferToThread() function which can run your synchronous code off to the side, while allowing the twisted code to continue to process incoming operations. Thus you'd do something like: def process( dataset ): dl = [ remote_call( x ) for x in dataset] dl = defer.DeferredList( dl ) def on_all_results( results ): reactor.deferToThread( sync_process, (results,)).addCallback( process ) return dl.addCallback( on_all_results ) (I'm typing all of that from the distance of a few years of memory decay, so take it as loosely this, with the proper function names and the like). Threads aren't really part of the twisted way in my understanding, but they can be used if necessary AFAIK, and they will let your application remain responsive to network events during the processing. Yep, you're correct here Mike (except it's `twisted.internet.defer.deferToThread` rather than `twisted.internet.reactor.deferToThread`). If it is safe to call `sync_process` in a thread, then this may be a good approach as well, and it will free up the reactor to continue to respond to events (assuming `sync_process` plays nicely - ie, is written in Python or is an extension that releases the GIL, of course). In my post, I was trying to highlight the idea that there's not really anything special going on in a Twisted program. You can choose to block if you wish, if the consequences (events go unserviced for a while) are acceptable to you. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Solved - Python: automate input to MySQL query
On Wed, Sep 23, 2009 at 10:49 AM, D'Arcy J.M. Cain da...@druid.net wrote: Of course you can get around this by specifying every field and using AS to change the names to manager_id and employee_firstname, etc. but if you are going to do that anyway, why not just do it once in the database instead of littering the code? In my case, I sometimes generate entity classes from automatically from the database. So, I am not typing them, but the field names on some of my classes will be longer than they need to be. Also, I only have to use the AS when I am doing joins, which I don't do as often as selects, inserts, and/or updates. So now I would have to type the long redundant column name for those 3 types of queries, instead of saving me from typing AS in the joins. -- http://mail.python.org/mailman/listinfo/python-list
Searching Dictionary
i am trying to search a large Python dictionary for a matching value. The results would need to be structured into a new dictionary with the same structure. Thanks. The structure is like this { Key : [{'item':value,'item2':value,' item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}], Key2 : [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}], Key3 : [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}] } -- http://mail.python.org/mailman/listinfo/python-list
Re: easy question, how to double a variable
On Tue, 22 Sep 2009 02:34:53 +, Steven D'Aprano wrote: On Mon, 21 Sep 2009 13:50:23 -0500, David C Ullrich wrote: But you actually want to return twice the value. I don't see how to do that. What? Seriously? You're saying it _can_ be done in Python? They must have added something to the standard library again. I mean how can you return twice a value without a twice function to start with? I've tried. You'd think def twice(n): return twice(n) would work, but I get this really long error message. You're not just yanking the OP's chain??? That would be cruel. I mean the guy has enough problems already... -- http://mail.python.org/mailman/listinfo/python-list
Idiom for last word in a string
I recently ran across this construct for grabbing the last (whitespace delimited) word in a string: s.rsplit(None,1)[1] It was somewhat obvious from the context what it was supposed to do, but it took a bit of Googling to figure out exactly what was going on. When I want the last word in a string, I've always done this: s.split()[-1] I was wondering what the advantage of the rsplit(None,1)[1] approach would be other than inducing people to learn about the maxsplit argument that is accepted by the split() methods? -- Grant Edwards grante Yow! I want a VEGETARIAN at BURRITO to go ... with visi.comEXTRA MSG!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Get error message from FTPLib
On Sep 23, 1:46 pm, Bakes ba...@ymail.com wrote: I am using ftplib for a project, using a try/except loop. I would like to find out the exception, but I am a python newbie and do not know how. How, in a try/except loop would I find the ftplib exception? For a bit on exception handling in general, check out the section within the Python tutorial: http://docs.python.org/tutorial/errors.html. As far as the ftplib module goes, it has an attribute named 'all_errors.' It's a tuple that contains all of the Exception types that ftplib.FTP methods will throw. You can do something like the following: try: FTP_instance.do_something() except ftplib.all_errors, e: handle_an_error(e) I do something much like that in an NMS-like application I wrote. -- Thanks, Jeff mcjeff.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for last word in a string
On Sep 23, 2:47 pm, Grant Edwards inva...@invalid.invalid wrote: I recently ran across this construct for grabbing the last (whitespace delimited) word in a string: s.rsplit(None,1)[1] It was somewhat obvious from the context what it was supposed to do, but it took a bit of Googling to figure out exactly what was going on. When I want the last word in a string, I've always done this: s.split()[-1] I was wondering what the advantage of the rsplit(None,1)[1] approach would be other than inducing people to learn about the maxsplit argument that is accepted by the split() methods? -- Grant Edwards grante Yow! I want a VEGETARIAN at BURRITO to go ... with visi.com EXTRA MSG!! hello, perhaps rsplit generates as many elements in the list as absolutely necesary compared to the whole list returned by split()? konstantin -- http://mail.python.org/mailman/listinfo/python-list
Open file on remote linux server
Hi I'm looking to do something like this f = f.openfileobj(remotefileloc, localfilelikeobj) my remote files are on a solaris box that i can access using ssh (could prehap request othe protocols if necessary) anyone got any ideas? many thanks Charlie (ps. tried this on the python-forum but didn't seem to go on so apologies if i'm cross posting) -- View this message in context: http://www.nabble.com/Open-file-on-remote-linux-server-tp25531253p25531253.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Querying for ownership of file shared by Samba fails with MemoryError: allocating SECURITY_DESCRIPTOR
I have just learned how to use the win32security module (within Windows, of course) to determine file ownership. When running against local drives or windows shares, this works fine, as shown in the following code (Python 2.4/2.5 with PyWin extensions): import win32security file = 'c:/temp/test.txt' #Using the win32security module get ownership information ownerSecurity= win32security.GetFileSecurity(file,win32security.OWNER_SECURITY_INFORMATION) ownerSID = ownerSecurity.GetSecurityDescriptorOwner () owner,domain,type = win32security.LookupAccountSid (None, ownerSID) print File %s is owned by %s\\%s % (file,domain,owner) However, when I run this against a file on an SMB mounted file system (the server is AIX Unix),the following error is raised: File C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py, line 325, in RunScript exec codeObject in __main__.__dict__ File C:\scripts\testfileinfo.py, line 17, in ? ownerSecurity= win32security.GetFileSecurity(file,win32security.OWNER_SECURITY_INFORMATION) MemoryError: allocating SECURITY_DESCRIPTOR Interestingly, searching the G**gle for the string MemoryError: allocating SECURITY_DESCRIPTOR results in only two primary hits, back to 2003, which look like this: Anyone have any ideas on what the problem might be here (M: is a Win98 shared disk space - command was issued from a PythonWin session running on a Win 2000 machine): GetFileSecurity(M:\\autoexec.bat, OWNER_SECURITY_INFORMATION) Traceback (most recent call last): File interactive input, line 1, in ? MemoryError: allocating SECURITY_DESCRIPTOR Win95,98,ME use the FAT32 filesystem. This has absolutely no ACL or permission capabilities on it. Win NT, 2K, XP use NTFS by default, which allows ACLS. Any insights would be greatly appreciated. Steve Walker middleforkgis aht gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for last word in a string
At Wed, 23 Sep 2009 18:47:05 + (UTC), Grant Edwards wrote: I recently ran across this construct for grabbing the last (whitespace delimited) word in a string: s.rsplit(None,1)[1] It was somewhat obvious from the context what it was supposed to do, but it took a bit of Googling to figure out exactly what was going on. When I want the last word in a string, I've always done this: s.split()[-1] I was wondering what the advantage of the rsplit(None,1)[1] approach would be other than inducing people to learn about the maxsplit argument that is accepted by the split() methods? s.rsplit(None, 1) is a cheaper operation because it splits the string *only once*. -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for last word in a string
At Wed, 23 Sep 2009 18:47:05 + (UTC), Grant Edwards wrote: I recently ran across this construct for grabbing the last (whitespace delimited) word in a string: s.rsplit(None,1)[1] It was somewhat obvious from the context what it was supposed to do, but it took a bit of Googling to figure out exactly what was going on. When I want the last word in a string, I've always done this: s.split()[-1] I was wondering what the advantage of the rsplit(None,1)[1] approach would be other than inducing people to learn about the maxsplit argument that is accepted by the split() methods? s.rsplit(None, 1) is a cheaper operation because it splits the string *only once*. -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for last word in a string
At Wed, 23 Sep 2009 18:47:05 + (UTC), Grant Edwards wrote: I recently ran across this construct for grabbing the last (whitespace delimited) word in a string: s.rsplit(None,1)[1] It was somewhat obvious from the context what it was supposed to do, but it took a bit of Googling to figure out exactly what was going on. When I want the last word in a string, I've always done this: s.split()[-1] I was wondering what the advantage of the rsplit(None,1)[1] approach would be other than inducing people to learn about the maxsplit argument that is accepted by the split() methods? s.rsplit(None, 1) is a cheaper operation because it splits the string *only once*. -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for last word in a string
At Wed, 23 Sep 2009 18:47:05 + (UTC), Grant Edwards wrote: I recently ran across this construct for grabbing the last (whitespace delimited) word in a string: s.rsplit(None,1)[1] It was somewhat obvious from the context what it was supposed to do, but it took a bit of Googling to figure out exactly what was going on. When I want the last word in a string, I've always done this: s.split()[-1] I was wondering what the advantage of the rsplit(None,1)[1] approach would be other than inducing people to learn about the maxsplit argument that is accepted by the split() methods? s.rsplit(None, 1) is a cheaper operation because it splits the string *only once*. -- http://mail.python.org/mailman/listinfo/python-list
Re: pygui - showing an image
yes, that did the trick. i was not aware of all the examples in Test, only the three Demo projects. thanks! 2009/9/22 David Robinow drobi...@gmail.com: There's an example in Tests/21-image.py See if that helps. -- http://mail.python.org/mailman/listinfo/python-list
pycopg2 build problems
Hi, I'm trying to install psycopg2 on my system. I followed the instruction in INSTALL file and gave the command python setup.py build running build running build_py running build_ext error: No such file or directory Where is the file or directory missing. Any help is appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for last word in a string
akonsu wrote: On Sep 23, 2:47 pm, Grant Edwards inva...@invalid.invalid wrote: I recently ran across this construct for grabbing the last (whitespace delimited) word in a string: s.rsplit(None,1)[1] It was somewhat obvious from the context what it was supposed to do, but it took a bit of Googling to figure out exactly what was going on. When I want the last word in a string, I've always done this: s.split()[-1] I was wondering what the advantage of the rsplit(None,1)[1] approach would be other than inducing people to learn about the maxsplit argument that is accepted by the split() methods? -- Grant Edwards grante Yow! I want a VEGETARIAN at BURRITO to go ... with visi.comEXTRA MSG!! hello, perhaps rsplit generates as many elements in the list as absolutely necesary compared to the whole list returned by split()? konstantin Indeed, and if the string is long it has a measurable effect: $ python -m timeit -ss = 'oneword '*1000 s.rsplit(None, 1)[-1] 10 loops, best of 3: 2.23 usec per loop $ python -m timeit -ss = 'oneword '*1000 s.split()[-1] 1000 loops, best of 3: 191 usec per loop Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: custom data warehouse in python vs. out-of-the-box ETL tool
snfctech wrote: @Martin: I originally thought that there was nothing magical about building a data warehouse, but then I did a little research and received all sorts of feedback about how data warehouse projects have notorious failure rates, that data warehouse design IS different than normal RDBMS - and then there's the whole thing about data marts vs. warehouses, Kimball vs. Inmon, star schemas, EAV tables, and so on. So I started to think that maybe I needed to get a little better read on the subject. Yes failure rate for data warehouse projects is quite high, so are other IT projects without data warehouses. Data warehouse design is not that much different than 'normal' RDBMS, you are following the same decisions for example: - Do I rather have multiple copies of data than slow or complicated access? If yes how do I ensure integrity? - How do I do access control on value level? - Do I need fail over or load balancing, if yes how much of it can I do on the application level? The thing is if you never have designed a database from a database point of view because you used abstractions that hide these ugly details then yes, Data warehouses are different than normal RDBMS. Yes you can make it all sound very complicated by throwing PHB words in like meta schema's, dimensional approach, subject orientated, etc. I like to see it more like I have a couple of data sources, I want to combine them in a way that I can do neat stuff with it. The 'combine them' part is the data warehouse design, the 'neat stuff' part are the clients that use that data warehouse. If you wish you can start making it more complicated by saying but my data sources are also my clients, but that is another step. I guess you can sum up all this by saying a data warehouse is a method of gathering already existing data and present them in a different way, the concept is simple, the details can be complicated if you want/need it to be. -- MPH http://blog.dcuktec.com 'If consumed, best digested with added seasoning to own preference.' -- http://mail.python.org/mailman/listinfo/python-list
Re: pycopg2 build problems
On Sep 23, 2009, at 3:24 PM, devaru wrote: Hi, I'm trying to install psycopg2 on my system. I followed the instruction in INSTALL file and gave the command python setup.py build running build running build_py running build_ext error: No such file or directory Where is the file or directory missing. Any help is appreciated. Try asking on the psycopg2 mailing list. Good luck Philip -- http://mail.python.org/mailman/listinfo/python-list
Re: Open file on remote linux server
On Sep 23, 12:04 pm, The Bear c.poll...@bangor.ac.uk wrote: Hi I'm looking to do something like this f = f.openfileobj(remotefileloc, localfilelikeobj) my remote files are on a solaris box that i can access using ssh (could prehap request othe protocols if necessary) anyone got any ideas? many thanks Charlie (ps. tried this on the python-forum but didn't seem to go on so apologies if i'm cross posting) -- View this message in context:http://www.nabble.com/Open-file-on-remote-linux-server-tp25531253p255... Sent from the Python - python-list mailing list archive at Nabble.com. I don't know of any Python library that will give you that kind of access to a remote file over ssh. It sounds like a fun project though! If nothing else, you can install the ssh filesystem for Fuse, and just mount the remote filesystem as if it was local. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Searching a large dictionary
i am trying to search a large Python dictionary for a matching value. The results would need to be structured into a new dictionary with the same structure. Thanks. The structure is like this { Key : [{'item':value,'item2':value,' item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}], Key2 : [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}], Key3 : [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}] } On Sep 22, 7:16 pm, Dave Angel da...@ieee.org wrote: Support Desk wrote: I need help searching a large python dictionary. The dictionary is setup like so Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}] Key2[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}] Key3[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}] What would be the best way to search for a specific value of item1 and add all the results to a new dictionary? Thanks With all the messages I've seen so far on this thread, all you've managed to do is confuse it further. I suggest you start over (new thread) with a legal program defining a single dictionary (with real values for Key, Key2, and value, and without extra quote marks which make it fail to compile even if we guess what you're doing with the three keys). I suggest that at least some relevant parts of the data should not be all identical, so we can tell what's important. Use copy paste from working code. Then given a real dictionary, describe what you really want to search for, and what acceptable results would be. And also specify the programming language, version, and OS environment. Thanks. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in python
On Wed, Sep 23, 2009 at 1:14 PM, Rudolf yellowblueyel...@gmail.com wrote: Can someone tell me how to allocate single and multidimensional arrays in python. I looked online and it says to do the following x = ['1','2','3','4'] However, I want a much larger array like a 100 elements, so I cant possibly do that. I want to allocate an array and then populate it using a for loop. Thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list In python they're called 'lists'. There are C-style array objects but you don't want to use them unless you specifically have to. You can create an empty list like so: x = [] and then put items into it with a for loop like so: for item in some_iterable: x.append(item) But in simple cases like this there's also the list comprehension syntax which will do it all in one step: x = [item for item in some_iterable] But again in a case like this, if you're simply populating a list from an iterable source you would just say: x = list(some_iterable) For multidimensional 'arrays' you just put lists in lists. (Or use NumPy if you really want arrays and are doing lots of wild processing on them.) But if you do this: two_dimensional_list = [ [] for var in some_iterable] The list of lists you create thereby will contain multiple references to the /same/ inner list object. This is something that catches many people unawares. You have to go back to using a for loop: x = [] for n in range(100): x.append([(n, m) for m in range(10)]) (That will create a list of one hundred lists, each of which contains ten tuples.) Good luck. -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in python
On Wed, Sep 23, 2009 at 1:22 PM, Donn donn.in...@gmail.com wrote: On Wednesday 23 September 2009 19:14:20 Rudolf wrote: I want to allocate an array and then populate it using a for loop. You don't need to allocate anything, just use the list or dictionary types. l=[] #empty list for x in range(1,500): l.append(x) Of course, in this example you could just say, l = range(1,500) Or in python 3, l = list(range(1,500)) -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in python
Donn wrote: On Wednesday 23 September 2009 19:14:20 Rudolf wrote: I want to allocate an array and then populate it using a for loop. You don't need to allocate anything, just use the list or dictionary types. l=[] #empty list for x in range(1,500): l.append(x) \d Works great if you want 4,999,999 elements. ;-) Omit the '1' if you want all five million. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: Most active coroutine library project?
On Wed, Sep 23, 2009 at 2:05 PM, exar...@twistedmatrix.com wrote: On 05:00 pm, sajmik...@gmail.com wrote: On Sun, Aug 23, 2009 at 11:02 AM, Phillip B Oldham phillip.old...@gmail.com wrote: I've been taking a look at the multitude of coroutine libraries available for Python, but from the looks of the projects they all seem to be rather quiet. I'd like to pick one up to use on a current project but can't deduce which is the most popular/has the largest community. Libraries I looked at include: cogen, weightless, eventlet and circuits (which isn't exactly coroutine-based but it's event-driven model was intriguing). Firstly, are there any others I've missed? And what would the consensus be on the which has the most active community behind it? -- http://mail.python.org/mailman/listinfo/python-list Coroutines are built into the language. There's a good talk about them here: http://www.dabeaz.com/coroutines/ But what some Python programmers call coroutines aren't really the same as what the programming community at large would call a coroutine. Jean-Paul Really? I'm curious as to the differences. (I just skimmed the entry for coroutines in Wikipedia and PEP 342, but I'm not fully enlightened.) Warm regards, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: Searching Dictionary
Support Desk wrote: i am trying to search a large Python dictionary for a matching value. The results would need to be structured into a new dictionary with the same structure. Thanks. The structure is like this { Key : [{'item':value,'item2':value,' item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}], Key2 : [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}], Key3 : [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}] } If you're only going to follow a small part of my suggestion, probably better if you had ignored it entirely. Here is the entire suggestion again, for closer study: With all the messages I've seen so far on this thread, all you've managed to do is confuse it further. I suggest you start over (new thread) with a legal program defining a single dictionary (with real values for Key, Key2, and value, and without extra quote marks which make it fail to compile even if we guess what you're doing with the three keys). I suggest that at least some relevant parts of the data should not be all identical, so we can tell what's important. Use copy paste from working code. Then given a real dictionary, describe what you really want to search for, and what acceptable results would be. And also specify the programming language, version, and OS environment. There are still syntax errors in the fragment you quoted, and you don't supply enough context to actually try it. You don't supply values for the class Key or for the value, and you don't ask what you are going to search for, nor what you expect the result to be. If I called a mechanic and told him I had trouble starting a motor vehicle, but refused to tell him anything else, he might guess a bad battery, out of gas, bad starter. But he probably wouldn't think to ask me if I had lost my keys. And all the stuff about the starter wouldn't help if I had neglected to tell him it was a rope-started lawn mower. And if I did it a second time, he'd probably hang up on me. My wife's car needed a jump-start today, which is why I'm distracted on that theme. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: arrays in python
On Wednesday 23 September 2009 22:12:24 Ethan Furman wrote: Works great if you want 4,999,999 elements. ;-) Omit the '1' if you want all five million. Yes. Fenceposts always get me :) And I was just reminded that one can: l=range(500) \d -- home: http://otherwise.relics.co.za/ 2D vector animation : https://savannah.nongnu.org/projects/things/ Font manager : https://savannah.nongnu.org/projects/fontypython/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Solved - Python: automate input to MySQL query
On Wed, 23 Sep 2009 11:37:07 -0700 Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Wed, 23 Sep 2009 10:49:51 -0400, D'Arcy J.M. Cain da...@druid.net declaimed the following in gmane.comp.python.general: from pg import DB # PyGreSQL db = DB() # uses my default PostgeSQL database res = db.query( SELECT * FROM employee, manager WHERE manager.id = employee.id).dictresult() print res[0]['id'] # is this the employee's ID or the manager's? print res[0]['firstname'] # same question [...] Since I would never recommend using * in production code (if someone changes the database schema, all your assumptions about returned fields changes anyway), then yes -- in my usage I WOULD itemize the Look again. I am using a database module that returns dicts so I never have to worry about the order of returned fields. fields to specify what order each is to be returned, and maybe even specify an as name to avoid duplicate column names (but in program I just like nice, readable code. Specifying every field and adding AS statements just makes it harder to read - and write. code, even that is not needed, as the columns are returned in the order specified so code /knows/ that the first column is name from /this/ table and the other column with name is from /that/ table). Unless you get a dictionary return. In any case, I have a strong philosophical objection to using the same name to refer to two different things regardless of any operational issues. The manager.firstname and employee.firstname are not the same thing and should have different names to reflect that. A similar issue comes up in the classic situation of the inventory table price field and the sale item price field. They sound like the same thing but they are not. One is the current price in the catalogue and the other is the price it was sold for at a particular time. They need different names for that reason. -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: recommendation for webapp testing?
On Sep 17, 8:19 am, Simon Brunning si...@brunningonline.net wrote: 2009/9/17 Schif Schaf schifsc...@gmail.com: What's the difference between WebDriver and Selenium? Selenium runs in a browser, and usesJavaScriptto perform all your automated actions. It need a browser running to work. Several are supported, Firefox, Safari, IE and I think others. You are at thier mercy of the browser'sJavaScriptengine - I've often had trouble with IE's XPath support, for instance - tests will run fine in Firefox and safari, but not work in IE. One big advantage of Selenium is that there an IDE available, a Firefox add-on which will allow you to record actions. This is useful for building regression tests and acceptance tests for bugs. Sadly, it often tempts people into writing their acceptance tests after the fact, too - a grave mistake IMHO. Selenium tests can be written in Python, Ruby, Java, and in the form of HTML tables. This last seems quite popular with QAs for some reason which escapes me entirely. WebDriver runs outside a browser. It can be (and usually is) used to drive a real browser, though there's is a HtmlUnit driver available, which bypasses any real browser and goes direct to the site you are testing. Even this last option, though, does allow the testing of sites which make use ofJavaScript- which is just about all of them these days. It makes use of native drivers for each of the browsers it supports, so it runs very much faster than Selenium. Since it presents the test program with its own version of the page's DOM tree, it's also less likely to give browser incompatibilities. WebDriver tests can be written in Java or Python, at the moment. The Selenium people have recognized the superiority of the WebDriver approach, so the nascent Selenium 2 will use WebDriver under the covers. For the moment, though, you have to pick one or the other. Mechanize is a superb library for its intended purpose - I use it all the time. It's lack of support for pages withJavaScript functionality, though, means it's not very useful at a testing tool for modern web sites. if you ask flier liu (http://code.google.com/p/pyv8) veeery nicely, he _might_ be persuaded to make the work he's doing be free software. hint: if you check closely into the pyv8 tests, you'll see a module w3c.py which implements DOM. in other words, he's writing a command-line-web-browser-without-the- gui-to-get-in-the-way. in other words, he's taking HTML off the web and _executing the javascript_ (using pyv8) to construct the exact same kind of page that a user would normally see _if_ you actually put the resultant DOM (after the javascript is done executing) into a web browser's display engine. the reason why he's doing is this is because he has quite literally miilllions of web pages to analyse, and working with e.g. selenium just absolutely does not cut the mustard, performance-wise. so, if you can get him to make the work he's doing free software, you will get a test suite whereby you can have pyv8 actually execute the on-page javascript, then use e.g. BeautifulSoup to walk the resultant DOM, and can do proper analysis of the DOM, which would otherwise be impossible. l. -- http://mail.python.org/mailman/listinfo/python-list