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 [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 [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: popen4 - get exit status
* Dennis Lee Bieber [120828 07:11]: > On Mon, 27 Aug 2012 15:43:59 -0800, Tim Johnson > declaimed the following in gmane.comp.python.general: > > > * Benjamin Kaplan [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 > [email protected]://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
Re: New to python, do I need an IDE or is vim still good enough?
* Grant Edwards [121229 10:02]: > On 2012-12-27, mogul 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: Good Python IDE
* Sourabh Mhaisekar [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 [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
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 [120607 14:19]: > On Thu, 07 Jun 2012 20:20:47 GMT > jkells 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 [120607 15:20]: > On Thu, 7 Jun 2012 15:09:36 -0800 > Tim Johnson 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 [120607 17:01]: > On Thu, 7 Jun 2012 16:43:26 -0800 > Tim Johnson 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
Re: Installing MySQLdb via FTP?
* Prasad, Ramit [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
Re: Installing MySQLdb via FTP?
* Corey Richardson [120608 11:39]: > On Fri, 8 Jun 2012 09:55:23 -0800 > Tim Johnson 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 [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 [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: which one do you prefer? python with C# or java?
* Tomasz Rola [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: Python Card alternatives?
* rzed [110611 05:14]: > Desktop apps don't seem to be the wave of the future, but they still > serve a useful purpose today. They can be ideal for a quick database > table management screen, or a data entry front end for a program with > a bunch of parameters. It's not easy enough to build a quick utility > with a GUI front end, though. Wax and PythonCard (and maybe others) > tried to hit that niche, but development on both is spotty at best. > Some claim that Dabo's gui builder is a good one for this purpose, and > maybe it can be. Are there any other, better solutions? > > I've been looking at Rebol lately, and it has some points of interest. > I much prefer Python as a language, but Rebol View's layout > specifications are wonderfully concise, and the support code seems to > be fairly straightforward as well. Has anyone tried to mimic their > approach in Python? I've used rebol for over 11 years. Longer than I have used python. I've not used rebol/view however, since my meal-ticket is console and web progamming. I'm guessing that you are going to find that difficult to do, but my suggestion would be: 1)Get into one of the rebol communities - probably thru altme. 2)You will find that most rebol programmers work in other languages also, and quite a few (like me) in python. 3)You are likely to get a lot of ideas there. cheers -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
dummy, underscore and unused local variables
Consider the following code: for i in range(mylimit): foo() running pychecker gives me a """ Local variable (i) not used """ complaint. If I use for dummy in range(mylimit): ## or for _ in range(mylimit): I get no complaint from pychecker. I would welcome comments on best practices for this issue. NOTE: I see much on google regarding unused local variables, however, doing a search for 'python _' hasn't proved fruitful. I would like to see comments here specifically on the use for `range' On a related note: from the python interpreter if I do >>> help(_) I get Help on bool object: class bool(int) | bool(x) -> bool .. I'd welcome comments on this as well. :) I expect to be edified is so many ways, some of them unexpected. 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: dummy, underscore and unused local variables[thanks]
* Tim Johnson [110613 07:58]: > > :) I expect to be edified is so many ways, some > of them unexpected. Thanks for all of the responses and for those which might come later. I'm going to stick with the convention of using a variable beginning with `dummy' and stick that in my snippet generator. cheers -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Trapping MySQLdb warnings
Using Python 2.6.5 on linux. When using MySQLdb I am getting warnings printed to stdout, but I would like to trap, display and log those warnings. In the past I have used _mysql_exceptions.Warning, but that approach is not working in this case. My cursor is created with the relevant following code: ## connection object self.__conn = MySQLdb.connect(db = self.__db, host = self.__host, user = self.__user, passwd = self.__passwd) ## cursor object self.__rdb = self.__conn.cursor() ## And implemented as : try : self.__rdb.execute(S) except _mysql_exceptions.Warning,e: raise e ## replace with log(e) What else needs to be done? TIA -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Trapping MySQLdb warnings
* geremy condra [110615 18:03]:
> On Wed, Jun 15, 2011 at 6:58 PM, Tim Johnson wrote:
> > Using Python 2.6.5 on linux.
> >
> > When using MySQLdb I am getting warnings printed to stdout, but I would
> > like to trap, display and log those warnings.
<.>
> Have you tried
> http://docs.python.org/library/warnings.html#temporarily-suppressing-warnings
Hi Geremy:
I just looked at the docs there. This is a new module (to me), and
I am unsure of the implementation or whether this is what I should
use.
I tried the following :
try :
self.__rdb.execute(S)
except warnings.catch_warnings:
std.mrk('',0,"mysql.py:196") ## DEBUG call
## and it does not look like my code modification
## is catching the warning.
Thanks for introducing me to this new module, but I'm not
sure if it is what I should be using.
BTW: End of day in this part of the world. I look forward to any other comments
on this subject tomorrow.
chees
--
Tim
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Trapping MySQLdb warnings
* Tim Johnson [110615 18:53]:
> * geremy condra [110615 18:03]:
> > On Wed, Jun 15, 2011 at 6:58 PM, Tim Johnson wrote:
> > > Using Python 2.6.5 on linux.
> > >
> > > When using MySQLdb I am getting warnings printed to stdout, but I would
> > > like to trap, display and log those warnings.
> <.>
> > Have you tried
> > http://docs.python.org/library/warnings.html#temporarily-suppressing-warnings
> Hi Geremy:
> I just looked at the docs there. This is a new module (to me), and
> I am unsure of the implementation or whether this is what I should
> use.
> I tried the following :
> try :
> self.__rdb.execute(S)
> except warnings.catch_warnings:
> std.mrk('',0,"mysql.py:196") ## DEBUG call
> ## and it does not look like my code modification
> ## is catching the warning.
Well, I am so far, absolutely baffled. I've looked at the docs for
the `warning' module. No real examples that I can see. and why has
the _mysql_exceptions.Warning exception no longer working?
grrr..
Be good to hear some other experiences 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: Trapping MySQLdb warnings
* Terry Reedy [110616 10:50]: > On 6/16/2011 11:55 AM, Tim Johnson wrote: > >* Tim Johnson [110615 18:53]: > >>* geremy condra [110615 18:03]: > >>>On Wed, Jun 15, 2011 at 6:58 PM, Tim Johnson wrote: > >>>>Using Python 2.6.5 on linux. > >>>> > >>>>When using MySQLdb I am getting warnings printed to stdout, but I would > >>>>like to trap, display and log those warnings. > >><.> > > The machinery in the warnings module is only for instances of > subsclasses of Warning. Are the warnings from MySQLdb properly such > objects? If so, what class are they? The warnings are sent directly to stdout. No way that I know of to find out what classes they are.. > >>>Have you tried > >>>http://docs.python.org/library/warnings.html#temporarily-suppressing-warnings > >> Hi Geremy: > >> I just looked at the docs there. This is a new module (to me), and > >> I am unsure of the implementation or whether this is what I should > >> use. > >> I tried the following : > >>try : > >>self.__rdb.execute(S) > >>except warnings.catch_warnings: > > warnings.catch_warnings is a context manager, not an exception. Thanks for that. > This is a TypeError in 3.x, which requires that exceptions be > instances of BaseException. Try > except warnings.Warning, warn: > > Substitute specific MySQLdb warning class, whatever it is, for Warning. OK. I'll stack 'em up and see what happens. Must look at docs first. 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: Trapping MySQLdb warnings
* Terry Reedy [110616 10:50]:
<...>
> Substitute specific MySQLdb warning class, whatever it is, for Warning.
Hmm! Consider the following code:
try :
self.__rdb.execute(S)
raise MySQLdb.Warning('danger, danger Monte Python') ## just for grins
except MySQLdb.Warning,e:
std.debug("e",e,0,0,'mysql.py:195',0) ## DEBUG GLOBAL
## result:
INSPECTING `e' (F:mysql.py:195):
danger, danger Monte Python
## Question:
Am I initializing the cursor to raise warnings? I *so* rusty at this, but I
suspect that something needs to be done with either the instantiation of the
'parent' connection object or the cursor object itself.
--
Tim
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Trapping MySQLdb warnings
* srinivas hn [110616 11:06]:
> Hi Tim,
>
> Use this method it will sort tour problem.
>
> def do_query(insert_query):
>import warnings
>
> with warnings.catch_warnings():
> warnings.simplefilter('error', MySQLdb.Warning)
> try:
> cursor.execute(insert_query)
> conn.commit()
> return 'Success'
> except MySQLdb.Error, error:
> logging.error("Error in insertion %s query is ", error)
> return 'Failure'
> finally:
> conn.close()
>
>
> try:
>xyz = do_query(insert_query)
> except MySQLdb.Warning, warning:
>logging.warning(warning)
>
>
> you need to use the with statement and then you need to catch the warnings
> hope it helps
Yeah!
Got some tweaking to do, but will post back again on working code.
At least I am now raising errors.
thanks *very* much.
--
Tim
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Trapping MySQLdb warnings
* srinivas hn [110616 11:06]:
> Hi Tim,
>
>import warnings
>
> with warnings.catch_warnings():
> warnings.simplefilter('error', MySQLdb.Warning)
> try:
> cursor.execute(insert_query)
> conn.commit()
> return 'Success'
> except MySQLdb.Error, error:
> logging.error("Error in insertion %s query is ", error)
> return 'Failure'
> finally:
> conn.close()
>
> try:
>xyz = do_query(insert_query)
> except MySQLdb.Warning, warning:
>logging.warning(warning)
Hi Again srinavas:
For an overview, I need to interate thru a file, executing each
line as an insert statement. Based on your valuable input, I have
the following:
##
def __process_line(self):
"""For each line in the file .."""
try :
self.db.simple(self.read())
except MySQLdb.Warning,e:
## catching warnings here, log, count, abort
## or some other action based on implementation
print(e) ## and count, log etc
##
def simple(self,insert_query):
"""Executing one line."""
cursor = self.__rdb
with warnings.catch_warnings():
warnings.simplefilter('error', MySQLdb.Warning)
cursor.execute(insert_query)
## This works well, but I'd like to do something further: Control is
transfered back to the calling function's `except' block when the
first warning is found. There can be and are multiple warning
conditions on each line. Is there a way to trap all of them?
I am unclear from the docs that I am reading at
http://docs.python.org/library/warnings.html
whether that can be done.
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
Parsing a dictionary from a format string
Currently using python 2.6, but am serving some systems that have
older versions of python (no earlier than.
Question 1:
With what version of python was str.format() first implemented?
Question 2:
Given the following string:
S = 'Coordinates: {latitude}, {longitude}'
Is there a python library that would provide an optimal way
to parse from S the following
{'latitude':"",'longitude':""}
?
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: Parsing a dictionary from a format string
* Tim Johnson [110620 10:28]:
> Currently using python 2.6, but am serving some systems that have
> older versions of python (no earlier than.
> Question 1:
> With what version of python was str.format() first implemented?
> Question 2:
> Given the following string:
> S = 'Coordinates: {latitude}, {longitude}'
> Is there a python library that would provide an optimal way
> to parse from S the following
> {'latitude':"",'longitude':""}
> ?
P.S. :
One solution would be
import re
re.findall(r'\{([^}]*)\}', s) ## I think, being a regex dummy..
But perhaps there is something more efficient than re?
cheers
--
Tim
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a dictionary from a format string
* Hans Mulder [110620 12:15]: > On 20/06/11 20:14:46, Tim Johnson wrote: > >Currently using python 2.6, but am serving some systems that have > >older versions of python (no earlier than. > >Question 1: > > With what version of python was str.format() first implemented? Duh! > It might be a matter of taste; it might depend on how familiar > you are with 're'; it might depend on what you mean by 'optimal'. As in speed. ## and then there is this - which I haven't tested a lot: def grabBetween(src,begin,end): """Grabs sections of text between `begin' and `end' and returns a list of 0 or more sections of text.""" parts = src.split(begin) res = [] for part in parts: L = part.split(end) if len(L) > 1: res.append(L[0]) return res I think later today, I will run some time tests using the `re' module as well as your function and the one above. BTW: To be more clear (hopefully) I was checking to see if there was a compiled method/function to do this. 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: Parsing a dictionary from a format string
* Tim Johnson [110620 13:00]:
>
> I think later today, I will run some time tests using the `re'
> module as well as your function and the one above.
OK: Functions follow:
def grabBetween(src,begin,end):
"""Grabs sections of text between `begin' and `end' and returns a list of
0 or more sections of text."""
parts = src.split(begin)
res = []
for part in parts:
L = part.split(end)
if len(L) > 1:
res.append(L[0])
return res
def splitExtractDict(src,default):
"""Extract dictionary keys for a format string using
`grabBetween', which uses the `split' string method."""
D = {}
keys = grabBetween(src,'{','}')
for k in keys :
D[k] = default
return D
def reExtractDict(src,default):
"""Extract dictionary keys for a format string using `re'"""
D = {}
keys = re.findall(r'\{([^}]*)\}', src)
for k in keys :
D[k] = default
return D
## From Hans Mulder
def findExtractDict(src,default):
start = -1
keys,D = [],{}
while True:
start = src.find('{', start+1)
if start == -1:
break
end = src.find('}', start)
if end > start:
keys.append(src[start+1:end])
for k in keys :
D[k] = default
return D
###
Now here are results using a small file and a lot of
reps for each function call, just to give some meaningful
times.
###
Using `split' : 0.0309112071991
Using `re.find' : 0.0205819606781
Using `find' : 0.0296318531036
I will note that the last method did not produce
correct results, but I also note that Hans did not
promise tested code :).
It is reasonable to suppose the `re' provides the
faster method.
cheers
--
Tim
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Handling import errors
* Guillaume Martel-Genest [110621 12:53]:
> What is the pythonic way to handle imports error? What is bugging me
> is that the imports can't be inside a function (because I use them in
> different places in the script and thus they have to be in the global
> scope). I would write something like:
Suppose you do something like this:
try :
mod = __import__('mymodulename')
except ImportError:
pass ## replace with error handling here
so `mod' is global if you execute the above code as top-level,
*but* you can also pass `mod' as an argument like any other
variable, as far as I know and far as I have done.
--
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 "" 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 [110704 12:00]: > On Jul 4, 1:11 pm, Tim Johnson 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() 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 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 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 [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 [110704 13:47]: > On Jul 4, 3:30 pm, Tim Johnson wrote: > > > > Thanks for the reply: *but* > > dir() 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 > > 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
Re: Testing if a global is defined in a module
* Steven D'Aprano [110704 15:18]: > > You are mistaken. TestAddresses is *not* a member of an imported module. It > is a member of the current module, which may or may not happen to point to > the same object as the other module as well. You are correct. I mispoke or misapplied. See my last post. > > >'usingCgi' is the only data variable defined in > > It seems to me that your approach here is unnecessarily complex and fragile. > I don't know what problem you are trying to solve, but trying to solve it > by intraspecting differences that aren't differences is surely the wrong > way to do it. See my last post... -- 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
* Steven D'Aprano [110704 15:48]: > Tim Johnson wrote: > > >> It seems to me that your approach here is unnecessarily complex and > >> fragile. I don't know what problem you are trying to solve, but trying to > >> solve it by intraspecting differences that aren't differences is surely > >> the wrong way to do it. > > See my last post... > > > Yes, but what are you actually *trying to do*? "Detecting data members" is > not an end in itself. Why do you think you need to detect data members? Steven, I'm building a documentation system. I have my own MVC framework and the goal is to have a documentation module for each project. Thanks again for the clarifications. I always learn a lot from you. -- 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 Angelico [110704 16:19]: > On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson wrote: > > Steven, I'm building a documentation system. I have my own MVC framework > > and the goal is to have a documentation module for each project. > > > > Is there a reason for not using Doxygen / Autodoc / etc, or at least > something in the same style? They work from specially-formatted > comments in the source code, rather than the compiled module object. I want this as a component of my system. It will be bound to a relational data-structure-based 'core' that defines relationships between all files in the project. :) It's called *collateral* And yes, I have worked with comment-based systems, including my own, that worked with multi-language projects. Best 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
* Ian Kelly [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
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 [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
* [email protected] [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 [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 [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
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 [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
Re: Hostmonster : Installing MySQLdb at a specific location
* Tim Johnson [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
Re: what is the advantage of Django when comparing with LAMP and J2EE platform?
* smith jack [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
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
Maximum post data length
I am currently using python 2.6. For years I have used my own cgilib module which in turn uses the stand python cgi library module. The implementation is : self.form = cgi.FieldStorage(keep_blank_values=1) I'm looking for an approach that would enable both client- and server-side validation without duplication or writing additional scripting. Here's one approach I am considering: The form holds a hidden field with a "magic" name that can be read both from the DOM on the client side and from the cgilib module on the server side. The value for the field would be a json structure that would have as the upper-level keys field names and values would be in turn be json-like (dictionary) values. Example etc The kicker might be that I have one series of forms that have hundreds of elements. I could end up with the value of `validator.descriptors' being thousands of bytes long. :)And don't bother to tell me that forms that large are nuts, you'd be preaching to the long converted. Does anyone know if the cgi module might choke on the size of a POST'ed field OR the total length of the posted form data? POST method only. And that is plan A (I have plans B and C) Thanks -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
PEP for module naming conventions
I need to be better informed on naming conventions for modules. For instance, I need to create a new module and I want to make sure that the module name will not conflict with any future or current python system module names. There may be a PEP for this, if so, a URL to such a PEP would suffice for my inquiry. Also, if there is an index of PEPs, a link to such would also be appreciated. thanks -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP for module naming conventions
* David Marek [110311 13:20]: > Hi, > > Have you read PEP 8? http://python.org/dev/peps/pep-0008/ > I don't think it's possible to be sure that the name of your module > won't conflict with system module name (if you'll follow conventions). > > You can find the list of all PEPs at http://python.org/dev/peps/ Thank you for the links David. > -- > David Marek > [email protected] > http://davidmarek.cz And interesting web site. The future is with us. > > On Fri, Mar 11, 2011 at 10:52 PM, Tim Johnson wrote: > > I need to be better informed on naming conventions for modules. For > > instance, I need to create a new module and I want to make sure that > > the module name will not conflict with any future or current python > > system module names. > > > > There may be a PEP for this, if so, a URL to such a PEP would > > suffice for my inquiry. Also, if there is an index of PEPs, a link > > to such would also be appreciated. > > > > thanks > > -- > > Tim > > tim at johnsons-web.com or akwebsoft.com > > http://www.akwebsoft.com > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing many python scripts, in a large corporate environment.
* Phat Fly Alanna [110312 07:22]: > We've been doing a fair amount of Python scripting, and now we have a > directory with almost a hundred loosely related scripts. It's > obviously time to organize this, but there's a problem. These scripts > import freely from each other and although code reuse is generally a > good thing it makes it quite complicated to organize them into > directories. > > There's a few things that you should know about our corporate > environment: > > 1) I don't have access to the users' environment. Editing the > PYTHONPATH is out, unless it happens in the script itself. > 2) Users don't install things. Systems are expected to be *already* > installed and working, so setup.py is not a solution. > > I'm quite willing to edit my import statements and do some minor > refactoring, but the solutions I see currently require me to divide > all the code strictly between "user runnable scripts" and > "libraries", which isn't feasible, considering the amount of code. > > Has anyone out there solved a similar problem? Are you happy with it? Slightly similar - time doesn't permit details, but I used among other things 4 methods that worked well for me: 1)'Site modules' with controlling constants,including paths 2)Wrappers for the __import__ function that enabled me to fine - tune where I was importing from. 3)Cut down on the number of executables by using 'loaderers'. 4)I modified legacy code to take lessons from the MVC architecture, and in fact my architecture following these changes could be called 'LMVCC' for loader model view controller config I hope I've made some sense with these brief sentences. -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Changing class name causes process to 'hang'
I'm using Python 2.6.5 on ubuntu 10.04 32-bit. My issue however, is with a code base that goes back to 2002, which at that time was 1.5~ or so. I have been since that time using my own cgi module which in turn, uses the python standard `cgi' module. The object instantiation has looked something like this: ## code below cgi = cgilib.cgitools() ## /code I choose to create a new cgi module by copying `cgilib' as `cgirev' and renamed the `cgitools' to `Cgi' so that the instantiation looked like ## code below cgi = cgirev.Cgi() ## /code And ran into problems, the cgi script would run almost to completion, but acted like it lost track of the stack at some point and would not terminate. I deleted all .pyc files associated with any file that might be a dependency. That did not solve the problem. After scratching my head and swearing for a couple of hours, I changed the name of the `Cgi' class back to `cgitools' and everything worked. ## code below cgi = cgirev.Cgi() ## /code 1)This is a mystery to me that may likely hide other issues that may come to bite me later. 2)I don't want to be stuck with the `cgitools' classname. I have never used a debugger with python. Never had to, python's error messages have always been my friend and mentor, but in this case there are no error messages. I would welcome hints on how to trouble-shoot this issue. TIA -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing many python scripts, in a large corporate environment.
* Tim Johnson [110312 10:41]: <...> 3)Cut down on the number of executables by using 'loaderers'. Sheesh! Typo, meant to say 'loaders'.. sorry -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing class name causes process to 'hang'
* Terry Reedy [110312 13:28]:
> On 3/12/2011 2:53 PM, Tim Johnson wrote:
>
> Is 'cgilib' *your* wrapper of the cgi module, or from a third party.
cgilib is my module. I use the cgi module as follows:
## code below
import cgi
self.form = cgi.FieldStorage(keep_blank_values=1)
## /code
> Without seeing cgitools/cgirev, it is hard to say. Something like
>
> while True:
> try:
> x = cgitools()
> break
> except NameError
> pass
>
> would produce the symptom ;-)
Hmm! I'm unsure what you mean here, but
I did do something like this:
## code below
if __name__=="__main__":
import sys,traceback
sys.stderr = sys.stdout ##
try :
print("Content-type: text/html\n")
print("")
cgi = CGI()
print("here")
print("CGI OUTPUT TEST")
for i in range(cgi.len_path_parts()):
print("path part # %d requested: %s" % (i,str(cgi[i])))
except :
traceback.print_exc()
## /code
And I get
CGI OUTPUT TEST
path part # 0 requested: test
path part # 1 requested: this
Whether I use CGI or cgitools as the class name.
But, if I use CGI as the class name and instantiate from a large application
with numerous dependecies, the process hangs.
The same happens if I 'alias' cgitools, as in
class CGI(cgitools):
pass
It is as if some gremlin lives on my system and insists that I use
the name `cgitools' and only the name `cgitools'. I'm sure
this comes from a side effect somewhere in the process.
thanks for the reply
--
Tim
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Changing class name causes process to 'hang'
* Terry Reedy [110312 17:45]:
> >## code below
> > import cgi
> > self.form = cgi.FieldStorage(keep_blank_values=1)
> >## /code
> And cgitools is a class therein?
Code above is called with/from cgitools
> > Hmm! I'm unsure what you mean here, but
>
> If the name 'cgitools' is used *somewhere*, not necessary in cgilib
> itself, other than in the class header itself, but the resulting
> NameError is *somehow* caught inside a retry loop, then your total
> application would exhibit the symptom you describe ('hanging').
That is one thing that I have looked for - and so far I have found nothing.
> This could happen if there is a bare 'except:' statement (these
> are not recommended) that needs to be specific 'except
> SomeError:'.
> >The same happens if I 'alias' cgitools, as in
> >class CGI(cgitools):
> > pass
>
> You mean you leave 'class cgitools()...' alone within cgilib and
> just add that? That would discredit the theory above. What if you
> use a different alias, like 'moretools'? Are you on an OS where
> 'cgi' and 'CGI' could get confused?
I am on linux. And the 'alias' was introduced experimentally after
the symptoms began. And `CgiTools' also results in
non-termination.
> >It is as if some gremlin lives on my system and insists that I use
> >the name `cgitools' and only the name `cgitools'. I'm sure
> >this comes from a side effect somewhere in the process.
> >thanks for the reply
One other thing I just realized:
The process stops inside of a function call to another object
method, if that method call is removed, the process teminates.
:) I may have a solution later today, and will relay it to you if
found. Must have coffee first.
thanks for your interest, I really appreciate it.
--
Tim
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Changing class name causes process to 'hang'
* Tim Johnson [110313 08:27]:
> One other thing I just realized:
> The process stops inside of a function call to another object
> method, if that method call is removed, the process teminates.
> :) I may have a solution later today, and will relay it to you if
> found. Must have coffee first.
I've had coffee, and also I've eaten a bit of crow. If I had no
dignity to spare I might have dropped this thread after the last
post, but I owe it to those who might come after me to explain
what happened. If I have any excuse, it is that I wrote this code
when I had about a month of python experience.
So here we go...
The cleanup part is to write a logfile. The logfile is written by
the write() method of a log object. The method was coded to accept
any number of data types and execute based on the type from an
if/elif/else code block. The cgi object was passed to the method.
The original code follows:
## code begins
if type(args) == type({}): ## it's a dictionary
args['time_date_stamp'] = '%s%d' %
(std.local_time(),std.randomize(8))
keys = args.keys()
keys.sort()
for key in keys:
outfile.write('\t%s: %s\n' % (key,args[key]))
elif type(args) == type(''):
outfile.write('%s\n%s\n' % (std.local_time(),args))
elif std.IsCgiObj(args): ## dump the cgi object
dump = args.getEnv('time_date_stamp=%s' %
(std.local_time()))
for line in dump:
outfile.write(' %s\n' % line)
else : ## default = it's a list
if args:
outfile.write('time_date_stamp=%s\n' %
(std.local_time()))
for arg in args:
outfile.write(' %s\n' % arg)
## /code ends
I did two obvious things wrong here:
First of all, std.IsCgiObj() returned false when I changed
the class name because std.IsCgiObj() tested for an explicit
match of 'cgitools' with the objects __class__.__name__ member.
Secondly, and worse, the default of the test block was an assumption
and I did not test the assumption. Bad, bad, very bad!
Therefore my code attempted to process the object as a list and down
the Rabit Hole we went. And I ended up with some *really* big
logfiles :).
Following is a tentative revision:
## code begins
elif 'instance' in (str(type(args))): ## it's an object
if hasattr(args,'getEnv'): ## test for method
dump = args.getEnv('time_date_stamp=%s' %
(std.local_time()))
for line in dump:
outfile.write(' %s\n' % line)
else :
erh.Report("object passed to logger.write()
must have a `getEnv()' method" )
else : ## it's a list
if type(args) != []: ## make no assumptions
erh.Report('List expected in default condition
of logger.write()')
if args:
outfile.write('time_date_stamp=%s\n' %
(std.local_time()))
for arg in args:
outfile.write(' %s\n' % arg)
## /code ends
## erh.Report() writes a messages and aborts process.
Of course, I could have problems with an object with a
malfunctioning getEnv() method, so I'll have to chew that one over
for a while.
I appreciate Terry's help. I'd welcome any other comments. I'm
also researching the use of __class__.__name__. One of my questions
is: can the implementation of an internal like __class__.__name__
change in the future?
--
Tim
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: Changing class name causes process to 'hang'
* Terry Reedy [110313 13:46]: > On 3/13/2011 3:17 PM, Tim Johnson wrote: > >* Tim Johnson [110313 08:27]: > > Your fundamental problem is that you changed the api of your module. > When you do that, No. I created a 'fork' of the original so that the 'fork' uses a different interface. The original API remains in legacy code unchanged... > you have to review all code that uses that api -- > or that depends on it. See above. > The test should be (and should have been) >elif isinstance(args, cgi.cgitools): Oh of course, forgot about isinstance. That is a good tip! > This would have and will fail with a loud AttributeError when > cgitools is renamed. Understood. And AttributeError would be my friend and mentor nevertheless. > Consider upgrading to 2.7 if you have not and using the logging module. :) I like my logging module, I believe it may have 'anticipated' the 2.7 module. And I can't count on my client's servers to host 2.7 for a while. > > Double double underscore names are 'special' rather than necessarily > 'private'. These two are somewhat documented (3.2 Reference, 3.1, > "__class__ is the instance’s class", "__name__ is the class name"). > So they will not change or disappear without notice. I expect them > to be pretty stable. Good to hear. Thanks Terry. -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: organizing many python scripts, in a large corporate environment.
* bukzor [110313 15:48]: > > Thanks Tim. > > I believe I understand it. You create loaders in a flat organization, > in the same directory as your shared library, so that it's found Not in the same directory as shared libraries. > naturally. These loaders use custom code to find and run the "real" > scripts. This seems to be a combination of solutions d) and e) in my > above post. In my case, the loader 1)Executes code that would otherwise be duplicated. 2)Loads modules (usually from a lower-level directory) based on keywords passed as a URL segment. > > It seems to have few disadvantages, although it does obfuscate where > to find the "real" code somewhat. It also has the implicit requirement > that all of your scripts can be categorized into a few top-level > categories. Correct. In my case that is desirable. > I'll have to think about whether this applies in my > situation... cheers -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP for module naming conventions
* Ben Finney [110313 17:15]: > Tim Johnson writes: > > > I need to be better informed on naming conventions for modules. For > > instance, I need to create a new module and I want to make sure that > > the module name will not conflict with any future or current python > > system module names. > > You'll never be able to make sure of that, and you would be needlessly > eliminating a whole lot of potentially useful names for your modules. > > Have you read and understood PEP 328, which introduces the distinction > between relative and absolute imports? It's designed to avoid the > problem your describing http://www.python.org/dev/peps/pep-0328/>. Have read, don't fully understand, but it sounds like the dust hasn't settled yet. It will sink in. thanks tim > > There may be a PEP for this, if so, a URL to such a PEP would suffice > > for my inquiry. Also, if there is an index of PEPs, a link to such > > would also be appreciated. > > PEP 0 is the index of all PEPs > http://www.python.org/dev/peps/pep-/>. > > -- > \ “Pinky, are you pondering what I'm pondering?” “I think so, | > `\ Brain, but if we have nothing to fear but fear itself, why does | > _o__) Elanore Roosevelt wear that spooky mask?” —_Pinky and The Brain_ | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Dynamic loading of module with explicit file path
FYI: Using python 2.6 on ubuntu 10, backward compatibilty to 2~ needed. Self-employed programmer 24 years. Python 9 years, part-time. I'm not addressing an existing problem, but looking for ideas that might help me to do some upgrading (if needed). I'd like to solicit comments on the following methods for dynamically loading a module from an explicit file path. Code is all untested! ## 1 :: Go there and get it. import sys,os def my_import(module_name,path): cwd = os.getcwd() os.chdir(path) if sys.path[0] != "": sys.path.insert(0,"") module = __import__(module_name) os.chdir(cwd) return module ## 2 :: temporarily modify sys.path, no dir change import sys def my_import(module_name,path): sys_path = sys.path sys.path.insert(0,path) module = __import__(module_name) sys.path = sys_path return module ## 3 :: use the imp module import imp def my_import(module_name,path): fp, pathname, description = imp.find_module(module_name,[path]) module = imp.load_module(module_name, fp, pathname, description) return module TIA -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Where to put .pth files on slax
Hello: I'm trying to put together a test platform on a slax OS. Python 2.7 packages appear to be at /user/lib/python2.7. Where is the appropriate place to put a .pth file? Note, I have django on this system too, but slax does not resolved system paths. And that is 'slax' not 'slack'. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Where to put .pth files on slax
* Tim Johnson [110325 12:59]: > Hello: I'm trying to put together a test platform on a slax OS. > Python 2.7 packages appear to be at /user/lib/python2.7. > > Where is the appropriate place to put a .pth file? I must have stumped the chumps. And this chump hasn't used pth files in a coon's age. I just used the PYTHONPATH environment variable. --- Solved. --- > Note, I have django on this system too, but slax does not resolved > system paths. And that is 'slax' not 'slack'. > -- > Tim > tim at johnsons-web dot com or akwebsoft dot com > http://www.akwebsoft.com > -- > http://mail.python.org/mailman/listinfo/python-list -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Incompatible _sqlite3.so
I have python 2.6.5 on my main workstation with ubuntu 10.04. I am attempting to set up a temporary test platform on an asus netbook with slax running from an SD card. I have installed a python 2.7 module on the slax OS. (I can't find a python 2.6.5 module for slax). For those who don't know, slax is a "pocket" OS and is very limited. In the original slax install with python 2.7, there is not _sqlite3.so available. I copied _sqlite3.so from my workstation and I am getting the following error message: "... undefined symbol: PyUnicodeUCS4_DecodeUTF8." I suspect that this is a version problem. I'd like to try _sqlite3.so for python 2.7 (32-bit). If anyone has one or can tell me where get one, I would appreciate it. I am reluctant to install 2.7 on my workstation right now. 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: Incompatible _sqlite3.so
* Alexander Kapps [110327 13:58]: > On 27.03.2011 23:24, Tim Johnson wrote: > >I have python 2.6.5 on my main workstation with ubuntu 10.04. I am > >attempting to set up a temporary test platform on an asus netbook > >with slax running from an SD card. I have installed a python 2.7 > >module on the slax OS. (I can't find a python 2.6.5 module for > >slax). For those who don't know, slax is a "pocket" OS and is very > >limited. In the original slax install with python 2.7, there is not > >_sqlite3.so available. I copied _sqlite3.so from my workstation and > >I am getting the following error message: > >"... undefined symbol: PyUnicodeUCS4_DecodeUTF8." > > > >I suspect that this is a version problem. I'd like to try > >_sqlite3.so for python 2.7 (32-bit). If anyone has one or can tell > >me where get one, I would appreciate it. I am reluctant to install > >2.7 on my workstation right now. > > > >thanks > > Slax is a very modular and flexible "pocket OS"/Live distro. It's > everything but limited .There are many additional modules available. > > Python 2.6: > http://www.slax.org/modules.php?action=detail&id=3118 That module is *not* trusted. See the warning? > Several sqlite related packages, you probably need one of the > pysqlite modules: > http://www.slax.org/modules.php?search=sqlite&category= Python 2.7 comes with its own sqlite module, but for some reason, the slax sqlite module does not provide the .so file > Finally, it's quite easy to build your own Slax modules: > http://www.slax.org/documentation_create_modules.php I'm really pressed for time, getting ready for a trip. The ** quickest would be the so file itself, maybe from the slack site or if someone has one they can send me. ** Alternatively I would try building python 2.7 from source on slax and extracting the file - I haven't used slax in some time, but earlier versions had pretty complete build tools. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Incompatible _sqlite3.so
* Alexander Kapps [110327 15:14]: > On 28.03.2011 00:21, Tim Johnson wrote: > > >>Python 2.6: > >>http://www.slax.org/modules.php?action=detail&id=3118 > > > > That module is *not* trusted. See the warning? > > > You don't trust an unverified package from the Slax site, but you > would trust some other stranger on the python-list, to not give you > a manipulated .so? You're either too paranoid or not paranoid enough > ;-) Probably not paranoid enough. Although I don't care if I hose slax on an SD card, my workstation is another matter. FYI: I have never used sqlite3 with python but am trying to put together a 'package' to tutor mysql django on the netbook. So.. I built python 2.76 on my desktop. When I do >> import sqlite3 python2.7 tells me that it can't find _sqlite3. Sure enough, no _sqlite3.so at /usr/local/lib/python2.7/lib-dynload So what else do I need to obtain install _sqlite3.so for my desktop? *NOTE* we now are discussing my ubuntu 10.04 workstation, not slax. thanks for the replies -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Incompatible _sqlite3.so
* Tim Johnson [110327 16:59]: > * Alexander Kapps [110327 15:14]: > > On 28.03.2011 00:21, Tim Johnson wrote: > > > > >>Python 2.6: > > >>http://www.slax.org/modules.php?action=detail&id=3118 > > > > > > That module is *not* trusted. See the warning? > > > > > > You don't trust an unverified package from the Slax site, but you > > would trust some other stranger on the python-list, to not give you > > a manipulated .so? You're either too paranoid or not paranoid enough > > ;-) > Probably not paranoid enough. Although I don't care if I hose > slax on an SD card, my workstation is another matter. > > FYI: I have never used sqlite3 with python but am trying to put > together a 'package' to tutor mysql django on the netbook. > So.. I built python 2.76 on my desktop. When I do > >> import sqlite3 > python2.7 tells me that it can't find _sqlite3. > Sure enough, no _sqlite3.so at > /usr/local/lib/python2.7/lib-dynload > So what else do I need to obtain install _sqlite3.so for > my desktop? I had to install libsqlite3-dev. Now I have sqlite3 working on python 2.7 on my desktop. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com -- http://mail.python.org/mailman/listinfo/python-list
Programmatically log in and request XML
FYI: Using python 2.7 on ubuntu 10.04.
I have acquainted myself with the parsing of XML data using an input file as
test data. Now I need to make a request the feed itself, and capture
that field as data.
I need to do the following:
1)Programmatically log into a site with user and password.
2)Make a GET request to a site under the same domain.
Since I have used urllib2 in the past,
>From http://docs.python.org/library/urllib2.html
I am offering a modification of the example under the heading:
"""
Use of Basic HTTP Authentication
"""
import urllib2
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm=None,
uri='http://retsgw.flexmls.com:80/rets2_0/Login',
user='**',
passwd='**')
opener = urllib2.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib2.install_opener(opener)
urllib2.urlopen('http://retsgw.flexmls.com/rets2_0/GetMetadata?Type=METADATA-TABLE&ID=Property:A&Format=STANDARD-XML')
Am I at the correct starting point?
If so, I can take it from there
If not,
Can someone recommend a better approach?
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: Codes do not run
* SKHUMBUZO ZIKHALI [110524 07:26]:
> Hi:
>
> I am learning Python on my own using a " Guide to Programming with Python"
> book. Author of the book is Micheal Dawson and I am using version 2.3.5 of
> python. When I try to run the code I do not get required results. The
> picture
> could not be loaded. I get trackback message regarding undefined module.The
> example from the book is as follows:
>
> from liveswires import games
>
> games.init(screen_width = 640, screen_height = 480, fps = 50)
> wall_image = games.load_image("wall.jpg", transparent = False)
> games.screen.background = wall_image
>
> games.screen.mainloop()
>
> Can anyone please assist me.
You should provide
1)the traceback itself.
2)Version of python
3)Operating system
4)All relevant code
Also
Do the following :
import sys
print(sys.path)
Do you see the liveswires module in the path?
--
Tim
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
--
http://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: 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
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
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: Idiomatic code validator?
* Terry Reedy [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
Re: Idiomatic code validator?
* Steve D'Aprano [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?
* Steve D'Aprano [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: 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: 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: 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.
* Paul Rudin [170103 23:17]: > Tim Johnson writes: > > > * 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. > > 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
* Paul Rudin [170103 23:17]: > Tim Johnson writes: > > > * 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. > > 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
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: Restore via pip to new OS
* Paul Moore [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 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
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: Pip Version Confusion
* Steven D'Aprano [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
Re: Pip Version Confusion
* Tim Johnson [180324 10:32]:
> * Steven D'Aprano [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
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: 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
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
* 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
* 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
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: 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
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: 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
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: 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
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 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
