Re: who moved reload?
On Tue, 2011-04-19 at 12:41 -0400, Calvin Spealman wrote: > I have a great solution : stop using reload. It often dangerous and > more often silly. > Yeah, I'm there. Some of this is just learning a new way of thinking about the language. I can see that not using reload at all makes more sense (Run --> Run Module) from the editor window which does what I want with a mouse click... so I'm done with reload... In the past I didn't use IDLE... just vi, reload(yadda yadda) in the terminal, repeat till bored. There were some inconsistencies with from yadda yadda import *... and it seems that reload was deliberately hidden in imp to solve some of that problem. And we can still use imp.reload() to reload the module without stopping the interpreter, so all is good. Thanks. -- Kind regards, M Harris -- http://mail.python.org/mailman/listinfo/python-list
Can anyone tell me where the old MacPython "16 ton" logo came from?
I'm curious to understand how come the original MacPython logo is of a 16 ton weight (rather than, say the word 'python' or a picture of a snake)? You can see the logo here: https://homepages.cwi.nl/~jack/macpython/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Can anyone tell me where the old MacPython "16 ton" logo came from?
On Sunday, July 15, 2018 at 1:49:22 PM UTC+1, Christian Heimes wrote: > On 2018-07-15 14:05, Mark wrote: > > I'm curious to understand how come the original MacPython logo is of a 16 > > ton weight (rather than, say the word 'python' or a picture of a snake)? > > You can see the logo here: https://homepages.cwi.nl/~jack/macpython/ > > Most obscure references in Python are based on Monty Python sketches, > e.g. https://www.youtube.com/watch?v=o13glRURgTE Thanks to both of you, I understand it now:-) -- https://mail.python.org/mailman/listinfo/python-list
pyz and concurrent.futures
I have two apps, one GUI one console, both using PySide2 bindings to Qt 5. Both use concurrent.futures and a processing pool to spread their work over multiple CPUs. I've written my own deployment script (since I can't get a successfull deploy with cx-freeze, py2exe, or pyinstaller) which creates this structure: myapp/ myapp/python/ # copy of Python 3.6 i.e., WinPython's python-3.6.7 dir myapp/myapp.pyz myapp/*.DLL # some custom and commercial DLLs the apps depend on I create the .pyz by copying myapp's .py files, running python3 -m compileall -b on the copied dir, then deleting all the original .py files, then renaming myapp.py as __main__.py and then zipping it all up as myapp.pyz. I can then run the programs using .bat files like this: Console app: "%~dp0\python\python.exe" "%~dp0\myapp.pyz" %* GUI app: "%~dp0\python\pythonw.exe" "%~dp0\myapp.pyz" %* The GUI app works fine. One significant difference is that the GUI app has two threads, the main thread running the GUI and a worker thread in which the calls to concurrent.futures process pool are made. Whereas the console app uses a single thread. Another difference is that the GUI app has an event loop and the console app doesn't. The console app works fine in the dev dir, but silently fails when run as a pyz. And it fails executing the same code as the GUI app (they share many modules). Has anyone encountered this issue before and have a solution? I plan to try to use two threads for the console app to see if that helps; but I'd still like to understand what is causing the problem. -- https://mail.python.org/mailman/listinfo/python-list
Re: pyz and concurrent.futures
I've now just tried with Python 3.7.1 and the same problem persists, so I'll now try to use a second thread for the console app. PS For these CPU-intensive apps which use multiprocessing to use all the CPUs, compared with Python 3.4, 3.6 is 13% faster, and 3.7 is 33% faster! -- https://mail.python.org/mailman/listinfo/python-list
Why is "if fileitem.file:" (almost) never false?
How do I detect that a particular form element is a file upload or if the file upload has worked? In the Python cgi module documentation I found suggested code... form = cgi.FieldStorage() fileitem = form["userfile"] if fileitem.file: # It's an uploaded file; count lines I've tried something like this in a test script and fileitem.file evaluates to true when form element "userfile" is just a text box in the web page. When "userfile" is a type="file" it evaluates true when I select a real file to upload and when I manually type in a false path to a file that doesn't exist. When I do upload a file, the script correctly prints out the file contents (fileitem.value) so the upload does work OK. It seems that provided there's a form element called "userfile" then fileitem.file evaluates to true provided the form has enctype="multipart/form-data" (it doesn't matter if the file upload works or if the form element is not type="file"). When I tried different forms without the enctype then fileitem.file evaluated to false when userfile was either type="text" or type="file". My conclusion is that if fileitem.file: detects enctype of form rather than if a particular element is a file upload. How do I detect that a particular form element is a file upload or if the file upload has worked? My best suggestion (but I'd like to hear your views) is to use: if fileitem.filename and len(fileitem.value): # It's an uploaded file When the form element userfile is just a text box or the form lacks the enctype then the filename attribute evaluates to false. When I supply an incorrect file path to the file form element the upload fails so len(fileitem.value) evaluates to false. When I upload a real file, both fileitem.filename and len(fileitem.value) evaluate to true. If I upload a real file that's empty then fileitem.value is an empty string so len(fileitem.value) evaluates to false which is not quite right (an empty file is an obscure test but it is a valid file to upload). Any suggestions for improvements would be gratefully received. Thanks Mark PS if it's relevant, I'm using Windows2000, Python 2.3.2, the shebang includes -u, Apache 2.0.42 and Firefox 1.0.4. -- http://mail.python.org/mailman/listinfo/python-list
Moinmoin config
Hi, I have Moinmoin 1.3.4 installed and working on Linux RHEL3.0. However, all screen elements are lined up on the left hand side. How can I get it displayed like the wiki at: http://moinmoin.wikiwikiweb.de/HelpOnConfiguration instead of this ? -> LANShieldOS Release Notes Search: * MarkRuedy * UserPreferences * HelpOnEditing * HelpContents * HelpForBeginners * UserPreferences * FrontPage * RecentChanges * FindPage * HelpContents * Edit * Show Changes * Get Info * Subscribe * FrontPage -- http://mail.python.org/mailman/listinfo/python-list
Re: Moinmoin config
Hi Patrick, Sorry about the cross post, but I could not find a moin list. Do you have a sub folder or a better name? I searched for moin and for wiki but only found some actual wikis and some groups with only a few members. Anyway, I checked my data_underlay_dir and it is valid and contains one subdir, called pages, which has a huge set of subdirs. Do you know where else I can turn? Thanks Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Moinmoin config
The missing link under /var/www/html was exactly the problem. Somehow missed this in the labyrinth of setup instructions. I have another question, and as of yet, have not found another discussion group for moinmoin, so sorry, but here goes: I have a table and would like the table borders to go away. Although it doesn't talk about border widths explicitliy, the HelpOnTables seems to point to this : But that does nothing to the border lines. Adjusting width in the same line does work to change the size of the table, but it doesn't seem to understand 'border'. Anyone know how to make the borders disappear? Thanks Mark -- http://mail.python.org/mailman/listinfo/python-list
Yet another logo design...
Hi, I'm relatively new to python and have been reading some of the topics on the Python logo and marketing issues etc. Long story short here is a contemporary logo design by myself: http://www.imagezilla.com/img.php?im=1182129642_logo.png Any comments welcome... *runs* -- http://mail.python.org/mailman/listinfo/python-list
good IIS 6.0(win2k3) python CGI web ext. setup instructions
Here is a good set of instructions for setting up web extenstions for python CGI on windows 2003 server... Not sure why anyone would want to use IIS but here they are none the less... http://python.markrowsoft.com/iiswse.asp Cheers, Mark -- http://mail.python.org/mailman/listinfo/python-list
Cannot import mod_python modules
Hi, I've just installed the Win32 build of mod_python 3.1.4 for Python 2.4 and have setup my Apache config file with the LoadModule and PythonHandler directives and then copied "mod_python.so" to my Apache modules directory. I restarted Apache and decided to do a quick cgi.test() and it shows that mod_python listed under server software section. OK, next I tried mptest.py, but I get an Internal Server Error. The traceback recorded in the error log says "No module named _apache" mptest.py: from mod_python import apache def handler(req): req.write("Hello World!") return apache.OK Why doesn't this work? or rather what have I missed? -- http://mail.python.org/mailman/listinfo/python-list
Re: Cannot import mod_python modules
Thanks for the reply Steve, I have re-installed mod_python and re-configured Apache and it works now. I'm not exactly sure what I done differently, but oh well at least it works now :) Regards, Mark. -- http://mail.python.org/mailman/listinfo/python-list
New to Python, Help to get script working?
Hey guys, I found this website that has a script in order to increase numbers to a live viewing stream. Being new to python, I keep running into problems trying to get it to work. The original site is here, as he talks about how it works. It is the top article. http://www.ericzhang.me/ I have successfully installed python 3.3 for windows, pip and livestreamer that is needed for it to work. They are in my scripts folder. I either do not understand the script or it no longer works. It is more than likely my error. I get errors on line 19 and cant get it to work at all. The included code is located here https://gist.github.com/Xeroday/6468146/raw/1b7fb468551a4ba5b73ea3c0b7bc47591c3a8c51/Twitch.py If anybody could provide some incite on how to get it to work, how the variables work, and such, I would be so grateful! Mark -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
Thanks for the replies, I was hoping that one of you guys could actually try it for me, as it might be easier to correct? In the meantime i will install 2.7 instead of 3.3 and give it a try. Once again, i have very little experience in this, which is why i am looking for help :) I am more worried about getting it to work then knowing whats wrong, but it could also be helpful haha Thanks Mark -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
On Sunday, December 15, 2013 4:19:47 PM UTC-5, Mark wrote: > Thanks for the replies, I was hoping that one of you guys could actually try > it for me, as it might be easier to correct? In the meantime i will install > 2.7 instead of 3.3 and give it a try. > > > > Once again, i have very little experience in this, which is why i am looking > for help :) I am more worried about getting it to work then knowing whats > wrong, but it could also be helpful haha > > > > Thanks > > > > Mark I originally get an indent error on line 19, i delete the indent and i get ***'return outside function (Twitch.py, line 19) Thats where i am at. This is on version 2.7 If anybody could correct this for me or provide some incite. i would be very grateful. If any of you would be available for some sort of chat to fix it, I would also love to do something like that. Thanks again Mark -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote: > On Mon, Dec 16, 2013 at 12:37 PM, Steven D'Aprano > > wrote: > > > Step 1: replace the modified version of the script with a known good copy. > > > > > > > Actually, this might be where the problem is, unfortunately. Not the > > OP's fault at all. I went and looked at the post linked to, and it has > > buggy indentation. (Quite possibly indicates that the author has > > two-space tabs, and didn't notice a bug slipping in. I dunno.) > > > > Along the way, though, I learned that the script in question is > > entirely for generating fake twitch.tv viewers so as to get your > > stream highlighted fraudulently, so I'm rather less inclined to help. > > Got a legitimate use for this, or are you just trying to cheat your > > way to fame? > > > > ChrisA Thanks for the reply, the answer is yes and no, i already have about 2400 followers and half mil views, i just wanted to see if i could get it to work. So after taking everybody's advice, fixed the indentation as mentioned by the expert above. :) After, this is what i came up with Traceback (most recent call last): File "C:\Python27\Scripts\Twitch.py", line 9, in numberOfViewers = int(sys.argv[1]) IndexError: list index out of range Is this where i would plug in the variables to make it work? I'm not quite sure about how you would plug in those numbers >>> -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
On Monday, December 16, 2013 2:09:38 AM UTC-5, Mark wrote: > On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote: > > > On Mon, Dec 16, 2013 at 12:37 PM, Steven D'Aprano > > > > > > wrote: > > > > > > > Step 1: replace the modified version of the script with a known good copy. > > > > > > > > > > > > > > > > > > > Actually, this might be where the problem is, unfortunately. Not the > > > > > > OP's fault at all. I went and looked at the post linked to, and it has > > > > > > buggy indentation. (Quite possibly indicates that the author has > > > > > > two-space tabs, and didn't notice a bug slipping in. I dunno.) > > > > > > > > > > > > Along the way, though, I learned that the script in question is > > > > > > entirely for generating fake twitch.tv viewers so as to get your > > > > > > stream highlighted fraudulently, so I'm rather less inclined to help. > > > > > > Got a legitimate use for this, or are you just trying to cheat your > > > > > > way to fame? > > > > > > > > > > > > ChrisA > > > > Thanks for the reply, the answer is yes and no, i already have about 2400 > followers and half mil views, i just wanted to see if i could get it to work. > > > > So after taking everybody's advice, fixed the indentation as mentioned by the > expert above. :) After, this is what i came up with > > > > Traceback (most recent call last): > > File "C:\Python27\Scripts\Twitch.py", line 9, in > > numberOfViewers = int(sys.argv[1]) > > IndexError: list index out of range > > > > Is this where i would plug in the variables to make it work? I'm not quite > sure about how you would plug in those numbers > > >>> okay so i kinda get it now, running it in cmd, i use the following command - python twitch.py 10 10. I am running it within the scripts directory. I get the following error in cmd: Syntax Error: invalid syntax >>>python twitch.py 10 10 File " line 1 python twitch.py 10 10 -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
On Monday, December 16, 2013 2:43:45 AM UTC-5, Mark wrote: > On Monday, December 16, 2013 2:09:38 AM UTC-5, Mark wrote: > > > On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote: > > > > > > > On Mon, Dec 16, 2013 at 12:37 PM, Steven D'Aprano > > > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > Step 1: replace the modified version of the script with a known good > > > > copy. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Actually, this might be where the problem is, unfortunately. Not the > > > > > > > > > > > > > > OP's fault at all. I went and looked at the post linked to, and it has > > > > > > > > > > > > > > buggy indentation. (Quite possibly indicates that the author has > > > > > > > > > > > > > > two-space tabs, and didn't notice a bug slipping in. I dunno.) > > > > > > > > > > > > > > > > > > > > > > > > > > > > Along the way, though, I learned that the script in question is > > > > > > > > > > > > > > entirely for generating fake twitch.tv viewers so as to get your > > > > > > > > > > > > > > stream highlighted fraudulently, so I'm rather less inclined to help. > > > > > > > > > > > > > > Got a legitimate use for this, or are you just trying to cheat your > > > > > > > > > > > > > > way to fame? > > > > > > > > > > > > > > > > > > > > > > > > > > > > ChrisA > > > > > > > > > > > > Thanks for the reply, the answer is yes and no, i already have about 2400 > > followers and half mil views, i just wanted to see if i could get it to > > work. > > > > > > > > > > > > So after taking everybody's advice, fixed the indentation as mentioned by > > the expert above. :) After, this is what i came up with > > > > > > > > > > > > Traceback (most recent call last): > > > > > > File "C:\Python27\Scripts\Twitch.py", line 9, in > > > > > > numberOfViewers = int(sys.argv[1]) > > > > > > IndexError: list index out of range > > > > > > > > > > > > Is this where i would plug in the variables to make it work? I'm not quite > > sure about how you would plug in those numbers > > > > > > >>> > > > > okay so i kinda get it now, running it in cmd, i use the following command - > > python twitch.py 10 10. I am running it within the scripts directory. > > > > I get the following error in cmd: > > > > Syntax Error: invalid syntax > > >>>python twitch.py 10 10 > >File " line 1 > > python twitch.py 10 10 is there a more effecient way of doing this? I just hold shift and right click to run cmd from the folder, File is located in C:\Python27\Scripts -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
On Monday, December 16, 2013 2:48:56 AM UTC-5, Mark wrote: > On Monday, December 16, 2013 2:43:45 AM UTC-5, Mark wrote: > > > On Monday, December 16, 2013 2:09:38 AM UTC-5, Mark wrote: > > > > > > > On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote: > > > > > > > > > > > > > > > On Mon, Dec 16, 2013 at 12:37 PM, Steven D'Aprano > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Step 1: replace the modified version of the script with a known good > > > > > copy. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Actually, this might be where the problem is, unfortunately. Not the > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > OP's fault at all. I went and looked at the post linked to, and it has > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > buggy indentation. (Quite possibly indicates that the author has > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > two-space tabs, and didn't notice a bug slipping in. I dunno.) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Along the way, though, I learned that the script in question is > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > entirely for generating fake twitch.tv viewers so as to get your > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > stream highlighted fraudulently, so I'm rather less inclined to help. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Got a legitimate use for this, or are you just trying to cheat your > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > way to fame? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ChrisA > > > > > > > > > > > > > > > > > > > > > > > > > > > > Thanks for the reply, the answer is yes and no, i already have about 2400 > > > followers and half mil views, i just wanted to see if i could get it to > > > work. > > > > > > > > > > > > > > > > > > > > > > > > > > > > So after taking everybody's advice, fixed the indentation as mentioned by > > > the expert above. :) After, this is what i came up with > > > > > > > > > > > > > > > > > > > > > > > > > > > > Traceback (most recent call last): > > > > > > > > > > > > > > File "C:\Python27\Scripts\Twitch.py", line 9, in > > > > > > > > > > > > > > numberOfViewers = int(sys.argv[1]) > > > > > > > > > > > > > > IndexError: list index out of range > > > > > > > > > > > > > > > > > > > > > > > > > > > > Is this where i would plug in the variables to make it work? I'm not > > > quite sure about how you would plug in those numbers > > > > > > > > > > > > > > >>> > > > > > > > > > > > > okay so i kinda get it now, running it in cmd, i use the following command > > - > > > > > > python twitch.py 10 10. I am running it within the scripts directory. > > > > > > > > > > > > I get the following error in cmd: > > > > > > > > > > > > Syntax Error: invalid syntax > > > > > > >>>python twitch.py 10 10 > > > > > >File " line 1 > > > > > > python twitch.py 10 10 > > > > is there a more effecient way of doing this? I just hold shift and right > click to run cmd from the folder, > > > > File is located in C:\Python27\Scripts It was my understanding that you need to meet the arguments by running the in cmd with the numbers after? I am sorry to show my true noobyness and really appreciate the help. -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
On Monday, December 16, 2013 2:52:05 AM UTC-5, Mark wrote: > On Monday, December 16, 2013 2:48:56 AM UTC-5, Mark wrote: > > > On Monday, December 16, 2013 2:43:45 AM UTC-5, Mark wrote: > > > > > > > On Monday, December 16, 2013 2:09:38 AM UTC-5, Mark wrote: > > > > > > > > > > > > > > > On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Mon, Dec 16, 2013 at 12:37 PM, Steven D'Aprano > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Step 1: replace the modified version of the script with a known > > > > > > good copy. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Actually, this might be where the problem is, unfortunately. Not the > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > OP's fault at all. I went and looked at the post linked to, and it has > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > buggy indentation. (Quite possibly indicates that the author has > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > two-space tabs, and didn't notice a bug slipping in. I dunno.) > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Along the way, though, I learned that the script in question is > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > entirely for generating fake twitch.tv viewers so as to get your > > > > > > > >
Re: New to Python, Help to get script working?
On Monday, December 16, 2013 2:55:23 AM UTC-5, Mark wrote: > On Monday, December 16, 2013 2:52:05 AM UTC-5, Mark wrote: > > > On Monday, December 16, 2013 2:48:56 AM UTC-5, Mark wrote: > > > > > > > On Monday, December 16, 2013 2:43:45 AM UTC-5, Mark wrote: > > > > > > > > > > > > > > > On Monday, December 16, 2013 2:09:38 AM UTC-5, Mark wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Sunday, December 15, 2013 9:33:17 PM UTC-5, Chris Angelico wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Mon, Dec 16, 2013 at 12:37 PM, Steven D'Aprano > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Step 1: replace the modified version of the script with a known > > > > > > > good copy. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Actually, this mig
Re: New to Python, Help to get script working?
I am sorry if the way I posted messages was incorrect. Like I said, I am new to google groups and python quite a bit but i am trying to do things correctly by you guys. The errors that I am getting were not necessarily posting traceback messages. In those messages I posted my last bit of confusion, how to properly run the program while meeting the arguments. Thanks Frank for giving me a little hint at that. Now in that directory in cmd, i type in python twitch.py 10 10. When i do this I get "thread error" posting infinitely down my stream. So it looks like the program is actually running now, just some im possibly missing? Once again I do have pip and livestreamer installed and the exact py file i have is located here: http://www.mediafire.com/view/3m10s9rwvatxd96/twitch.py Once again thanks for help, Mark -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
I am sorry, using google groups i cant tell what you see... Anyways, I guess i will just make lots of lines instead of long sentences? How about this, the first person that can get this to work for me... I will paypal them 20 dollars for helping me. I just want to get this thing up and going. Ive posted where i am having trouble and got 2 replies talking about spacing... and not fixing any issues or giving advice. Either that or somebody who thinks they might be able to help, can you plz reply? Thanks again Mark -- https://mail.python.org/mailman/listinfo/python-list
Re: New to Python, Help to get script working?
Actually i live stream nearly everyday for 2 years, the problem with twitch is that the more "popular" people get first dibs and get treated better, have better perks, and all of that... Its all based on your initial viewer count, 90% of viewers just click the top video. All my views and numbers are based on me streaming for over 2 years. Anyways, I wasnt trying to cause trouble, i did post what happened when i ran the program. There was no traceback error, Here is my post from 2 days ago: Now in that directory in cmd, i type in python twitch.py 10 10. When i do this I get "thread error" posting infinitely down my cmd prompt. So it looks like the program is actually running now, just some im possibly missing? Once again I do have pip and livestreamer installed and the exact py file i have is located here: http://www.mediafire.com/view/3m10s9rwvatxd96/twitch.py Yes i do want it to work, and i would offer money to somebody who would actually help me, if it helped me to make it work faster. Is there not one person that can help a guy out? Mark -- https://mail.python.org/mailman/listinfo/python-list
Complete beginner, any help appreciated :) - For Loops
Hi there, I'm a complete beginner to Python and, aside from HTML and CSS, to coding in general. I've spent a few hours on it and think I understand most of the syntax. However, I'm wondering a bit about For Loops. I know that the basic syntax for them is to define a list, and then to use something like: for x in y However, what does "for" and "in" mean in this context? Can anyone help me to understand this? I know it's a really basic question, but hopefully it will see me on my way to coding properly :) Thanks a lot. -- http://mail.python.org/mailman/listinfo/python-list
Re: Complete beginner, any help appreciated :) - For Loops
Thanks a lot for the answers everyone, I really appreciate you getting back to me so quickly. I think that I understand where I am with this now :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Threads vs Processes
On Wed, 26 Jul 2006 10:54:48 -0700, Carl J. Van Arsdall wrote: > Alright, based a on discussion on this mailing list, I've started to > wonder, why use threads vs processes. The debate should not be about "threads vs processes", it should be about "threads vs events". Dr. John Ousterhout (creator of Tcl, Professor of Comp Sci at UC Berkeley, etc), started a famous debate about this 10 years ago with the following simple presentation. http://home.pacbell.net/ouster/threads.pdf That sentiment has largely been ignored and thread usage dominates but, if you have been programming for as long as I have, and have used both thread based architectures AND event/reactor/callback based architectures, then that simple presentation above should ring very true. Problem is, young people merely equate newer == better. On large systems and over time, thread based architectures often tend towards chaos. I have seen a few thread based systems where the programmers become so frustrated with subtle timing issues etc, and they eventually overlay so many mutexes etc, that the implementation becomes single threaded in practice anyhow(!), and very inefficient. BTW, I am fairly new to python but I have seen that the python Twisted framework is a good example of the event/reactor design alternative to threads. See http://twistedmatrix.com/projects/core/documentation/howto/async.html . Douglas Schmidt is a famous designer and author (ACE, Corba Tao, etc) who has written much about reactor design patterns, see "Pattern-Oriented Software Architecture, Vol 2", Wiley 2000, amongst many other references of his. -- http://mail.python.org/mailman/listinfo/python-list
Re: Threads vs Processes
On Thu, 27 Jul 2006 20:53:54 -0700, Nick Vatamaniuc wrote: > Debugging all those threads should be a project in an of itself. Ahh, debugging - I forgot to bring that one up in my argument! Thanks Nick ;) Certainly I agree of course that there are many applications which suit a threaded design. I just think there is a general over-emphasis on using threads and see it applied very often where an event based approach would be cleaner and more efficient. Thanks for your comments Bryan and Nick, an interesting debate. -- http://mail.python.org/mailman/listinfo/python-list
Using cElementTree and elementtree.ElementInclude
I have an elementtree created with cElementTree. I then use ElementInclude to resolve some xinclude elements. But then I want to move those included elements to be children of the root root.append(included_child) but I get an error message TypeError: 'append() argument 1 must be Element, not instance' The type of included_child is 'instance'. The type of the cElementTree children is 'Element'. How do I resolve this conflict? I am using cElementTree version 1.0.3 and elementtree version 1.2.6 and python version 2.3.4. Will later versions correct the problem? Thanks, Mark -- http://mail.python.org/mailman/listinfo/python-list
[Fwd: Using cElementTree and elementtree.ElementInclude]
Original Message Subject: Using cElementTree and elementtree.ElementInclude Date: Mon, 23 Oct 2006 09:40:24 -0500 From: Mark E. Smith <[EMAIL PROTECTED]> Organization: AEDC To: python-list@python.org > cElementTree cannot hold ElementTree instances. > > can you post a small but self-contained example showing how you got this > error? > #from elementtree.ElementTree import ElementTree, dump # This works from cElementTree import ElementTree, dump # This does not from elementtree import ElementInclude etree = ElementTree(file='xml_in.xml').getroot() dump(etree) ElementInclude.include(etree) dump(etree) for child in etree.find('./included_root').findall('./*'): # Copy the child down to the root etree.append(child) # Remove the root/included_root etree.remove(etree.find('./included_root')) dump(etree) http://www.w3.org/2001/XInclude";> Thanks for the help. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: ftputil upload error
On Sat, 02 Dec 2006 04:03:53 -0800, Croteam wrote: > FTPIOError: 550 popravak.txt: Access is denied. Seems pretty self-explanatory to me. M -- http://mail.python.org/mailman/listinfo/python-list
Client side COM and Python Problem
Hey Guys, Im new to working with com but i only want to do one thing. I have activestate python and am trying to get python to run a simple function in a com enabled 3d program called 3dsmax. If i try and execute a function over the com interface it works fine as long as i dont try and run the function with an argument. when i run it with an argument like so. "o.mypingmax("test string")" it gives me an error in my client app and an error in python. please help me understand this error and what i am doing wrong? I have tried a similar script in another language and it works. but python does not like it. #code import win32com.client o = win32com.client.Dispatch("MAX.Application.8") o.mypingmax("test string") # Python Error Traceback (most recent call last): File "", line 1, in ? File "C:\Python24\lib\site-packages\win32com\client\dynamic.py", line 491, in __getattr__ raise pythoncom.com_error, details com_error: (-2147220992, 'CONNECT_E_NOCONNECTION', None, None) #client Application error (3dsmax script output) -- Argument count error: mypingmax wanted 1, got 0 during OLE automation function call Sorry if its blindingly obvious but i just cant work out what is going on. Cheers, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: pwinauto to remote automate a GUI ?
Hi, Tim Golden wrote: > [baitelli] > > | pywinauto is a set of python modules to automate the > | Microsoft Windows GUI. > | With the lines below we start and atomates the apllication Notepad: > | > | from pywinauto import application > | app = application.Application() > | app.start('C:\Notepad.exe') > | ... pywinauto automation code > | > | Question: Is it possible to start and automate a remote GUI > | using Python? > > One way might be to have something like > Pyro (http://pyro.sf.net) running on the > remote machine linked to a proxy on the local > machine. > > TJG People have been doing this before... if you do a search for pywinauto on google code search the 2nd link will be... http://www.google.com/codesearch?hl=en&q=+pywinauto+show:SFnFI9XuSEk:FSZQBcwvc98:VkWgdDuEj0U&sa=N&cd=2&ct=rc&cs_p=http://codespeak.net/download/pypy/pypy-0.9.0.tar.gz&cs_f=pypy-0.9.0/py/documentation/talk/pytest-overview.txt#a0 It seems that integration wth PyTest might allow you to do what you want. I think it works something like: - You have python installed on the test machine - It is listening on a port? - You send over code that you want executed - and you get the data returned by the code. But other then that - I don't really know - I am no python Guru (especially not networking!) Glad that you are looking at pywinauto though :-) Mark -- http://mail.python.org/mailman/listinfo/python-list
Stani's Python Editor is looking for a new webhost
Dear Stani, Very much wishing you a new and great web host for the new year. I feel and read also from so many that you are doing a great service for Python users an d being an example of the Free software movement. i thank you very much and hope you will be back on the web soon. What help do you need now and what kind and level of contributions ( in expertise or lack of it) can we offer. All the best for the new year. markandeya -- http://mail.python.org/mailman/listinfo/python-list
Re: Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever sepa
I,too,gave semen from the mount. mark "don freeman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> >> I suppose he could point at what he saw and wither it. >> > > Jesus would then give a sermon from the mount: > > Let the Puritans wear fig leaves over their eyes! > -- http://mail.python.org/mailman/listinfo/python-list
Python + Cairo widget examples.. where can i get them?
Hey, a while ago i found a widget somewhere that was written in python with the cairo extension. that widget wasn't just a window.. it was a window without decorations and a red round thing in it. now i was trying to find that thing again and i`ve searched over a million blogs (oke not that much but alot) and i can`t find it.. so can someone point me to a python sample with a decorationless window/widget? all other python samples are also welcome. Thanx in favor. -- http://mail.python.org/mailman/listinfo/python-list
Newbie help understanding...
Hi I am trying to get a piece of code to work based on an exercise in a book. Any help appreciated. Can someone please explain what is going on here. I am trying to read from a text file a list of cards with the following format and sort firstly by suit and then by rank h 1 d 2 c 5 s 9 h2 d3 etc... I get the following error; Traceback (most recent call last): File "F:/###UNI###/ITC106/ass2/cardread.py", line 25, in t.append( t[0] + 400 ) AttributeError: 'str' object has no attribute 'append' def read_cards(filename): cards = [] for card in open(filename, 'r'): cards.append(card.strip()) return cards # read the deck of cards from a file filename = 'cards.txt' cards = read_cards(filename) for t in read_cards(filename): if t[1] == 'h': t.append( t[0] + 100 ) elif t[1] == 'd': t.append( t[0] + 200 ) elif t[1] == 'c': t.append( t[0] + 300 ) else: t.append( t[0] + 400 ) print read_cards(filename) Regards J -- http://mail.python.org/mailman/listinfo/python-list
totally lost newbie
Hi all I posted earlier on this but have changed my approach so here is my latest attempt at solving a problem. I have been working on this for around 12 hours straight and am still struggling with it. Write a program that reads the values for a random list of cards from a file, where each line in the file specifies a single card with the rank and then the suit separated by a space. The rank should be an integer in the range of 1 to 13 (Ace:1, King:13), while the suit should be a lower case character in the set { 'h', 'd', 'c', 's' }. Sort the card entries into suits ordered by rank, and print out the ordered list. Hint: sort the list first by rank, and then by suit. The format of the cards.txt file is; 1 h 1 d 13 c 10 s and so on for the whole deck. Can someone help me to get the mycomp function to work. Any help appreciated J def read_cards(filename): cards = [] for card in open(filename, 'r'): # strip the trailing newline character cards.append(card.strip()) return cards filename = 'cards.txt' cards = read_cards(filename) def cards_str2tup(cards): cards_tup = [] for card in cards: rank, suit = card.split() cards_tup.append((suit, int(rank))) return cards_tup def cards_tup2str(cards_tup): cards = [] space = ' ' for tup in cards_tup: suit, rank = tup s = str(rank) + space + suit cards.append(s) return cards def mycmp( a, b): #define the order in which the characters are to be sorted order = [ 'h', 'd', 'c', 's' ] # if the characters from each element ARENT the same if a[1] <> b[1]: #return the result of comparing the index of each elements character in the order list return cmp( order.index( a[1] ), order.index( b[1] ) ) #otherwise else : #return the result of comparing each elements number return cmp( a[0], b[0] ) cards.sort( mycmp ) #print cards -- http://mail.python.org/mailman/listinfo/python-list
Eval and raw string ??
Eval() doesn't seem to recognize the r'string' format. Is there a way around this. Example: If I input: -> eval("r'C:\tklll\ndfd\bll'") I get the output: Traceback (most recent call last): File "", line 1, in eval("r'C:\tklll\ndfd\bll'") File "", line 1 r'C:klll ^ SyntaxError: EOL while scanning single-quoted string The same principle applies for exec. Thanks in advance, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Using Regular Expresions to change .htm to .php in files
On Thu, 23 Aug 2007 12:27:10 -0700, Tobiah wrote: > sed "s/.htm/.php/g" < $each > /tmp/$$ This line should be: sed "s/\.htm$/.php/g" < $each > /tmp/$$ -- http://mail.python.org/mailman/listinfo/python-list
i can`t get python working on the command line (linux)
Hey, first of all: sorry for the 100% n00b question i`m brand new to python and i seem to start off with the biggest problem of all.. not even getting python to work. i`m running Fedora core 7 test 2 and all the python based applications are working fine (like pirut, pipet, and some other yum related tools) but when i try to run this script: #!/usr/bin/python # # python script tel.py # gevonden door Jan Mooij 24 september 2000 # from sys import * from string import * # Create an empty dictionary. count = {} for line in open(argv[1], 'r').readlines(): for word in split(line): if count.has_key(word): count[word] = count[word] + 1 else: count[word] = 1 words = count.keys() words.sort() for word in words: print "%15s\t%10d" % (word, count[word]) and i`ve put it in tel.py (just the same as in the sample) than chmod it to 777 (just to make sure it isn`t a permission issue) and than i run it with: ./tel.py now this is the error that i get: Traceback (most recent call last): File "./tel.py", line 12, in for line in open(argv[1], 'r').readlines(): IndexError: list index out of range also i`m not even getting the most simple sample code to work.. "Hello World". everything works fine when i first enter the python console by typing python. than i have the >>> things than print "Hello World" gives me the expected result but that`s not what i want.. i want to do it from a file.. the solution is probable extremely simple but i have no idea as a complete n00b in python. i do have alot php experience. hope someone could help me out with this. o and any function that i use in python gives me "command not found: print/whatever function i use" (probable just a simple yum install command that i need to do to get this working.. just try to figure that out with no python knowledge) Thanx alot in favor. -- http://mail.python.org/mailman/listinfo/python-list
Idiom for running compiled python scripts?
Hi, I'm new to python and looking for a better idiom to use for the manner I have been organising my python scripts. I've googled all over the place about this but found absolutely nothing. I'm a linux/unix command line guy quite experienced in shell scripts etc. I have a heap of command line utility scripts which I run directly. What is the best way to create python command line scripts but exploit the (loadonly) speed-up benefit of python compiled code? E.g. say I have a python script "myprog.py". I could just execute that directly each time but that means it is "compiled" each time I run it which is not efficient and adds to startup time. I have been creating a complimentary script "myprog" stub which just does: #!/usr/bin/env python from myprog import main if __name__ == "__main__": main() Of course this compiles myprog.py into myprog.pyc on first run as I am wanting. I have one of these stubs for all my python scripts I've created so far. Is there not a better way? Do I have to create a separate stub each time? I find it a bit messy to require a pair of scripts for each utility and it also contributes some inefficiency. Given the above stub is so boilerplate, why does python not provide a general stub/utility mechanism for this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for running compiled python scripts?
So given the lack of response it seems that there is probably no such idiom and that I should not be concerned by the inefficiency inherent in running .py scripts directly? I did some time tests and sure, the speed gain is slight, but it is a gain none the less. -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for running compiled python scripts?
On Fri, 23 Mar 2007 14:03:12 +1100, Steven D'Aprano wrote: > Since you've done these tests already, perhaps you can tell us what gain > you actually got? About the same as you, ~20 msecs for my small script samples. > Of course you have to type the "c". You're not deleting the source files > away are you? *wink* Sorry, the wink is lost on me? Of course I am not deleting the sources. In fact, I am also talking about python scripts being called from shell scripts. I guess I'm just surprised that the python installation does not provide a small stub invoker, e.g: A small script called "python_compile_and_run" in "pseudo" code: #!/usr/bin/env python import sys # Following is invalid syntax unfortunately :( from sys.argv[1].rstrip('.py') import main sys.argv = sys.argv[1:] if __name__ == "__main__": main() so I could just do a "python_compile_and_run myscript.py" and it would do what I want, i.e. run myscript.pyc if available and valid, generate and run it if necessary. -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for running compiled python scripts?
On Fri, 23 Mar 2007 22:24:07 +1100, Steven D'Aprano wrote: > if not os.path.exists(compiledname) or \ os.stat(compiledname)[MT] < > os.stat(scriptname)[MT]: > # compiled file doesn't exist, or is too old Surely the validity check done by Python is more sophisticated than this? Doesn't the binary file have to be compiled under the same python version etc? > Now don't forget to test whether launching the subshell takes longer > than the 20ms you might save. All that effort, and wouldn't it be ironic > if it was actually *slower* than executing the script from scratch each > time... But Python proper is executing all the above anyhow isn't it? So the 20 msecs advantage I measured already includes this logic. Anyhow, I give up. Compilation, it seems, only applies to python modules. Compilation is not appropriate for Python scripts. Should be in the FAQ. -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for running compiled python scripts?
On Fri, 23 Mar 2007 07:47:04 -0700, Alex Martelli wrote: > You can use > > python -c 'import myscript; myscript.main()' > > and variations thereon. Hmmm, after all that, this seems to be close to what I was looking for. Thanks Alex. Didn't find anything about this in your cookbook! (I'm just starting reading it whole - best way to really learn the language I think). So the general purpose invoking bash script e.g. "runpy" is merely something like: # #!/bin/bash if [ $# -lt 1 ]; then echo "usage: `basename $0` script.py [script args ..]" exit 1 fi PROG=$1 DIR=`dirname $PROG` MOD=`basename $PROG` MOD=${MOD%.py} shift exec python -c "import sys; \ sys.argv[0] = \"$PROG\"; \ sys.path.append(\"$DIR\"); \ import $MOD; $MOD.main()" $@ # So I timed "~/bin/myscript.py myargs" against "runpy ~/bin/myscript.py myargs" but got only maybe a couple of millisec improvement (using a 1000 line myscript.py which just immediately exits - to try and push the advantage!). So I agree - the ends do not justify the means here and I'll just execute myscript.py directly. Still not sure why python does not provide this as a "python --compile_and_run myscript.py" option though?! ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for running compiled python scripts?
On Sat, 24 Mar 2007 07:21:21 -0700, irstas wrote: > Also, rstrip doesn't work like you think it does. > 'pyxyypp.py'.rstrip('.py') == 'pyx' Well there is embarrassing confirmation that I am a python newbie :( > I timed it against running plain .py and running .pyc directly. It > seemed to be roughly on par with running .pyc directly, and about 18ms > faster than running .py. The file had 600 lines (21kb) of code. So see my point at least? I'm still not sure why this approach is ill-favoured? Thanks very much for all the detailed responses here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for running compiled python scripts?
On Sat, 24 Mar 2007 07:21:21 -0700, irstas wrote: > A simple implementation that "works": Not quite irstas BTW .. > import imp, sys, os > c = sys.argv[1] > if not os.path.exists(c + 'c') or os.stat(c).st_mtime > os.stat(c + > 'c').st_mtime: > import compiler > compiler.compileFile(c) > del sys.argv[0] > imp.load_compiled('__main__', c + 'c') The above doesn't actually work for my test script. I have an atexit call in the script which is deleting some temp files and I get the following traceback on termination when run with the above: Error in atexit._run_exitfuncs: Traceback (most recent call last): File "atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/home/mark/bin/myscript.py", line 523, in delete if files.tempdir: AttributeError: 'NoneType' object has no attribute 'tempdir' Error in sys.exitfunc: Traceback (most recent call last): File "/usr/lib/python2.4/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/home/mark/bin/myscript.py", line 523, in delete if files.tempdir: AttributeError: 'NoneType' object has no attribute 'tempdir' The appropriate source code is: At the start of main() .. # Ensure all temp files deleted on exit import atexit atexit.register(files.delete) and then from my class "files": @staticmethod def delete(): '''Called to delete all temp files''' if files.tempdir: shutil.rmtree(files.tempdir) Something about the environment is not quite the same. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: Idiom for running compiled python scripts?
On Sun, 25 Mar 2007 13:40:33 +1000, Steven D'Aprano wrote: > Because this is entirely a trivial saving. Who cares? Sheesh. > ... > Saving 18ms on a script that takes 50ms to execute *might* be > worthwhile, ... I don't understand your attitude. Sure, we are talking slight savings in machine efficiency but I am sure the python developers have laboured many long hours on subtle optimisations of the virtual machine, many of which probably dwarf the issue discussed here. Tell them their work is trivial and unnecessary. Every little bit helps. Why do I concern myself with this inefficiency - because it is there. Of course I realise the modern mantra that "premature optimisation is the root of all evil" but I don't subscribe to it. Programmers have been "encouraged" to not give a toss about efficiency and the outcome is all too apparent - most software today looks and runs like a pile of crap. -- http://mail.python.org/mailman/listinfo/python-list
How to find to HTML strings and 'save' them?
Hi All, Apologies for the newbie question but I've searched and tried all sorts for a few days and I'm pulling my hair out ;[ I have a 'reference' HTML file and a 'test' HTML file from which I need to pull 10 strings, all of which are contained within tags, e.g.: http://www.someplace.com/";>Go Someplace Once I've found the 10 I'd like to write them to another 'results' html file. Perhaps a 'reference results' and a 'test results' file. >From where I would then like to 'diff' the results to see if they match. Here's the rub: I cannot find a way to pull those 10 strings so I can save them to the results pages. Can anyone please suggest how this can be done? I've tried allsorts but I've been learning Python for 1 week and just don't know enough to mod example scripts it seems. don't even get me started on python docs.. ayaa ;] Please feel free to teach me to suck eggs because it's all new to me :) Thanks in advance, Mark. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to find to HTML strings and 'save' them?
Great, thanks so much for posting that. It's worked a treat and I'm getting HTML files with the list of h2 tags I was looking for. Here's the code just to share, what a relief :) : ... from BeautifulSoup import BeautifulSoup import re page = open("soup_test/tomatoandcream.html", 'r') soup = BeautifulSoup(page) myTagSearch = str(soup.findAll('h2')) myFile = open('Soup_Results.html', 'w') myFile.write(myTagSearch) myFile.close() del myTagSearch ... I do have two other small queries that I wonder if anyone can help with. Firstly, I'm getting the following character: "[" at the start, "]" at the end of the code. Along with "," in between each tag line listing. This seems like normal behaviour but I can't find the way to strip them out. There's an example of stripping comments and I understand the example, but what's the *reference* to the above '[', ']' and ',' elements? for the comma I tried: soup.find(text=",").replaceWith("") but that throws this error: AttributeError: 'NoneType' object has no attribute 'replaceWith' Again working with the 'Removing Elements' example I tried: soup = BeautifulSoup("you are a banana, banana, banana") a = str(",") comments = soup.findAll(text=",") [",".extract() for "," in comments] But if I'm doing 'import beautifulSoup' this give me a "soup = BeautifulSoup("you are a banana, banana, banana") TypeError: 'module' object is not callable" error, "import beautifulSoup from BeautifulSoup" does nothing Secondly, in the above working code that is just pulling the h2 tags - how the blazes do I 'prettify' before writing to the file? Thanks in advance! Mark. .. On Mar 25, 6:51 pm, Jorge Godoy <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > Hi All, > > > Apologies for the newbie question but I've searched and tried all > > sorts for a few days and I'm pulling my hair out ;[ > > > I have a 'reference' HTML file and a 'test' HTML file from which I > > need to pull 10 strings, all of which are contained within tags, > > e.g.: > > http://www.someplace.com/";>Go Someplace > > > Once I've found the 10 I'd like to write them to another 'results' > > html file. Perhaps a 'reference results' and a 'test results' file. > >>From where I would then like to 'diff' the results to see if they > > match. > > > Here's the rub: I cannot find a way to pull those 10 strings so I can > > save them to the results pages. > > Can anyone please suggest how this can be done? > > > I've tried allsorts but I've been learning Python for 1 week and just > > don't know enough to mod example scripts it seems. don't even get me > > started on python docs.. ayaa ;] Please feel free to teach me to suck > > eggs because it's all new to me :) > > > Thanks in advance, > > > Mark. > > Take a look at BeautifulSoup. It is easy to use and works well with some > malformed HTML that you might find ahead. > > -- > Jorge Godoy <[EMAIL PROTECTED]>- Hide quoted text - > > - Show quoted text - -- http://mail.python.org/mailman/listinfo/python-list
Need better run/edit method. I have to restart the shell after every script change.
Hello, What I need to know is if there is a better method to run/edit modules on my pc. I'm currently running the IDLE shell under Python 2.5, on Windows XP. Every time I edit my .txt or .py file, I have to restart the IDLE shell for the changes to take effect. It's pretty annoying. Assuming IDLE is already open, here are the steps that I typically take: 1. Open .txt version of module or script using notepad 2. make changes 3. save .txt file as .txt file 4. save .txt file as .py file 5. reset IDLE 6. import module again As you can see, I'm wasting a lot of time with this method. Maybe there is some better sofware available, or maybe I'm just not utilizing the tools at my disposal. Either way I would greatly appreciate any insight into this problem. Thanks in advance, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Need better run/edit method. I have to restart the shell after every script change.
Thanks guys. I'll give it a try. Brian Blais wrote: > Mark wrote: > > I'm currently running the IDLE shell under Python 2.5, on Windows XP. > > > > Every time I edit my .txt or .py file, I have to restart the IDLE shell > > for the changes to take effect. It's pretty annoying. Assuming IDLE is > > already open, here are the steps that I typically take: > > > > 1. Open .txt version of module or script using notepad > > 2. make changes > > 3. save .txt file as .txt file > > 4. save .txt file as .py file > > 5. reset IDLE > > 6. import module again > > > > why do you involve notepad, and .txt files? Instead, try this: > > 1. Run Idle > 2. Choose File/New Window > 3. Edit your .py file, and save it as a .py file > 4. Choose Run/Run Module > 5. Make changes, and save again > 6. Choose Run/Run Module > 7. etc... > > you don't need to close IDLE ever. IDLE refers to the editor, and the shell > that > runs connected to it. If you have just the shell, you can open the editor > with > File/New Window. If you have just the editor, you can choose Run/Python > Shell or > Run/Run Module depending on what you want to do, to get the shell. > > You can also take a .py file in the Windows explorer, right-click, and choose > "Open > with IDLE" to start editing it directly. > > You shouldn't save things as .txt, because then IDLE will not recognize it is > python > you are writing, and the right-click trick probably won't work either. You > should > never use Notepad, because it is just icky, and doesn't know about any > programming > languages. :) > > Hope this helps, > > Brian Blais > > > -- > - > > [EMAIL PROTECTED] > http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
dynamic argument name for functions
I want to pass a value to an argument of a function. The argument name is dynamic and is stored in a variable. How do I call the function using with arg_name and value as the parameters. thanks mark For ex: def function(arg1='None', arg2='None', arg3='None'): print arg1 print arg2 print arg3 arg_name = 'arg1' arg_value = 'i am passing a value to argument 1' function(???) -- http://mail.python.org/mailman/listinfo/python-list
Re: dynamic argument name for functions
On 1/12/07, Carsten Haese <[EMAIL PROTECTED]> wrote: On Fri, 2007-01-12 at 20:22 +, Simon Brunning wrote: > On 1/12/07, mark <[EMAIL PROTECTED]> wrote: > > I want to pass a value to an argument of a function. The argument name is > > dynamic and is stored in a > > variable. How do I call the function using with arg_name and value as the > > parameters. > > thanks > > arg_name = 'arg1' > > arg_value = 'i am passing a value to argument 1' > > function(???) > > Untested: > > function(**{arg_name: arg_value}) My version is superior: I tested it before replying. ;) both work like charm! ;-)! thanks mark -- http://mail.python.org/mailman/listinfo/python-list
Re: How to write code to get focuse the application which is open from server
Hi, There are better places to find me then on comp.lang.python (just too much traffic for me) pywinauto forums: http://forums.openqa.org/forum.jspa?forumID=15 or subscribe pywinauto mailing list: https://lists.sourceforge.net/lists/listinfo/pywinauto-users vithi wrote: > MatchError: Could not find 'Print' in '['', u'Transparent Windows > Client0', u'Transparent Windows Client2', u'Transparent Windows > Client1', u'Print - Remote', u'Transparent Windows Client', u'Print > - RemoteTransparent Windows Client']' > > This is the code > import sys > import time > import application > app = application.Application() > qi=app.window_(title_re = ".*ArcView.*") > time.sleep(2) > qi.TypeKeys("%FP") > time.sleep(2) > > app.Print.Ok.CloseClick() > > My guess is that problem above is that teh title of the window is u"Print - \\Remote", and "Print" is not enough information for pywinauto to go on. I suggest you replace the last line with one of the following... app.PrintRemote.Ok.CloseClick() app.window_(title_re = "Print - .*").Ok.CloseClick() Someone also was wondering why they do not have to call Application.Start() or Application.Connect() explicitly - that is because the first call to app.window_() will initialize the application appropriately. The reason for this is that most usages ended up being a) Connect to a window with specific title, then use that window in the next line - so I was trying to avoid duplication. Thanks Mark -- http://mail.python.org/mailman/listinfo/python-list
creating a dictionary
i have few variables and i want to create a dictionary with these variables such that the keys are the variable names and the corresponding values are the variable values.how do i do this easily? for ex: var1='mark' var2=['1','2','3'] my_dict = create_my_dictionary(var1, var2) and my_dict is {'var1':'mark', 'var2':['1','2','3']} is there a function for create_my_dictionary? -- http://mail.python.org/mailman/listinfo/python-list
.pth configuration method not working
Sys.path doesn't recognize any directories that I add using the .pth method. I'm running Windows XP if that helps diagnose the problem. Here is what I've done: The original output of sys.path: ['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat- win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\ \site-packages'] I've added a file "MyPaths.pth" to "C:\Python25\". MyPaths.pth contains one line that reads: C:\Python25\MyModules. For some reason sys.path won't ever recognize that C:\Python25\MyModules exists. This is very frustrating because I know that this method is supposed to work. ANY help would be appreciated. Thanks in advance, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: CTypes
Hi, On Feb 3, 6:22 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I forgot to mention I am running Windows 98SE. Hmm - pywinauto is not supported on Windows 98 - it relies competely on Unicode. You could try renaming all the functions ending in W to ending in A e.g. change GetModuleFileNameExW to GetModuleFileNameExA - but I am fairly sure that this would NOT solve all the problems you would have trying to run on W98. As far as I know (not 100% sure) but ctypes should have no problem on W98 - it is a pywinauto requirement for Unicode. Another thing to look into might be Unicows.dll (which gives some Unicode functions to W98) Mark -- http://mail.python.org/mailman/listinfo/python-list
standardized us address
Hi Is there any python module that will convert address to standard US address format: for ex: 314 south chauncey avenue should be: 314 s chauncey ave thanks mark -- http://mail.python.org/mailman/listinfo/python-list
python mms library
Hi Is there a library for creating mms message in python? thanks mark -- http://mail.python.org/mailman/listinfo/python-list
calling php function from python
is it possible to call a php function from python and use a class from php in python? i want to use mmslib which creates mms messages and the only implementation is a php mmslib implementation. thanks a lot! mark -- http://mail.python.org/mailman/listinfo/python-list
Re: PyDev on Mac
On Sun, 18 Feb 2007 10:50:37 +0100, Diez B. Roggisch wrote: > Just wait until my crystal ball comes back from the cleaners, and I > will start looking at your problem. > > As you can lay back and do nothing while that happens, I suggest you > take this highly entertaining read: Now that is an entertaining twist to the standard "RTFM" response! Hadn't seen that one before. -- http://mail.python.org/mailman/listinfo/python-list
getting a thread out of sleep
Right now I have a thread that sleeps for sometime and check if an event has happened and go back to sleep. Now instead I want the thread to sleep until the event has occured process the event and go back to sleep. How to do this? thanks mark class eventhndler(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): while True: time.sleep(SLEEPTIME) ''''do event stuff''' -- http://mail.python.org/mailman/listinfo/python-list
Re: getting a thread out of sleep
On 20 Feb 2007 20:47:57 -0800, placid <[EMAIL PROTECTED]> wrote: > On Feb 21, 3:08 pm, mark <[EMAIL PROTECTED]> wrote: > > Right now I have a thread that sleeps for sometime and check if an > > event has happened and go back to sleep. Now instead I want the thread > > to sleep until the event has occured process the event and go back to sleep > > > > class eventhndler(threading.Thread): > > def __init__(self): > > threading.Thread.__init__(self) > > def run(self): > > while True: > > time.sleep(SLEEPTIME) > > ''''do event stuff''' > > The way i would do this is by using an threading.Event ( > http://docs.python.org/lib/event-objects.html ) > > > > class eventhandler(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > self.event = threading.Event() > def run: > while True: > # block until some event happens > self.event.wait() > """ do stuff here """ > self.event.clear() > > > the way to use this is to get the main/separate thread to set() the > event object. Can you give an example of how to get the main threead to set teh event object? this is exactly what i wanted to do! thanks a lot! mark -- http://mail.python.org/mailman/listinfo/python-list
Re: getting a thread out of sleep
On 20 Feb 2007 21:26:18 -0800, placid <[EMAIL PROTECTED]> wrote: > On Feb 21, 4:21 pm, "placid" <[EMAIL PROTECTED]> wrote: > > On Feb 21, 4:12 pm, mark <[EMAIL PROTECTED]> wrote: > > > On 20 Feb 2007 20:47:57 -0800, placid <[EMAIL PROTECTED]> wrote: > > > > On Feb 21, 3:08 pm, mark <[EMAIL PROTECTED]> wrote: > > > > > Right now I have a thread that sleeps for sometime and check if an > > > > > event has happened and go back to sleep. Now instead I want the thread > > > > > to sleep until the event has occured process the event and go back to > > > > > sleep > > > > > > > class eventhndler(threading.Thread): > > > > > def __init__(self): > > > > > threading.Thread.__init__(self) > > > > > def run(self): > > > > > while True: > > > > > time.sleep(SLEEPTIME) > > > > > ''''do event stuff''' > > > > > > The way i would do this is by using an threading.Event ( > > > >http://docs.python.org/lib/event-objects.html) > > > > > > > > > > > > class eventhandler(threading.Thread): > > > > def __init__(self): > > > > threading.Thread.__init__(self) > > > > self.event = threading.Event() > > > > def run: > > > > while True: > > > > # block until some event happens > > > > self.event.wait() > > > > """ do stuff here """ > > > > self.event.clear() > > > > > > > > > > the way to use this is to get the main/separate thread to set() the > > > > event object. > > > > > Can you give an example of how to get the main threead to set teh event > > > object? > > > this is exactly what i wanted to do! > > > thanks a lot! > > > mark> > oops I've miss-typed the thread variable name the following should > work > > > if __name__ == "__main__": > evtHandlerThread = eventhandler() > evtHandlerThread.start() > > # do something here # > evtHandlerThread.event.set() > > # do more stuff here # > evtHandlerThread.event.set() > > Can I have the same thread process two or more events? Can you tell how to do this? The code you gave is waiting on one event right. How can I do it for more events? thanks a lot! mark -- http://mail.python.org/mailman/listinfo/python-list
Re: getting a thread out of sleep
On 21 Feb 2007 14:47:50 -0800, placid <[EMAIL PROTECTED]> wrote: > On Feb 22, 3:23 am, mark <[EMAIL PROTECTED]> wrote: > > On 20 Feb 2007 21:26:18 -0800, placid <[EMAIL PROTECTED]> wrote: > > > > > > > > > On Feb 21, 4:21 pm, "placid" <[EMAIL PROTECTED]> wrote: > > > > On Feb 21, 4:12 pm, mark <[EMAIL PROTECTED]> wrote: > > > > > On 20 Feb 2007 20:47:57 -0800, placid <[EMAIL PROTECTED]> wrote: > > > > > > On Feb 21, 3:08 pm, mark <[EMAIL PROTECTED]> wrote: > > > > > > > Right now I have a thread that sleeps for sometime and check if > > > > > > > an > > > > > > > event has happened and go back to sleep. Now instead I want the > > > > > > > thread > > > > > > > to sleep until the event has occured process the event and go > > > > > > > back to sleep > > > > > > > > > class eventhndler(threading.Thread): > > > > > > > def __init__(self): > > > > > > > threading.Thread.__init__(self) > > > > > > > def run(self): > > > > > > > while True: > > > > > > > time.sleep(SLEEPTIME) > > > > > > > ''''do event stuff''' > > > > > > > > The way i would do this is by using an threading.Event ( > > > > > >http://docs.python.org/lib/event-objects.html) > > > > > > > > > > > > > > > > class eventhandler(threading.Thread): > > > > > > def __init__(self): > > > > > > threading.Thread.__init__(self) > > > > > > self.event = threading.Event() > > > > > > def run: > > > > > > while True: > > > > > > # block until some event happens > > > > > > self.event.wait() > > > > > > """ do stuff here """ > > > > > > self.event.clear() > > > > > > > > > > > > > > the way to use this is to get the main/separate thread to set() the > > > > > > event object. > > > > > > > Can you give an example of how to get the main threead to set teh > > > > > event object? > > > > > this is exactly what i wanted to do! > > > > > thanks a lot! > > > > > mark> > > > oops I've miss-typed the thread variable name the following should > > > work > > > > > > > > if __name__ == "__main__": > > > evtHandlerThread = eventhandler() > > > evtHandlerThread.start() > > > > > # do something here # > > > evtHandlerThread.event.set() > > > > > # do more stuff here # > > > evtHandlerThread.event.set() > > > > > > > > > Can I have the same thread process two or more events? Can you tell > > how to do this? The code you gave is waiting on one event right. How > > can I do it for more events? > > thanks a lot! > > mark > > I don't think a thread can block on more than one event at a time. But > you can make it block on more then one event one at a time. > > > > class eventhandler(threading.Thread): >def __init__(self): >threading.Thread.__init__(self) >self.events = [threading.Event(), threading.Event()] >self.currentEvent = None >def run: >while True: >for event in self.events: >self.currentEvent = event ># block until some event happens >self.currentEvent.wait() >""" do stuff here """ >self.currentEvent.clear() > > if __name__ == "__main__": > evtHandlerThread = eventhandler() > evtHandlerThread.start() > > # do something here # > evtHandlerThread.currentEvent.set() > > # do more stuff here # > evtHandlerThread.currentEvent.set() > > > > what the thread does is sequentially waits for two events to happen > and then execute the same code. You could change this code to perform > different functions for different event objects. Once the thread starts it is going to wait on the event that is the first element of the list right? This would mean : evtHandlerThread.currentEvent.set(): that I have only one event right? Can you explain how I can have different event objects. I dont see how I can do different functinos for same event. Thanks a lot! mark -- http://mail.python.org/mailman/listinfo/python-list
Re: getting a thread out of sleep
On 21 Feb 2007 16:10:51 -0800, placid <[EMAIL PROTECTED]> wrote: > On Feb 22, 10:20 am, mark <[EMAIL PROTECTED]> wrote: > > On 21 Feb 2007 14:47:50 -0800, placid <[EMAIL PROTECTED]> wrote: > > > > > > > > > On Feb 22, 3:23 am, mark <[EMAIL PROTECTED]> wrote: > > > > On 20 Feb 2007 21:26:18 -0800, placid <[EMAIL PROTECTED]> wrote: > > > > > > > On Feb 21, 4:21 pm, "placid" <[EMAIL PROTECTED]> wrote: > > > > > > On Feb 21, 4:12 pm, mark <[EMAIL PROTECTED]> wrote: > > > > > > > On 20 Feb 2007 20:47:57 -0800, placid <[EMAIL PROTECTED]> wrote: > > > > > > > > On Feb 21, 3:08 pm, mark <[EMAIL PROTECTED]> wrote: > > > > > > > > > Right now I have a thread that sleeps for sometime and check > > > > > > > > > if an > > > > > > > > > event has happened and go back to sleep. Now instead I want > > > > > > > > > the thread > > > > > > > > > to sleep until the event has occured process the event and go > > > > > > > > > back to sleep > > > > > > > > > > > class eventhndler(threading.Thread): > > > > > > > > > def __init__(self): > > > > > > > > > threading.Thread.__init__(self) > > > > > > > > > def run(self): > > > > > > > > > while True: > > > > > > > > > time.sleep(SLEEPTIME) > > > > > > > > > ''''do event stuff''' > > > > > > > > > > The way i would do this is by using an threading.Event ( > > > > > > > >http://docs.python.org/lib/event-objects.html) > > > > > > > > > > > > > > > > > > > > class eventhandler(threading.Thread): > > > > > > > > def __init__(self): > > > > > > > > threading.Thread.__init__(self) > > > > > > > > self.event = threading.Event() > > > > > > > > def run: > > > > > > > > while True: > > > > > > > > # block until some event happens > > > > > > > > self.event.wait() > > > > > > > > """ do stuff here """ > > > > > > > > self.event.clear() > > > > > > > > > > > > > > > > > > the way to use this is to get the main/separate thread to set() > > > > > > > > the > > > > > > > > event object. > > > > > > > > > Can you give an example of how to get the main threead to set teh > > > > > > > event object? > > > > > > > this is exactly what i wanted to do! > > > > > > > thanks a lot! > > > > > > > mark> > > > > > oops I've miss-typed the thread variable name the following should > > > > > work > > > > > > > > > > > > if __name__ == "__main__": > > > > > evtHandlerThread = eventhandler() > > > > > evtHandlerThread.start() > > > > > > > # do something here # > > > > > evtHandlerThread.event.set() > > > > > > > # do more stuff here # > > > > > evtHandlerThread.event.set() > > > > > > > > > > > > > Can I have the same thread process two or more events? Can you tell > > > > how to do this? The code you gave is waiting on one event right. How > > > > can I do it for more events? > > > > thanks a lot! > > > > mark > > > > > I don't think a thread can block on more than one event at a time. But > > > you can make it block on more then one event one at a time. > > > > > > > > > > class eventhandler(threading.Thread): > > >def __init__(self): > > >threading.Thread.__init__(self) > > >self.events = [threading.Event(), threading.Event()] > > >self.currentEvent = None > > >def run: > > >while True: > > >for event in self.events: > > >self.currentEvent
guess file type in python
Is there any way to guess the file type using python? thanks mark For example in unix: file code.py code.py: a python script text executable file Eccentric.gif Eccentric.gif: GIF image data, version 89a, 237 x 277 -- http://mail.python.org/mailman/listinfo/python-list
Pyflakes pre-commit hook in subversion
http://tarekziade.wordpress.com/2006/11/01/protecting-a-python-svn-code-base-with-the-pre-commit-hook/ Is it possible to check code in python before committing to svn using pyflakes, pythontidy Pyflakes and Subversion Pyflakes is a nice little utility that checks your Python code for errors. The main advantage over PyChecker and PyLint is that it is much faster and gives almost no false positives. Today I wrote a little hack on top of the enforcer pre-commit script which forces the code you check in to pass pyflakes. Eg, the users of svn will see the following output if they try to check in code which has errors pyflakes can detect: $ svn ci -m "fix" completion.py Sendingcompletion.py Transmitting file data .svn: Commit failed (details follow): svn: 'pre-commit' hook failed with error output: Pyflakes found 1 error(s)/warning(s): kiwi/trunk/examples/completion.py:1: undefined name 'test' The small "configuration" file for enforce can be found here. Can you share enforcer file? or a means to ensure safe code in python repo -- http://mail.python.org/mailman/listinfo/python-list
Traversing python datatypes via http
Is it possible to traverse say python lists via http:// say there is a list in the memory can we traverse the list using list/next list/prev list/first list/last is there a pythonic library to do that? thanks -- http://mail.python.org/mailman/listinfo/python-list
urllib slow on Leopard
I've recently switched from Ubuntu to OS X Leopard. I have some python scripts which download info from the web. The scripts were working fine before on Ubuntu, but urllib seems to work really slowly on Leopard. I tried an example from the docs: >>> import urllib2 >>> f = urllib2.urlopen('http://www.python.org/') >>> print f.read(100) http://www.w3.org/TR/xhtml1/DTD/xhtm >>> The line f = ... takes about a minute to return - but otherwise returns the predicted result. My web connection seems fine, so has anyone got any ideas as to what the problem might be? -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib slow on Leopard
mark wrote: > I've recently switched from Ubuntu to OS X Leopard. I have some python > scripts which download info from the web. The scripts were working fine > before on Ubuntu, but urllib seems to work really slowly on Leopard. > > I tried an example from the docs: > > >>> import urllib2 > >>> f = urllib2.urlopen('http://www.python.org/') > >>> print f.read(100) > "http://www.w3.org/TR/xhtml1/DTD/xhtm > >>> > > The line f = ... takes about a minute to return - but otherwise returns > the predicted result. My web connection seems fine, so has anyone got > any ideas as to what the problem might be? I found that by configuring the network manually (specifying static IP address, etc.) it sped the whole thing up. Go figure. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3 and my Mac (Leopard)
On Wed, Dec 24, 2008 at 5:11 PM, Dan wrote: > > Wanted to learn python, got Mark Summerfield's new book "Programming in > Python 3". Having a hard time getting python 3 and IDLE working on my Mac > with Leopard. The mac "resources" on the python.org site seem a bit out of > date, and don't really mention python 3. Are there any resources out there? > Is the python community just not interested in Macs? I've tried googling and > the usual search strategies. Any help would be appreciated. > > DAN I used the following link when installing Python 3 on my Mac running Leopard, it worked like a charm: http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/ These instructions are based around installing Python 3 alongside your existing install, which is what I was looking for. YMMV, especially concerning IDLE, I haven't used it with 3.0 as of yet. -Mark -- http://mail.python.org/mailman/listinfo/python-list
looking for tips on how to implement "ruby-style" Domain Specific Language in Python
I want to implement a internal DSL in Python. I would like the syntax as human readable as possible. This means no disturbing '.;()\' characters. I like to have the power of the hosting language as well. Thats why I want to build it as an internal DSL and NOT as a external DSL. I want the DSL as human readable as possible: >>> open_browser navigate_to 'www.openstreetmap.org' website search 'Von-Gumppenberg-Strasse, Schmiechen' verify search_result zoom in <<< Martin Fowler recommends "Method Chaining" to build internal DSLs: >>> Browser("http://www.openstreetmap.org/";) \ .search("Von-Gumppenberg-Strasse, Schmiechen") \ .zoom_in() <<< I guess that it is possible to argue that this means the same. Nevertheless I do not like all the parentheses and punctuation necessary to satisfy the Python interpreter. The reason why I need this is that I want to have non technical people review the files written in the DSL. I already know that there are parser frameworks available but I want to build it as internal DSL in Python (Yes, I know ANTLR, Ply, and whatnot). How would one approach this in Python? Do I need to build a custom loader which compiles *.dsl files to *.pyc files? Is it possible to switch between the custom DSL and the standard Python interpreter? -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for tips on how to implement "ruby-style" Domain Specific Language in Python
> So you can't make an internal DSL like this that uses Python's built- > in grammar. You'd have to hack the parser or settle for an external > preprocessor. This time it is really hard for me but I begin accepting the fact that I will have to build an external DSL. I experimented some weeks ago with ANTLR and the tools work fine but I do not like the extra effort to learn and maintain the extra tooling. I think that in the beginning the DSL language will have to change a very often as new features are added. To implement a standardized rock solid language like SQL ANTLR might be the perfect tool but to develop something from scratch that will be expanded interactively a internal DSL has huge benefits. Please not that I really like ANTLR. It is just the first tool I used for this task and I want to double check if other tools fit better to my needs. I will look into Ply and Pyparsing over the next weeks unless someone points out that there is some special tool that makes growing a new "fast evolving" language as easy as building an internal DSL. Maybe this is all overkill and there is a hacking ruby-style DSLs with regular expressions recipe out there? So far I could not find one. > However, the gist of it seems to be that you want to be able to write > files in your DSL that can be imported just like a regular Python > module. Yes, that can be done. > > See PEP 302, Import Hooks: > > http://www.python.org/dev/peps/pep-0302/ > > Python's standard importer looks for files with *.py, *.pyc, *.pyd, or > *.so extensions. You could write an importer that looks for *.dsl > files, and, instead of loading it as a Python file, invokes your DSL > parser. This is really helpful. Thanks for giving me directions. Mark -- http://mail.python.org/mailman/listinfo/python-list
Unpacking byte strings from a file of unknown size
Hi; I'm trying to use the struct.unpack to extract an int, int, char struct info from a file. I'm more accustomed to the file.readlines which works well in a 'for' construct (ending loop after reaching EOF). # This does OK at fetching one 10-byte string at a time: # (4, 4, 2 ascii chars representing hex) info1, info2, info3 = struct.unpack('http://mail.python.org/mailman/listinfo/python-list
Re: Unpacking byte strings from a file of unknown size
Thanks I tested your solution and that works. One of the things that didn't work was for chunk in myfile.read(10): info1, info2, info3 = struct.unpack('http://mail.python.org/mailman/listinfo/python-list
Re: Unpacking byte strings from a file of unknown size
> this code python interprets as: > > data = myfile.read(10) > for chunk in data: > . > Aha - now that you put it that way it makes sense. And thanks to all who replied - I'll try out the other suggestions too. Mark -- http://mail.python.org/mailman/listinfo/python-list
compressed serialization module
I used pickle and found the file was saved in text format. I wonder whether anyone is familiar with a good compact off-the-shelf module available that will save in compressed format... or maybe an opinion on a smart approach for making a custom one? Appreciate it! I'm a bit of a n00b but have been looking around. I found a serialize.py but it seems like overkill. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: compressed serialization module
Thanks guys. This is for serializing to disk. I was hoping to not have to use too many intermediate steps, but I couldn't figure out how to pickle data into zipfile without using either intermediate string or file. That's cool here's what I'll probably settle on (tested) - now just need to reverse steps for the open function. def saveOjb(self, dataObj): fName = self.version + '_' + self.modname + '.dat' f = open(fName, 'w') dStr = pickle.dumps(dataObj) c = dStr.encode("bz2") pickle.dump(c, f, pickle.HIGHEST_PROTOCOL) f.close() I'm glad to see that "encode()" is not one of the string ops on the deprecate list (using Python 2.5). Thx, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: compressed serialization module
On Nov 17, 3:08 pm, [EMAIL PROTECTED] wrote: > Mark> def saveOjb(self, dataObj): > Mark> fName = self.version + '_' + self.modname + '.dat' > Mark> f = open(fName, 'w') > Mark> dStr = pickle.dumps(dataObj) > Mark> c = dStr.encode("bz2") > Mark> pickle.dump(c, f, pickle.HIGHEST_PROTOCOL) > Mark> f.close() > > Hmmm... Why pickle it twice? > > def saveOjb(self, dataObj): > fName = self.version + '_' + self.modname + '.dat' > f = open(fName, 'wb') > f.write(pickle.dumps(dataObj, pickle.HIGHEST_PROTOCOL).encode("bz2")) > f.close() > > Skip I wasn't sure whether the string object was still a string after "encode" is called... at least whether it's still an ascii string. And if not, whether it could be used w/ dumps. I tested your variation and it works the same. I guess your "write" is doing the same as my "dump", but may be more efficient. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
django model problem
Hi, Say I have these simple models: class Musician(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) class Album(models.Model): artist = models.ForeignKey(Musician) name = models.CharField(max_length=100) Now in `Musician` I want to add a field "last_album". How can I do that? I'd like to be able to write: m = Musician(pk=1) print m.last_album.name When I try: last_album = models.OneToOneField(Album) it somehow works but creates a (useless) unique index for last_album. And I don't need additional related field in the Album model (it's also created now). Thanks, MS -- http://mail.python.org/mailman/listinfo/python-list
Re: django model problem
> I think the first thing you need to do is decide if there is going to be > more than one Musician object. and more than one Album object. > Presently you are giving all musicians the same first_name and > last_name. I suggest you look up the documentation for the special > method __init__() > > Then you need to realize that assigning new attributes to an instance > object needs to be done inside an instance method, either __init__() or > some other method with a self parameter. What you say would normally make sense, but it's Django and it works that way here. See: http://docs.djangoproject.com/en/dev/topics/db/models/#fields Regards MS -- http://mail.python.org/mailman/listinfo/python-list
Re: django model problem
> > Anyway, since I don't have time to actually install and configure Django > to experiment, I'd suggest you post a query on the django-users mailing > list, at http://groups.google.com/group/django-users Yes, that's what I did - it seems my problem is either a tough one, or it's just impossible to do what I want. Anyway great thanks for your interest and help! Regards, MS -- http://mail.python.org/mailman/listinfo/python-list
New fonts for python docs site
e.g. see http://docs.python.org/library/index.html Please tell me this is a mistake? 3.X docs are the same. -- http://mail.python.org/mailman/listinfo/python-list
Re: New fonts for python docs site
On Thu, 23 Apr 2009 11:41:45 +0200, Marco Mariani wrote: > Looks ok. What do you see? Hmm, I was seeing a ugly jagged bit-mapped font, but only on the docs.python.org site. So I cleared out my firefox cache and restarted and it now looks fine. Never seen that one before. Sorry for the now silly post. I'd looked at the site yesterday and it looked fine and after seeing the ugly fonts coupled with the docs site update of today, I jumped to a silly conclusion. -- http://mail.python.org/mailman/listinfo/python-list
Re: What IDE support python 3.0.1 ?
On Wed, 15 Apr 2009 22:45:35 +, Benjamin Peterson wrote: > Why do you think you're wasting time with 2.x? I'm a relative newbie to python as well but I'd agree that there is at least a small degree of time "wasted" learning python 2.x simply because the standard library of python 3.x has been cleaned up and consolidated which makes learning it slightly easier. -- http://mail.python.org/mailman/listinfo/python-list
Help with setting local variables of class
im trying to create a class user so that i can do r=User(1) r._user.keys() ['rating', 'last_name', 'pageviews', 'ip', 'number_polls', 'site', 'myrand', 'hotmail', 'number_activities', 'skype', 'id', 'city', 'rawpassword', 'number_useraudios', 'zip', 'number_votes', 'last_login', 'number_userpics', 'music', 'email', 'number_pages', 'username', 'number_posts', 'hash', 'number_comments', 'number_pictures', 'first_name', 'yahoo', 'groups', 'heroes', 'favoritestuff', 'number_usermessages_sent', 'vanity', 'interests', 'television', 'number_uservideos', 'created', 'dob', 'gender', 'number_friends', 'liketomeet', 'htmlcodes', 'aim', 'movies', 'password', 'books', 'profilepic', 'number_usermessages', 'email_subscribe', 'number_communities'] so i want this to become r.rating r.last_name r.pageviews and so on r.username r.photos() and so on but i want to set the keys of the user row as the keys of User self but i m not sure how to do it for i in self._user.keys(): self[i]=self._user[i] gives an error Traceback (most recent call last): File "", line 1, in File "api.py", line 40, in __init__ self[i]=self._user[i] AttributeError: instance has no attribute '__setitem__' You can do something like self.update(_user) doesnt work either Traceback (most recent call last): File "", line 1, in File "api.py", line 39, in __init__ self.update(self._user) AttributeError: user instance has no attribute 'update' Any thoughts on how to set this? class User: """user object """ def __init__(self, id): self._id = id self._user=db.query('select * from users where id=$id',vars=locals()) if not self._user: self._validuser=False self._username='' self._firstname='' self._lastname='' self._dob='' self._gender='' self._sex='' else: self._user=self._user[0] self._validuser=True self._username=self._user.username self._firstname=self._user.first_name self._lastname=self._user.last_name self._dob=self._user.dob self._gender=self._user.gender self._sex=self._user.gender for i in self._user.keys(): self[i]=self._user[i] def userrow(self): return db.query('select * from users where id=$self._id',vars=locals())[0] def photos(self): return db.query('select pic,id, username from userpics where user_id=$self._id',vars=locals()) -- http://mail.python.org/mailman/listinfo/python-list
Re: Compare 2 files and discard common lines
On Thu, 29 May 2008 01:36:44 -0700, loial wrote: > I have a requirement to compare 2 text files and write to a 3rd file > only those lines that appear in the 2nd file but not in the 1st file. > > Rather than re-invent the wheel I am wondering if anyone has written > anything already? Of course you can do this at any linux or unix command line simply by: comm -13 file1 file2 >file3 -- http://mail.python.org/mailman/listinfo/python-list
Re: how should i use this function?
On Jun 4, 6:58 pm, Gandalf <[EMAIL PROTECTED]> wrote: > > > > But I pywin32 use it all the time i havepywinauto > As the author of pywinauto - I can safely say that just because you have and use pywinauto does NOT mean you have pywin32. pywin32 is not needed for pywinauto. (it uses ctypes to access what it needs). You might find that there are more people who can help you at http://clearspace.openqa.org/community/pywinauto/pywinauto_users (though I do not give the best support in the world - so messages have sat there for a while unanswered!) Thanks Mark -- http://mail.python.org/mailman/listinfo/python-list
Summing a 2D list
Hi all, I have a scenario where I have a list like this: UserScore 1 0 1 1 1 5 2 3 2 1 3 2 4 3 4 3 4 2 And I need to add up the score for each user to get something like this: UserScore 1 6 2 4 3 2 4 8 Is this possible? If so, how can I do it? I've tried looping through the arrays and not had much luck so far. Any help much appreciated, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Summing a 2D list
On Jun 12, 3:02 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Mark wrote: > > Hi all, > > > I have a scenario where I have a list like this: > > > User Score > > 1 0 > > 1 1 > > 1 5 > > 2 3 > > 2 1 > > 3 2 > > 4 3 > > 4 3 > > 4 2 > > > And I need to add up the score for each user to get something like > > this: > > > User Score > > 1 6 > > 2 4 > > 3 2 > > 4 8 > > > Is this possible? If so, how can I do it? I've tried looping through > > the arrays and not had much luck so far. > > > Any help much appreciated, > > Show us your efforts in code so far. Especially what the actual data looks > like. Then we can suggest a solution. > > Diez Hi Diez, thanks for the quick reply. To be honest I'm relatively new to Python, so I don't know too much about how all the loop constructs work and how they differ to other languages. I'm building an app in Django and this data is coming out of a database and it looks like what I put up there! This was my (failed) attempt: predictions = Prediction.objects.all() scores = [] for prediction in predictions: i = [prediction.predictor.id, 0] if prediction.predictionscore: i[1] += int(prediction.predictionscore) scores.append(i) I did have another loop in there (I'm fairly sure I need one) but that didn't work either. I don't imagine that snippet is very helpful, sorry! Any tips would be gratefully recieved! Thanks, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Summing a 2D list
John, it's a QuerySet coming from a database in Django. I don't know enough about the structure of this object to go into detail I'm afraid. Aidan, I got an error trying your suggestion: 'zip argument #2 must support iteration', I don't know what this means! Thanks to all who have answered! Sorry I'm not being very specific! -- http://mail.python.org/mailman/listinfo/python-list
Re: Summing a 2D list
On Jun 12, 3:45 pm, Aidan <[EMAIL PROTECTED]> wrote: > Aidan wrote: > > Mark wrote: > >> John, it's a QuerySet coming from a database in Django. I don't know > >> enough about the structure of this object to go into detail I'm > >> afraid. > > >> Aidan, I got an error trying your suggestion: 'zip argument #2 must > >> support iteration', I don't know what this means! > > > well, if we can create 2 iterable sequences one which contains the user > > the other the scores, it should work > > > the error means that the second argument to the zip function was not an > > iterable, such as a list tuple or string > > > can you show me the lines you're using to retrieve the data sets from > > the database? then i might be able to tell you how to build the 2 lists > > you need. > > wait you already did... > > predictions = Prediction.objects.all() > pairs = [(p.predictor.id,p.predictionscore) for p in predictions] > > those 2 lines will will build a list of user/score pairs. you can then > replace the call to zip with pairs > > any luck? Thanks Aidan, this works great! Thanks also to everyone else, I'm sure your suggestions would have worked too if I'd been competent enough to do them properly! -- http://mail.python.org/mailman/listinfo/python-list
Re: Different times between Python and System
On Mon, 14 Apr 2008 00:31:34 -0700, Josh wrote: > Hmm... That didn't work out so well that time. I feel like an idiot. > Previously there has been an hour difference between the system time and > the time that python reports. Thanks for the laugh though Josh. That was funny! :) -- http://mail.python.org/mailman/listinfo/python-list
eggy IDE
Hello, I have written an open source IDE in python and Qt, called eggy. Eggy supports several languages, including python, ruby, C, C++, java, perl and others. Eggy also supports group projects over the lan or internet - with live changes, lets you compile and run your code, supports templates and lets you write your own plugins very easily. You also have syntax highlighting, autocompletion, an integrated bash shell and the option of chatting with group partners. You can read more about it here: http://eggy.student.utwente.nl";>http://eggy.student.utwente.nl it free and open source (GPL). Regards, Mark PS: if anyone is interested in helping out with the project, feel free to write and submit a plugin (in python), its really easy and some ideas are posted on the website. -- http://mail.python.org/mailman/listinfo/python-list
(in memory) database
Hi there, I need to extract data from text files (~4 GB) on this data some operations are performed like avg, max, min, group etc. The result is formated and written in some other text files (some KB). I currently think about database tools might be suitable for this. I would just write the import from the text files and ... the tool does the rest. The only problem I can imagine is that this would not be fast enough. But I would give it a shoot. Unfortunately I have only some knowledge of SQLite which is not an option here. Some additional requirements I can think of are: - Python (I want to hone my programming skills too) - Python-only (no C-lib) for simplicity (installation, portability). Therefore SQLite is not an option - must be fast - I like SQL (select a, b from ...) this would be nice (row[..] + ... is a little hard getting used to) So far I found PyDBLite, PyTables, Buzhug but they are difficult to compare for a beginner. Cheers, Mark -- http://mail.python.org/mailman/listinfo/python-list
standalone buildbot possible/ don't have a remote
I want to start small and setup a buildbot on one machine (no slaves). I hope this is possible. I assume I only need one master in this case (without slave config)??? from my master.cfg c['slaves'] = [] ... (rest of the sample config) b1 = {'name': "buildbot-full", # 'slavename': "bot1name", 'builddir': "full", 'factory': f1, } Do I need some configuration that the builder uses the master instance? I experimented a bit and searched for a similar configuration so far without success :-(( I did run the buildbot testsuite without errors. Here is one problem the buildbot writes out on console: 2008-09-28 20:43:10+0200 [-] maybeStartBuild : [] [] 2008-09-28 20:43:10+0200 [-] : want to start build, but we don't have a remote Another thing I can think of is to set up two processes on one machine, which would be a bit of an overhead. Cheers, Mark -- http://mail.python.org/mailman/listinfo/python-list