Re: Pips for python2 and python3
On 3/21/21 5:44 PM, Dan Stromberg wrote: python3 -m pip install Got it. Thanks a lot. -- Tim tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Pips for python2 and python3
On 3/21/21 5:14 PM, MRAB wrote: Tn 2021-03-21 23:13, Tim Johnson wrote: Using ubuntu 20.04 as a recent install with python3 (3.8.5) which was installed as part of the original distribution install and python2 (2.7.18) that has been installed using apt. I have a large amount of utilities written in python2 which I need to maintain until I convert that code to python3 I see numerous caveats regarding the installing of pips for both these versions. I would welcome advice on how to proceed which could very well be accomplished by links to relevant discussions or documentation. I'd suggest using the pip module: python2 -m pip and: python3 -m pip Understood. In addition, I 'm pretty sure that all I need to do is copy dist-utils from my old machine to the new one. The python2 versions of the two machines are very close. thank you MRAB -- Tim tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Pips for python2 and python3
Using ubuntu 20.04 as a recent install with python3 (3.8.5) which was installed as part of the original distribution install and python2 (2.7.18) that has been installed using apt. I have a large amount of utilities written in python2 which I need to maintain until I convert that code to python3 I see numerous caveats regarding the installing of pips for both these versions. I would welcome advice on how to proceed which could very well be accomplished by links to relevant discussions or documentation. thanks -- Tim tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: ModuleNotFoundError with click module
On 12/1/19 11:46 PM, Peter Otten wrote: Tim Johnson wrote: OK. Now I have /usr/local/lib/python3.7/site-packages/Click-7.0.dist-info/ which holds the following files: INSTALLER LICENSE.txt METADATA RECORD top_level.txt WHEEL I haven't a clue as to how to proceed! Never seen this before ... Just leave it alone ;) Furthermore, google is offering me nothing conclusive. Where to go from here! P.S. It looks like that directory is sort of a stub; regardless of my take on it I am no longer having the ModuleNotFoundError. Once you can import it you can find the actual module or package with $ /usr/bin/python3.7 -c 'import click; print(click.__file__)' In this case it's a package, so you'll probably see (something like) /usr/local/lib/python3.7/site-packages/click/__init__.py rather than /usr/local/lib/python3.7/site-packages/click.py /usr/local/lib/python3.7/site-packages/ Good Explanation. Thanks again Peter. new since python 1.5 -- Tim tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: ModuleNotFoundError with click module
On 12/1/19 3:41 PM, Tim Johnson wrote: On 12/1/19 12:26 AM, Peter Otten wrote: Tim Johnson wrote: Using linux ubuntu 16.04 with bash shell. Am retired python programmer, but not terribly current. I have moderate bash experience. When trying to install pgadmin4 via apt I get the following error traceback when pgadmin4 is invoked: Traceback (most recent call last): File "setup.py", line 17, in from pgadmin.model import db, User, Version, ServerGroup, Server, \ File "/usr/share/pgadmin4/web/pgadmin/__init__.py", line 19, in from flask import Flask, abort, request, current_app, session, url_for File "/usr/local/lib/python3.7/site-packages/flask/__init__.py", line 21, in from .app import Flask File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 34, in from . import cli File "/usr/local/lib/python3.7/site-packages/flask/cli.py", line 25, in import click ModuleNotFoundError: No module named 'click' If I invoke python3 (/usr/local/bin/python3), version 3.7.2 and invoke >>> import click click is imported successfully. In this invocation, sys.path is: ['', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/home/tim/.local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/site-packages'] $PYTHONPATH is empty when the bash shell is invoked $PATH as follows: /home/tim/bin:/home/tim/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin click.py can be found at /usr/local/lib/python3.7/site-packages/pipenv/patched/piptools/ in turn click.py imports click, presumably as the package, which appears to be at /usr/local/lib/python3.7/site-packages/pipenv/vendor/click Any number of settings of PYTHONPATH to the various paths above has failed to resolve the ModuleNotFoundError Same issues with attempting install from a virtual environment. Any help will be appreciated. thanks tim I'm too lazy to look into the details of your paths -- I'd just make sure that click is installed with the same interpreter and user as pgadmin4, e. g. globally $ sudo /usr/local/bin/python3 -m pip install click $ sudo /usr/local/bin/python3 path/to/setup.py install # or whatever it takes to install pgadmin4 OK. Now I have /usr/local/lib/python3.7/site-packages/Click-7.0.dist-info/ which holds the following files: INSTALLER LICENSE.txt METADATA RECORD top_level.txt WHEEL I haven't a clue as to how to proceed! Never seen this before ... Furthermore, google is offering me nothing conclusive. Where to go from here! P.S. It looks like that directory is sort of a stub; regardless of my take on it I am no longer having the ModuleNotFoundError. Peter has a been a great help. Couldn't have done it without him. cheers -- Tim tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: ModuleNotFoundError with click module
On 12/1/19 12:26 AM, Peter Otten wrote: Tim Johnson wrote: Using linux ubuntu 16.04 with bash shell. Am retired python programmer, but not terribly current. I have moderate bash experience. When trying to install pgadmin4 via apt I get the following error traceback when pgadmin4 is invoked: Traceback (most recent call last): File "setup.py", line 17, in from pgadmin.model import db, User, Version, ServerGroup, Server, \ File "/usr/share/pgadmin4/web/pgadmin/__init__.py", line 19, in from flask import Flask, abort, request, current_app, session, url_for File "/usr/local/lib/python3.7/site-packages/flask/__init__.py", line 21, in from .app import Flask File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 34, in from . import cli File "/usr/local/lib/python3.7/site-packages/flask/cli.py", line 25, in import click ModuleNotFoundError: No module named 'click' If I invoke python3 (/usr/local/bin/python3), version 3.7.2 and invoke >>> import click click is imported successfully. In this invocation, sys.path is: ['', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/home/tim/.local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/site-packages'] $PYTHONPATH is empty when the bash shell is invoked $PATH as follows: /home/tim/bin:/home/tim/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin click.py can be found at /usr/local/lib/python3.7/site-packages/pipenv/patched/piptools/ in turn click.py imports click, presumably as the package, which appears to be at /usr/local/lib/python3.7/site-packages/pipenv/vendor/click Any number of settings of PYTHONPATH to the various paths above has failed to resolve the ModuleNotFoundError Same issues with attempting install from a virtual environment. Any help will be appreciated. thanks tim I'm too lazy to look into the details of your paths -- I'd just make sure that click is installed with the same interpreter and user as pgadmin4, e. g. globally $ sudo /usr/local/bin/python3 -m pip install click $ sudo /usr/local/bin/python3 path/to/setup.py install # or whatever it takes to install pgadmin4 OK. Now I have /usr/local/lib/python3.7/site-packages/Click-7.0.dist-info/ which holds the following files: INSTALLER LICENSE.txt METADATA RECORD top_level.txt WHEEL I haven't a clue as to how to proceed! Never seen this before ... Furthermore, google is offering me nothing conclusive. Where to go from here! -- Tim tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: ModuleNotFoundError with click module
On 12/1/19 12:26 AM, Peter Otten wrote: Tim Johnson wrote: Using linux ubuntu 16.04 with bash shell. Am retired python programmer, but not terribly current. I have moderate bash experience. When trying to install pgadmin4 via apt I get the following error traceback when pgadmin4 is invoked: Traceback (most recent call last): snipped ... File "/usr/local/lib/python3.7/site-packages/flask/cli.py", line 25, in import click ModuleNotFoundError: No module named 'click' If I invoke python3 (/usr/local/bin/python3), version 3.7.2 and invoke >>> import click click is imported successfully. ... I'm too lazy to look into the details of your paths -- I'd just make sure that click is installed with the same interpreter and user as pgadmin4, e. g. globally $ sudo /usr/local/bin/python3 -m pip install click $ sudo /usr/local/bin/python3 path/to/setup.py install # or whatever it takes to install pgadmin4 Like I said, I'm not current. Yikes. Now I have /usr/local/lib/python3.7/site-packages/clic-0.1.3.dist-info/ After I have my coffee I will attempt to proceed from there with whatever it takes to finalize thanks -- Tim tj49.com -- https://mail.python.org/mailman/listinfo/python-list
ModuleNotFoundError with click module
Using linux ubuntu 16.04 with bash shell. Am retired python programmer, but not terribly current. I have moderate bash experience. When trying to install pgadmin4 via apt I get the following error traceback when pgadmin4 is invoked: Traceback (most recent call last): File "setup.py", line 17, in from pgadmin.model import db, User, Version, ServerGroup, Server, \ File "/usr/share/pgadmin4/web/pgadmin/__init__.py", line 19, in from flask import Flask, abort, request, current_app, session, url_for File "/usr/local/lib/python3.7/site-packages/flask/__init__.py", line 21, in from .app import Flask File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 34, in from . import cli File "/usr/local/lib/python3.7/site-packages/flask/cli.py", line 25, in import click ModuleNotFoundError: No module named 'click' If I invoke python3 (/usr/local/bin/python3), version 3.7.2 and invoke >>> import click click is imported successfully. In this invocation, sys.path is: ['', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/home/tim/.local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/site-packages'] $PYTHONPATH is empty when the bash shell is invoked $PATH as follows: /home/tim/bin:/home/tim/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin click.py can be found at /usr/local/lib/python3.7/site-packages/pipenv/patched/piptools/ in turn click.py imports click, presumably as the package, which appears to be at /usr/local/lib/python3.7/site-packages/pipenv/vendor/click Any number of settings of PYTHONPATH to the various paths above has failed to resolve the ModuleNotFoundError Same issues with attempting install from a virtual environment. Any help will be appreciated. thanks tim -- https://mail.python.org/mailman/listinfo/python-list
Re: Your IDE's?
* Rich Shepard [190326 15:19]: > On 2019-03-25 21:38, John Doe wrote: > > > What is your favorite Python IDE? > > Emacs on Slackware. I'm an old Slacker, but got lazy and even older, so now use ubuntu. I also use emacs to which I have added evil and elpy; and further customized with plenty of my own elisp code. They won't take any of that away unless they pry it from my cold, dead fingers, but that's just me. :) I wouldn't wish emacs or vim on anyone who didn't feel that the learning curve was worth it. MTCW -- Tim Johnson http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Managing pipenv virtualenvs
* Test Bot [190326 15:44]: > If the chapters are not contiguous then I can't find a reason to delete > them (previous venv). Moreover it would be better practice to keep separate > venv and not to use a single venv for multiple codebase. Highly discouraged > should be to use the systemwide interpreter. > > Moreover the whole idea of using pipenv/pip is to make the venv easy to > recreate. That being said I would focus more on whether my > pipfile/requirements.txt is maintained properly or not. If it is then > spinning up the same venv is an easy task. thanks again, Test Bot ... > On Wed, Mar 27, 2019, 4:21 AM Tim Johnson wrote: > > > * Test Bot [190326 14:18]: > > > Nothing much i think. If you are properly managing dependencies for each > > > venv, then each new venv should have the same state as the previous one > > Good to hear > > > > > along with some extra dependencies for each new chapter (haven't gone > > > through the specific book, but I am assuming that in the book, every > > > chapter builds on the previous one). > > The author's source code is on github, so I downloaded all of it > > for my edification. > > > > It appears that consecutive chapters do not always build on the > > following, i.e. have the previous chapter files. > > > > I guess I will find out why ... > > thank you > > > On a personal note it sounds strange why the author wants to have > > different > > > venv's for each chapter. > > > > > > On Wed, Mar 27, 2019, 3:30 AM Tim Johnson wrote: > > > > > > > I'm on ubuntu 16.04 > > > > > > > > using pipenv for the "Django for Beginners..." tutorial book. > > > > > > > > each chapter instructs me to create a new virtual environment with a > > > > folder under ~/.local/share/virtualenvs > > > > > > > > folders are named with the project name followed by an hyphen and a > > > > brief codified string. > > > > examples > > > > helloworld-_e28Oloi > > > > pages-Du4qJjUr > > > > > > > > What would happen if I deleted the first folder, which was created > > > > in a previous chapter? > > > > > > > > ... trying to minimize my SSD real estate. > > > > thanks > > > > -- > > > > Tim Johnson > > > > http://www.tj49.com > > > > -- > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > > Tim Johnson > > http://www.tj49.com > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list -- Tim Johnson http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Managing pipenv virtualenvs
* Test Bot [190326 14:18]: > Nothing much i think. If you are properly managing dependencies for each > venv, then each new venv should have the same state as the previous one Good to hear > along with some extra dependencies for each new chapter (haven't gone > through the specific book, but I am assuming that in the book, every > chapter builds on the previous one). The author's source code is on github, so I downloaded all of it for my edification. It appears that consecutive chapters do not always build on the following, i.e. have the previous chapter files. I guess I will find out why ... thank you > On a personal note it sounds strange why the author wants to have different > venv's for each chapter. > > On Wed, Mar 27, 2019, 3:30 AM Tim Johnson wrote: > > > I'm on ubuntu 16.04 > > > > using pipenv for the "Django for Beginners..." tutorial book. > > > > each chapter instructs me to create a new virtual environment with a > > folder under ~/.local/share/virtualenvs > > > > folders are named with the project name followed by an hyphen and a > > brief codified string. > > examples > > helloworld-_e28Oloi > > pages-Du4qJjUr > > > > What would happen if I deleted the first folder, which was created > > in a previous chapter? > > > > ... trying to minimize my SSD real estate. > > thanks > > -- > > Tim Johnson > > http://www.tj49.com > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list -- Tim Johnson http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Managing pipenv virtualenvs
I'm on ubuntu 16.04 using pipenv for the "Django for Beginners..." tutorial book. each chapter instructs me to create a new virtual environment with a folder under ~/.local/share/virtualenvs folders are named with the project name followed by an hyphen and a brief codified string. examples helloworld-_e28Oloi pages-Du4qJjUr What would happen if I deleted the first folder, which was created in a previous chapter? ... trying to minimize my SSD real estate. thanks -- Tim Johnson http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Determining latest stable version for download
* Tim Johnson [190320 10:46]: > Some time in the near future I will want to install the latest > current stable version of python on a remote server. I anticipate > that I will either use wget from the server shell or download to my > workstation and transfer via FTP. I will need source to compile. > > I see python source at https://www.python.org/ftp/python/. > > How do I determine the following? > 1) Latest current stable version of python 3* > 2) Correct tarfile for linux - at this time I assume it will be >linux centOS Thanks for the constructive replies. I'll attempt a compile from source after this weekend. I'll use these instructions: https://my.hostmonster.com/hosting/help/python-install as a guide and post results under a topic more appropriate to my goal: that of installing and running later versions of python on a shared server (sans root access). -- Tim Johnson http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Determining latest stable version for download
* Michael Torrie [190320 19:22]: > On 03/20/2019 07:10 PM, Tim Johnson wrote: > > * Ian Kelly [190320 12:00]: > >> 1) https://www.python.org/downloads/ has release information. Based on that > >> you would currently want 3.7.2. Make sure you actually download 3.7.2 and > >> not 3.7.2rc1. > > Understood. Thanks. Your info is the solution. > > I always found maintaining software installed from tarball on a remote > server was difficult at best. > > You mentioned it will be on CentOS. If you have CentOS 7, the EPEL > repository (nearly required by all installations in my opinion), has a > package for Python 3.6, called python36. The advantage there is that it > will be updated with point releases and kept somewhat secure by your > normal yum update process. > > Also you might check out RedHat's Software Collections at > https://www.softwarecollections.org/en/. They have Python 3.6 in it, > and I imagine 3.7 will be there soon. Software Collections might not > work for you as it installs to /opt and stays out of the default path. > It's more for developers who want to play with multiple versions of > languages and compilers. Michael, I should have asked the following question: Would I be able to install from the EPEL Repository or the Redhat Software Collections to a local ~/bin? thanks again -- Tim Johnson http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Determining latest stable version for download
* Michael Torrie [190320 19:22]: > On 03/20/2019 07:10 PM, Tim Johnson wrote: > > * Ian Kelly [190320 12:00]: > >> 1) https://www.python.org/downloads/ has release information. Based on that > >> you would currently want 3.7.2. Make sure you actually download 3.7.2 and > >> not 3.7.2rc1. > > Understood. Thanks. Your info is the solution. > > I always found maintaining software installed from tarball on a remote > server was difficult at best. > > You mentioned it will be on CentOS. If you have CentOS 7, the EPEL > repository (nearly required by all installations in my opinion), has a > package for Python 3.6, called python36. The advantage there is that it > will be updated with point releases and kept somewhat secure by your > normal yum update process. > > Also you might check out RedHat's Software Collections at > https://www.softwarecollections.org/en/. They have Python 3.6 in it, > and I imagine 3.7 will be there soon. Software Collections might not > work for you as it installs to /opt and stays out of the default path. > It's more for developers who want to play with multiple versions of > languages and compilers. I'm currently on a shared server hosted by Hostmonster. I don't have root access, so a local install would be my only option. If local install doesn't work or is insufficient, then I would switch to a VPS. Since I'm retired and only a hobbyist in my Golden Years :), a shared server would be sufficient and cheaper, so that is my first choice. Having said that, if I have to go with a VPS (and root access) your information is very helpful. Thank you. -- Tim Johnson http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Determining latest stable version for download
* Ian Kelly [190320 12:00]: > 1) https://www.python.org/downloads/ has release information. Based on that > you would currently want 3.7.2. Make sure you actually download 3.7.2 and > not 3.7.2rc1. Understood. Thanks. Your info is the solution. > 2) The tarfiles are not distro-specific. For Linux there are really only > two options: Python-3.7.2.tar.xz and Python-3.7.2.tgz. The only difference > is that one is compressed with xz and the other is compressed with gzip. > Pick the .xz unless you're unable to decompress it. > On Wed, Mar 20, 2019 at 12:43 PM Tim Johnson wrote: > > > Some time in the near future I will want to install the latest > > current stable version of python on a remote server. I anticipate > > that I will either use wget from the server shell or download to my > > workstation and transfer via FTP. I will need source to compile. > > > > I see python source at https://www.python.org/ftp/python/. > > > > How do I determine the following? > > 1) Latest current stable version of python 3* > > 2) Correct tarfile for linux - at this time I assume it will be > >linux centOS > > > > TIA > > -- > > Tim Johnson > > http://www.tj49.com > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list -- Tim Johnson http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Determining latest stable version for download
Some time in the near future I will want to install the latest current stable version of python on a remote server. I anticipate that I will either use wget from the server shell or download to my workstation and transfer via FTP. I will need source to compile. I see python source at https://www.python.org/ftp/python/. How do I determine the following? 1) Latest current stable version of python 3* 2) Correct tarfile for linux - at this time I assume it will be linux centOS TIA -- Tim Johnson http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Pip Version Confusion
* Tim Johnson <t...@akwebsoft.com> [180324 10:32]: > * Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> [180324 08:29]: > > On Sat, 24 Mar 2018 07:40:17 -0800, Tim Johnson wrote: > > > > > I'm on Ubuntu 16.04. > > > > > > I'm getting the following message from pip: > > > > > > You are using pip version 8.1.1, however version 9.0.3 is available. You > > > should consider upgrading via the 'pip install --upgrade pip' command. > > [...] > > > Not sure how to resolve - please advise, thanks > > > > > > Well, what happens when you try running > > > > pip install --upgrade pip > tim@linus:~/Downloads$ pip install --upgrade pip > Requirement already up-to-date: pip in > /home/tim/.local/lib/python2.7/site-packages > > > > I expect that you've probably got two (or more!) pips installed, and > > somehow sometimes you get one and sometimes the other. The problem is, it > > seems to me, that we can get pip installed through at least three > > mechanisms: > >pips all over the place ... pips, pips2, pips2.7 >all but /usr/bin/pip2 show version as 9.0.3 >/usr/bin/pip2 is version 8.1.1 ># code follows > #!/usr/bin/python > # EASY-INSTALL-ENTRY-SCRIPT: 'pip==8.1.1','console_scripts','pip2' > __requires__ = 'pip==8.1.1' > import sys > from pkg_resources import load_entry_point > > if __name__ == '__main__': > sys.exit( > load_entry_point('pip==8.1.1', 'console_scripts', 'pip2')() > ) > > Looks like I should not have install pip via the ubuntu package manager. From the package manager: python-pip/xenial-updates,xenial-updates,now 8.1.1-2ubuntu0.4 all [installed] python-pip-whl/xenial-updates,xenial-updates,now 8.1.1-2ubuntu0.4 all [installed,automatic] Think I've found it... I'll trying 'deinstalling' that package and see if the nonsense goes away. Thank you Steven! -- Tim Johnson http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Pip Version Confusion
* Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> [180324 08:29]: > On Sat, 24 Mar 2018 07:40:17 -0800, Tim Johnson wrote: > > > I'm on Ubuntu 16.04. > > > > I'm getting the following message from pip: > > > > You are using pip version 8.1.1, however version 9.0.3 is available. You > > should consider upgrading via the 'pip install --upgrade pip' command. > [...] > > Not sure how to resolve - please advise, thanks > > > Well, what happens when you try running > > pip install --upgrade pip tim@linus:~/Downloads$ pip install --upgrade pip Requirement already up-to-date: pip in /home/tim/.local/lib/python2.7/site-packages > > I expect that you've probably got two (or more!) pips installed, and > somehow sometimes you get one and sometimes the other. The problem is, it > seems to me, that we can get pip installed through at least three > mechanisms: pips all over the place ... pips, pips2, pips2.7 all but /usr/bin/pip2 show version as 9.0.3 /usr/bin/pip2 is version 8.1.1 # code follows #!/usr/bin/python # EASY-INSTALL-ENTRY-SCRIPT: 'pip==8.1.1','console_scripts','pip2' __requires__ = 'pip==8.1.1' import sys from pkg_resources import load_entry_point if __name__ == '__main__': sys.exit( load_entry_point('pip==8.1.1', 'console_scripts', 'pip2')() ) Looks like I should not have install pip via the ubuntu package manager. > - installing pip by hand, via source or some other mechanism; > > - using ensure-pip in a sufficiently recent Python; > > - using your OS's package manager. > > And of course each version of Python can have its own pip. > > > To diagnose this, I would try: > > Query your package manager, what version of pip does it say is installed? > > How many versions of Python do you have installed? Which one are you > running? > > Precisely what command line did you give to get the message above? > > If you cd out of whatever directory you are in, does the message change? > > If you run pip as a different user, what happens? > > If you run "locate pip", how many pip installations does it find, and > what are they? > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list -- Tim Johnson http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Pip Version Confusion
I'm on Ubuntu 16.04. I'm getting the following message from pip: You are using pip version 8.1.1, however version 9.0.3 is available. You should consider upgrading via the 'pip install --upgrade pip' command. # But then I get this : tim@linus:~/Downloads$ which pip /home/tim/.local/bin/pip # and this: tim@linus:~/Downloads$ pip --version pip 9.0.3 from /home/tim/.local/lib/python2.7/site-packages (python 2.7) Not sure how to resolve - please advise, thanks -- Tim -- https://mail.python.org/mailman/listinfo/python-list
Re: Restore via pip to new OS
* Paul Moore <p.f.mo...@gmail.com> [180314 15:42]: > Use pip freeze rather than pip list. That will give you the > information in "requirements file" format that pip install -r can > read. > > On 14 March 2018 at 23:20, Tim Johnson <t...@akwebsoft.com> wrote: <...> > > Can I duplicate the same packages on the new OS by > > pip -r piplist.txt? Thank you Paul. Cheers -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Restore via pip to new OS
I'm currently running both python and python3 on ubuntu 14.04. Plan is to do a complete re-install of ubuntu 16.04 on a fresh hard drive. I've accumulated a list of pip-install packages via pip list > piplist.txt. Can I duplicate the same packages on the new OS by pip -r piplist.txt? thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Import name conflicts
* Steve D'Aprano <steve+pyt...@pearwood.info> [170418 16:08]: > On Wed, 19 Apr 2017 04:28 am, Tim Johnson wrote: > > > Using python 2.7~ > > > > For testing and edification purposes: > > > > I have a project which has a controllers package at the directory > > level just below the root. > > Do you mean the root of the file system? > > > >>From the top-level (root) of the project, I start my python > > interpreter. > > Don't do that. You are defeating the whole purpose of packages. > > The point of a package is to the caller, it appears like a single library, > while still allowing it to contain multiple files internally with its own > fine structure. > > If your package structure looks like this: > > X/controllers/ > +-- __init__.py > +-- imp.py > ... any other modules and sub-packages > > > then you should start Python from X, not from X/controllers. > > Or even better, you should ensure X is in sys.path (there are various ways > to do that), and then start Python from anywhere. > > > > The packages is called 'controllers' and has a submodule named 'imp' > > > > I do the following: > >>>> a = __import__('imp') > >>>> dir(a) > > ['C_BUILTIN', 'C_EXTENSION', 'IMP_HOOK', 'NullImporter', > > 'PKG_DIRECTORY', ] > > # object a is the builtin imp module > > > Like (nearly) all __dunder__ methods and functions, __import__ is reserved > for use by Python and you shouldn't need to use it. > > The conventional ways to access packages.imp are (untested): > > # As a user of the controllers package > import controllers.imp as a > > # Within the controllers package > from __future__ import absolute_imports > from . import imp as a > > > You only need the "from __future__ ..." directive once per module, but it > must be the very first line of executable code. (It can only be preceded by > blank lines or comments.) > > To get access to the standard library imp, you do this: > > # As a user of the controllers package > import imp as b > > # Within the controllers package > import imp as b > > > [...] > > Now, suppose a python upgrade provides a package called controllers > > or there's some great third-party package available called > > controllers. > > If you have two modules/packages with the same name, there's no clean way to > access one or the other. That's not how importing works. Whichever module > is found in the search path (sys.path) shadows the other. > > That's both a feature and an annoyance, depend on whether you find it useful > or not. But that's how it is. > > In the case of name conflicts between modules, your choices are: > > - live with the conflict; > - rename the conflicting module; > - manually adjust sys.path when and as needed to avoid one and > get the other, then reverse your adjustments to do the opposite. Thanks for the input. I'm running out of time today, so just want to thank you for your input and advice. The overriding issue is how to have a strategy so that some future conflict does not clobber a whole bunch of apps. Between Ben's and your subsequent comments, I've got a solution. cheers -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Import name conflicts
* Ben Finney <ben+pyt...@benfinney.id.au> [170418 14:58]: > Tim Johnson <t...@akwebsoft.com> writes: > > > Using python 2.7~ > > In Python 2, you should turn on the “default import is absolute” by > issuing the statement:: > > from __future__ import absolute_import > > as one of the first statements in each module. > > When you migrate your code to PYthon 3, that will be the default > behaviour. > > > The packages is called 'controllers' and has a submodule named 'imp' > > To avoid the module named ‘imp’ in the standard library, your code > should import ‘imp’ using a relative import. See PEP 328 > <URL:https://www.python.org/dev/peps/pep-0328/#rationale-for-relative-imports>. > > So, you'd do:: > > from . import imp > > to import the ‘imp’ module relative to the current package. > > > I do the following: > > >>> a = __import__('imp') > > It is best to avoid calling dunder functions directly; they are > available for overriding the internals of language features, and > *invoking* one is best done by just using the corresponding language > feature. > > Instead, use either the ‘import’ statement, or the ‘importlib’ standard > library module <URL:https://docs.python.org/2/library/importlib.html>, > specifically the ‘importlib.import_module’ function:: > > import importlib > > a = importlib.import_module('.imp') > > > Now, suppose a python upgrade provides a package called controllers or > > there's some great third-party package available called controllers. > > You don't even have to imagine that far: there is already a standard > library module named ‘imp’, so you already have that problem to contend > with :-) > > That is the distinction that led to “absolute” import versus “relative” > import. > > > How do I access the 'global' controllers package? > > * Enable “default import is absolute”, as described above. > > * Issue a normal import statement: the absolute import search path will > be used. > > I hope that helps. Lots of help Ben ... Beware, I started my career coding in ASM, then C, then python, so I'm prone to get under the hood and start playing with the wires. I made a simple test module called 'controllers' in another directory, used __import__ to get the 'local' imp module from the local controllers package then changed directories to the location of the "global" controllers module (in sys.path). Popped "controllers" from sys.modules and then called __import__ again to get that module as another variable. To reiterate Ben's method with working code and upper-level importlib: >>> from __future__ import absolute_import >>> import importlib >>> i = importlib.import_module('.imp',package='controllers') # # package arg needed >>> dir(i) ['COLORS', 'CONTROLLER', 'DBNAME', 'DBPWD', 'DBUSERNAME', 'ID_COL', 'JOB', 'MYTABLE', 'RECID', 'TABLEFORMAT', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'load', 'std'] # dir(i) verifies that 'i' is my 'local' 'imp' module >>> i1 = importlib.import_module('imp') >>> dir(i1) # result not shown # verifies 'i1' is my "global" imp module # Now, to load my alternate controllers module, I have to do # this: import os, sys sys.modules.pop('controllers') os.chdir('/alternate/controllers/directory') c = importlib.import_module('controllers') # now dir(c) verifies that c is my alternate 'controllers' module # NOTE: in my scenario, we could expect that the alternate # 'controller' module would be in sys.path. Some iteration might # be needed thanks Ben. :) I guess I have a plan -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Import name conflicts
Using python 2.7~ For testing and edification purposes: I have a project which has a controllers package at the directory level just below the root. >From the top-level (root) of the project, I start my python interpreter. The packages is called 'controllers' and has a submodule named 'imp' I do the following: >>> a = __import__('imp') >>> dir(a) ['C_BUILTIN', 'C_EXTENSION', 'IMP_HOOK', 'NullImporter', 'PKG_DIRECTORY', ] # object a is the builtin imp module Now I do >>> b = __import__('controllers.imp', fromlist=['controllers']) >>> dir(b) ['COLORS', 'CONTROLLER', 'DBNAME', 'DBPWD', 'DBUSERNAME', 'ID_COL', 'JOB', 'MYTABLE', 'RECID', 'TABLEFORMAT', ...] # object b is the imp module in the controllers package. # I've resolved a potential name collision ... Now, suppose a python upgrade provides a package called controllers or there's some great third-party package available called controllers. How do I access the 'global' controllers package? thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I
* Paul Rudin <paul.nos...@rudin.co.uk> [170103 23:17]: > Tim Johnson <t...@akwebsoft.com> writes: > > > * Antonio Caminero Garcia <tonycam...@gmail.com> [170102 20:56]: > >> Guys really thank you for your answers. Basically now I am more > >> emphasizing in learning in depth a tool and get stick to it so I > >> can get a fast workflow. Eventually I will learn Vim and its > >> python developing setup, I know people who have been programming > >> using Vim for almost 20 years and they did not need to change > >> editor (that is really awesome). > > > > Bye the way, one thing I like about the GUI based vim is that it > > supports tabs, where emacs does not. > > M-x package-install tabbar :) Thank you. list-packages is my friend ... -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
* Paul Rudin <paul.nos...@rudin.co.uk> [170103 23:17]: > Tim Johnson <t...@akwebsoft.com> writes: > > > * Antonio Caminero Garcia <tonycam...@gmail.com> [170102 20:56]: > >> Guys really thank you for your answers. Basically now I am more > >> emphasizing in learning in depth a tool and get stick to it so I > >> can get a fast workflow. Eventually I will learn Vim and its > >> python developing setup, I know people who have been programming > >> using Vim for almost 20 years and they did not need to change > >> editor (that is really awesome). > > > > Bye the way, one thing I like about the GUI based vim is that it > > supports tabs, where emacs does not. > > M-x package-install tabbar :) Thank you. list-packages is my friend ... -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
* Antonio Caminero Garcia[170102 20:56]: > Guys really thank you for your answers. Basically now I am more > emphasizing in learning in depth a tool and get stick to it so I > can get a fast workflow. Eventually I will learn Vim and its > python developing setup, I know people who have been programming > using Vim for almost 20 years and they did not need to change > editor (that is really awesome). Bye the way, one thing I like about the GUI based vim is that it supports tabs, where emacs does not. And check out the vim plugins for python Good Luck! -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
* Antonio Caminero Garcia[170102 02:50]: <> > Now, I am thinking about giving a try to Visual Studio Code > Edition (take a look, it sounds good > https://marketplace.visualstudio.com/items?itemName=donjayamanne.python). > I need an editor for professional software development. What would > you recommend to me? The best thing - as has been emphasised by others regarding this topic - is to establish tools, stick with them and learn them well. I use two approaches on linux: 1)From Gnome terminal I run MC (midnight commander) as my default file manager with vim (in terminal mode) as the MC default editor. This method is used for ad-hoc editing of python source code, but also for system editing in general. 2)I use emacs with elpy mode in GUI mode for large-scale work. Elpy is so helpful, I'm almost embarassed to admit being a pythonist. To compound the embarassment, the elpy developer is extremely helpful and very generous. :) -> I've used gvim (GUI mode) extensively in the past. I find vim more "nimble", thus my preferance for quick-and-dirty edits. Emacs, on the other hand, is enormously extendable and I have implemented extensive keymapping. For me, augmenting keymapping with the emacs help system trumps vim's more nimble approach. In addition, I've implemented an auxilary help system using emacs' built-in browser so that I can call up category - based "cheat-sheats" with simple html highlighting and hyperlinking. My caveat is that both vim and emacs are a tough learning curve. Vimscript extends vim, elisp extends emacs. In both cases, one is essentially learning an additional programming language. One's personal preference for input devices should also be considered, IMHO : I prefer the keyboard over pointing devices and a trackball over a mouse for pointing device. I use a small-footprint 68-key tenkeyless keyboard with a standalone keypad with my left hand (trackball is on the right). I've also programmed the keypad extensively for emacs. The bottom line, as others have stated, is to consistently stick with some approach that fits one's personal preferences. We are fortunate to have so many options. -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: What is currently the recommended way to work with a distutils-based setup.py that requires compilation?
* Ivan Pozdeev via Python-list[161106 17:28]: > https://wiki.python.org/moin/WindowsCompilers has now completely replaced > instructions for `distutils`-based packages (starting with `from > distutils.core import setup`) with ones for `setuptools`-based ones > (starting with `from setuptools import setup`). > > However, if I have a `distutils`-based `setup.py`, when I run it, > `setuptools` is not used - thus the instructions on the page don't work. > > It is possible to run a `distutils`-based script through `setuptools`, as > `pip` does, but it requires the following code > (https://github.com/pypa/pip/blob/8.1.2/pip/req/req_install.py#L849 ): > > python -u -c "import setuptools, tokenize;__file__=; > exec(compile(getattr(tokenize, 'open', open)(__file__).read() > .replace('\\r\\n', '\\n'), __file__, 'exec'))" > > They can't possibly expect me to type that on the command line each time, > now can they? Ivan, it looks like you aren't getting any answers from seasoned list gurus to your question. So, I'm going to take a stab at this and I hope you are not mislead or misdirected by my comments. > They can't possibly expect me to type that on the command line each time, The code that you are quoting above can be placed in a script file and executed at will. Once you get the syntax correct, you will then be able to execute that script at any time. I don't know what operating system you are using: Linux and Mac work pretty much similarly when it comes to console scripts, windows will have a different approach, but not radically so. I hope this helps or puts you on a constructive path. > I also asked this at http://stackoverflow.com/q/40174932/648265 a couple of > days ago (to no avail). > > -- > > Regards, > Ivan > > -- > https://mail.python.org/mailman/listinfo/python-list -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Idiomatic code validator?
* Steve D'Aprano <steve+pyt...@pearwood.info> [160920 16:29]: > On Wed, 21 Sep 2016 01:41 am, Tim Johnson wrote: > > > Not to confuse idiomatic code validation with pep8 validation (I use > > elpy on emacs) > > > > Is there such a thing as a validator for _idiomatic_ code? > > > Yes, it is called a linter. There are various linters available: > > pylint, pychecker, jedi, flake > > > there may be others. Depending on how good the linter is, they will do > things like flag unused arguments, dead code, use of deprecated features, > and so forth. Some of them may be very opinionated, e.g. flag uses of map() > as unidiomatic and recommend a list comprehension instead. Whether you > agree with that opinion or not is up to you. Sorry. Should have added this: It might be useful for me to use a more "opinionated" linter outside of my "IDE". cheers > -- > Steve > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure > enough, things got worse. :) Again. Sorry! -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Idiomatic code validator?
* Steve D'Aprano <steve+pyt...@pearwood.info> [160920 16:29]: > On Wed, 21 Sep 2016 01:41 am, Tim Johnson wrote: > > > Not to confuse idiomatic code validation with pep8 validation (I use > > elpy on emacs) > > > > Is there such a thing as a validator for _idiomatic_ code? > > > Yes, it is called a linter. There are various linters available: > > pylint, pychecker, jedi, flake thanks Steve : I use flake8 thru elpy. I'm guessing that my inquiry is redundant. (I might need to look at more fine-grained configuration thru elpy) cheers - tj - > > there may be others. Depending on how good the linter is, they will do > things like flag unused arguments, dead code, use of deprecated features, > and so forth. Some of them may be very opinionated, e.g. flag uses of map() > as unidiomatic and recommend a list comprehension instead. Whether you > agree with that opinion or not is up to you. > > > > > -- > Steve > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Idiomatic code validator?
* Terry Reedy <tjre...@udel.edu> [160920 11:48]: > On 9/20/2016 11:41 AM, Tim Johnson wrote: > > Not to confuse idiomatic code validation with pep8 validation > > Strictly speaking, there cannot be a mechanical PEP 8 validator, as any > mechanical checker violates the admonitions of the beginning sections > 'Introductions' and 'A Foolish Consistency is the Hobgoblin of Little > Minds'. For this reason, the core developers request the author of the > checker formerly known as 'pep8' to change its name, which he did. elpy uses flake8 https://github.com/jorgenschaefer/elpy/wiki/Configuration > > Is there such a thing as a validator for _idiomatic_ code? > > What would such a thing do? Flag supposedly non-idiomatic code? Or mark > code recognized as 'idiomatic', with no implication either way about other > code? Why not? > > I have Knupp's "Writing Idiomatic Python" and have bookmarked some > > advisory websites that illustrate idiomatic style. > > Do they all agree on 'idiomatic'? Not likely, I would not expect them to. Thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Idiomatic code validator?
Not to confuse idiomatic code validation with pep8 validation (I use elpy on emacs) Is there such a thing as a validator for _idiomatic_ code? I have Knupp's "Writing Idiomatic Python" and have bookmarked some advisory websites that illustrate idiomatic style. thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Importing two modules of same name
* dieter[160209 23:03]: > Carl Meyer writes: > > ... > > If you omit the future-import in Python 2.7, `import config` will import > > the neighboring app/config.py by default, and there is no way to import > > the top-level config.py. > > There is the "__import__" builtin function which allows to specify > the "parent package" indirectly via its "globals" parameter. This > way, you can import the "top-level" config (passing an empty "globals"). Thanks. I used __import__ as part of a custom load() function that I used in my own framework when I was developing CGI sites. I never used the globals parameter tho'. If I start -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Importing two modules of same name
Before proceding, let me state that this is to satisfy my curiousity, not to solve any problem I am having. Scenario : Web application developed at /some/dir/sites/flask/ If I have a package - let us call it app and in my /some/dir/sites/flask/app/__init__.py is the following: from config import config imports the config dictionary from /some/dir/sites/flask/config.py (the real-case scenario is M. Grinberg's tutorial on Flask). What if I wanted to add a module in the app package and call it from __init__.py That entails having two modules name config one at /some/dir/sites/flask/config.py and the other at /some/dir/sites/flask/app/config.py What would be the proper way to do this? (If proper at all :)) I realize that it may not be best practices. And is a practice that I avoided in the past. FYI: Platform - python 2.7 on Ubuntu 14.04. Experience: long-time python CGI programmer before retiring about 3 years ago. Thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Importing two modules of same name
* Carl Meyer[160209 15:28]: > Hi Tim, <...> > The proper way to do this in Python 2.7 is to place `from __future__ > import absolute_import` at the top of flask/app/__init__.py (maybe best > at the top of every Python file in your project, to keep the behavior > consistent). Once you have that future-import, `import config` will > always import the top-level config.py. To import the "local" config.py, > you'd either `from . import config` or `import app.config`. > > Python 3 behaves this way without the need for a future-import. > > If you omit the future-import in Python 2.7, `import config` will import > the neighboring app/config.py by default, and there is no way to import > the top-level config.py. Thanks for setting me straight Carl. I'm including the full package constructor (app/__init__.py) code for other's edification and further comment (if deemed necessary). Some commented annotation added ## from __future__ import absolute_import from flask import Flask from flask.ext.bootstrap import Bootstrap from flask.ext.mail import Mail from flask.ext.moment import Moment from flask.ext.sqlalchemy import SQLAlchemy # Import top-level config from config import config # Import same-level config avoiding name collision from . import config as cfg bootstrap = Bootstrap() mail = Mail() moment = Moment() db = SQLAlchemy() def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) bootstrap.init_app(app) mail.init_app(app) moment.init_app(app) db.init_app(app) from .main import main as main_blueprint app.register_blueprint(main_blueprint) return app Cheers -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Using subprocess to capture a progress line
* Chris Warrick <kwpol...@gmail.com> [15 00:55]: > On 10 November 2015 at 23:47, Tim Johnson <t...@akwebsoft.com> wrote: > > Using python 2.7.6 on ubuntu 14.04 <..> > There is no \n character at the end — which means that > p.stdout.readline() cannot return. In fact, if you printed repr() of > the line you read, you would get this: > > b'\r[download] 54.9% of 2.73MiB at 26.73KiB/s ETA 00:47\r[download] > 55.0% of 2.73MiB at 79.33KiB/s ETA 00:15\r…snip…\r[download] 100% of > 2.73MiB in 00:01\n' > > The download line is implemented using \r, which is the carriage > return character (return to the first character), and then by > overwriting characters that were already printed. > > The solution? There are numerous. I’ll help you by obscuring the worst one. > > (1) [recommended] figure out how to make youtube_dl work as a library, > read its main file to figure out the problem. Don’t mess with > subprocess. Was my first goal, had some problems, but I have solved them in part by finding the good documentation of the developers. I.E., the subprocess method _is_ going away and I will be using the youtube_dl module. > (2) [don’t do it] do you need to intercept the lines? If you don’t set > stderr= and stdout=, things will print just fine. Got to try that before using the module, just for edification. > (3) [DON’T DO IT] .ernq() punenpgre ol punenpgre naq znxr n zrff. > > PS. Thank you for setting a sensible Reply-To header on your messages. > Which is something the list should be doing. LOL! Glad to help :) Thanks for the reply and the further education. Cheers -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Using subprocess to capture a progress line
* Chris Warrick <kwpol...@gmail.com> [15 07:54]: > On 11 November 2015 at 17:16, Tim Johnson <t...@akwebsoft.com> wrote: > >> (2) [don’t do it] do you need to intercept the lines? If you don’t set > >> stderr= and stdout=, things will print just fine. > > Got to try that before using the module, just for edification. > > At which point your initial code sample will become: > ### > p = subprocess.Popen(list(args)) > ### > Yeah, 'list is redundant. Progress is now showing, but I forgot to say that I've lost the original intent, and that was to examine each line so that I could pull out the title. No matter. I'm on the way to make the youtube_dl module working. cheers -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Using subprocess to capture a progress line
* Chris Angelico <ros...@gmail.com> [151110 14:35]: > On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson <t...@akwebsoft.com> wrote: > > I've written a command-line "wrapper" for youtube-dl, executing > > youtube-dl as a subprocess. > > > > -- > > youtube-dl reports download progress on one line. I.E. the line is > > overwritten numerous times with no carriage return until the > > downloading is finished. > > -- > > > > Sounds to me like a possible buffering problem. But since youtube-dl > is implemented in Python, you might find it easier to "pip install > youtube_dl" and work with the methods directly: > > >>> import youtube_dl > >>> youtube_dl.YoutubeDL().download(["m39ydsOPSww"]) Frankly, I'd prefer - in the long run - to use youtube_dl (the module). But, when I do as you have suggested (and have tried previously) I get the following: youtube_dl.utils.DownloadError: ERROR: no suitable InfoExtractor I've briefly researched the error and so far haven't come up with an solution - guessing that other setup code is needed ... As for the buffering issue, at this point, I'll try using a lower-level function like sys.stdout.write when the line tests for '[download]' and 'ETA'. :) more elegant solutions welcome. I do intend to investigate using youtube_dl, once subprocess has been dealt with. thanks for the quick reply -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Using subprocess to capture a progress line
Using python 2.7.6 on ubuntu 14.04 The application in question is run with bash and gnome-terminal : I've written a command-line "wrapper" for youtube-dl, executing youtube-dl as a subprocess. -- youtube-dl reports download progress on one line. I.E. the line is overwritten numerous times with no carriage return until the downloading is finished. -- The following code runs the youtube-dl command and reports each line as output by youtube-dl ### p = subprocess.Popen(list(args), stderr=subprocess.STDOUT, stdout=subprocess.PIPE) while True: line = p.stdout.readline() if not line: break tmp = line.strip() print tmp ### However this method not does show the download progress _until_ the download is complete. To clarify : follows is output from my app running youtube-dl. I've annotated the line in question with '###' [youtube] ZIgnHPqp0Dk: Downloading webpage [youtube] ZIgnHPqp0Dk: Downloading video info webpage [youtube] ZIgnHPqp0Dk: Extracting video information [youtube] ZIgnHPqp0Dk: Downloading js player en_US-vfljDEtYP [youtube] ZIgnHPqp0Dk: Downloading DASH manifest [download] Destination: Someday Soon - Judy Collins 1969.avi.m4a ### the line below is not seen until download is finished. [download] 100% of 7.58MiB in 00:12.85KiB/s ETA 00:00 [ffmpeg] Correcting container in "Someday Soon - Judy Collins 1969.avi.m4a" [ffmpeg] Destination: Someday Soon - Judy Collins 1969.avi.mp3 Deleting original file Someday Soon - Judy Collins 1969.avi.m4a (pass -k to keep) Is there a way to code subprocess so the the progress is being shown? In my case lines being output aren't being shown unless a newline is sent, or so I understand it. FYI : the need for this function in this case is trivial, but the solution will be enlightening for me and have other uses, I'll bet. thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Using subprocess to capture a progress line
* Tim Johnson <t...@akwebsoft.com> [151110 14:55]: > * Chris Angelico <ros...@gmail.com> [151110 14:35]: > > On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson <t...@akwebsoft.com> wrote: > > > I've written a command-line "wrapper" for youtube-dl, executing > > > youtube-dl as a subprocess. > > > > > > -- > > > youtube-dl reports download progress on one line. I.E. the line is > > > overwritten numerous times with no carriage return until the > > > downloading is finished. > > > -- > > > > > > > Sounds to me like a possible buffering problem. But since youtube-dl > > is implemented in Python, you might find it easier to "pip install > > youtube_dl" and work with the methods directly: > > As for the buffering issue, at this point, I'll try using a > lower-level function like sys.stdout.write when the line > tests for '[download]' and 'ETA'. That method doesn't work ... so far. Oh well. -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Using subprocess to capture a progress line
* Tim Johnson <t...@akwebsoft.com> [151110 14:55]: > * Chris Angelico <ros...@gmail.com> [151110 14:35]: > > On Wed, Nov 11, 2015 at 9:47 AM, Tim Johnson <t...@akwebsoft.com> wrote: > > > I've written a command-line "wrapper" for youtube-dl, executing > > is implemented in Python, you might find it easier to "pip install > > youtube_dl" and work with the methods directly: <<...> > > > >>> import youtube_dl > > >>> youtube_dl.YoutubeDL().download(["m39ydsOPSww"]) > > Frankly, I'd prefer - in the long run - to use youtube_dl (the > module). > > But, when I do as you have suggested (and have tried previously) I > get the following: > > youtube_dl.utils.DownloadError: ERROR: no suitable InfoExtractor > It looks as if the developers are constantly upgrading. I just upgraded youtube_dl sudo pip install --upgrade youtube_dl And ran the code which is provided under the topic "EMBEDDING YOUTUBE-DL" at https://github.com/rg3/youtube-dl/blob/master/README.md At I got a successful download, AFAICS -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
testing, please disregard
I have had some problems with another python.org ML. I am sending this to see if it is received. Please disregard. thanks -- Tim http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT]Royal pardon for codebreaker Turing
* Steven D'Aprano steve+comp.lang.pyt...@pearwood.info [131224 16:19]: Tim Johnson wrote: * Steven D'Aprano st...@pearwood.info [131224 07:05]: On Tue, 24 Dec 2013 00:32:31 +, Mark Lawrence wrote: Maybe of interest to some of you http://www.bbc.co.uk/news/technology-25495315 While I'm happy for Alan Turing, may he rest in peace, I think the thousands of other homosexuals who have been prosecuted for something which shouldn't be a crime in the first place might be a bit peeved that he is singled out for a pardon. The LGBTs that I know are happy to hear about it... How many of them have been prosecuted themselves? If they have been, did they get pardoned as well? In case it wasn't obvious, I'm not objecting to Turing being pardoned. I'm suggesting that there are probably thousands of people whose lives were equally ruined, and they haven't been pardoned. I'm sure that Turing wasn't the only person who was forced into taking hormone therapy, he probably wasn't the only person driven to suicide, and I know that he wasn't the only one who lost his job and career because of the hateful laws. Turing's prosecution was an especially spiteful example, given his role in the war effort, but many others suffered equally. Some may even be alive today. Where is their royal pardon? I'm not sure if you have a cause or if you want an argument. You'll get none from me. I - like many others, and perhaps you as well - carry the scars of man's inhumanity to man. Justice for that has its venue and it isn't on this ML. Go find your cause and its venue. I'm done with this. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT]Royal pardon for codebreaker Turing
* Steven D'Aprano st...@pearwood.info [131224 07:05]: On Tue, 24 Dec 2013 00:32:31 +, Mark Lawrence wrote: Maybe of interest to some of you http://www.bbc.co.uk/news/technology-25495315 While I'm happy for Alan Turing, may he rest in peace, I think the thousands of other homosexuals who have been prosecuted for something which shouldn't be a crime in the first place might be a bit peeved that he is singled out for a pardon. The LGBTs that I know are happy to hear about it... Personally, I think that people ought to throw a party celebrating Turing's rehabilitation, and do it right outside the Russian Embassy. :) Yeah! -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT]Royal pardon for codebreaker Turing
OT * Mark Lawrence breamore...@yahoo.co.uk [131223 15:39]: Maybe of interest to some of you http://www.bbc.co.uk/news/technology-25495315 I note the following Dr Alan Turing was an exceptional man with a brilliant mind, said Mr Grayling. He said the research Turing carried out during the war at Bletchley Park undoubtedly shortened the conflict and saved thousands of lives. From my research - general (and later president) Eisenhower seemed to think that Project Ultra save millions (not thousands) of lives, shortened and maybe won the War. - Never forget. /OT -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: ogg2mp3 utility?
* Tim Johnson t...@akwebsoft.com [131113 17:06]: I've written an application that does some audio file conversions. I use mutagen for some of the mp3 file manipulation, but to convert ogg files to mp3 format I've been using subprocess to run the ogg2mp3 perl utility. (available from http://marginalhacks.com/) by David Madison. It's a spot on great app, but I would like to be able to keep it all one codebase. Are there any python utility that anyone could recommend? I've downloaded ogg2mp3.py (http://emptybits.com/ogg2mp3/ogg2mp3) by Darren Stone http://bitmason.com, I've compared two conversions. Thus far, the perl utility produces a clearer playback, but I have not yet played with the options available from the python script. Both scripts rely on oggdec, ogginfo and lame. On the mac available through macports, available on other *nixes as well. If anyone is interested, I'd welcome feedback on the python script above and I will fiddle with it (not being an audio expert) to see if I can get the playback improved. I've looked at pymedia also. Have not tested it. FYI.cheers -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
ogg2mp3 utility?
I've written an application that does some audio file conversions. I use mutagen for some of the mp3 file manipulation, but to convert ogg files to mp3 format I've been using subprocess to run the ogg2mp3 perl utility. (available from http://marginalhacks.com/) by David Madison. It's a spot on great app, but I would like to be able to keep it all one codebase. Are there any python utility that anyone could recommend? thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com, http://www.tj49.com -- https://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen instance hangs
* Nobody nob...@nowhere.com [130830 06:55]: On Thu, 29 Aug 2013 17:00:21 -0800, Tim Johnson wrote: ## This appears to be what works. def __exec(self,args) : Run the process with arguments p = subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE) while 1 : output = p.stdout.read() If the process tries to write more than a pipe's worth of data to stderr, before closing stdout, it will block indefinitely. If you want to process both stdout and stderr, you have to be able to consume the data in whatever order the process generates it, which means either using multiple threads or (on Unix) select/poll or non-blocking I/O. This is what the .communicate() method does (threads on Windows, select/poll on Unix). The alternative is to merge both streams with stderr=subprocess.STDOUT, or redirect one of them to a file (or /dev/null, etc). In earlier code I, I was merging them... :) Like I said: gnarly! What if I were to do something like: ## code while 1: output = p.stout.read() err = p.stderr.read() ## trapping for AttributeError, etc.. ## /code break'ing if either no output or value in `err' ?? The objective is to display all output, but to also separate error messages from normal output. thank you -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen instance hangs
* Jerry Hill malaclyp...@gmail.com [130830 07:48]: On Fri, Aug 30, 2013 at 11:32 AM, Tim Johnson t...@akwebsoft.com wrote: The objective is to display all output, but to also separate error messages from normal output. I still think you want to use communicate(). Like this: p = subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE) output, err = p.communicate() That's it. No need for a loop, or manually handling the fact that stderr and/or stdout could end up with a full buffer and start to block. The following code : p = subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE) errmsg,output = p.communicate() ... Hangs this code : p = subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE) while 1 : output = p.stdout.read() if output : print(output) else : break ... works -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
subprocess.Popen instance hangs
using Python 2.7.1 on OS X 10.7.5 I'm managing a process of drush using an instance of subprocess.Popen The process has a '--verbose' option. When that option is passed as part of the initializer `args' argument, the process will hang. It should be no surprise as drush output with the --verbose option can be _extremely_ verbose, and I can do without it, but I would like to learn how to handle it. I've googled this topic, but my poor little brain is yet to sort out all of the content found. ## my relevant code follows : p = subprocess.Popen(args,stderr=subprocess.STDOUT,stdout=subprocess.PIPE) ## wait() is 'forever' if '--verbose' used exit_status = p.wait() output = p.stdout.read() ## done I 'suspect' that using a tempfile may be the solution, if so, I could use some examples. thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen instance hangs
* MRAB pyt...@mrabarnett.plus.com [130829 11:04]: On 29/08/2013 19:34, Tim Johnson wrote: could use some examples. The subprocess will terminate when it has finished writing its output, but because you're not consuming any of the output (you're waiting for it to finish), the buffer fills up and blocks the subprocess. Try reading the output or using the .communicate method. Alternatively, pass an open file as the stdout argument. Kudos to all for the replies. Here is some code to review: ## execute process and read output p = subprocess.Popen(args,stderr=subprocess.STDOUT,stdout=subprocess.PIPE) while 1 : output = p.stdout.read() if output : print(output) else : break ## Check for errors exit_status = p.wait() if exit_status : if p.stderr : self.__err('Process terminated with exit status: %s' % (str(exit_status)), 'Following error message was found:' p.stderr.read()) else : self.__err('Process terminated with exit status: %s' % (str(exit_status))) Without any error from the drush process, this works fine. I can't quite figure out how to simulate/cause an error from drush, so I would welcome comments on the error handling thanks again -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen instance hangs
* Tim Johnson t...@akwebsoft.com [130829 10:51]: using Python 2.7.1 on OS X 10.7.5 I'm managing a process of drush using an instance of subprocess.Popen ... ## This appears to be what works. def __exec(self,args) : Run the process with arguments p = subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE) while 1 : output = p.stdout.read() if output : print(output) else : break errmsg = p.communicate()[1] if errmsg : self.__err('Process terminated with error:',errmsg) ## Thanks again, gnarly one for me. I am eternally a noob! -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is Ruby on Rails more popular than Django?
* rh richard_hubb...@lavabit.com [130307 20:21]: On Wed, 6 Mar 2013 17:55:12 -0900 Tim Johnson t...@akwebsoft.com wrote: I believe that indifference on the part of Python to fastcgi is a self-inflicted wound. I don't believe that there is any good excuse for such indifference, except for a sort of bureaucratic inertia. It's sad, when you consider how well python is designed Python is not indifferent to fastcgi, django is indifferent to fastcgi. and how crappily PHP is designed and how easy it is to set up and deploy drupal in the same environment. I speak from my own experience. -- http://mail.python.org/mailman/listinfo/python-list I stand corrected, that was a typo. thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is Ruby on Rails more popular than Django?
* mar...@python.net mar...@python.net [130306 09:31]: My questions: 1. Why is Ruby on Rails much more popular than Django? If you already know/work with Python than I would go the Django route. RoR and Django are not that much different nowadays as far as methodologies. The main differences I think between RoR and Django are that one is Ruby-based and one is Python-based. Other than that, if you can get used to one you can get used to the other. I had problems getting django to work on my hostmonster account which is shared hosting and supports fast_cgi but not wsgi. I put that effort on hold for now, as it was just RD for me, but I would welcome you to take a look at this link where I opened a ticket. https://code.djangoproject.com/ticket/19970 From what I inferred there and from the django ML, the django community is indifferent to fastcgi and the shared hosting environment. As someone is new to shared hosting environments (I would mostly on dedicated servers) I get the impression that django is cutting itself out of some (if not a lot) of the market. I don't know about RoR tho -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is Ruby on Rails more popular than Django?
* Albert Hopkins mar...@letterboxes.org [130306 17:14]: On Wed, Mar 6, 2013, at 02:16 PM, Tim Johnson wrote: I had problems getting django to work on my hostmonster account which is shared hosting and supports fast_cgi but not wsgi. I put that effort on hold for now, as it was just RD for me, but I would welcome you to take a look at this link where I opened a ticket. https://code.djangoproject.com/ticket/19970 From what I inferred there and from the django ML, the django community is indifferent to fastcgi and the shared hosting environment. As someone is new to shared hosting environments (I would mostly on dedicated servers) I get the impression that django is cutting itself out of some (if not a lot) of the market. I don't know about RoR tho I haven't any experience with shared hosting, so can't help you there. I did do some work with lighttpd and fast_cgi and the Django docs worked fine for that. But you're right. wsgi is pretty much the standard for web services in Python, like DB API is to relational database access. Ruby has Rack. Python has WSGI. I believe that indifference on the part of Python to fastcgi is a self-inflicted wound. I don't believe that there is any good excuse for such indifference, except for a sort of bureaucratic inertia. It's sad, when you consider how well python is designed and how crappily PHP is designed and how easy it is to set up and deploy drupal in the same environment. I speak from my own experience. respectfully : -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Good Python IDE
* Sourabh Mhaisekar sourabh8...@gmail.com [130106 07:11]: Hello All, I am recently started couple of projects in Python, one in Python GTK and one in Python Qt. I want a good IDE (For Windows ) for Python which gives support for Python as well as PyGtk and PyQt. Features I am looking for * Support for Core Python Auto-completion. * Support for PyGtk and PyQt * Support for either Bazaar (preferred) or CVS I haven't developed on windows in over 10 years, but as I recall, pythonwin worked well for me at the time. I don't recall whether the 2nd and 3rd features you refer to were available, but the first was. It is easy enough to try. Now I use vim for all of my work. I pretty-much hand-rolled my own IDE, which is typical of vimmers. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Good Python IDE
* Tetsuya i...@noi.com [130106 14:43]: On 01/06/2013 11:13 PM, Tim Johnson wrote: Now I use vim for all of my work. I pretty-much hand-rolled my own IDE, which is typical of vimmers. I did like you, too. I use vim for everything: coding in python, django, js, html, C/C++, bash, even email (inside mutt, of course). Yes, Yes... Start with an empty ~/.vimrc, and then build up the configuration day by day, adding one single plugin at a time, driven by your daily needs, it's the better thing to do IMHO. Thus vim becomes a full fledged IDE for everything, and it does it *your* way, not *its* way. :) Great minds run in the same gutter ... BTW, vim is available also under Windows. Where I started using it. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: New to python, do I need an IDE or is vim still good enough?
* Grant Edwards invalid@invalid.invalid [121229 10:02]: On 2012-12-27, mogul morten.gulda...@gmail.com wrote: I'm new to python, got 10-20 years perl and C experience, all gained on unix alike machines hacking happily in vi, and later on in vim. Now it's python, and currently mainly on my kubuntu desktop. Do I really need a real IDE, as the windows guys around me say I do, No. or will vim, git, make and other standalone tools make it the next 20 years too for me? I've been using vim for 12 years now. And it works pretty good for me as an IDE. I've written a lot of vimscripts to make vim better do my bidding and made generous use of contributed scripts. I see no reason to think that I would be more productive using anything else, but that is just me. Along the way, I did use emacs as well and ended doing quite a bit of elisping. Elisp does have the advantage of asynchronously running the interpereter inside of the editor Just one thing that I wouldn't mind seeing in vim. I do find vim a bit more nimble than emacs, but each to his/her own. It's wonderful to have all of the choices. They'll take away my vim when they pry it from my cold, dead fingers. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: popen4 - get exit status
* Dennis Lee Bieber wlfr...@ix.netcom.com [120828 07:11]: On Mon, 27 Aug 2012 15:43:59 -0800, Tim Johnson t...@akwebsoft.com declaimed the following in gmane.comp.python.general: * Benjamin Kaplan benjamin.kap...@case.edu [120827 15:20]: The popen* functions are deprecated. You should use the subprocess module instead. No, I'm stuck with py 2.4 on one of the servers I'm using and Shouldn't be a problem: -=-=-=- 17.1 subprocess -- Subprocess management New in version 2.4. Thanks Dennis, I had misread the docs, you're right - after rereading them I has able to implement subprocess - glad to have it as I no longer have any servers to 'service' with anything older than 2.4. And Ben, please accept my apologies for seeming so dismissive. cheers tj The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several other, older modules and functions, such as: -=-=-=- -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ -- http://mail.python.org/mailman/listinfo/python-list -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
popen4 - get exit status
In bash I do the following: linus:journal tim$ /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup -bash: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory linus:journal tim$ echo $? 127 In python, use os.popen4 I do the following: fin,fout = os.popen4('/home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup;echo $?') results = fout.readlines() results ['/bin/sh: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory\n', '127\n'] Well, I got the exit code as the last item in the results, but I'm wondering if there is a better way. From help(os) - I don't find any variables dedicated to holding exit status. Any ideas? thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: popen4 - get exit status
* Benjamin Kaplan benjamin.kap...@case.edu [120827 15:20]: The popen* functions are deprecated. You should use the subprocess module instead. No, I'm stuck with py 2.4 on one of the servers I'm using and there will not be an upgrade for a few months. I'm really trying to set up something portable between linux-python 2.4 and darwin-python 2.7 thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: popen4 - get exit status
* Dave Angel d...@davea.name [120827 15:20]: On 08/27/2012 06:39 PM, Tim Johnson wrote: In bash I do the following: linus:journal tim$ /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup -bash: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory linus:journal tim$ echo $? 127 In python, use os.popen4 I do the following: fin,fout = os.popen4('/home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup;echo $?') results = fout.readlines() results ['/bin/sh: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory\n', '127\n'] Well, I got the exit code as the last item in the results, but I'm wondering if there is a better way. From help(os) - I don't find any variables dedicated to holding exit status. According to: http://docs.python.org/library/popen2.html http://docs.python.org/library/popen2.html The only way to retrieve the return codes for the child processes is by using the poll() or wait() methods on the Popen3 http://docs.python.org/library/popen2.html#popen2.Popen3 and Popen4 http://docs.python.org/library/popen2.html#popen2.Popen4 classes; these are only available on Unix. This information is not available when using the popen2() http://docs.python.org/library/popen2.html#module-popen2, popen3() http://docs.python.org/library/popen2.html#popen2.popen3, and popen4() http://docs.python.org/library/popen2.html#popen2.popen4 functions, However, unless you're using an old version of Python (2.5 or below), you should be using the subprocess module. Thanks DaveA and see my reply to Benjamin that will do it. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
* Tomasz Rola rto...@ceti.pl [120611 11:18]: On Sat, 9 Jun 2012, Yesterday Paid wrote: I'm planning to learn one more language with my python. Someone recommended to do Lisp or Clojure, but I don't think it's a good idea(do you?) So, I consider C# with ironpython or Java with Jython. It's a hard choice...I like Visual studio(because my first lang is VB6 so I'm familiar with that) but maybe java would be more useful out of windows. what do you think? If you don't know C yet, I second recommendation to learn it. It is a very 70-tish and 80-tish language, but it is still very relevant if you want to call yourself a programmer (rather than a hobbyist, with all credits due to clever genius hobbyists out there). There are things I would rather do in C than in any other language (like, writing a Python interpreter or Linux kernel - wait, what you say they have been written already?). Also, it gives one a way to handtune the code quite a lot (at expense of time, but this is sometimes acceptable), to the point where next choice is assembly (and results not necessarily better)... Later on, since C and C++ share quite a bit, you can gradually include C++ elements into your code, thus writing in a kinda bettered C (compiled with C++ compiler), using constructs like const to make your programs more correct. And you will learn to not use new for variables, which is good thing. However, some C++ constructs include performance penalty, so it is good to not better it too much. I concur, I worked in C and C++ for 12 years. I added C++ later in my programming life. I don't recommend C++ for single programmers. - that is to say - 1 coder for 1 codebase. One can do good enough OOP in ansi C believe it or not, I learned to. It is interesting to note that most of linux is written in C, rather than C++ and is not python as well? - Common Lisp - nice industrial standard (depends on one's preferred definition of nice, of course, as well as industrial and standard) I took a hard look at Common Lisp at one time. I got the impression that the Common Lisp is not to Lisp what Ansi C is to C. IOWS, there does remain incompatibilities between different Common Lisp implementations. Whereas Ansi C is pretty strict as code portability (or was so when I was working in it) -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing MySQLdb via FTP?
* Corey Richardson co...@octayn.net [120608 11:39]: On Fri, 8 Jun 2012 09:55:23 -0800 Tim Johnson t...@akwebsoft.com t...@akwebsoft.com wrote: See the thread titled Python libraries portable? you will note that Corey Richardson makes the statement that MySQLdb is a C extension. I accepted that statement, but upon looking at the directories (I am on Mac Lion, but believe it may be the same for Linux) I see no binaries, just straight .py and .pyc files. http://mysql-python.hg.sourceforge.net/hgweb/mysql-python/MySQLdb-2.0/file/566baac88764/src It definitely is. The C extension part is the '_mysql' module, here it is /usr/lib64/python2.7/site-packages/_mysql.so. MySQLdb (of which _mysql is a part) uses that to provide a DB-API 2.0 compliant API. Understood. I missed that because the shared object file is in another directory. On mac (darwin) it is /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing MySQLdb via FTP?
* Tim Johnson t...@akwebsoft.com [120609 07:30]: http://mysql-python.hg.sourceforge.net/hgweb/mysql-python/MySQLdb-2.0/file/566baac88764/src It definitely is. The C extension part is the '_mysql' module, here it is /usr/lib64/python2.7/site-packages/_mysql.so. MySQLdb (of which _mysql is a part) uses that to provide a DB-API 2.0 compliant API. Understood. I missed that because the shared object file is in another directory. On mac (darwin) it is /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ I would note that some programming languages with mysql APIs access the mysql client library directly from the PL's code base (newlisp as an example) or use TCP/IP to query the mysql server directly (rebol as an example) -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: which one do you prefer? python with C# or java?
* Yesterday Paid howmuchisto...@gmail.com [120609 14:52]: I'm planning to learn one more language with my python. Someone recommended to do Lisp or Clojure, but I don't think it's a good idea(do you?) So, I consider C# with ironpython or Java with Jython. It's a hard choice...I like Visual studio(because my first lang is VB6 so I'm familiar with that) but maybe java would be more useful out of windows. I am kind on the same wavelength as becky_lewis - and bye the way is not clojure based on java? Two lesser known programming languages that I have done extensive development with in the past are rebol (www.rebol.com) and newlisp (http://www.newlisp.org/) newlisp and rebol are both *symbolic* languages as well as newlisp is very *functional* The additional advantage of using newlisp is that the very mention of newlisp drives the lispers crazy. Just mention 'newlisp' and watch the spittle fly. On the other hand, clojure and C# have a much larger user base. (small-user-base) is why I don't use newlisp or rebol for any new projects. MTCW -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing MySQLdb via FTP?
* Prasad, Ramit ramit.pra...@jpmorgan.com [120608 09:38]: Is it possible to install MySQLdb via FTP? 1)I have a hostmonster account with SSH. I have been able to log in and install MySQLdb from the shell. Works fine. 2)Now I have a client who wants to have a hostmonster account and we will need MySQLdb. I *will not* have SSH access since (as I understand it) hostmonster allows SSH access from 1 IP only. 3)The hostmonster account services (I.E. cpanel) does not have any service to do this. 4)I wouldn't need to make the install on PYTHONPATH as my resources will handle sys.path configuration. This isn't an immediate need so URLs and pointers to relevant discussions would suffice. Why not just write a script that will install it for them and then give them a copy of that script? Alternatively, have the client contact hostmonster and have them install it; I imagine a decent webhost would be able to do this manually if asked via email/ticket. No they would not. In fact, the hoster that I am trying to get my client away from won't either. It would be great to find a dependable hoster that *would* do manually installs, but most seem to be a one-size fits all. I would imagine that if you know where all the files go, it would be possible copy all the files over FTP and have it work. Granted, I am not familiar with installing this package so I could be wrong. See the thread titled Python libraries portable? you will note that Corey Richardson makes the statement that MySQLdb is a C extension. I accepted that statement, but upon looking at the directories (I am on Mac Lion, but believe it may be the same for Linux) I see no binaries, just straight .py and .pyc files. *However* as it often turns out, I was barking up the wrong tree. A very nice gentleman (I presume) emailed me privately to say (I'm sure to save me the public embarassment because I should have though of it myself) Ssh to your client and from the client ssh hostmonster and therein is the solution. I guess I would have thought of it in the next few days whilst visiting the little boys room or mowing the lawn, but Kudos to Rod Person for his solution. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Installing MySQLdb via FTP?
Is it possible to install MySQLdb via FTP? 1)I have a hostmonster account with SSH. I have been able to log in and install MySQLdb from the shell. Works fine. 2)Now I have a client who wants to have a hostmonster account and we will need MySQLdb. I *will not* have SSH access since (as I understand it) hostmonster allows SSH access from 1 IP only. 3)The hostmonster account services (I.E. cpanel) does not have any service to do this. 4)I wouldn't need to make the install on PYTHONPATH as my resources will handle sys.path configuration. This isn't an immediate need so URLs and pointers to relevant discussions would suffice. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python libraries portable?
* Corey Richardson co...@octayn.net [120607 14:19]: On Thu, 07 Jun 2012 20:20:47 GMT jkells jtke...@verizon.net jtke...@verizon.net wrote: We are new to developing applications with Python. A question came up concerning Python libraries being portable between Architectures.More specifically, can we take a python library that runs on a X86 architecture and run it on a SPARC architecture or do we need to get the native libraries for SPARC? Pure-python libraries should run wherever Python does, if it doesn't, that's a bug. C extensions to CPython shouldn't have any platform incompatibilities, but of course you'll need to recompile. Perhaps this respons to this thread contains a possible solution to my question subject Installing MySQLdb via FTP? Does this mean that I could copy my MySQLdb module directly from my workstation via ftp to a server, and have it work, given that sys.path contained the path? -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python libraries portable?
* Corey Richardson co...@octayn.net [120607 15:20]: On Thu, 7 Jun 2012 15:09:36 -0800 Tim Johnson t...@akwebsoft.com t...@akwebsoft.com wrote: Does this mean that I could copy my MySQLdb module directly from my workstation via ftp to a server, and have it work, given that sys.path contained the path? No, absolutely not. MySQLdb is a C extension. Assuming same architecture and shared libraries, it will *probably* work, but no guarantees. If any of those are different, even slightly, it will break. Yeah, you're right - I knew that and I had forgotten! Sorry. So what to do if I can't install from the command line? I could use python's external command tools like subprocess.call(), but am not sure what the implications would be since privileges might be limited. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python libraries portable?
* Corey Richardson co...@octayn.net [120607 17:01]: On Thu, 7 Jun 2012 16:43:26 -0800 Tim Johnson t...@akwebsoft.com t...@akwebsoft.com wrote: So what to do if I can't install from the command line? I could use python's external command tools like subprocess.call(), but am not sure what the implications would be since privileges might be limited. https://github.com/petehunt/PyMySQL/ is your best option, when it comes to using mysql without C extensions. I don't even know if it works, but it's the only one I could fine. Thanks, but I need to add my own thread about how to install on a server without the command line being available? I kind of hijacked this one.. Will post tomorrow. cheers -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Decouplable CMS in python?
:)I'm sure decouplable is a word. If not it should be. I have written my own framework. This has been a work in progress as a consequence of projects that I have done over the last 10 years. I need a CMS that sits on top of the framework. One of the starting points that I have considered is finding a fairly simple, but well-written CMS in python and adapting it. It may very well turn out that I would have to start from 'scratch', nevertheless, reviewing code for such a simple CMS would be informative. I'm thinking that, as an example - django-cms - would be too complex, regardless of its merits. Any recommendations? thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: MySQLdb on Mac Lion
* Ned Deily n...@acm.org [111012 18:12]: In article 20111013005244.gk6...@johnsons-web.com, Tim Johnson t...@akwebsoft.com wrote: I'm most experienced with MySQLdb on ubuntu, which is installed via apt-get or synaptic. I am setting up a mac mini with osX 10.7 (Lion). Macports makes py27-mysql 1.2.2 available, but are there any .dmg packages available? I strongly recommend you stick with MacPorts or Homebrew. There are too many things that can go wrong on OS X 10.6 or 10.7 if you try to install MySQL client libraries, MySQLdb, and Python from different places. IME, the binary installers for OS X provided by the MySQL are inconsistently built between versions and often need the library paths need to be tweaked. The only major drawback of using MacPorts is that it will download (and possibly build) its own version of Python but it's a small price to pay: search the archives of Stackoverflow to see how dismayingly often this topic comes up. Thanks for that Ned. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
MySQLdb on Mac Lion
I'm most experienced with MySQLdb on ubuntu, which is installed via apt-get or synaptic. I am setting up a mac mini with osX 10.7 (Lion). Macports makes py27-mysql 1.2.2 available, but are there any .dmg packages available? thanks -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
* DevPlayer devpla...@gmail.com [110928 04:31]: On Sep 27, 10:25 pm, alex23 wuwe...@gmail.com wrote: rantingrick rantingr...@gmail.com wrote: Since, like the bible the zen is self contradicting, any argument utilizing the zen can be defeated utilizing the zen. And like the Bible, the Zen was created by humans as a joke. If you're taking it too seriously, that's your problem. If however you want to learn about the accepted rules for formatting code then you need to read PEP-8! PEP 8 is our style guide. Contradiction is only seen by narrow perspectve. Calling the Bible a joke is used to hurt people, not enlighten them. Those words show bitter arrogance, not constructive critism as it ignores how others feel about that book. What benefit to others is gained by calling someones belief a joke? My wife and I are devout christians, but not fundamentalist. We would not take rantingrick too seriously. If _you_ take him seriously, you're just giving him 'street cred'. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
* Devin Jeanpierre jeanpierr...@gmail.com [110924 19:07]: Padding numbers with leading zeroes is very common. I'm surprised that more languages don't make it a string method. By making it a string method, instead of a function, we force all implementations of strings to implement that method. That sort of sucks, and it's a reason not to include it as a method. Why does it suck? And why do people say 'suck' so much, especially in technical venues? :) Just answer the first question, the second is rhetorical. I think that your answer, regardless of whether I agree with it may edify me serendipitously. It can, after all, be implemented as a function, and in doing so (with the appropriate operator overloading) that function could work with multiple implementations of strings. Instead any implementation of a string must implement that method. That's a waste. I'm not sure what you mean. I've written my own `split' function. I don't believe that there would be any conflict if you wrote your own `zfill' function. Or if there would be, I'd want to know before I hurt myself. regards -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
* Devin Jeanpierre jeanpierr...@gmail.com [110925 16:37]: Why does it suck? The gist of what I was saying is that it's possible to define functions that do this generically so that one implementation of zfill can work with multiple implementations of strings. That is kind of 'spot on' for me. Before I started using python, I worked in rebol - where (at that time), there was a limited number of function names available because of limited namespacing (and the binary was a fraction the size of python). So I learned to take that approach. Having to reimplement every time when one implementation would do is bothersome and generally isn't done unless it has to be (thus why mmap lacks a zfill method). Having to do more work than necessary sucks, as does having partial str implementations that don't do everything str does. Ideally, I would claim that if some interface will have multiple implementations, it should have as few methods as possible to make implementation as easy as possible, and move as much as possible _away_ from methods and into functions that work with arbitrary implementations of the interface. This minimizes the amount of work that must be done for implementors and thus makes life better. It's also true that it's bad practice to have objects with large APIs, not for convenience reasons but because it increases object coupling, something that good object oriented design seeks to eliminate. The idea there is that the less ways you can have your object interacted with / interact with other objects, the easier it is to think of the way state flows. I agree with this in principle, but it doesn't really matter for strings. The situation I see with something like zfill as-a-method is that it has nearly negligible benefit (less imports vs function?) and some detriment. So I would conclude it should not exist. Other people look at this differently. Good response. Thank you. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
* Chris Angelico ros...@gmail.com [110925 13:50]: On Mon, Sep 26, 2011 at 4:54 AM, Petite Abeille petite.abei...@gmail.com wrote: On Sep 25, 2011, at 8:46 PM, Tim Johnson wrote: Why does it suck? And why do people say 'suck' so much, especially in technical venues? :) It's a technical term: http://www.osnews.com/images/comics/wtfm.jpg Also, because technical people are opinionated windbags. Goes with the territory. :) I always felt that to be courteous, to the point and reserved cost me less typing time. And since I'm self-employed and only charge for productive time for clients, that's being cost-conscious for me. Of course I've been known to get a little crazy about PHP. So don't let me get started... BTW: If you like ranting as a spectator sport, I have found the Common Lisp newsgroup to be among the most spectacular. But that's just me. -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
* Passiday passi...@gmail.com [110924 09:47]: ... I have been coding in many other languages, most of the time it was Java and C#. I don't like the function mess of PHP (ie, loads and loads of functions without any namespaces etc), but I'd like to think that Python is different. It is ... In my brief coding experience I have stumbled upon Python zfill(width) method, and I thought, really, do you have to include such a narrow- purpose method in the basic method set? Perhaps there are more such methods that are nice when you need them, but then again, you don't put all the possible methods in the standard set. I think that you have raised an interesting question here. I've been coding in python for 9 years and I have never used it. Perhaps there is reason such method is in the basic library, and my complaints are unbased? It could be some sort of legacy. I imagine we will hear from some more senior pythonists on this matter. Or, perhaps the language is on course to bloat out and get filled with tens and hundreds of special-purpose methods that render the language structure chaotic? From my observance, python has developed with care and prudence. I have a feeling (instinctive of course), that Guido van Rossum is/was more likely to say 'no' to a request for a new implementation that Rasmus Lerdorf. MTCW -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
* Arnaud Delobelle arno...@gmail.com [110924 12:04]: On 24 September 2011 20:34, MRAB pyt...@mrabarnett.plus.com wrote: In my brief coding experience I have stumbled upon Python zfill(width) method, [...] It could be some sort of legacy. I imagine we will hear from some more senior pythonists on this matter. The documentation says New in version 2.2.2. But zfill has been in the string module for a lot longer. :) Like I said. See timestamp. http://mail.python.org/pipermail/python-bugs-list/1999-July/35.html I was coding C/C++ and ASM back then -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Reconciling os.path.getmtime vs ftp.sendcmd('MDTM filename')
* Tim Johnson t...@akwebsoft.com [110914 18:18]: * Chris Rebert c...@rebertia.com [110914 16:46]: On Wed, Sep 14, 2011 at 12:50 PM, Tim Johnson t...@akwebsoft.com wrote: I have written a class that uses ftplib.FTP as the parent. I need to reconcile the modified time of a workstation file with that same filename on a remote server. Let's say we have a file called '400.shtml'. I get the mtime on my workstation by os.path.getmtime('400.shtml') 1311648420.0 http://docs.python.org/library/os.path.html#os.path.getmtime Your sample seems to be a typical Unix timestamp: Yup. Needs to be converted to a timedate stamp, methinks. http://en.wikipedia.org/wiki/Unix_time I'll look at that tomorrow. Late here. And I use ftp.sendcmd('MDTM 400.shtml') ## for the remote server '213 20110726004703' RFC 3659 - Extensions to FTP Sec 3. File Modification Time (MDTM) http://tools.ietf.org/html/rfc3659#section-3 (Note: Code 213 = File status response) and '213 20110726004703'[4:] should give me the string representation of the timedate stamp on the remote file. FYI: datetime.datetime.fromtimestamp(mod_time) Is probably what I was looking for. However, for my purposes - I'm going to take another approach. Every uploaded file is defined in an object stored on my workstationr: I will store the MDTM string after upload and then on the next upload, compare the stored string with the return value from ftp.sendcmd('MDTM ' + filename) Thanks for the input. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Reconciling os.path.getmtime vs ftp.sendcmd('MDTM filename')
I have written a class that uses ftplib.FTP as the parent. I need to reconcile the modified time of a workstation file with that same filename on a remote server. Let's say we have a file called '400.shtml'. I get the mtime on my workstation by os.path.getmtime('400.shtml') 1311648420.0 And I use ftp.sendcmd('MDTM 400.shtml') ## for the remote server '213 20110726004703' My question is how to compare the two outputs? Pointers to documentation and other resources are invited. thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Reconciling os.path.getmtime vs ftp.sendcmd('MDTM filename')
* Chris Rebert c...@rebertia.com [110914 16:46]: On Wed, Sep 14, 2011 at 12:50 PM, Tim Johnson t...@akwebsoft.com wrote: I have written a class that uses ftplib.FTP as the parent. I need to reconcile the modified time of a workstation file with that same filename on a remote server. Let's say we have a file called '400.shtml'. I get the mtime on my workstation by os.path.getmtime('400.shtml') 1311648420.0 http://docs.python.org/library/os.path.html#os.path.getmtime Your sample seems to be a typical Unix timestamp: Yup. Needs to be converted to a timedate stamp, methinks. http://en.wikipedia.org/wiki/Unix_time I'll look at that tomorrow. Late here. And I use ftp.sendcmd('MDTM 400.shtml') ## for the remote server '213 20110726004703' RFC 3659 - Extensions to FTP Sec 3. File Modification Time (MDTM) http://tools.ietf.org/html/rfc3659#section-3 (Note: Code 213 = File status response) and '213 20110726004703'[4:] should give me the string representation of the timedate stamp on the remote file. Thanks. I will look at the unix_time entry soon. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Thoughts about documentation for non-python resource files
I'm looking for comments and/or URLs to discussions on this topic. I use my own MVC system. A component of this system generates documentation from python docstrings. Of course this system also comprises many non-python filetypes : css, html, txt, js, xml etc. Views, which are txt or html files can be handled by my system's built-in relationships between controllers and views. For other non-python files which are not found directly to controllers, css, js, html, xml all support comments and documentation can be (and is) build into the comments. Before I proceded and 'roll my own' protocol for generating documentations for these above-mention filetypes, I'd like to know if there is any such protocols being used already. Example : A pythonic way to generate documentations on a javascript file as well as its functions, objects etc. Any comments welcome. thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: what is the advantage of Django when comparing with LAMP and J2EE platform?
* smith jack thinke...@gmail.com [110802 11:37]: There are so many choice to do the same thing, so is there any special advantage Django brings to user? Django is a python framework, J2EE is a java platform (my apologies if I use 'framework' incorrectly). Our customers want PHP,perl or python, not java. The definition for LAMP given at http://en.wikipedia.org/wiki/LAMP_(software_bundle) - for what it is worth includes python and defines LAMP as sort of generic (as I read it). Thus django *could* be considered a LAMP bundle, perhaps. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Hostmonster : Installing MySQLdb at a specific location
* Tim Johnson t...@johnsons-web.com [110731 11:47]: I don't want to discourage any further input, but I'm looking at https://my.hostmonster.com/cgi/help/000531?step=000531 regarding installing django and I think the instructions can be extrapolated for MySQLdb. I will report what happens... I received a link for the Hostmonster helpdesk to https://my.hostmonster.com/cgi/help/530 My experience was that I had to modify some of the paths from the original. When I ran the python setup.py install routine, python complained that it could not find `lib64' thusly, I created $HOME/.local/lib/python2.4/site-packages Furthermore, seems that setup.py did not copy all files from the installation directory. The result was a UserWarning regarding multiple imports of the _mysql module when I invoked import MySQLdb. I solved that by adding the installation directory to my PYTHONPATH. A relevant excerpt from .bashrc looks like this: #BEGIN - # line one export PYTHONPATH=$HOME/.local/lib64/python/site-packages:$PYTHONPATH # line two export PYTHONPATH=$HOME/.local/lib64/python2.4/site-packages:$PYTHONPATH # line three export PYTHONPATH=$HOME/admin/.install/MySQL-python-1.2.3:$PYTHONPATH # line four export PATH=$HOME/.local/bin:$PATH #END Where $HOME/admin/.install/MySQL-python-1.2.3 is the package install directory. I have been spoiled by ubuntu. Furthemore, it has been a long time since I did a package install where I don't have root privileges. Results may vary, I hope this is helpful to someone else. cheers -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Hostmonster : Installing MySQLdb at a specific location
I've using MySQLdb for years, but always on servers where I had system-wide access. I have an account on Hostmonster and would like to do some development there, but although python2.6 is available, MySQLdb is not installed. I do not believe there is a system-wide access, nor do I expect sysadmins to do my any favors. I have SSH access and it is a linux OS. uname -a gives me: Linux host266.hostmonster.com 2.6.32-42.1.BHsmp #1 SMP Tue Jun 28 17:06:41 MDT 2011 x86_64 x86_64 x86_64 GNU/Linux A 'local' bin directory is provided. I have downloaded MySQL-python-1.2.3 and am looking at the docs, but so far I haven't found any documentation that tells me how (or if) I may install to anything other than a default path. Any comments are welcome. TIA tim -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Hostmonster : Installing MySQLdb at a specific location
* Tim Johnson t...@johnsons-web.com [110731 11:01]: I've using MySQLdb for years, but always on servers where I had system-wide access. I have an account on Hostmonster and would like to do some development there, but although python2.6 is available, MySQLdb is not installed. I do not believe there is a system-wide access, nor do I expect sysadmins to do my any favors. I have SSH access and it is a linux OS. uname -a gives me: Linux host266.hostmonster.com 2.6.32-42.1.BHsmp #1 SMP Tue Jun 28 17:06:41 MDT 2011 x86_64 x86_64 x86_64 GNU/Linux A 'local' bin directory is provided. I have downloaded MySQL-python-1.2.3 and am looking at the docs, but so far I haven't found any documentation that tells me how (or if) I may install to anything other than a default path. I don't want to discourage any further input, but I'm looking at https://my.hostmonster.com/cgi/help/000531?step=000531 regarding installing django and I think the instructions can be extrapolated for MySQLdb. I will report what happens... -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Function docstring as a local variable
Consider the following: ## code def test(): This is my docstring print(??) ## can I print the docstring above? ## /code It possible for a function to print it's own docstring? thanks (pointers to docs could be sufficient) -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Function docstring as a local variable
* Andrew Berg bahamutzero8...@gmail.com [110710 09:59]: -BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 On 2011.07.10 12:41 PM, Tim Johnson wrote: It possible for a function to print it's own docstring? def test(): ... Hi there. ... print(test.__doc__) Holy Moly. Of course! thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Function docstring as a local variable
* pyt...@bdurham.com pyt...@bdurham.com [110710 14:17]: I'm not sure how a function can get a generic handle to itself, but if you're willing to hardcode the function name, then this technique works: def test(): This is my doc string print test.__doc__ test() Works for me. Works for the application I'm after. thanks Here's a related question: I can get the docstring for an imported module: import tmpl as foo print(foo.__doc__) Python templating features Author - tim at akwebsoft dot com ## Is it possible to get the module docstring ## from the module itself? Thanks again -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Function docstring as a local variable
* Carl Banks pavlovevide...@gmail.com [110710 15:18]: On Sunday, July 10, 2011 3:50:18 PM UTC-7, Tim Johnson wrote: Here's a related question: I can get the docstring for an imported module: import tmpl as foo print(foo.__doc__) Python templating features Author - tim at akwebsoft dot com ## Is it possible to get the module docstring ## from the module itself? print __doc__ Thanks Carl. Where is general documentation on the subject of variables beginning with 2 underscores? I'm presuming the key phrase is 'builtin variables'. I'm searching too ... -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Function docstring as a local variable
* Chris Rebert c...@rebertia.com [110710 16:14]: Where is general documentation on the subject of variables beginning with 2 underscores? I've never heard that phrase used to describe __doc__ or its friends. :) That why I wasn't satified with my search results. Look in the underscore section of the documentation index: http://docs.python.org/genindex-_.html And that is what I was looking for. thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing if a global is defined in a module
* Ian Kelly ian.g.ke...@gmail.com [110704 20:37]: It sounds like what you really want is to detect the names *exported* by the module, then. i Yes! Why not do it the same way Python does it? If the module defines an __all__ attribute, then it is taken to be a sequence of strings which are the exported names. Otherwise, the exported names are taken to be all the names in the module dict that don't begin with an underscore. :) Oh here we go again. Another python feature I didn't know about or have forgotten. Thanks very much for that. Good tip -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Testing if a global is defined in a module
Using Python 2.6 on ubuntu 10.04. inspect module : I want to 'inspect' a module and get a list of all functions, classes and global variables in that module. ## A module has been imported, and we call `getmembers' members = inspect.getmembers(mod) ## While iterating thru `members', we test to see ## if an object is defined in the module. for m in members: obj = m[1] res = inspect.getmodule(obj) ## It appears that getmodule returns None for ## all but functions and classes. Example, for a module name `mvcInstall', when a class name `Install' that is defined in the module is passed as an argument to inspect.getmodule, the values returned is something like module 'mvcInstall' from '/home/tim/prj/cgi/libraries/python/mvcInstall.py' Likewise for functions defined in the module. ** But ** when global variables such as strings, booleans, integers are passed as an argument to getmodule, the value returned is `None'. What else can I do here? thanks -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing if a global is defined in a module
* rantingrick rantingr...@gmail.com [110704 12:00]: On Jul 4, 1:11 pm, Tim Johnson t...@johnsons-web.com wrote: Well if you follow the python style guide (and most accepted styles for global notation) then it's a trial exercise. You don't even have to import anything!!! :) GLOBAL_STR = 'str' GLOBAL_FLOAT = 1.3 GLoBaL_Bs = '' dir() ['GLOBAL_FLOAT', 'GLOBAL_STR', 'GLoBaL_Bs', '__builtins__', '__doc__', '__name__', '__package__', 'item'] for item in dir(): if item.isupper(): print 'Found Global!', item Thanks for the reply: *but* dir(targetmodule) will also show globals from other modules imported by the target module. So I would need a way to distinguish between those imported and those defined in targetmodule print(dir(targetmodule)) = ['Install', 'TestAddresses', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'chmod', 'consoleMessage', 'cp', 'debug', 'erh', 'exists', 'halt', 'is_list', 'load', 'makePath', 'mkdir', 'process', 'sys', 'traceback', 'usingCgi'] where 'TestAddresses' is a member of an imported module and 'usingCgi' is the only data variable defined in targetmodule regards -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing if a global is defined in a module
* Chris Rebert c...@rebertia.com [110704 13:16]: What else can I do here? Look at the names in the module's import statements using the `ast` module, and exclude those from the set of names defined in the module. Won't work for `from foo import *`, but that's bad practice and should be refactored anyway. I'm completely new to the `ast' module, so I will have to research that one. Thanks for the tip -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing if a global is defined in a module
* rantingrick rantingr...@gmail.com [110704 13:47]: On Jul 4, 3:30 pm, Tim Johnson t...@johnsons-web.com wrote: Thanks for the reply: *but* dir(targetmodule) will also show globals from other modules imported by the target module. So I would need a way to distinguish between those imported and those defined in targetmodule Okay, then do some processing on the source. You can use regexps or the module mentioned earlier by Chris. I think I'm making this unnecessarily complicated. I had used something like: from spam import TestAddresses ## just for grins Which is something that I almost never do in practice. Also, you pointed out the UC naming convention, which I was unacquainted with, being self-employed, self-taught and a one-man crew who doesn't spend as much time as he should reading PEPs. I'm going to go for the predicate test as second argument to getmembers with something like: def isdata(self,obj,name): Check if an object is of a type that probably means it's data. return (not (inspect.ismodule(obj) or inspect.isclass(obj) or inspect.isroutine(obj) or inspect.isframe(obj) or inspect.istraceback(obj) or inspect.iscode(obj))) and name.issupper() ## Untested code thanks again -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list