Logic Programming
Yes! The question rears its head once again! ;o) I have done some search and trial and horrors.. (PyLog has vanished?) But I fail to find anything useful when it comes to do Logic Programming (e.g. Prolog'ish) in the context of Python. And yes, I tend to beleive that I need to! No, I do not really like the idea of piping def's and queries to SWI-prolog ála PyProlog. So, I would be *so* happy if someone could point at some module that gives me the possibility to define a knowledgebase and queries from within Python and still access the structures from Python code. *pleeze!* -- http://mail.python.org/mailman/listinfo/python-list
Re: default variable in python $_
rh0dium wrote:
> Hi all,
>
> So I have this simple little routine.. say like this..
>
>
> def foo()
>return {"a":"b", "b":"c"}
>
> if foo():
>print "Have foo"
>
>
> Now I want the dictionary item a (ie. b)
>
> How can I do it the above way or do I still have to go like this..
>
> def foo()
>return {"a":"b", "b":"c"}
>
> z = foo()
> if z:
>print "Have foo"
>print z['a']
>
> This is where $_ in perl is awesome - There must be a default variable
> in python right?
As said in earlier response, such a default variable is *dangerous* at
best!
Not knowing much about Perl and guessing that the $_ is a global
storage space, my immediate thought is; What happens if you have
multiple threads?
The example is too simplified to give any clues as to what you are
needing the feature for.
Guessing that you want to generate some dict() and use the result once
and then discard, write:
foo_default = 1
def foo(): return(generate_some_dict())
you can further write
foo().get('a', foo_default)
giving compact code and ensuring that you get a well defined result
regardless what dictionary keys there are.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Experiences with Py2Exe
We use py2exe on regular basis for most of our app's, both for internal and external distribution. We then pack it to an installer using NSIS (http://nsis.sourceforge.net/Main_Page) which is also free :o) -- http://mail.python.org/mailman/listinfo/python-list
Re: Using py2exe to wrap a service?
Thanks guys! :o) It seems that no module is missing since the Service starts and the error message seem to indicate an error in the COM call to the AD. I would expect some other exception.. I do have a separate thread for the asyncore.loop() as I otherwise would risk a lockup. I do not call pythoncom.CoInitialize () as I tend to expect a module wrapping COM stuff to do that. Since I am not really into Windows, I have to ask you, do I make a wrong assumption here? Some further info that may be of interest: python 2.4.3 active_directory 0.4 py2exe 0.6.5 pywin32 208 The Service code is taken from MyService.py supplied with py2exe as a sample. Rgrds//M -- http://mail.python.org/mailman/listinfo/python-list
Re: Using py2exe to wrap a service?
Tim Golden wrote:
> [MaR]
>
> | I do not call pythoncom.CoInitialize () as I tend to expect a module
> | wrapping COM stuff to do that.
>
> Hmmm. A slightly philosophical point.
[snip]
:o) I agree!
I have added the CoInit.. call to the __init__() of the threaded class
(I understood the documentation as that was a proper place.)
The exception message changed!
Unfortunately I get little wiser.. (yes I confess.. I am spoonfed with
unix ;o)
The instance's SvcRun() method failed
File "win32serviceutil.pyc", line 785, in SvcRun
File "MailProxySvc.pyc", line 132, in SvcDoRun
File "MailProxySvc.pyc", line 100, in setup
File "D:\projects\MailProxy\AddressDB.py", line 54, in
loadPersonsFromAD
File "active_directory.pyc", line 367, in search
File "active_directory.pyc", line 217, in query
File "win32com\client\gencache.pyc", line 540, in EnsureDispatch
File "win32com\client\CLSIDToClass.pyc", line 50, in GetClass
exceptions.KeyError: '{B08400BD-F9D1-4D02-B856-71D5DBA123E9}'
//M
--
http://mail.python.org/mailman/listinfo/python-list
Re: Using py2exe to wrap a service?
Tim Golden wrote: [snip..] > At this point there are several options open to us: > > (in no particular order) > 1) You could nudge the code at line 217 to make use of > that suggestion. > 2) I could do that and send you the result. > 3) I could alter the module so it doesn't use gencache > at all. I don't seem to be using any constants so the > Dispatch might as well be dynamic. > 4) None of the above. > > I'm happy to do (3) and send it to you privately if you're > willing to try. Of course, it might not be the cause > of the problem in any case! > > TJG Really appreciate! Reading the page you indicate, I tried solution 3 as it seemed to be the favored one by the author.. I simply added the lines, doing the import and the setting the flag, in a copy of the active_directory module. But maybe you thought of some other nudging? Some kind of progress anyway, I guess (see below). Maybe your offer to do your option (3) is worthwhile after all? //M The instance's SvcRun() method failed File "win32serviceutil.pyc", line 785, in SvcRun File "MailProxySvc.pyc", line 132, in SvcDoRun File "MailProxySvc.pyc", line 100, in setup File "AddressDB.pyc", line 55, in loadPersonsFromAD File "active_directory_M.pyc", line 369, in search File "active_directory_M.pyc", line 219, in query File "win32com\client\gencache.pyc", line 536, in EnsureDispatch File "win32com\client\gencache.pyc", line 520, in EnsureModule File "win32com\client\gencache.pyc", line 287, in MakeModuleForTypelib File "win32com\client\makepy.pyc", line 223, in GenerateFromTypeLibSpec File "win32com\client\gencache.pyc", line 141, in GetGeneratePath exceptions.IOError: [Errno 2] No such file or directory: 'D:\\projects\\MailProxy\\dist\\library.zip\\win32com\\gen_py\\__init__.py' -- http://mail.python.org/mailman/listinfo/python-list
Re: Using py2exe to wrap a service?
CONCLUSION:
Tim Golden sent me a patched version of his active_directory.py ver 0.4
and that solved my problem!
Thanks all for your attention and in particular, Tim!
//Maria
111a112
> from win32com.client.gencache import EnsureDispatch
180c181
< _connection = Dispatch ("ADODB.Connection")
---
> _connection = EnsureDispatch ("ADODB.Connection")
216c217
< command = Dispatch ("ADODB.Command")
---
> command = EnsureDispatch ("ADODB.Command")
419a421
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: does anybody earn a living programming in python?
walterbyrd wrote: > If so, I doubt there are many. My share of the waterfall :o) I do earn my (preposterously nice *wink*) salary from doing *all* major efforts, at the company I work for, in Python. Not only that, since I started out here some 5 years ago, nearly all software development of new thingys have moved to.. right! Python! That adds three more people. (We do use some Java for PDA's and also C++, the last just for maintenance of older SW) And even more, some of our PLC programmers use Python to auto-render PLC code for Siemens(!), significantly increasing their productivity in each and every project. So I guess you just have to listen in on the right frequencies *wink again* //M -- http://mail.python.org/mailman/listinfo/python-list
Re: Socks server and client code in Python (Twisted?)
The answer may depend somewhat on whether your app is doing mostly storage (filessystem) or calculations (cpu). If you need to handle a fair number of sockets but do little processing, you may wish to look at the standard modules asyncore/asynchat. But Twisted is not a bad advice :o) Maybe a little more threshold to get started and you will have to co-deploy it with your app. -- http://mail.python.org/mailman/listinfo/python-list
Re: Making sure script only runs once instance at a time.
A very brutal but simple and effective method is to bind() to a socket on localhost eg (127.0.0.1, 4711), listen() but never accept(). Any other process trying to to bind() on the same port will fail.. When the process dies, the port is released automatically, pending som timedelay.. But this assumes you have an execution environment where this is acceptable. A sysadmin may have objections ;o) -- http://mail.python.org/mailman/listinfo/python-list
Re: [Off topic] Software epigrams
On Mon, May 13, 2013, at 05:20 AM, Steven D'Aprano wrote: > My, it's been a long time since I've seen these: > > http://pu.inf.uni-tuebingen.de/users/klaeren/epigrams.html > > They pre-date the Zen of Python by at least a decade, and quite frankly I > think many of them miss the mark. But whether you agree or disagree with > them, they're worth reading. Yes, they're all over the place, but worth reading. My favorite is: 101: Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve. -- http://mail.python.org/mailman/listinfo/python-list
Re: Illegal seek error with seek() and os.lseek()
On Tue, May 14, 2013, at 03:00 PM, [email protected] wrote: > I am trying to use os.open() and os.lseek() methods to operate on a > device file in Linux. My code goes something like this - > > # first, open the file as a plain binary > try: > self.file = open(/dev/relpcfpga, "r+b", buffering=0) > > except IOError: > raise IOError ('Failed to open.') > > # Figure out file size > self.file.seek(0, 2) > self.file_size = self.file.tell() > > > The method seek() complains "OSError: [Errno 29] Illegal seek" > The device relpcfpga is a char device. > > The same code works with a normal text file. > I have tried to use os.open() and os.lseek() methods, but see the same > error. > Is there a different method to operate on device files? Some file streams are not seekable. Specifically, some (all?) char devices aren't seekable (because e.g. they can't be rewound or they have no end). You'd get the same error in C (well it would return -1). See also: http://www.linuxintro.org/wiki/Device -- http://mail.python.org/mailman/listinfo/python-list
Re: String object has no attribute "append"
On Tue, May 28, 2013, at 02:25 PM, Matt Graves wrote:
> I receive this error while toying around with Functions...
>
> def pulldata(speclist,speccolumn):
> with open('profiles.csv', 'r') as f:
> reader = csv.reader(f)
> for column in reader:
> (speclist).append(column[('speccolumn')])
>
> pulldata(speclist = 'numbers', speccolumn = "0")
>
>
> >Traceback (most recent call last):
> > File "C:\Desktop\Python\CFI\Devices V2\users.py", line 17, in
> >pulldata(speclist = 'numbers', speccolumn = "0")
> > File "C:\Desktop\Python\CFI\Devices V2\users.py", line 16, in pulldata
> >(speclist).append(column[('speccolumn')])
> >AttributeError: 'str' object has no attribute 'append'
>
> I'm getting the error because it should say "numbers.append", but it is
> reading it as "(speclist).append".
Because it indeed says "(speclist).append"... am I missing something?
--
http://mail.python.org/mailman/listinfo/python-list
Re: Reading log and saving data to DB
On Wed, Aug 14, 2013, at 09:18 AM, Guy Tamir wrote: > Hi all, > > I have a Ubuntu server running NGINX that logs data for me. > I want to write a python script that reads my customized logs and after > a little rearrangement save the new data into my DB (postgresql). > > The process should run about every 5 minutes and i'm expecting large > chunks of data on several 5 minute windows.. > > My plan for achieving this is to install python on the server, write a > script and add it to cron. > > My question is what the simplest way to do this? > should i use any python frameworks? Rarely do I put "framework" and "simplest way" in the same set. I would do 1 of 2 things: * Write a simple script that reads lines from stdin, and writes to the db. Make sure it gets run in init before nginx does and tail -F -n 0 to that script. Don't worry about the 5-minute cron. * Similar to above but if you want to use cron also store in the db the offset of the last byte read in the file, then when the cron job kicks off again seek to that position + 1 and begin reading, at EOF write the offset again. This is irrespective of any log rotating that is going on behind the scenes, of course. -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing / threading confusion
On Thu, Sep 5, 2013, at 03:27 PM, Paul Pittlerson wrote: > I'm trying to understand data handling using multiprocessing and > threading, haven't gotten very far without running into problems. This is > my code: [snip (not sure why you are using multiprocessing and threading at the same time] > What I expect to happen is the Debugger object will receive one string at > a time, and read it from the queue. But that's not what I see the the > output, the "started worker" stuff seems to print for every process, but > "ticked" and "exited" will show up in unpredictable ways, I'm guessing > they overwrite each other and therefore will not always appear in the > output. > > So I'm looking for help in trying to make sense of this kind of stuff, I > thought this was the basic functionality that Queue() would take care of > unless there is some other problem in my code. My output is probably totally different than your output. I only get the processes starting. Here's why: This stuff all runs asynchronously. When you start the "Debugger" thread.. I see you put a sleep() in it, but that guarantees nothing. At least on my machine which is somewhat loaded ATM, by the time the Processes are started, the Debugger thread has already finished (because of the check to see if the queue was empty). Apparently it is took longer than 1 second from the time the Debugger was started and the first Process was started. Likewise, what you are getting is probably a case where the queue is momentarily empty by the time the debugger loop gets ahold of the queue lock and checks to see if it's empty. Therefore the Debugger quits. Also because of the asynchronicity of processes, threads, you can not guarantee the order that the processes will get the opportunity to put() into the queue. Also you can't (and shouldn't) depend on the time that __del__ gets called. It can get called at any time, in any order and sometimes not at all.* Hope this helps. * http://docs.python.org/3/reference/datamodel.html?highlight=__del__#object.__del__ -- https://mail.python.org/mailman/listinfo/python-list
Re: os.system() not responding on django... any reason?
On Fri, Mar 1, 2013, at 09:24 AM, Roy Smith wrote: > In article <[email protected]>, > Jaiky wrote: > > [a lot of code involving ssh and paramiko] > > Here's a few general suggestions: > > 1) Try to reduce this to the smallest possible amount of code which > demonstrates the problem. You gave us a page full of complicated stuff. > Keep hacking away lines of code that don't change the behavior until you > get it down to something small and understandable. > > 2) Try to eliminate environmental problems. You're running this under > django? Does it work as a stand-alone process (i.e. without django)? Also, what is the context (Is it running in a Django view; a model? a signal handler? in settings?)? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is Ruby on Rails more popular than Django?
> My questions: > 1. Why is Ruby on Rails much more popular than Django? AFAIK Rails got a slightly longer head start than Django. And it has been said that RoR's first killer app was a screencast. A little marketing can go a long way. Since then Django has caught up a bit with RoR in terms of maturity and adoption (I think this is in part because of RoR's adoption slowing due to it not being the NKOTB anymore (not to mention a few security embarrassments)) . > 2. Why is there a much stronger demand for Ruby on Rails developers than > Django/Python developers? I'm not sure how big the difference is, but it's probably related to its early(er) adoption. Same reason that there is a stronger demand for PHP coders. PHP hit it big first, so there is a lot more PHP code to maintain. > 3. If Doppler Value Investing were your project instead of mine, would > you recommend the Ruby on Rails route or the Django route? If you already know/work with Python than I would go the Django route. RoR and Django are not that much different nowadays as far as methodologies. The main differences I think between RoR and Django are that one is Ruby-based and one is Python-based. Other than that, if you can get used to one you can get used to the other. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help me with Event handlers please
On Sun, Mar 17, 2013, at 03:30 PM, Dreamer wrote: > Hi can anybody share some expertise on event handlers...i need to use em > to update user activity in my web appthanks in advance > Cheers You're proably going to need to be more specific about what help you need. Just a generic "give me a hand with X" is probably not going to get you very far. -a -- http://mail.python.org/mailman/listinfo/python-list
