Re: [Tutor] Talking between C++ Python ?
On Friday 06 April 2007 08:29, Alan Gauld wrote: R. Alan Monroe [EMAIL PROTECTED] wrote I have written a Python app, a company who don't use Python want to integrate its back end with their C++ coded GUI. The data to from the C++, Python code consists of fairly large tables of up to 80,000 items. SQLite? That's a good idea if the apps are co-located. I had, for some reason, assumed they must be remote from each other when I suggested SOAP, but if they are co-located then a database is a good solution for those volumes. It probably requires that each end implements a poller to check for updates and a table or column to be added to indicate the status. Alan G. Yep both apps are on the same machine, the company just wants to put a corporate GUI on my Python code to claim it as their own because they cant work out how to convert some of the Python to C++ - I leverage the Python interpreter parsing to evaluate some fairly complex and user changeable logical expressions + I have written a class that sits on top of Reportlab to generate the PDF manuals. They don't want to re-write that either :) I am now learning C++, its interesting - takes a lot of code to do what in Python takes a line or two I had never heard of SOAP - there is just so much out there but it does seem to be for remote apps. SQLite ? - just Googled it and it looks interesting. Licence seems OK too - these guys are allergic to the GPL - reportlab is BSD. That's another reason that they want their own GUI - QT4 on windows Thanks once again Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Talking between C++ Python ?
Hi all, I have written a Python app, a company who don't use Python want to integrate its back end with their C++ coded GUI. At the moment they are proposing using CSV files to communicate between the Python C++, ie C++ GUI generates a CSV, calls Python back end, back end does the work and generates return CSV, Python exits back to C++. This would work but seems a bit messy. Any comments of suggestions on a better solution ? The data to from the C++, Python code consists of fairly large tables of up to 80,000 items. Many thanks for your help in advance Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Talking between C++ Python ?
On Thursday 05 April 2007 18:54, Alan Gauld wrote: Dave S [EMAIL PROTECTED] wrote At the moment they are proposing using CSV files to communicate between the Python C++, ie C++ GUI generates a CSV, calls Python back end, back end does the work and generates return CSV, Python exits back to C++. This would work but seems a bit messy. Any comments of suggestions on a better solution ? Sounds like a job for SOAP or XML/RPC. I'd probably opt for SOAP in this case. Have a look at the various python SOAP modules. pySOAP is one example. Alan G. Thanks for that - I will go investigate - Once the back end is integrated - its pay day £ :) Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] My Python project - an update
Very valid points, I was not aware that MD5 had been cracked :) Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] My Python project - an update
Just to say thank you. Over the last few months I have been asking a lot of dumb questions about python (and qt on the qt mailing list) ... anyhow I finished my pet project, all 5500 lines of it. I previously explained what it was but to recap ... I developed a QT Python app that scans both configuration and data collected from remote security systems, up to 80,000 data attributes per site. After scanning it reports any inconsistencies or errors via a GUI giving them a severity level and an option to correct the error or acknowledge and enter override text. It generates a certificate PDF with an embedded md5 authentication string when the site has been audited. From its analysis of the data it also generates both a detailed user reference PDF and a detailed engineer reference PDF specifically for the site. In my field this has never been done before - lots of very impressed people after several demonstrations. I released it under the GPL but apparently my terms of employment state that it belongs my employer ... who does not want it on sourceforge ... Where is it now ... its being integrated into a proprietary application as a groundbreaking audit/commissioning function (still running my Python code as a back end) and apparently I am due some kind of company reward ... My thoughts on my first Python QT project ... would have been nice if I could have given it to the community ... wonder what they will pay me ? ... Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Best IDE for Python
On Thursday 25 January 2007 03:12, Shadab Sayani wrote: Hi, I am using vim editor to code my project in python.Is there a good IDE where in I type the name of the class object and then dot then all the attributes of the object are displayed so on.I tried to install IDLE but I have no idea how to install tkinter? Any help that enables me to use good IDE as soon as possible is appreciated Thanks and Regards, Shadab I use ... http://www.die-offenbachs.de/detlev/eric.html ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] pyw bug ?
Hi all, My GUI app dumps some diagnostic output to the terminal, starting it from an XP terminal, all is well. Starting it as app.pyw so no terminal is needed - and err - the app randomly locks because the diagnostic output is - backing up ? Remove diagnostic output app.pyw is 100% reliable. ... mmm ... windows mutter mutter Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 'root' dir of a package from within the package ?
On Tuesday 09 January 2007 10:55, Michael Lange wrote: On Mon, 8 Jan 2007 19:24:37 + Dave S [EMAIL PROTECTED] wrote: Hi all, I have written a python package, which works fine, the 'root' directory is 'my_app' with sub directories within in, complete with there __init__.py files. I need to work out the path to the root directory from within the app, os.path gives me pythons path! - oh and its in XP. Any suggestions ? Hi Dave, app_root = os.path.abspath(sys.path[0]) or, within the main executable .py file, app_root = os.path.abspath(os.path.dirname(__file__)) should do the trick. I hope this helps Michael Many thanks, Sorry for the delay - work got in the way :) Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] 'root' dir of a package from within the package ?
Hi all, I have written a python package, which works fine, the 'root' directory is 'my_app' with sub directories within in, complete with there __init__.py files. I need to work out the path to the root directory from within the app, os.path gives me pythons path! - oh and its in XP. Any suggestions ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT GPL project finished, presentation looming
On Thursday 07 December 2006 22:35, Alan Gauld wrote: Dave S [EMAIL PROTECTED] wrote They will be concerned about using my app because I am one person. What if I get hit by a bus ! what if I leave ? This is a common problem in big companies including my own. For years they wouldn't even use the GNU software because it was unsupported. I even had to buy a commercial version of emacs for about $300... Ouch that must have hurt :( Eventually cygnus started offering support (for $5K per year) and they allowed us to use emacs, gcc etc Eventually even X windows. Cool :) Now they are more relaxed and we use Linux to run our internal DHCP and DNS, even some web servers... ...(It appears that none of the company's IT professionals can program !) That's also not unusual. In fact our company appears to be slowly heading that way. We used to have 11,000 IT professionals of which around 5000 were developers. Now we have 13,000 IT professionals of whom about 1000 still write code. The coding is mainly offshored to India and Eastern Europe. Our internal people are being retrained on higher value roles like business analysis, design/architecture, deployment/integration and project management. So sad - programming is s much creative fun. I have heard it being called an art form - I would agree with that. So I now program in python as and when I can and call it prototyping... They call it progress. 'progress' ... mmm 'modern man management' ... (cynical mmm ...) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] subprocess pyw conflict ?
On Thursday 07 December 2006 00:31, Luke Paireepinart wrote: Dave S wrote: Hi all, I thought I had my solution with subprocess ... my test code ... #!/usr/bin/env python # -*- coding: iso8859_1 -*- import subprocess a = subprocess.Popen('tasklist.exe', bufsize=0, stdout=subprocess.PIPE, universal_newlines=True) op = a.stdout.readlines() for i in op: if i.split(' ')[0] == 'gmanager.exe': f = open('E:\Documents and Settings\All Users\Desktop\gsr_running', 'w') f.close() works a treat when I run it as proc.py detects the process I am looking for writes a dummy file to the desktop. :) but I get a black windows terminal flash up. The code will eventually run in an app.pyw so to check it would be OK I renamed my working proc.py to proc.pyw - it fails :(, No window (as expected), no dummy file (not expected) - the process gmanager.exe is running. So there seems to be a problem with subprocess pyw Googling I found ... https://sourceforge.net/tracker/?func=detailatid=105470aid=1358527grou p_id=5470 So I tried the suggested workaround with proc.pyw ... #!/usr/bin/env python # -*- coding: iso8859_1 -*- import subprocess a = subprocess.Popen('tasklist.exe', bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True) op = a.stdout.readlines() a.stdin.close() for i in op: if i.split(' ')[0] == 'gmanager.exe': f = open('E:\Documents and Settings\All Users\Desktop\gsr_running', 'w') f.close() Still zip, and because there is no terminal, I cannot view any errors ! Any suggestions welcome :) Well, because I'm batting 0 on this thread so far, I think I'll just go ahead and suggest another bad solution! You could try redirecting the output of sys.stderr to a file, and you might be able to see the error message! :D If you hadn't said 'any suggestions welcome' I might've kept this to myself :P Ahhh .. 'any suggestions' is an SOS call - all any any ideas are warmly greeted :) import sys class TestClass(object): def __init__(self): self.data = [] def write(self,item): self.data.append(item) a = TestClass() sys.stderr = a salfjdsljfka321423 print a.data ['\nTraceback (most recent call last):', '\n', ' File pyshell#14, line 1, in -toplevel-\n', 'salfjdsljfka321423\n', NameError: name 'salfjdsljfka321423' is not defined\n] Except instead of a file-like class, you could just use a real file. But then it would only leave the last line intact. So you'd probably want to make a class that wraps a file object, where the write method just appends to an internal list, and it writes it all out to the file when you call the Class.close() or whatever. Actually, I guess the program stops executing on an exception... Hmm, not really sure what you'd do exactly. Sure, there are better solutions, and this doesn't really help you with your original problem, but it at least lets you see your error message! HTH, -Luke Thanks for that - I will give it a go post back :) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] subprocess pyw conflict ?
On Thursday 07 December 2006 10:25, Dave S wrote: On Thursday 07 December 2006 00:31, Luke Paireepinart wrote: Dave S wrote: Hi all, I thought I had my solution with subprocess ... my test code ... #!/usr/bin/env python # -*- coding: iso8859_1 -*- import subprocess a = subprocess.Popen('tasklist.exe', bufsize=0, stdout=subprocess.PIPE, universal_newlines=True) op = a.stdout.readlines() for i in op: if i.split(' ')[0] == 'gmanager.exe': f = open('E:\Documents and Settings\All Users\Desktop\gsr_running', 'w') f.close() works a treat when I run it as proc.py detects the process I am looking for writes a dummy file to the desktop. :) but I get a black windows terminal flash up. The code will eventually run in an app.pyw so to check it would be OK I renamed my working proc.py to proc.pyw - it fails :(, No window (as expected), no dummy file (not expected) - the process gmanager.exe is running. So there seems to be a problem with subprocess pyw Googling I found ... https://sourceforge.net/tracker/?func=detailatid=105470aid=1358527gr ou p_id=5470 So I tried the suggested workaround with proc.pyw ... #!/usr/bin/env python # -*- coding: iso8859_1 -*- import subprocess a = subprocess.Popen('tasklist.exe', bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True) op = a.stdout.readlines() a.stdin.close() for i in op: if i.split(' ')[0] == 'gmanager.exe': f = open('E:\Documents and Settings\All Users\Desktop\gsr_running', 'w') f.close() Still zip, and because there is no terminal, I cannot view any errors ! Any suggestions welcome :) Well, because I'm batting 0 on this thread so far, I think I'll just go ahead and suggest another bad solution! You could try redirecting the output of sys.stderr to a file, and you might be able to see the error message! :D If you hadn't said 'any suggestions welcome' I might've kept this to myself :P Ahhh .. 'any suggestions' is an SOS call - all any any ideas are warmly greeted :) import sys class TestClass(object): def __init__(self): self.data = [] def write(self,item): self.data.append(item) a = TestClass() sys.stderr = a salfjdsljfka321423 print a.data ['\nTraceback (most recent call last):', '\n', ' File pyshell#14, line 1, in -toplevel-\n', 'salfjdsljfka321423\n', NameError: name 'salfjdsljfka321423' is not defined\n] Except instead of a file-like class, you could just use a real file. But then it would only leave the last line intact. So you'd probably want to make a class that wraps a file object, where the write method just appends to an internal list, and it writes it all out to the file when you call the Class.close() or whatever. Actually, I guess the program stops executing on an exception... Hmm, not really sure what you'd do exactly. Sure, there are better solutions, and this doesn't really help you with your original problem, but it at least lets you see your error message! HTH, -Luke Thanks for that - I will give it a go post back :) Oh my head OK after much tinkering I got the following to work with .pyw # scan windows task list to see if GSR is running f = os.popen('tasklist.exe', 'r') plist = f.readlines() f.close gsr_running = False # scan for GSR program for line in plist: if line.split(' ')[0] == 'gmanager.exe': gsr_running = True A Dave can relax, chill, project finished ... all works ... god .. (homer simpson moment !) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] OT GPL project finished, presentation looming
OK this is an OT question I have just finished a Python QT project for work, written in my own free time over the last several months (and with a lot of help from you guys :). Its 5500 lines of python over several modules (for me that huge) and a CSV 'rules' file of 500 lines, all GPL'd We use a commercial program that connects to remote intruder alarm systems and downloads their configs. Up to 80,000 software attributes per site. My python QT app scans the database files (.dbf), decodes them, scans them against a CSV list of rules and throws any anomaly's out to a GUI. It essentially audits the site programming checking for incorrect programming, configuration errors etc. In addition it generates audited PDF certificates, engineer summary's PDFs and user manuals PDFs for each specific site. Sometime in January I have to give a presentation and I know one of the questions will be. Its what we want but you are not a company, what if you leave ? I need an answer,.. What am I asking ... If need be are any of you for hire ? Dave PS it looks great, would love to post some pngs but it would violate the list rules :( ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT GPL project finished, presentation looming
On Thursday 07 December 2006 17:54, Luke Paireepinart wrote: Dave S wrote: [snip explanation of program] Sounds really cool! Its a bit niche - but cool Sometime in January I have to give a presentation and I know one of the questions will be. Its what we want but you are not a company, what if you leave ? I need an answer,.. My understanding is that if it's GPL'ed, they can use it whether you work there or not. Is that not true? Sorry I did not mean that, the GPL thing is AOK What am I asking ... If need be are any of you for hire ? Why would hiring someone else help in this situation? I work for national company, they are very interested in what I am doing, there is nothing else in the marketplace that does this, but they are used to dealing with large software company's. They will be concerned about using my app because I am one person. What if I get hit by a bus ! what if I leave ? what happens when a new version of controller comes out new CSV rules need to be written - what would they do ? Its all GPL so no secrets, my guess is that if $$ was offered to the Python community someone would be willing to maintain the code but I am unsure of how it would actually work ? Is it a case of hello, python programmer for hire ? or is there an 'official' procedure that I can include in my presentation ? I would guess this is a common problem for GPL software being introduced into commercial settings (the whole support thing). (It appears that none of the company's IT professionals can program !) Dave PS it looks great, would love to post some pngs but it would violate the list rules :( You can just upload the PNGs to a free webhost and link us to them, like Photobucket or Imageshack. I imagine people just don't want big attachments in their e-mail. If you give them a link to the picture then they only have to download it if they really want to see what it is. OK I will do my presentation then do that as a kind of thank you for all your help :) HTH, -Luke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XP catching execl o/p ?
On Tuesday 05 December 2006 23:32, Alan Gauld wrote: Dave S [EMAIL PROTECTED] wrote Struggling with python XP again. My app needs to know if a certain program is running on my XP box os.execl('') It throws the output to the terminal + I need the exact path to the executable (a bit of a trial) Any ideas how I can catch the output ? Look at the popen family of functions in the os module, and then look at the subporocess module which supercedees them (but the docs are expressed in tems of the oold functions!) Use subprocess because the older popen functions don't always work reliably on Windows - there is a separate popen as part of the winall package, but I think subprocess.Popen works Ok. There is more on this, including a simple example using subprocess, in my OS topic in my tutorial. HTH, OK playing around I knocked up some test code ... #!/usr/bin/env python # -*- coding: iso8859_1 -*- import subprocess a = subprocess.Popen('tasklist.exe', bufsize=0, shell=False, stdout=subprocess.PIPE, stderr=None, stdin=None, universal_newlines=True) op = a.stdout.readlines() for i in op: #print i #print pass #raw_input() This gives me what I need except when it runs windows flashes up a large black terminal window for a split second (yuk) This test would be performed while my app is running so thats not so good :) Any ideas on how to stop it displaying ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XP catching execl o/p ?
On Wednesday 06 December 2006 08:48, Tim Golden wrote: | Struggling with python XP again. My app needs to know if a | certain program is running on my XP box As a complete alternative, consider using WMI: code - UNTESTED import os, sys import wmi c = wmi.WMI () for process in c.Win32_Process (Name=excel.exe): print Excel is running break else: print Excel is not running /code (Uses: http://timgolden.me.uk/python/wmi.html) TJG Just looked at WMI - didn't know it existed ! Am going down the subprocess route first as its 'built in'. If that does not work - hello WMI Cheers Dave This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XP catching execl o/p ?
On Wednesday 06 December 2006 11:04, Kent Johnson wrote: Dave S wrote: Hi all, Struggling with python XP again. My app needs to know if a certain program is running on my XP box Ideal world - I can get the output of 'tasklist.exe' into a string. I have tried os.execl('') It throws the output to the terminal + I need the exact path to the executable (a bit of a trial) and os.startfile('...') it throws the output to a different window, but no exact path needed I'm not sure if this is helpful, but here is a program that uses subprocess.Popen() to capture the output of cmd.exe. It makes a text file which contains all the command help. By Scott David Daniels, taken from http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl=en; import subprocess as subp p = subp.Popen(cmd.exe /X/D/F:ON, stdin=subp.PIPE, stdout=subp.PIPE, stderr=subp.STDOUT) flag = (@@} print p.stdin, PROMPT, flag print p.stdin, HELP print p.stdin, EXIT text = p.stdout.read() p.wait() helptext = text[text.index(flag + 'HELP') + len(flag) + 4 : text.index(flag + 'EXIT')] words = [line.split(None, 1)[0] for line in helptext.split('\n') if line.strip()] commands = [word for word in words if word.isupper()] dest = open('cmd_help.txt', 'wb') p = subp.Popen(cmd.exe /X/D/F:ON, stdin=subp.PIPE, stdout=dest, stderr=subp.STDOUT) print p.stdin, PROMPT () print p.stdin, HELP for command in commands: print p.stdin, HELP, command print p.stdin, EXIT p.wait() dest.close() Kent The above is usefull, I am starting to print out these snippets for reference :). I have got subprocess to get the data I am now trying to get rid of the windows terminal flashing on my screen. Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XP catching execl o/p ?
On Wednesday 06 December 2006 11:43, Dave S wrote: On Tuesday 05 December 2006 23:32, Alan Gauld wrote: Dave S [EMAIL PROTECTED] wrote Struggling with python XP again. My app needs to know if a certain program is running on my XP box os.execl('') It throws the output to the terminal + I need the exact path to the executable (a bit of a trial) Any ideas how I can catch the output ? Look at the popen family of functions in the os module, and then look at the subporocess module which supercedees them (but the docs are expressed in tems of the oold functions!) Use subprocess because the older popen functions don't always work reliably on Windows - there is a separate popen as part of the winall package, but I think subprocess.Popen works Ok. There is more on this, including a simple example using subprocess, in my OS topic in my tutorial. HTH, OK playing around I knocked up some test code ... #!/usr/bin/env python # -*- coding: iso8859_1 -*- import subprocess a = subprocess.Popen('tasklist.exe', bufsize=0, shell=False, stdout=subprocess.PIPE, stderr=None, stdin=None, universal_newlines=True) op = a.stdout.readlines() for i in op: #print i #print pass #raw_input() This gives me what I need except when it runs windows flashes up a large black terminal window for a split second (yuk) This test would be performed while my app is running so thats not so good :) Any ideas on how to stop it displaying ? Dave 10 carrot idiot here :) change from test.py to test.pyw :) dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] subprocess pyw conflict ?
Hi all, I thought I had my solution with subprocess ... my test code ... #!/usr/bin/env python # -*- coding: iso8859_1 -*- import subprocess a = subprocess.Popen('tasklist.exe', bufsize=0, stdout=subprocess.PIPE, universal_newlines=True) op = a.stdout.readlines() for i in op: if i.split(' ')[0] == 'gmanager.exe': f = open('E:\Documents and Settings\All Users\Desktop\gsr_running', 'w') f.close() works a treat when I run it as proc.py detects the process I am looking for writes a dummy file to the desktop. :) but I get a black windows terminal flash up. The code will eventually run in an app.pyw so to check it would be OK I renamed my working proc.py to proc.pyw - it fails :(, No window (as expected), no dummy file (not expected) - the process gmanager.exe is running. So there seems to be a problem with subprocess pyw Googling I found ... https://sourceforge.net/tracker/?func=detailatid=105470aid=1358527group_id=5470 So I tried the suggested workaround with proc.pyw ... #!/usr/bin/env python # -*- coding: iso8859_1 -*- import subprocess a = subprocess.Popen('tasklist.exe', bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True) op = a.stdout.readlines() a.stdin.close() for i in op: if i.split(' ')[0] == 'gmanager.exe': f = open('E:\Documents and Settings\All Users\Desktop\gsr_running', 'w') f.close() Still zip, and because there is no terminal, I cannot view any errors ! Any suggestions welcome :) Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] XP catching execl o/p ?
Hi all, Struggling with python XP again. My app needs to know if a certain program is running on my XP box Ideal world - I can get the output of 'tasklist.exe' into a string. I have tried os.execl('') It throws the output to the terminal + I need the exact path to the executable (a bit of a trial) and os.startfile('...') it throws the output to a different window, but no exact path needed Any ideas how I can catch the output ? Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XP catching execl o/p ?
On Tuesday 05 December 2006 20:58, Luke Paireepinart wrote: Dave S wrote: Hi all, Struggling with python XP again. My app needs to know if a certain program is running on my XP box Ideal world - I can get the output of 'tasklist.exe' into a string. I have tried os.execl('') It throws the output to the terminal + I need the exact path to the executable (a bit of a trial) and os.startfile('...') it throws the output to a different window, but no exact path needed Any ideas how I can catch the output ? You could try redirecting sys.stdout to a file-like class instance you create. OK ... could you give me a bit more on that ? ... probably me being a bit dense :) Cheers Dave Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] XP catching execl o/p ?
On Tuesday 05 December 2006 23:32, Alan Gauld wrote: Dave S [EMAIL PROTECTED] wrote Struggling with python XP again. My app needs to know if a certain program is running on my XP box os.execl('') It throws the output to the terminal + I need the exact path to the executable (a bit of a trial) Any ideas how I can catch the output ? Look at the popen family of functions in the os module, and then look at the subporocess module which supercedees them (but the docs are expressed in tems of the oold functions!) Use subprocess because the older popen functions don't always work reliably on Windows - there is a separate popen as part of the winall package, but I think subprocess.Popen works Ok. There is more on this, including a simple example using subprocess, in my OS topic in my tutorial. HTH, Thanks for your help - I will take a look. :) Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] finding AcroRd32.exe - a better way ?
My app generates an on the fly PDF manual by using reportlab, once generated I would like it to be automatically opened and displayed by XP adobe reader. Here's where I get stuck. ... os.execv('E:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe', ('/n', '/s', 'user.pdf')) Does what I need and works great but I manualy searched around to find the path to AcroRd32.exe. Short of writting some code to scan any adobe dirs for this exe is there a more elegant way for me to ensure my app will work on any windows machine ? Any pointers would be greatly appreciated Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] finding AcroRd32.exe - a better way ?
On Thursday 30 November 2006 20:50, Terry Carroll wrote: On Thu, 30 Nov 2006, Dave S wrote: My app generates an on the fly PDF manual by using reportlab, once generated I would like it to be automatically opened and displayed by XP adobe reader. Here's where I get stuck. ... os.execv('E:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe', ('/n', '/s', 'user.pdf')) Does what I need and works great but I manualy searched around to find the path to AcroRd32.exe. Short of writting some code to scan any adobe dirs for this exe is there a more elegant way for me to ensure my app will work on any windows machine ? try this: os.startfile('user.pdf') Neat, cool 100% what I was looking for :):):) Cheers Dave PS I would offer to buy you a pint - but you probably don't live near Bedford England ! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] exception not raised XP file ?
Due to some sloppy programming on a commercial app :) I have a problem. I have some directories on an XP machine, I need to know which of these directories (*.cab_tmp) contains a file that that is being accessed by another XP program. I set it up so that a known file (SIZES.DBF) in a known directory is being accessed by said program. If I attempt to open said file with wordpad I get the error 'the document ...SIZES.DBF... is being used by another application and cannot be accessed !' So I wrote the following code posDirNames = filter((lambda x: x[-7:] == 'cab_tmp'), os.listdir(gsrpath)) for dirName in posDirNames: print dirName for fileName in os.listdir(gsrpath + '/' + dirName): try: file = gsrpath + '/' + dirName + '/' + fileName if fileName == 'SIZES.DBF': print file, f = open(file, 'w') f.close() except: print 'xx', print fileName, sys.exc_info() Expecting it to raise an exception when it hits SIZES.DBF because I am opening the file to write - no exception is raised. I know it is scanning SIZES.DBF because my if statement picks it up. Any ideas ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] exception not raised XP file ?
On Saturday 18 November 2006 16:08, Roel Schroeven wrote: Dave S schreef: Due to some sloppy programming on a commercial app :) I have a problem. I have some directories on an XP machine, I need to know which of these directories (*.cab_tmp) contains a file that that is being accessed by another XP program. To me the easiest solution seems to be using Process Explorer or Handle from Sysinternals (at http://www.microsoft.com/technet/sysinternals currently). At first sight your Python solution looks good to me; I don't know why it doesn't work. Another approach I have used in the past is trying to rename the directory instead of trying to open a file in that directory: Windows cannot rename the directory when some program has a file open in that directory. At least that's my experience. Thanks for the tip :) Is it just me - I seem to run into a lot of weird behaviour in windows (but then I am a Linux Junky :) Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] free IDE for Python?
On Monday 13 November 2006 23:03, Vadhri, Srinivas wrote: Hi A newbie to Python. What is the free IDE for Python development activities? ActiveState's Komodo IDE needs a license and a fee. Any recommendations? Eric3/4 works for me :) http://www.die-offenbachs.de/detlev/eric3-screenshots.html Regards, Srinivas Vadhri ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] .sort(key = ???)
Hi, I have a bunch of lists within lists that I need to sort ref item [4], I can't access my code at the moment but I basically ... a = [[...], [...], ] a.sort(item4) def item4(a,b): return a[4], b[4] Having googled I think there is a better way of doing this with the key attribute a.sort(key= ?? ) I cant get a handle on how key works or how to code it for my needs. Can anyone help ? Thanks in advance Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] .sort(key = ???)
On Thursday 16 November 2006 22:35, John Fouhy wrote: On 17/11/06, Dave S [EMAIL PROTECTED] wrote: Hi, I have a bunch of lists within lists that I need to sort ref item [4], I can't access my code at the moment but I basically ... [...] Having googled I think there is a better way of doing this with the key attribute a.sort(key= ?? ) Yep, that's right. You need at least python2.4 for this, though. You need to pass the key= parameter a function that will take an element of your list, and return the comparison key. eg: def item4(elem): return elem[4] a.sort(key=item4) Since this is a common thing to do, there is a function in the operator module that you can use, instead of defining your own: import operator a.sort(key=operator.itemgetter(4)) (operator.itemgetter(4) will return a function that is basically equivalent to item4() above) HTH! Sure does - cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] file open (take 2)
On Wednesday 27 September 2006 21:59, Dave S wrote: Hi, I am trying to read in an ascii text file, do some alterations and write it back. file = open(self.config.get('pdf','cert') + '/cert.pdf' , 'r+') lines = file.readlines() ... process lines ... file.writelines(lines) file.close() works but ends up appending a second modified copy to the original ... as per the python ref. Am I right in thinking that the only way is to open with a 'r', close them open with a 'w' ? Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Thanks for all your input - that's great - I also learnt about file.rewind() and file.seek(0) :) Thanks once again Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] getting 'pwd' for XP ?
I currently running XP (like a fish out of water :) and I need to know the dir that the python script is executed from. a linux 'pwd' How can I achieve this - I have looked in sys os os.path but found nothing suitable Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting 'pwd' for XP ?
On Thursday 28 September 2006 16:42, Shantanoo Mahajan wrote: +++ Dave S [28-09-06 16:10 +0100]: | I currently running XP (like a fish out of water :) and I need to know | the dir that the python script is executed from. a linux 'pwd' How can I | achieve this - I have looked in sys os os.path but found nothing | suitable Python 2.4.3 (#2, Sep 26 2006, 15:27:42) [GCC 3.4.4 [FreeBSD] 20050518] on freebsd6 Type help, copyright, credits or license for more information. import os os.getcwd() '/tmp' os.getcwd() it is - must have missed it - thanks Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] file open (take 2)
Hi, I am trying to read in an ascii text file, do some alterations and write it back. file = open(self.config.get('pdf','cert') + '/cert.pdf' , 'r+') lines = file.readlines() ... process lines ... file.writelines(lines) file.close() works but ends up appending a second modified copy to the original ... as per the python ref. Am I right in thinking that the only way is to open with a 'r', close them open with a 'w' ? Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] module file copy ?
OK have I missed it - but which module is file copy in ? I looked all around OS but no luck - I can find rename(src, dst) but that's about it. Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] exit app withour raise ?
In the middle of an application, if someone presses the quit button I want to exit. At the moment i raise 'Quit button pressed' which works but spews a stack trace leading to the raise statement. Is there a neat way to just exit without a stack trace ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] exit app withour raise ?
On Sunday 17 September 2006 17:54, Alan Gauld wrote: In the middle of an application, if someone presses the quit button I want to exit. At the moment i raise 'Quit button pressed' which works but spews a stack trace leading to the raise statement. Is there a neat way to just exit without a stack trace ? raise SystemExit or more commonly import sys sys.exit() You can add an argument to exit and that will be the error value returned to the OS. Alan G. Thanks for that - it works great :) Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Package problem
I am having a problem with packaging. I have setup the PYTHONPATH to the core dir with __init__.py in the sub directories. It all worked as expected - then I hit a problem :( I have a module scanDBFs in dir main with a def of getDbfData The module I am executing is DocViewDoc in QT DocViewDoc can import with ... from main.scanDBFs import getDbfDir and execute it with ... a = getDbfData(dbf) So I know it works ... however I prefer to import main.scanDBFs and execute it with ... a = scanDBFs.getDbfData(dbf) So I can see which module it comes from However when i try the latter I get ... File ./DocViewDoc.py, line 80, in AuditEngine a = scanDBFs.getDbfData(dbf) NameError: global name 'scanDBFs' is not defined [EMAIL PROTECTED]:~/python_develop/unison/PxQxAudit/QT$ I am stuck ! - The only other thing Is that this is executed within a class, but that should not cause a problem. I have tried a = main.scanDBFs.getDbfData(dbf) but keep hitting the same problem. Any ideas ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Larger GUI design ?
I have managed to write a small GUI app, it had a frm_app.py from eric3s QT designer a dlg_app.py which defined a class that inherited the frm_app.py class ... all AOK I am now on a more ambitious project. There will be a main app screen, some dialogue screens for more info etc and a backend script analysing a database which will take some time to run. The backend script is almost there, just tons of auditing rules to write for it but the backend 'engine' is working. How to fit the GUI around it ? If I have my dlg_app.py inhereting frm_app.py all is well until I need a poppup dialogue. Would I define another module say dlg_info.py with its frm_info.py which I would import and call when needed generating its own QT object and window. And in that module code something like the following would make the window on the fly ? app = QApplication(sys.argv) win = info() app.setMainWidget(win) win.show() QObject.connect(app, SIGNAL('lastWindowClosed()'),app, SLOT('quit()')) app.exec_loop() Secondly my backend will take a while to run I would like to display a status bar in the GUI. The only way i can see to do this is to either (1) make my backend a class inherit dlg_app.py so I can access the QT widget directly or (2) pass info from the backend via a socket (yep know about them now!) to a QT script running in timerEvent() Which is the best method ? Or is there a better way ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Larger GUI design ?
On Tuesday 22 August 2006 17:15, Alan Gauld wrote: I am now on a more ambitious project. There will be a main app screen, some dialogue screens for more info etc and a backend script analysing a database which will take some time to run. How to fit the GUI around it ? If I have my dlg_app.py inhereting frm_app.py all is well until I need a poppup dialogue. Its usually better to make popups inherit directly from TopLevel rather than the parent form OK I will look into that Would I define another module say dlg_info.py with its frm_info.py Its usually best to put each significant window/dialog in its own form. It makes them easier to reuse in other projects for one thing! Code reuse is good would import and call when needed generating its own QT object and window. Not sure how QT works so can't comment on that. app = QApplication(sys.argv) Are you sure there isn't a QDialog base class somewhere in QT? Thats usually been the case in other GUI toolkits I've used. Base class ? OK you lost me - I will dig into the docs Secondly my backend will take a while to run I would like to display a status bar in the GUI. The only way i can see to do this is to either Sounds like a job for a thread... (2) pass info from the backend via a socket (yep know about them now!) to a QT script running in timerEvent() You can do this but threads are less resource greedy. I had not thought of a thread - thats a cool solution Thanks for your suggestions, Its probably obvious for you old hands but its a whole new world for us beginners :) You have given me enough info to run with - I will give it a go see what happens Dave HTH, Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] A list in list problem
Help :) I have been playing with this for several hours am totally stuck ! I am happy with the following ... a=[1,2,3] b=[5,6,7] a [1, 2, 3] b [5, 6, 7] g=[] g [] g.append(a) g [[1, 2, 3]] g.append(b) g [[1, 2, 3], [5, 6, 7]] So when I needed to make a list of a list in the following code I thought no problem ... def CSV_Lines(self, csv, from_, to): Returns a list of cleaned up lines from csv 'from_' line number 'to' line number clean_line = clean_csv = [] for string in range(from_, to): split_string = csv[string].split(',') split_string = split_string[1:-1] # Strip the LHS column + the /n' if split_string[0] == '' : continue # Skip empty lines print '##' print 'split_string ', split_string for string in split_string: if len(string) 0: clean_line.append(string[1:-1]) print 'clean_line ',clean_line clean_csv.append(clean_line) print 'clean_csv ',clean_csv clean_line = [] But I get clean_csv trouble ... [EMAIL PROTECTED]:~/python_develop/unison/PxQxAudit/main$ ./crosscheck.py ## split_string ['temp1', 'wow a variable', '', '', ''] clean_line ['temp1', 'wow a variable'] clean_csv ['temp1', 'wow a variable', [...]] ## split_string ['temp2', '', '', '', ''] clean_line ['temp2'] clean_csv ['temp1', 'wow a variable', [...], ['temp2']] [EMAIL PROTECTED]:~/python_develop/unison/PxQxAudit/main$ ie clean_csv ends up as ['temp1', 'wow a variable', [...], ['temp2']] instead of [[temp1, wow a variable], [temp2]] Please help Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A list in list problem
On Monday 21 August 2006 10:59, dave s wrote: Several hours +1 Sometimes it is usefull spelling out my problem in an email - seems to clarify it - maybe when I get to the 'im stuck' I should send an email to myself :) clean_csv.append(clean_line) ... should by clean_csv.append(clean_line[:]) But the real showstopper was clean_line = clean_csv = [] and then if len(string) 0: clean_line.append(string[1:-1]) changes clean_csv as well, I guess because its an appens not a reassignment Sorry for bothering you guys Dave Help :) I have been playing with this for several hours am totally stuck ! I am happy with the following ... a=[1,2,3] b=[5,6,7] a [1, 2, 3] b [5, 6, 7] g=[] g [] g.append(a) g [[1, 2, 3]] g.append(b) g [[1, 2, 3], [5, 6, 7]] So when I needed to make a list of a list in the following code I thought no problem ... def CSV_Lines(self, csv, from_, to): Returns a list of cleaned up lines from csv 'from_' line number 'to' line number clean_line = clean_csv = [] for string in range(from_, to): split_string = csv[string].split(',') split_string = split_string[1:-1] # Strip the LHS column + the /n' if split_string[0] == '' : continue # Skip empty lines print '##' print 'split_string ', split_string for string in split_string: if len(string) 0: clean_line.append(string[1:-1]) print 'clean_line ',clean_line clean_csv.append(clean_line) print 'clean_csv ',clean_csv clean_line = [] But I get clean_csv trouble ... [EMAIL PROTECTED]:~/python_develop/unison/PxQxAudit/main$ ./crosscheck.py ## split_string ['temp1', 'wow a variable', '', '', ''] clean_line ['temp1', 'wow a variable'] clean_csv ['temp1', 'wow a variable', [...]] ## split_string ['temp2', '', '', '', ''] clean_line ['temp2'] clean_csv ['temp1', 'wow a variable', [...], ['temp2']] [EMAIL PROTECTED]:~/python_develop/unison/PxQxAudit/main$ ie clean_csv ends up as ['temp1', 'wow a variable', [...], ['temp2']] instead of [[temp1, wow a variable], [temp2]] Please help Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A list in list problem
On Monday 21 August 2006 13:40, Alan Gauld wrote: So when I needed to make a list of a list in the following code I thought no problem ... def CSV_Lines(self, csv, from_, to): Returns a list of cleaned up lines from csv 'from_' line number 'to' line number clean_line = clean_csv = [] So clean_line is a reference to clean_csv which is a reference to a list. That is, both variables point to the same list? I don't think thats what you wanted... Remember that Python variables are references to objects, in this case they both reference the same list object. In the past I have assigned multiple variables by var1 = var2 = 0 when one of the variables is assigned a different value, another object is created and var1 var2 are separate. Without thinking I tried to do the same with the two lists. a=b=[] a [] b [] a=[1,2,3] a [1, 2, 3] b [] Tinkering some more I think it is the append that did it. a=b=[] a [] b [] a.append([1,2,3]) a [[1, 2, 3]] b [[1, 2, 3]] It appended to the common object and did not create a separate one ? I guess var1 = var2 = 0 is generally bad programming style ?. I keep trying to get my code more compact using list comprehension etc - in this case compact got me into trouble. I have tried looking at some open source projects eg kdissert,sbackup to get into good codeing habits but they are a bit above me. So I am learning by trying. (1 x GUI app written, a more advanced one on the way) Thanks for all your help Dave PS This is probably an impossible question but I always struggle to find names for variables - any hints ? print 'clean_line ',clean_line clean_csv.append(clean_line) So the list has just appended itself to itself, that why python shows the slightly wierd [...] because its a recursively defined list. That sounds bad - and sure confused me ! print 'clean_csv ',clean_csv clean_line = [] And now you make clean_line point to a new empty list So next time round the vcontents ofg the new clean line will be appended to the old one. Go back and initialise your lists as two separate lists and you will get what you expect. clean_line ['temp1', 'wow a variable'] clean_csv ['temp1', 'wow a variable', [...]] The original with itself tagged on. clean_line ['temp2'] clean_csv ['temp1', 'wow a variable', [...], ['temp2']] The above list with the new list added Just as expected :-) HTH, Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A list in list problem
On Monday 21 August 2006 17:41, Alan Gauld wrote: a=b=[] a [] b [] These are the same list. a=[1,2,3] But here you create a new list and assign it to a. a [1, 2, 3] b [] So a points to the new list and b to the original. Tinkering some more I think it is the append that did it. Yes, the append adds the data to the original list. a=b=[] a [] b [] a.append([1,2,3]) a [[1, 2, 3]] b [[1, 2, 3]] Exactly so. It appended to the common object and did not create a separate one ? Yes, the first assignment to 'a' created a new list and broke the shared reference. I almost never use the x=y=value style for this reason. For the minimal amount of typing I prefer either x = value1 y = value2 or tuple assignment: x,y = v1,v2 Which for lists is: x,y = [],[] ie two separate empty lists. I guess var1 = var2 = 0 is generally bad programming style ? Its fine if you're sure it's what you want, but what it looks like isn't always what you get... as you discovered :-) get my code more compact using list comprehension etc Compact code is not always a virtue. Tuple assignment seems to me a good compromise. And FWIW I try to limit tuple assignment to 3 values max just for clarity. Also I try to ensure the variables are linked in some way - like x,y coordinates, or similar types of variable: max_len, min_len etc Tupples, hadn't thought of that - I like it :) PS This is probably an impossible question but I always struggle to find names for variables - any hints ? Write a description of what it is there for - what does it do in the program. Abbreviate that to a couple of key words. That's your name... If you want a more detailed view find a copy of Code Complete by McConnell, it has a whole chapter on variable naming issues... Your variable names looked ok to me FWIW. Ahh buts that's the 5th time I have changed them - you should have seen the previous trys :) Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] rstrip() failure ?
I have a string problem. The following code skips the loop if the string 'app' is on the banned list ... self.ban_app_list = [' ', 'live_dat', 'exact_sl', 'html_str', 'valid_da', 'datacore', 'check_co', 'logger'] if app in self.ban_app_list: continue the string 'app' is derived from some more string splicing. All works well except for 'logger', the 'app' string becomes 'logger ' so no match. So I app.rstrip() thinking it would sort the problem. no go :( len(app) is still 8. OK ... I am stuck ... Is there a way to show the ascii values of the string - kind of hexedit for a string I am sure the padding blanks are just spaces rstrip() appears to disagree Any help greatly appreciated Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Doh!] rstrip() failure ?
On Wednesday 09 August 2006 20:45, dave s wrote: I have a string problem. The following code skips the loop if the string 'app' is on the banned list ... self.ban_app_list = [' ', 'live_dat', 'exact_sl', 'html_str', 'valid_da', 'datacore', 'check_co', 'logger'] if app in self.ban_app_list: continue the string 'app' is derived from some more string splicing. All works well except for 'logger', the 'app' string becomes 'logger ' so no match. So I app.rstrip() thinking it would sort the problem. no go :( len(app) is still 8. OK ... I am stuck ... Is there a way to show the ascii values of the string - kind of hexedit for a string I am sure the padding blanks are just spaces rstrip() appears to disagree Any help greatly appreciated Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Stupid basic error held me up for a couple of hours :) app.rstrip() should have been app = app.rstrip() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] rstrip() failure ?
On Wednesday 09 August 2006 21:11, you wrote: Is there a way to show the ascii values of the string - kind of hexedit for a string Try running repr() on the string: it will show an external programmer-friendly representation that should be easier to read. For example: ## msg = 'hello\000world' print repr(msg) 'hello\x00world' ## Thanks for that :) Have just found my solution without resorting to ascii strings after all but the above will be usefull Thanks once again Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] creating a method name on the fly
I need to scan a long list of QT tickboxes in a dialog. I need to execute pseudo code something like ... list = ['error_button', 'print_button' ... etc ] for key in list: button= list[key] print button, self.button.isChecked() where self.button.isChecked() becomes self.error_button.isChecked() ... self.print_button.isChecked() etc etc Can anyone tell me how to do this ? I have looked at apply but with no luck Thanks Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] open(file, 'rw') problem
Good morning, I am having a problem with file open, read write. The example shows my problem. I would have expected it to print a sequence 1,2,3,4 incrementing every time it is run. #!/usr/bin/env python import os, shutil, time basher_dir = '/home/dave/PodCasts' bit_bucket = basher_dir + '/xbit_bucket' cd_count = bit_bucket + '/xcd_count' if not os.path.isfile(cd_count): f = open(cd_count, 'w') f.write('0') f.close() f = open(cd_count,'rw') n = int(f.read()) n += 1 print n f.seek(0) f.write(str(n)) f.close() Instead I get ... [EMAIL PROTECTED]:~/my_files/python_develop/unison/podsplit$ ./test.py 1 Traceback (most recent call last): File ./test.py, line 20, in ? f.write(str(n)) IOError: [Errno 9] Bad file descriptor [EMAIL PROTECTED]:~/my_files/python_develop/unison/podsplit$ It appears to be a problem with me opening the file as 'rw' although I have googled and opening as 'rw' appears legal. Can you only open a file as 'r' or 'w' - ie open close the file twice ? Any ideas Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] open(file, 'rw') problem
On Thursday 27 July 2006 09:08, Andre Engels wrote: 2006/7/27, Dave S [EMAIL PROTECTED]: It appears to be a problem with me opening the file as 'rw' although I have googled and opening as 'rw' appears legal. Can you only open a file as 'r' or 'w' - ie open close the file twice ? If you use open(filename, 'rw'), the 'w' does not have effect, and you have opened the file read-only. To do what you want to do (both read and write with a file), you can use open(filename, 'r+') instead. Ahh .. thanks for the heads up - I thought there had to be a better way Cheers dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [SOLVED] Basic QT query #2
On Friday 14 July 2006 23:21, Dave S wrote: On Friday 14 July 2006 19:21, Dave S wrote: Hi all, I am trying to get to grips with QT, putting a friendly face on some of my apps :) Its early days and my first attempt but I expected the following to print 'hi it works' every second. There problem I am stuck with is ... The debugged program raised the exception unhandled RuntimeError underlying C/C++ object has been deleted At line 24 ie self.timer = self.startTimer(1000). First of all I did not have an assignment ie I just had self.startTimer(1000) realising Python would garbage collect I added an assignment but still the same problem. Also I am struggling with QObject.connect(self.tickerevent, PYSIGNAL(ticker), self.hello) I am unsure of what the source of the connect is - I suspect my guess of self.tickerevent is wrong. The source of the event should be PYSIGNAL(ticker) ? Any ideas or suggestions much appreciated Cheers Dave SOLVED - Sometimes trying trying is a good way to learn :) Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Basic QT query
Hi all, I am trying to get to grips with QT, putting a friendly face on some of my apps :) Its early days and my first attempt but I expected the following to print 'hi it works' every second. There problem I am stuck with is ... The debugged program raised the exception unhandled RuntimeError underlying C/C++ object has been deleted At line 24 ie self.timer = self.startTimer(1000). First of all I did not have an assignment ie I just had self.startTimer(1000) realising Python would garbage collect I added an assignment but still the same problem. Also I am struggling with QObject.connect(self.tickerevent, PYSIGNAL(ticker), self.hello) I am unsure of what the source of the connect is - I suspect my guess of self.tickerevent is wrong. The source of the event should be PYSIGNAL(ticker) ? Any ideas or suggestions much appreciated Cheers Dave ** MY QT MASTERPIECE :) ** import sys from qt import * from frm_livedata import frm class Ticker(QObject): def __init__(self): QObject.__init__, (self) self.timer = self.startTimer(1000) def timerEvent(self, ev): self.emit(PYSIGNAL(ticker)()) QObject.connect(self.tickerevent, PYSIGNAL(ticker), self.hello) def hello(): print 'hi it works' x=Ticker() if __name__ == '__main__': app = QApplication(sys.argv) win = frm() app.setMainWidget(win) win.show() QObject.connect(app, SIGNAL('lastWindowClosed()'),app, SLOT('quit()')) app.exec_loop() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Basic QT query #2
On Friday 14 July 2006 19:21, Dave S wrote: Hi all, I am trying to get to grips with QT, putting a friendly face on some of my apps :) Its early days and my first attempt but I expected the following to print 'hi it works' every second. There problem I am stuck with is ... The debugged program raised the exception unhandled RuntimeError underlying C/C++ object has been deleted At line 24 ie self.timer = self.startTimer(1000). First of all I did not have an assignment ie I just had self.startTimer(1000) realising Python would garbage collect I added an assignment but still the same problem. Also I am struggling with QObject.connect(self.tickerevent, PYSIGNAL(ticker), self.hello) I am unsure of what the source of the connect is - I suspect my guess of self.tickerevent is wrong. The source of the event should be PYSIGNAL(ticker) ? Any ideas or suggestions much appreciated Cheers Dave ** MY QT MASTERPIECE :) ** import sys from qt import * from frm_livedata import frm class Ticker(QObject): def __init__(self): QObject.__init__, (self) self.timer = self.startTimer(1000) def timerEvent(self, ev): self.emit(PYSIGNAL(ticker)()) QObject.connect(self.tickerevent, PYSIGNAL(ticker), self.hello) def hello(): print 'hi it works' x=Ticker() if __name__ == '__main__': app = QApplication(sys.argv) win = frm() app.setMainWidget(win) win.show() QObject.connect(app, SIGNAL('lastWindowClosed()'),app, SLOT('quit()')) app.exec_loop() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Doh - Sorted it rearranged the defs '__init__,' becomes '__init__' its always the simple things that eat the hours :) I am writting a QT front end displaying some information about my demon script 'live_datad.py'. The QT display now comes up (cheer!) but I need a couple of things ,,. First I need to know if if a 'live_datad' is running - Already tried looking in modules os.system('ps ax') no go. I need an equivalent of ps ax | grep live_datad. Second I need to get some simple data from the daemon, no more than 2-3 strings would do it reflecting the daemons status. I don't want to re-code it in classes, or do anything with sockets (they seem way too complex for me) is there a more elegant way than the daemon writing its status in an ascii file every few seconds and my QT app reading it - or is this an OK way of doing it ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] can't import module
Hi all, I wrote some script a while back but can no longer get it to run, since then I have upgraded my system from breezy to dapper (kubuntu) I now cannot import a module I wrote. I just know its got to be simple and am somewhat embarrassed that I cannot see the problem :( [EMAIL PROTECTED]:~/my_files/my_gg/gg1.4/get_data$ ./live_datad.py Traceback (most recent call last): File ./live_datad.py, line 15, in ? from logger import log ImportError: No module named logger OK that's my problem [EMAIL PROTECTED]:~/my_files/my_gg/gg1.4/get_data$ echo $PYTHONPATH /home/dave/my_files/my_gg/gg1.4/configs:/home/dave/my_files/my_gg/gg1.4/logs:/home/dave/my_files/my_gg/gg1.4/get_data:/home/dave/my_files/my_gg/gg1.4/gg_utils:/home/dave/my_files/my_gg/gg1.4/ipc:/home/dave/my_files/my_gg/gg1.4/process_data:/home/dave/my_files/my_gg/gg1.4/common_utils [EMAIL PROTECTED]:~/my_files/my_gg/gg1.4/get_data$ [EMAIL PROTECTED]:~/my_files/my_gg/gg1.4/get_data$ ls -al /home/dave/my_files/my_gg/gg1.4/gg_utils total 92 drwxr-xr-x 2 dave dave 4096 2006-03-27 13:03 . drwxr-xr-x 13 dave dave 4096 2006-06-07 22:12 .. -rwxr-xr-x 1 dave dave 1301 2005-01-31 20:35 archive_read.py -rw-r--r-- 1 dave dave 1612 2005-02-06 10:18 archive_read.pyc -rw-r--r-- 1 dave dave 1612 2005-02-06 12:44 archive_read.pyo -rwxr-xr-x 1 dave dave 2630 2005-02-04 22:54 convert_data.py -rw-r--r-- 1 dave dave 2631 2005-02-06 10:18 convert_data.pyc -rw-r--r-- 1 dave dave 2631 2005-02-06 12:44 convert_data.pyo -rw-r--r-- 1 dave dave 1146 2005-01-31 20:35 cookie_string.py -rw-r--r-- 1 dave dave 1315 2005-11-20 15:21 cookie_string.pyc -rw-r--r-- 1 dave dave 1420 2005-02-06 12:44 cookie_string.pyo -rwxr-xr-x 1 dave dave 1531 2005-02-04 12:34 dump_key.py -rw-r--r-- 1 dave dave 1470 2005-02-04 12:34 dump_key.pyc -rw-r--r-- 1 dave dave 1470 2005-02-06 12:44 dump_key.pyo -rwxr-xr-x 1 dave dave 1906 2005-01-31 20:35 html_strip.py -rw-r--r-- 1 dave dave 2069 2005-11-20 15:13 html_strip.pyc -rw-r--r-- 1 dave dave 2380 2005-02-06 12:44 html_strip.pyo -rwxr--r-- 1 dave dave 2646 2005-01-31 20:35 logger.py -rw-r--r-- 1 dave dave 3212 2005-11-20 15:13 logger.pyc -rw-r--r-- 1 dave dave 3546 2005-02-06 12:44 logger.pyo -rwxr-xr-x 1 dave dave 1873 2005-01-31 20:35 tail_log.py -rw-r--r-- 1 dave dave 1990 2005-02-06 10:18 tail_log.pyc -rw-r--r-- 1 dave dave 1990 2005-02-06 12:44 tail_log.pyo [EMAIL PROTECTED]:~/my_files/my_gg/gg1.4/get_data$ [EMAIL PROTECTED]:~/my_files/my_gg/gg1.4/get_data$ so logger.py is in PYTHONPATH so why can't live_data.d see it ? Any ideas .. Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can't import module
On Sunday 02 July 2006 11:29, Kent Johnson wrote: Dave S wrote: [EMAIL PROTECTED]:~/my_files/my_gg/gg1.4/get_data$ ./live_datad.py Traceback (most recent call last): File ./live_datad.py, line 15, in ? from logger import log ImportError: No module named logger [EMAIL PROTECTED]:~/my_files/my_gg/gg1.4/get_data$ echo $PYTHONPATH /home/dave/my_files/my_gg/gg1.4/configs:/home/dave/my_files/my_gg/gg1.4/l ogs:/home/dave/my_files/my_gg/gg1.4/get_data:/home/dave/my_files/my_gg/gg1 .4/gg_utils:/home/dave/my_files/my_gg/gg1.4/ipc:/home/dave/my_files/my_gg/ gg1.4/process_data:/home/dave/my_files/my_gg/gg1.4/common_utils I don't know why your import is failing, but from your PYTHONPATH it looks like you should consider making all the gg1.4 directories into packages, then you would have imports such as from gg_utils.logger import log This would simplify PYTHONPATH and I think reflect more accurately what you are doing. Thanks for replying :) The app is fairly big and distributed around the gg1.4 directory. I get the feeling that 'from logger import log' is the first of a lot of import problems, this script alone imports from another 7 modules from urllib import urlopen from time import strftime from cPickle import dump from datetime import datetime, time, timedelta from os import remove from logger import log from html_strip import html_strip from garbage_collect import garbage_collect from valid_day import valid_day from exact_sleep import sleep_delay,sleep_until from cookie_string import cookie_string from data_core import Data_Core from config import data_dir,HTML_addr, ipc_dir As far a putting everything into a package - I am a bit lost. Do you mean one big .py script or am I misunderstanding you ? Dave Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can't import module
On Sunday 02 July 2006 17:02, Dave Kuhlman wrote: On Sun, Jul 02, 2006 at 11:55:24AM +0100, Dave S wrote: [snip] Thanks for replying :) The app is fairly big and distributed around the gg1.4 directory. I get the feeling that 'from logger import log' is the first of a lot of import problems, this script alone imports from another 7 modules from urllib import urlopen from time import strftime from cPickle import dump from datetime import datetime, time, timedelta from os import remove from logger import log from html_strip import html_strip from garbage_collect import garbage_collect from valid_day import valid_day from exact_sleep import sleep_delay,sleep_until from cookie_string import cookie_string from data_core import Data_Core from config import data_dir,HTML_addr, ipc_dir So, ask yourself: Where is logger.py? Modules logger, html_strip, etc are not it the Python standard library (see: http://docs.python.org/lib/lib.html). Are they in your application? Are (were) they in some package that you had previously installed (but that needs to be re-installed)? They are all from my fair hand - coded about a year ago. I have just copied the whole directory to my new dapper system, changed PYTHONPATH and was somewhat supprised it has not just worked. One possible explanation for your problem is that when you upgraded from Ubuntu/Kubuntu breezy to dapper, you also upgraded from Python 2.3 to Python 2.4. If so, Python is now importing from: /usr/lib/python2.4/site-packages/ instead of: /usr/lib/python2.3/site-packages/ I see your point but because these are all my own packages I would guess the python version would be irrelevant If so, there might be Python modules that need to be re-installed by running Python 2.4 (instead of Python 2.3). I know that on my Kubuntu system, there is both Python 2.4 and 2.3. If the above is *not* the problem, then you need to find out where your application used to find these modules (e.g. logger). That will help you (or someone on this list) figure out how to enable Python and your live_datad.py application to find them. OK I am going to try a couple of real basic scripts and import a module to see where it all falls down. I will email back with the results :) Cheers Dave Hope this helps. Dave K. [snip] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can't import module
Here goes ... I have two files test1 and test2 ... [EMAIL PROTECTED]:~$ ls -l total 37620 drwx-- 8 dave dave 4096 2006-06-30 23:26 Desktop drwxr-xr-x 9 dave dave 4096 2006-06-15 22:48 google-earth drwxr-xr-x 13 dave dave 4096 2006-05-27 09:51 my_files drwxr-xr-x 2 dave dave 4096 2006-06-24 21:29 Pictures drwxr-xr-x 4 dave dave 4096 2006-07-02 03:00 PodCasts drwxr-xr-x 2 dave dave 4096 2006-06-16 21:30 qemu drwxr-xr-x 9 dave dave 4096 2006-06-30 22:30 SecondLife_1_10_5_1 -rw-r--r-- 1 dave dave 38438806 2006-06-30 18:53 SecondLife_1_10_5_1.tar.bz2 drwxr-xr-x 2 dave dave 4096 2006-07-02 17:43 test1 drwxr-xr-x 2 dave dave 4096 2006-07-02 17:41 test2 Two simple scripts parent and child ... [EMAIL PROTECTED]:~$ cd test2 [EMAIL PROTECTED]:~/test2$ cat child.py #!/usr/bin/env python # -*- coding: iso8859_1 -*- def hello(): print 'child says hello' [EMAIL PROTECTED]:~/test2$ cd ../test1 [EMAIL PROTECTED]:~/test1$ cat parent.py #!/usr/bin/env python # -*- coding: iso8859_1 -*- from child import hello def test(): print 'parent says hello' hello() test() And I hit my problem :( [EMAIL PROTECTED]:~/test1$ ./parent.py Traceback (most recent call last): File ./parent.py, line 4, in ? from child import hello ImportError: No module named child PYTHONPATH ... [EMAIL PROTECTED]:~/test1$ [EMAIL PROTECTED]:~/test1$ [EMAIL PROTECTED]:~/test1$ echo $PYTHONPATH /home/dave/my_files/my_gg/gg1.4/configs:/home/dave/my_files/my_gg/gg1.4/logs:/home/dave/my_files/my_gg/gg1.4/get_data:/home/dave/my_files/my_gg/gg1.4/gg_utils:/home/dave/my_files/my_gg/gg1.4/ipc:/home/dave/my_files/my_gg/gg1.4/process_data:/home/dave/my_files/my_gg/gg1.4/common_utils:/home/dave/test2 [EMAIL PROTECTED]:~/test1$ And where PYTHONPATH is set ... [EMAIL PROTECTED]:~/test1$ cat ~/.bashrc # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything [ -z $PS1 ] return # don't put duplicate lines in the history. See bash(1) for more options #export HISTCONTROL=ignoredups # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize # make less more friendly for non-text input files, see lesspipe(1) [ -x /usr/bin/lesspipe ] eval $(lesspipe) # set variable identifying the chroot you work in (used in the prompt below) if [ -z $debian_chroot -a -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # set a fancy prompt (non-color, unless we know we want color) case $TERM in xterm-color) PS1='${debian_chroot:+($debian_chroot)}\[\033[01;[EMAIL PROTECTED]: \[\033[01;34m\]\w\[\033[00m\]\$ ' ;; *) PS1='${debian_chroot:+($debian_chroot)[EMAIL PROTECTED]:\w\$ ' ;; esac # Comment in the above and uncomment this below for a color prompt #PS1='${debian_chroot:+($debian_chroot)}\[\033[01;[EMAIL PROTECTED]: \[\033[01;34m\]\w\[\033[00m\]\$ ' # If this is an xterm set the title to [EMAIL PROTECTED]:dir case $TERM in xterm*|rxvt*) PROMPT_COMMAND='echo -ne \033]0;[EMAIL PROTECTED]: ${PWD/$HOME/~}\007' ;; *) ;; esac # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. #if [ -f ~/.bash_aliases ]; then #. ~/.bash_aliases #fi # enable color support of ls and also add handy aliases if [ $TERM != dumb ]; then eval `dircolors -b` alias ls='ls --color=auto' #alias dir='ls --color=auto --format=vertical' #alias vdir='ls --color=auto --format=long' fi # some more ls aliases #alias ll='ls -l' #alias la='ls -A' #alias l='ls -CF' # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). #if [ -f /etc/bash_completion ]; then #. /etc/bash_completion #fi PYTHONPATH=/home/dave/my_files/my_gg/gg1.4/configs:/home/dave/my_files/my_gg/gg1.4/logs:/home/dave/my_files/my_gg/gg1.4/get_data:/home/dave/my_files/my_gg/gg1.4/gg_utils:/home/dave/my_files/my_gg/gg1.4/ipc:/home/dave/my_files/my_gg/gg1.4/process_data:/home/dave/my_files/my_gg/gg1.4/common_utils:/home/dave/test2 export EDITOR=vi [EMAIL PROTECTED]:~/test1$ Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can't import module
On Sunday 02 July 2006 20:12, Alan Gauld wrote: As far a putting everything into a package - I am a bit lost. Do you mean one big .py script or am I misunderstanding you ? You misunderstand him. Python allows you to reate a package structure of directories and files such that all of the files within the top level directory and the subdirectories are searched so you only need to specify the top level directory for all the files in subndirectories to be found. This requires creating some magic python definition files. Check the docs for details. The end result is that in pythonpath you add /some/path/myPackage and in your code you do from myPackage import someModule Check the docs for details. Alan G. Thanks for that - I never realised you could do that. It sound like a good solution and a lot less messy than the way I have created my own modules scripts. Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SOLVED :)
On Sunday 02 July 2006 18:32, Danny Yoo wrote: PYTHONPATH=/home/dave/my_files/my_gg/gg1.4/configs:/home/dave/my_files/my _gg/gg1.4/logs:/home/dave/my_files/my_gg/gg1.4/get_data:/home/dave/my_file s/my_gg/gg1.4/gg_utils:/home/dave/my_files/my_gg/gg1.4/ipc:/home/dave/my_f iles/my_gg/gg1.4/process_data:/home/dave/my_files/my_gg/gg1.4/common_utils :/home/dave/test2 Have you marked PYTHONPATH to be exportable? Your shell may not do this automatically unless explicitely told to do so. You solved it ! starting my PYTHONPATH with export did the trick for my demo files for live_datad.py. :) Thank you so much, I knew it had to be something relatively simple but I could just not see it. Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] can't import module
On Sunday 02 July 2006 18:48, Dave Kuhlman wrote: On Sun, Jul 02, 2006 at 10:32:51AM -0700, Danny Yoo wrote: PYTHONPATH=/home/dave/my_files/my_gg/gg1.4/configs:/home/dave/my_files/ my_gg/gg1.4/logs:/home/dave/my_files/my_gg/gg1.4/get_data:/home/dave/my_ files/my_gg/gg1.4/gg_utils:/home/dave/my_files/my_gg/gg1.4/ipc:/home/dav e/my_files/my_gg/gg1.4/process_data:/home/dave/my_files/my_gg/gg1.4/comm on_utils:/home/dave/test2 Have you marked PYTHONPATH to be exportable? Your shell may not do this automatically unless explicitely told to do so. A simple test -- In order to check PYTHONPATH do the following: $ python Python 2.4.3 (#1, Apr 11 2006, 20:59:32) [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9)] on linux2 Type help, copyright, credits or license for more information. import sys print sys.path Dave K. Thank you also. inadvertently I think you have given me the key to another problem that has been bugging me for a couple of weeks to do with paths and library's a python app accesses. ['', '/home/dave/my_files/my_gg/gg1.4/configs', '/home/dave/my_files/my_gg/gg1.4/logs', '/home/dave/my_files/my_gg/gg1.4/get_data', '/home/dave/my_files/my_gg/gg1.4/gg_utils', '/home/dave/my_files/my_gg/gg1.4/ipc', '/home/dave/my_files/my_gg/gg1.4/process_data', '/home/dave/my_files/my_gg/gg1.4/common_utils', '/home/dave/test2', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages/HTMLgen', '/usr/lib/python2.4/site-packages/Numeric', '/usr/lib/python2.4/site-packages/PIL', '/usr/lib/python2.4/site-packages/cairo', '/usr/lib/python2.4/site-packages/gst-0.10', '/usr/lib/python2.4/site-packages/gtk-2.0'] One question, where is the rest of PYTHONPATH defined, my section in .bashrc is only the first part, where do you get to define the /usr/lib part ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Looking for an open source project
Hi all, I have been playing around with Python for a while now and am looking for open source KDE projects written in Python that I can help with / learn from. Something relatively simple that uses Qt. (I am still a bit green) Any idea where I can get a list of projects. I checked out sourceforge but could not work out how to filter for Python. Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] smtplib mail header problem
On Wednesday 07 December 2005 22:47, Liam Clarke-Hutchinson wrote: Heheh, yah, the Python docs take a bit of scrutinisation to yield fruit. Also, when working with emails, you'll probably end up trying to figure what exactly what a RFC or three mean. Good luck, Liam But its all worth it, problem now solved work gets my emails :) Cheers Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] smtplib mail header problem
On Tuesday 06 December 2005 22:23, Liam Clarke-Hutchinson wrote: Okay, just checked the docs - sendmail( from_addr, to_addrs, msg[, mail_options, rcpt_options]) Note: The from_addr and to_addrs parameters are used to construct the message envelope used by the transport agents. The SMTP does not modify the message headers in any way. So my guess is that the spam agent is checking that from_addr, and getting an invalid email address and spitting the dummy. Most ISPs won't allow an invalid from_addr, although mine does.. Regards, Liam Clarke-Hutchinson Thanks for that I 'pydoc smtplib' but got somewhat confused :) Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] smtplib mail header problem
Hi all, I have a python script that works out emails my employer with parts that I have used. It has been great for 11ish months, now all my mail is classed as spam junked :( Apparently the reason for it being junked is ... 'No subject' and 'No Sender' I set up a small test script to isolate the problem using the core of the email code ... #!/usr/bin/env python # -*- coding: iso8859_1 -*- from smtplib import SMTP from time import sleep, strftime from datetime import datetime import sys email_SMTP = 'mail.pusspaws.net' email_addr = '[EMAIL PROTECTED]' def email_test(): for trys in xrange(10): try: mail_server = SMTP(email_SMTP) mail_server.login('', '') subject = 'Test Email' from_ = 'Dave Selby[EMAIL PROTECTED]' to = email_addr return_path = email_addr blog=Hi,\n\nThis is just a test msg = mail_headers(subject, from_, to, return_path) +'\r\n\r\n'+blog mail_server.sendmail(subject , email_addr, msg) mail_server.quit() # If we get to here, all is well, drop out of the loop break except: print 'Mailing error ... Re-trying ... '+str(trys+1)+' of 10\n' sleep(300) if trys==9: raise 'Mail Failure\n'+str(sys.exc_type)+'\n'+str(sys.exc_value) def mail_headers(subject, from_, to, return_path): Generate a formatted mail header string header = 'Return-Path: ' + return_path header = header + '\r\nFrom: ' + from_ header = header + '\r\nReply-To: ' + return_path header = header + '\r\nTo: ' + to header = header + '\r\nSubject: '+subject now=datetime.now() day = now.strftime('%a') date = now.strftime('%d %b %Y %X') header = header + '\r\nDate : ' + day + ', ' + date + ' -\r\n' return (header) email_test() From this I receive the following Return-Path: Test Delivered-To: [EMAIL PROTECTED] Received: (qmail 21696 invoked by uid 503); 6 Dec 2005 20:35:48 - Received: from unknown (HELO localhost.localdomain) ([EMAIL PROTECTED]) by host201.com with SMTP; 6 Dec 2005 20:35:48 - Return-Path: [EMAIL PROTECTED] From: Dave Selby[EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Test Email Date: Tue, 06 Dec 2005 20:35:47 - X-Bogosity: Ham, tests=bogofilter, spamicity=0.288675, version=0.95.2 X-UID: Status: R X-Status: NGC X-KMail-EncryptionState: X-KMail-SignatureState: X-KMail-MDN-Sent: Hi, This is just a test I cannot seem to set the top 'Return-path' correctly, any ideas how I do this ? also I have a sender so I am unsure why the spam filter picked this out. Any suggestions Cheers dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] smtplib mail header problem
On Tuesday 06 December 2005 21:13, Liam Clarke-Hutchinson wrote: Hi Dave, IIRC The first argument to sendmail() is the name of the account that's sending... So when you include your subject there, it seems your ISP is somewhat forgiving. Liam Clarke-Hutchinson| Contact Centre Advisor| Ministry of Economic Development DDI +64 3 962 2639 | Fax +64 3 962 6220 www.med.govt.nz Thanks for that heads up, I will amend the code try to re-send it ... Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter query?
Frames are used to help with positioning other widgets, yes. They are also used to affect how the application looks: you can change the background colour of Frames, and also the border (to make them look like they are sticking out, for example). But you can (and frequently will) put Frames inside other Frames. Example: from Tkinter import * tk = Tk() tk.config(background='pink') tk.geometry('400x400') frame1 = Frame(tk, background='blue') frame1.pack(side=LEFT, padx=15, pady=15, expand=True, fill=BOTH) frame2 = Frame(tk, background='green', borderwidth=3, relief=RAISED) frame2.pack(side=LEFT, padx=15, pady=15, expand=True, fill=BOTH) frame3 = Frame(frame1, background='red', borderwidth=3, relief=SUNKEN) frame3.pack(side=TOP, padx=15, pady=15, expand=True, fill=BOTH) frame4 = Frame(frame1, background='white', borderwidth=3, relief=GROOVE) frame4.pack(side=TOP, padx=15, pady=15, expand=True, fill=BOTH) label1 = Label(frame4, text='Hello world!') label1.pack(expand=True) tk.mainloop() Thank you, that has clarified a few points but raised a query. tk.geometry('400x400') does not appear to have any effect on its size when the window is drawn, the window is always the same size and short of maximizing it to full screen it is not adjustable. Just a minor query but interesting Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Tkinter query?
Hi all, Im on the Tkinter GUI learning curve :-) . Its going quite well - im reading O'reilly 'programming python' but I am unclear on the following I understand the standard form ie ... root = Tk() test = button(root, text = ..).pack() etc I also understand independant_win = Toplevel(root) But I do not understand where Frame fits in to this ... ie from Tkinter import * class Hello(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Why not just use 'class Hello(root)' ? Or have I missed the point :-[ Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter query?
Dave S wrote: Hi all, Im on the Tkinter GUI learning curve :-) . Its going quite well - im reading O'reilly 'programming python' but I am unclear on the following I understand the standard form ie ... root = Tk() test = button(root, text = ..).pack() etc I also understand independant_win = Toplevel(root) But I do not understand where Frame fits in to this ... ie from Tkinter import * class Hello(Frame): def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Why not just use 'class Hello(root)' ? Or have I missed the point :-[ Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor OK am I right in thinging a 'Frame' always has a parent of a Tk() or possibly Toplevel() and its used to help in positioning a widget window with .pack() ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] OT python Licences
This is a bit OT but here goes. My work wants me to write a fairly large python script to analyze some technical ASCII data files. Python and its libraries are GPL. That being the case am I right in thinking that my script would also have to be GPL and I would have to inform my employer as I hand it over ? Secondly it would have to run in Windows, The results could pop up on a DOS window. However I was looking at QT until I read the Windows license. Are there any widget libraries that would allow me to program for windows commercially without any license or fees ? Thanks in advance Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OT python Licences
Many thanks for all your input, you have been great. At the moment Tkinter is a favorite, I have started reading the documentation and it seems fairly straightforward + can do what I need. Many thanks once again :-) Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Windows user variable ?
Thanks for your help guys Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Windows user variable ?
Hi there, Probably no one will remember but I had a problem porting a python script to windows, I had a 'no such file error' Turned out that I called the file 'memo.txt', Windows decided it was a text file and it ended up as 'memo.txt.txt'. The windows display strips anything after the '.', found the problem via dos :) Anyhow - When logged into 2000 as an administrator or user is there a system variable that I can read to let the script know who I am logged in as ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Acessing files in Windows 2000
Danny Yoo wrote: [Windows bashing cut] Python's support for Windows stuff is actually quite good, thanks to the work of Mark Hammond: http://starship.python.net/crew/mhammond/ A lot of us here do use Windows for COM programming. Let's get back to talking about Python programming and let's help Dave with his problem. The os.path module contains a function called expanduser() that returns the home directory of a given user. http://www.python.org/doc/lib/module-os.path.html#l2h-1720 I believe this should reliably return a path that looks something like '\\Documents and Settings\\[username]' on Windows systems. Dave, what happens if you try something like this? ## import os.path print os.path.expanduser('~/memo.txt') f = open(os.path.expanduser('~/memo.txt')) ## Show us what you see, and we can work from there. Can you also give us the complete path where you see 'memo.txt' on your system? Just right click the file; it should show up somewhere on the file's property page. Best of wishes to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Hello again, Wow what a lot of replies. OK here goes. I know little about win 2000 so when I My computer C My documents I assumed that was where the my documents folder was, Having gone through what you guys said I also have C:\Documents and Settings\Administrator\My Documents So I copied memo.txt to C:\Documents and Settings\Administrator\My Documents, ammended my code memo_file = 'C:\Documents and Settings\Administrator\My Documents\memo.txt' csv_file = 'c:\data.csv' def palm_conv(): # The money sheet map1 = [[0]*5 for n in xrange(42)] map1_count = 6 # The time sheet map2 = [['']*7 for n in xrange(75)] map2_count = 0 day_map = {'sun':0, 'mon':1, 'tue':2, 'wed':3, 'thu':4, 'fri':5, 'sat':6} sh_offset = 0 ot_offset = 0 ca_offset = 0 pa_offset = 0 su_offset = 0 time_slot = 0 text_slot = 0 memo = open(memo_file, 'r') count = 0 raw_line = ' ' ... And got the following again ... Traceback (most recent call last): File C:\Documents and Settings\Administrator\Desktop\palm.py, line 268, in ? palm_conv() File C:\Documents and Settings\Administrator\Desktop\palm.py, line 54, in palm_conv memo = open(memo_file, 'r') IOError: [Errno 2] No such file or directory: 'C:\\Documents and Settings\\Administrator\\My Documents\\memo.txt' So I tried your test code got ... import os.path print os.path.expanduser('~/memo.txt') C:\Documents and Settings\Administrator/memo.txt f = open(os.path.expanduser('~/memo.txt')) Traceback (most recent call last): File pyshell#15, line 1, in ? f = open(os.path.expanduser('~/memo.txt')) IOError: [Errno 2] No such file or directory: 'C:\\Documents and Settings\\Administrator/memo.txt' Now starting to doubt my sanity I again re-checked C:\Documents and Settings\Administrator\My Documents and yes I do have a memo.txt there. In C:\Documents and Settings I have the folders administrator, all users and compy, I put a copy of memo.txt in compy as well changed my code, same problem Any ideas Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Acessing files in Windows 2000
[EMAIL PROTECTED] wrote: import os.path print os.path.expanduser('~/memo.txt') C:\Documents and Settings\Administrator/memo.txt f = open(os.path.expanduser('~/memo.txt')) Traceback (most recent call last): File pyshell#15, line 1, in ? f = open(os.path.expanduser('~/memo.txt')) IOError: [Errno 2] No such file or directory: 'C:\\Documents and Settings\\Administrator/memo.txt' Now starting to doubt my sanity I again re-checked C:\Documents and Settings\Administrator\My Documents and yes I do have a memo.txt there. Um --- So you have a file 'C:\Documents and Settings\Administrator\My Documents\memo.txt'... But you are attempting to open the file 'C:\Documents and Settings\Administrator\memo.txt'. There is a difference there! mmm ... I kind of see what you mean. Does anyone have like a realy large shovel so I can dig a hole and hide ? Thanks Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] 2d list matrix 7 x 75 problem
Hello, I need to generate a list 2d matrix of the kind ... [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']] except its dimensions need to be 7 x 75. I thought I had it sorted with map2 = [ [''] *7 ] *75 until the coding screwed up I realised I had 75 references to the same list :-( so I thought I would be clever with ... a=[0]*5 a [0, 0, 0, 0, 0] b=[a[:]]*5 same problem. It seems realy simple but how do I generate a 7 x 75 list matrix ? Dave Oh PS Is there a more elegant solution to if string == 'sun' or string == 'mon' or string == 'tue' or string == 'wed' or string == 'thu' or string == 'fri' or string == 'sat': the above works but any suggestions would be welcome :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 2d list matrix 7 x 75 problem
Jeff Shannon wrote: On Sun, 06 Mar 2005 09:49:43 +, Dave S [EMAIL PROTECTED] wrote: I need to generate a list 2d matrix of the kind ... [['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', '']] except its dimensions need to be 7 x 75. I thought I had it sorted with map2 = [ [''] *7 ] *75 until the coding screwed up I realised I had 75 references to the same list :-( Try: map2 = [['']*7 for n in range(75)] The list comprehension will execute ['']*7 each iteration, creating a new list instead of just creating new references to the same list. Oh PS Is there a more elegant solution to if string == 'sun' or string == 'mon' or string == 'tue' or string == 'wed' or string == 'thu' or string == 'fri' or string == 'sat': Try: if string in ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']: (Or perhaps look into using the datetime module, depending on how detailed your needs are.) Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Many thanks Dave :-) :-) :-) :-) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Am I storeing up problems ?
Danny Yoo wrote: On Sun, 2 Jan 2005, Dave S wrote: My matrix 'self.data' consists of a list of 110 items, each item is a dictionary of 250 keys, each key holds two lists, one of four items, one of 12 items. Hi Dave, Hmmm... what kind of data is being copied here? Python's data structures are desigined for flexibility, but sometimes that flexibility comes at the cost of some space. If we knew more about the data that's being stored, maybe we can think of a more compact representation. OK my app is tracking the ftse 250, the 110 items are time slots through a trading day, the 250 keys are ftse company names added dynamicly , the two lists are (4) a series of linked cookies to transmit info forward per company, and (12) financial stats for the particular company at a particular time. Companies in the 250 change randomly and there are not always exactly 250 (realy!), a linked cookie system is needed for a variety of info going forward not least as a count of how long any particular company has been on the ftse 250. The copy is needed so two days ftse figures can be viewed at any one time. Thurther apps can pull out ftse figures for a particular company going backwards .. you get the idea ! It all works its been a great learning experience to code. I needed to copy this matrix to 'self.old_data', so I have been using .deepcopy(), which works OK but is SLOW (12+ secs) Perhaps we can avoid making a separate copy of the data? Copying data structures can often be avoided. Why does your program try to copy the data structure? (Aside: one nonobvious example where copying can be avoided is in Conway's Game of Life: when we calculate what cells live and die in the next generation, we can actually use the 'Command' design pattern to avoid making a temporary copy of the world. We can talk about this in more detail if anyone is interested.) Once the matrix is copied, 'self.data' is re-constructed as the programme gathers data. To speed things up I changed my code to # This is the speeded up deepcopy() self.old_data = self.data self.data = [] for i in range(110): self.data.append({}) Query: Is all this OK, it works and quick as well, but I am concerned I may be leaving garbage in the Python PVM since I am shrugging off old 'self.old_data's which may be mounting up ? Whenever we reassign to self.old_data: self.old_data = self.data then whatever self.old_data was pointing at, before the assignment, should get garbage collected, if there are no other references to the old data. The code there isn't really doing any copying at all, but is rather just constructing a whole new empty data structure into 'self.data'. If so, then it does seem that you can avoid copying. I'd love to know a little bit more about the data that the program is collecting; if you have time, please feel free to tell us more details. Good luck to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] simple list query
OK simple query, I have a list consisting of about 250 items, I need to know if a particular item is in the list. I know this is better suited to a dictionary but thats not the way it ended up ;-) I could do a for loop to scan the list compare each one, but I have a suspission that there is a better way ? Any suggestions Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Am I storeing up problems ?
Hi there again, My matrix 'self.data' consists of a list of 110 items, each item is a dictionary of 250 keys, each key holds two lists, one of four items, one of 12 items. I needed to copy this matrix to 'self.old_data', so I have been using .deepcopy(), which works OK but is SLOW (12+ secs) Once the matrix is copied, 'self.data' is re-constructed as the programme gathers data. To speed things up I changed my code to # This is the speeded up deepcopy() self.old_data = self.data self.data = [] for i in range(110): self.data.append({}) Query: Is all this OK, it works and quick as well, but I am concerned I may be leaving garbage in the Python PVM since I am shrugging off old 'self.old_data's which may be mounting up ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Problems with class, no output
Hello again :-) , This script is very much a work in progress, and I think only the second time I have tried classes. What I expected it to do was to at least print 'hi there' so I know its alive, then dump some status info to my log program. It does zip, executes OK but no output. I just know you guys are going to tell me I have missed a () or . somewhere Any help gratefully appreciated Dave #!/usr/bin/env python # -*- coding: iso8859_1 -*- arch_data.py 1.0 This is the read archive data script from os import listdir from cPickle import load from logger import log from config import data_dir debug=True class Arch_data: def __init__(self): self.file_names=listdir(data_dir) self.file_names.sort() self.file_name_ptr=0 def read_next(): when executed reads next data file from data_dir extracts date, time,julian day,sequence count flag from the file name. Also adds last_file flag and contents of file to the list of returned parameters print 'hi there' file_name=self.file_names[self.file_name_ptr] # Ignore the archive_read.py utility script in the data dir ##if file_name=='archive_read.py': ##if debug: ##log('II','arch_data','Ignoring archive_read.py') ##self.file_name_ptr+=1 ##read.next() ##return # Extract info from the encoded filename :-) file_yy=file_name[:4] file_mm=file_name[4:6] file_dd=file_name[6:8] file_HH=file_name[9:11] file_MM=file_name[11:13] file_jj=file_name[14:17] file_seq=file_name[18:21] file_flag=file_name[22:24] if debug: log('II','arch_data','unpickling '+file_name) pickle_file=open(data_dir+file_name,'r') file=load(pickle_file) pickle_file.close() print file_yy,file_mm,file_dd,file_HH,file_MM,file_jj,file_seq,file_flag self.file_name_ptr+=1 arch_data=Arch_data() arch_data.read_next ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with class, no output
Dave S wrote: Hello again :-) , This script is very much a work in progress, and I think only the second time I have tried classes. What I expected it to do was to at least print 'hi there' so I know its alive, then dump some status info to my log program. It does zip, executes OK but no output. I just know you guys are going to tell me I have missed a () or . somewhere Any help gratefully appreciated Dave #!/usr/bin/env python # -*- coding: iso8859_1 -*- arch_data.py 1.0 This is the read archive data script from os import listdir from cPickle import load from logger import log from config import data_dir debug=True class Arch_data: def __init__(self): self.file_names=listdir(data_dir) self.file_names.sort() self.file_name_ptr=0 def read_next(): when executed reads next data file from data_dir extracts date, time,julian day,sequence count flag from the file name. Also adds last_file flag and contents of file to the list of returned parameters print 'hi there' file_name=self.file_names[self.file_name_ptr] # Ignore the archive_read.py utility script in the data dir ##if file_name=='archive_read.py': ##if debug: ##log('II','arch_data','Ignoring archive_read.py') ##self.file_name_ptr+=1 ##read.next() ##return # Extract info from the encoded filename :-) file_yy=file_name[:4] file_mm=file_name[4:6] file_dd=file_name[6:8] file_HH=file_name[9:11] file_MM=file_name[11:13] file_jj=file_name[14:17] file_seq=file_name[18:21] file_flag=file_name[22:24] if debug: log('II','arch_data','unpickling '+file_name) pickle_file=open(data_dir+file_name,'r') file=load(pickle_file) pickle_file.close() print file_yy,file_mm,file_dd,file_HH,file_MM,file_jj,file_seq,file_flag self.file_name_ptr+=1 arch_data=Arch_data() arch_data.read_next ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor Dope, too quick to ask for help - sorry def read_next(self): and arch_data.read_next() sorted it :-[ ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python structure advice ?
Sorry for the delay, real world work took me away ... everything was global, how you guys handle a modern structured language Don't worry this is one of the hardest bad habits to break. You are not alone. The easiest way is to just pass the data from function to function in the function parameters. Its not at all unusual for functions to have lots of parameters, global programmers tend to panic when they have more than a couple, yep ! but its not at all bad to have 5 or 6 - more than that gets unweildy I admit and is usually time to start thinking about classes and objects. I have ended up with my application in several separate directories. Separate modules is good. Separate directories for anything other than big programs (say 20 or more files?) is more hassle than its worth. The files are better kept in a single directory IMHO. The exception being modules designed for reuse... It just makes life simpler! Ive tried to be hyper organized and added my dirs in /usr/lib/python2.3/site-packages/mypath.pth /home/dave/mygg/gg1.3/live_datad /home/dave/mygg/gg1.3/logger /home/dave/mygg/gg1.3/utils /home/dave/mygg/gg1.3/datacore /home/dave/mygg/gg1.3 /home/dave/mygg/gg1.3/configs This works OK but I sometimes have to search around a bit to find where the modules are. Probarby part of the problem is I tend to write lots of small modules, debug them then import them into one controlling script, It works OK but I start to drown in files, eg my live_datad contains ... exact_sleep.py garbage_collect.py gg ftsed.e3p html_strip.py live_datad.py valid_day.pyc exact_sleep.pyc garbage_collect.pyc gg ftsed.e3s html_strip.pyc valid_day.py When I get more experienced I will try write fewer, bigger modules :-) My problem is that pretty much all the modules need to fix where they are when they exit and pick up from that point later on, There are two classic approaches to this kind of problem: 1) batch oriented - each step of the process produces its own output file or data structure and this gets picked up by the next stage. Tis usually involved processing data in chunks - writing the first dump after every 10th set of input say. This is a very efficient way of processing large chuinks of data and avoids any problems of synchronisation since the output chunks form the self contained input to the next step. And the input stage can run ahead of the processing or the processing aghead of the input. This is classic mainframe strategy, ideal for big volumes. BUT it introduces delays in the end to end process time, its not instant. I see your point, like a static chain, one calling the next passing data, the problem being that the links of the chain will need to remember their previous state when called again, so their output is a function of previous data + fresh data. I guess their state could be written to a file, then re-read. 2) Real time serial processing, typically constructs a processing chain in a single process. Has a separate thread reading the input data Got that working live_datad ... and kicks off a separate processing thread (or process) for each bit of data received. Each thread then processes the data to completion and writes the output. OK A third process or thread then assembles the outputs into a single report. Interesting ... This produces results quickly but can overload the computer if data starts to arrive so fast that the threads start to back up on each other. Also error handling is harder since with the batch job data errors can be fixed at the intermediate files but with this an error anywhere means that whole data processing chain will be broken with no way to fix it other than resubmitting the initial data. An interesting idea, I had not thought of this approach as an option even with its stated drawbacks. Its given me an idea for some scripting I have to do later on ... With my code now running to a few hundred lines (Don't laugh this is BIG for me :-D ) Its big for me in Python, I've only writtenone program with more than a thousand lines of Python wheras I've written many C/C++ programs in ecess of 10,000 lines Boy am I glad I chose to learn Python rather than C++, probarbly still be at 'hello world' ;-) and worked on several of more than a million lines. But few if any Python programs get to those sizes. HTH, Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python structure advice ?
Jeff Shannon wrote: Dave S wrote: Kent Johnson wrote: Why do you say this is 'cheaty'? A class is basically a collection of data (state) and functions to operate on that state. Sorry for the delay, real world work got in the way ... Well I understand classes to be used when multiple instances are required, I will only need one instance and as such it seemed a bit of a cheat, The trouble is I now pretty well understand the tools, but don't know how you guys use them in the real world. For what it's worth, it seems to me to be perfectly normal to have classes that are only ever intended to have a single instance. For example, you're never likely to need more than one HTML parser, and yet htmllib.HTMLParser is a class... Well if its good enough for a Python lib ... As Kent said, the main point of a class is that you have a collection of data and operations on that data bundled together. Whether you have one set of data to operate on, or many such sets, is mostly irrelevant (though classes are even more valuable when there *are* many sets of data). Defining a class isn't so much a statement that I want lots of things like this, as it is a declaration of modularity -- This stuff all belongs together as a unit. OK Im a reformed ('L' plate programmer) its going to be classes :-) Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python structure advice ?
Kent Johnson wrote: Dave S wrote: Separate modules is good. Separate directories for anything other than big programs (say 20 or more files?) is more hassle than its worth. The files are better kept in a single directory IMHO. The exception being modules designed for reuse... It just makes life simpler! Ive tried to be hyper organized and added my dirs in /usr/lib/python2.3/site-packages/mypath.pth /home/dave/mygg/gg1.3/live_datad /home/dave/mygg/gg1.3/logger /home/dave/mygg/gg1.3/utils /home/dave/mygg/gg1.3/datacore /home/dave/mygg/gg1.3 /home/dave/mygg/gg1.3/configs This works OK but I sometimes have to search around a bit to find where the modules are. Probarby part of the problem is I tend to write lots of small modules, debug them then import them into one controlling script, It works OK but I start to drown in files, eg my live_datad contains ... exact_sleep.py garbage_collect.py gg ftsed.e3p html_strip.py live_datad.py valid_day.pyc exact_sleep.pyc garbage_collect.pyc gg ftsed.e3s html_strip.pyc valid_day.py When I get more experienced I will try write fewer, bigger modules :-) It's just a guess from the filenames, but it looks like your live_datad package (directory) contains everything needed by live_datad.py. Spot on I would like to suggest a different organization. I tend to organize packages around a single functional area, and by looking at the dependencies of the modules in the package on other packages. For example, in my current project some of the packages are: - common.util - this is a catchall for modules that are not specific to this application, and don't depend on any other packages - common.db - low-level database access modules - cb.data - application-specific database access - the data objects and data access objects that the application works with - cb.import - modules that import legacy data into the application - cb.writer - modules that generate files - cb.gui - GUI components - cb.app - application-level drivers and helpers I have been getting in a muddle, html_strip.py, strips HTML, mines for data when it finds specific patterns returns a dictionary containing them. However I also use one of its functions in a utility convert_data.py reading in archived semi-processed HTML files. This cross dependance has occured several times and is getting messy, yours is an interesting approach, Its started me thinking... Anyway, the point is, if you organize your modules according to what they do, rather than by who uses them, you might make a structure that is less chaotic. HTH Kent ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python structure advice ?
Dave S wrote: Im sorry to bang on about Python structure, but I do struggle with it, having in the past got into very bad habits with loads of BASIC where everything was global, and Forth, and hand coded 8031, 8051, 6502 I cant get my head round how you guys handle a modern structured language :-) (PS before anyone flames me - I think Python is great and am determined to learn it ;-) ) I have ended up with my application in several separate directories. I have 'live_datad' a demon that extracts web data, at preset times and archives it, this will be run as a thread, and possible using a queue ... (still digesting info from query about IPCing) I have a 'data_core' which accepts data from either live_datad real time or the archive for testing, it builds up a large multi dimensional array with various pointers into the array. I have a statistical module 'data_stats' which analises the array pulling various stats. And finally I have an analytical module 'data_predict' which using the output from 'data_stats' data directly from the 'data_core' outputs statistical predictions of future data. I have written my 'live_datad', I have written my 'data_core' have a fairly good idea how to write the rest. My problem is that pretty much all the modules need to fix where they are when they exit and pick up from that point later on, ie more data comes from live_datad, it is passed to 'data_core' which updates the matrix, then 'data_stats' then 'data_predict' all called form the main script. This OK till the main script realizes that more data is avalible from 'live_datad', passes it to 'data_core' which must remember where it was and move on, and the same for the rest of the modules. To make the problem more acute the modules may not be called in exactly the same order depending on what I am trying to achieve. The 'remembering where is was' seems a continuous stumbling block for me. I have though of coding each module as a class but this seems like a cheat. I could declare copious globals, this seems messy, I could define each module as a thread get them talking via queues, given this serious thought but heeded warning in previous posts. I have thought about returning an list of saved 'pointers' which would be re-submitted when the function is called. I don't know which way to turn. With my code now running to a few hundred lines (Don't laugh this is BIG for me :-D ) I am going to have to make a structure decision and any suggestions would be appreciated. How would you approach it ? Dave ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor Having written this email, it has put my thoughts in order, though it seems a bit cheaty, wouldn't defining all modules that have to remember their internal state as classes be the best bet ? Dave ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python structure advice ?
Im sorry to bang on about Python structure, but I do struggle with it, having in the past got into very bad habits with loads of BASIC where everything was global, and Forth, and hand coded 8031, 8051, 6502 I cant get my head round how you guys handle a modern structured language :-) (PS before anyone flames me - I think Python is great and am determined to learn it ;-) ) I have ended up with my application in several separate directories. I have 'live_datad' a demon that extracts web data, at preset times and archives it, this will be run as a thread, and possible using a queue ... (still digesting info from query about IPCing) I have a 'data_core' which accepts data from either live_datad real time or the archive for testing, it builds up a large multi dimensional array with various pointers into the array. I have a statistical module 'data_stats' which analises the array pulling various stats. And finally I have an analytical module 'data_predict' which using the output from 'data_stats' data directly from the 'data_core' outputs statistical predictions of future data. I have written my 'live_datad', I have written my 'data_core' have a fairly good idea how to write the rest. My problem is that pretty much all the modules need to fix where they are when they exit and pick up from that point later on, ie more data comes from live_datad, it is passed to 'data_core' which updates the matrix, then 'data_stats' then 'data_predict' all called form the main script. This OK till the main script realizes that more data is avalible from 'live_datad', passes it to 'data_core' which must remember where it was and move on, and the same for the rest of the modules. To make the problem more acute the modules may not be called in exactly the same order depending on what I am trying to achieve. The 'remembering where is was' seems a continuous stumbling block for me. I have though of coding each module as a class but this seems like a cheat. I could declare copious globals, this seems messy, I could define each module as a thread get them talking via queues, given this serious thought but heeded warning in previous posts. I have thought about returning an list of saved 'pointers' which would be re-submitted when the function is called. I don't know which way to turn. With my code now running to a few hundred lines (Don't laugh this is BIG for me :-D ) I am going to have to make a structure decision and any suggestions would be appreciated. How would you approach it ? Dave ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Global presets ?
Thanks Guys, They are both good ways of getting round my problem, I appreciate your input will have a play. Cheers Dave :-) :-) :-) :-) ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Global presets ?
Alan Gauld wrote: have you considered making the root directory an environment variable? That way you can read the value (os.getenv) at the start of the script. And if you ever need to move the structure you can simply change the environment value. It also means different users can use their own structures by defining their own environment value... # File myvars.py value1 = 42 value2 = 'spam' Got ya so far .. # # File: prog1.py import myvars localvar = myvars.value1 myvars.value2 = 'Alan' Never thought of setting 'myvars.value2 = 'Alan'' I guess this would just set the variable in the myvars namespace since it could not change myvars.py itself. ## # File prog2.py import myvars newvar = myvars.value2 With you ... print myvars.value1 - 27 Have I misunderstood, should this not be 42 ? Typo or me not understanding ? ## Does that help? Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor