Re: Quick way to calculate lines of code/comments in a collection of Python scripts?

2016-10-24 Thread Stephen Tucker
Tomasz,

How about using the command prompt command FIND /C  on each of your source
files as follows:

FIND/C "#" >NumbersOfLinesContainingPythonComments.dat
FIND/C /V "#" >NumbersOfLinesNotContainingPythonComments.dat

You would end up with two files each with a column of line counts;

Import these lines into an Excel Spreadsheet and calculate whatever you
like with them.

Stephen.



On Sun, Oct 23, 2016 at 9:51 PM, Tomasz Rola  wrote:

> On Wed, Oct 05, 2016 at 01:56:59PM -0400, Malcolm Greene wrote:
> > Looking for a quick way to calculate lines of code/comments in a
> > collection of Python scripts. This isn't a LOC per day per developer
> > type analysis - I'm looking for a metric to quickly judge the complexity
> > of a set of scripts I'm inheriting.
> >
> > Thank you,
> > Malcolm
>
> A bit more than what you asked for (and sorry for being late) but I
> find sloccount quite good. Or at least interesting (computes sloc and
> some stats about project, given project dir or a single file with
> code):
>
> http://www.dwheeler.com/sloccount/
>
> --
> Regards,
> Tomasz Rola
>
> --
> ** A C programmer asked whether computer had Buddha's nature.  **
> ** As the answer, master did "rm -rif" on the programmer's home**
> ** directory. And then the C programmer became enlightened...  **
> ** **
> ** Tomasz Rola  mailto:tomasz_r...@bigfoot.com **
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: exist loop by pressing esc

2016-10-24 Thread John Gordon
In <6e030fd0-93c1-4d23-8656-e06c411b6...@googlegroups.com> chris alindi 
 writes:

> simple while loop range(10) if user press esc exits loop

range() is typically used with for loops, not while loops.

what is your while condition?
what use is the range() value?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: multiprocess passing arguments double asterisks

2016-10-24 Thread pic8690
On Sunday, October 23, 2016 at 3:44:16 PM UTC-5, Thomas Nyberg wrote:
> On 10/23/2016 03:12 AM, pic8...@gmail.com wrote:
> > import multiprocessing as mp
> >
> > def bar(**kwargs):
> >for a in kwargs:
> >   print a,kwargs[a]
> >
> > arguments={'name':'Joe','age':20}
> > p=mp.Pool(processes=4)
> > p.map(bar,**arguments)
> > p.close()
> > p.join()
> 
> What are you trying to do? The map method is similar to the map built-in:
> 
>   
> https://docs.python.org/2/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.map
>   https://docs.python.org/2/library/functions.html#map
> 
> map(function, iterable, ...)
> Apply function to every item of iterable and return a list of the results...
> 
> You can't apply it to keyword arguments like this. There are some 
> different SO threads talking about this sort of thing:
> 
>   
> http://stackoverflow.com/questions/13499824/using-python-map-function-with-keyword-arguments
>   
> http://stackoverflow.com/questions/10212445/python-map-list-item-to-function-with-arguments
>   
> http://stackoverflow.com/questions/16874244/python-map-and-arguments-unpacking
> 
> Maybe those (especially the last one) are helpful.
> 
> Cheers,
> Thomas
Thanks for the reply.

The code snippet given by Peter is not very clear

I would like to multiprocess a function which is written in python of the form 
bar(**kwargs) which returns a value.  This example does not return anything

Would you please use my example for the map function?

I appreciate your help,

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: multiprocess passing arguments double asterisks

2016-10-24 Thread Thomas Nyberg

On 10/24/2016 12:45 PM, pic8...@gmail.com wrote:

Thanks for the reply.

The code snippet given by Peter is not very clear

I would like to multiprocess a function which is written in python of the form 
bar(**kwargs) which returns a value.  This example does not return anything

Would you please use my example for the map function?

I appreciate your help,

I'm honestly not totally sure what you want to do. However, say you want 
to do the following (btw this is basically what Dennis said i nhis last 
email, but maybe I can help clarify):


kwargs = {'param1': val1, 'param2': val2})

Then you'd like to have the following two operations performed in 
separate processes:


bar(param1=val1)
bar(param2=val2)

In that case, I guess I would do something like the following. First 
define bar_wrapper as follows (*I haven't tested any code here!):


def bar_wrapper(pair):
key, val = pair
return bar(**{key: val})

Then I would probably do something like

map(bar_wrapper, kwargs.items())

I.e. basically what I'm doing is taking the key-val pairs and producing 
a list of them (as tuples). This is something that you can apply map 
too, but not with the original function. So then the wrapper function 
converts the tuple back to what you want originally.


Hopefully I'm understanding correctly and hopefully this helps.

Cheers,
Thomas
--
https://mail.python.org/mailman/listinfo/python-list


retain dimensions for numpy slice

2016-10-24 Thread duncan smith
Hello,
  I have several arrays that I need to combine elementwise in
various fashions. They are basically probability tables and there is a
mapping of axes to variables. I have code for transposing and reshaping
that aligns the variables / axes so the usual broadcasting rules achieve
the desired objective. But for a specific application I want to avoid
the transposing and reshaping. So I've specified arrays that contain the
full dimensionality (dimensions equal to the total number of variables).
e.g.

Arrays with shape,

[1,3,3] and [2,3,1]

to represent probability tables with variables

[B,C] and [A,B].

One operation that I need that is not elementwise is summing over axes,
but I can use numpy.sum with keepdims=True to retain the appropriate shape.

The problem I have is with slicing. This drops dimensions. Does anyone
know of a solution to this so that I can e.g. take an array with shape
[2,3,1] and generate a slice with shape [2,1,1]? I'm hoping to avoid
having to manually reshape it. Thanks.

Duncan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: retain dimensions for numpy slice

2016-10-24 Thread Peter Otten
duncan smith wrote:

> Hello,
>   I have several arrays that I need to combine elementwise in
> various fashions. They are basically probability tables and there is a
> mapping of axes to variables. I have code for transposing and reshaping
> that aligns the variables / axes so the usual broadcasting rules achieve
> the desired objective. But for a specific application I want to avoid
> the transposing and reshaping. So I've specified arrays that contain the
> full dimensionality (dimensions equal to the total number of variables).
> e.g.
> 
> Arrays with shape,
> 
> [1,3,3] and [2,3,1]
> 
> to represent probability tables with variables
> 
> [B,C] and [A,B].
> 
> One operation that I need that is not elementwise is summing over axes,
> but I can use numpy.sum with keepdims=True to retain the appropriate
> shape.
> 
> The problem I have is with slicing. This drops dimensions. Does anyone
> know of a solution to this so that I can e.g. take an array with shape
> [2,3,1] and generate a slice with shape [2,1,1]? I'm hoping to avoid
> having to manually reshape it. Thanks.

Can you clarify your requirement or give an example of what you want?

Given an array 

>>> a.shape
(2, 3, 1)

you can get a slice with shape (2,1,1) with (for example)

>>> a[:,:1,:].shape
(2, 1, 1)

or even

>>> newshape = (2, 1, 1)
>>> a[tuple(slice(d) for d in newshape)].shape
(2, 1, 1)

but that's probably not what you are asking for...

-- 
https://mail.python.org/mailman/listinfo/python-list


Why doesn't Python include non-blocking keyboard input function?

2016-10-24 Thread jladasky
After reading this rather vague thread...

https://groups.google.com/forum/#!topic/comp.lang.python/FVnTe2i0UTY

... I find myself asking why Python doesn't include a standard, non-blocking 
keyboard input function.  I have often wanted one myself.  The only way that 
I've ever achieved this behavior is:

1) by restricting the user to pressing Ctrl-C while the program is running, and 
catching a KeyboardInterrupt; or

2) loading a heavyweight GUI like wxPython or PyQt, and using its event loop to 
intercept keyboard events.

I gather that non-blocking keyboard input functions aren't the easiest thing to 
implement.  They seem to depend on the operating system.  Still, ease of use is 
a primary goal of Python, and the need for this feature must be common.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Quick way to calculate lines of code/comments in a collection of Python scripts?

2016-10-24 Thread MrJean1
On Wednesday, October 5, 2016 at 1:57:14 PM UTC-4, Malcolm Greene wrote:
> Looking for a quick way to calculate lines of code/comments in a
> collection of Python scripts. This isn't a LOC per day per developer
> type analysis - I'm looking for a metric to quickly judge the complexity
> of a set of scripts I'm inheriting.
> 
> Thank you,
> Malcolm

Here is a basic LOC counter for Python source files



Re: Signals and Threads in Python 3.5 or so

2016-10-24 Thread Dan Stromberg
On Mon, Oct 10, 2016 at 12:05 AM, dieter  wrote:
> Dan Stromberg  writes:
>> I have a program http://stromberg.dnsalias.org/~dstromberg/looper/
>> that I use and maintain.
>>
>> It's like GNU parallel or similar - yet another "run n processes, m at
>> a time" implementation.  Interestingly, I've only used/tested it on
>> Linux, but it's under a Microsoft copyright because Microsoft acquired
>> a Linux company I was working for.
>>
>> Anyway, it seems to work well, except one annoying bug.
>>
>> That bug is: if you control-C the top-level process, all the
>> subprocesses are left running.
>>
>> I've been thinking about making it catch SIGINT, SIGTERM and SIGHUP,
>> and having it SIGKILL its active subprocesses upon receiving one of
>> these signals.
>>
>> However, it's multithreaded, and I've heard that in CPython, threads
>> and signals don't mix well.
>
> I would not state it this way.
>
> Signals are delivered to processes (not process threads).
> That leads to the question which thread (in a multi thread application)
> will handle a signal when it arrives.
> In Python, the design decision has been not to use the currently
> running thread (which may not be a Python thread at all or
> may have executed Python code but at the moment runs C code outside
> of Python) but let the signal be handled deterministically by
> the main thread (once it starts again to execute Python code).
> This looks like a sane decision to me.

Thank you for the clear explanation.
-- 
https://mail.python.org/mailman/listinfo/python-list


Sphinx + autodoc + apidoc

2016-10-24 Thread Dan Stromberg
Hi folks.

I'm attempting to set up Sphinx to document several API's based on docstrings.

I've got something browseable for one example API using Sphinx +
autodoc + apidoc.

However, we aren't really a PEP8 shop; we use hard tabs expanded to 4
columns, and we use 120 columns total width (and sometimes a little
more :).

I'd love to switch to spaces, but it's not my decision, so...  And
it's hard for me to imagine going back to 80 columns - it's so
confining, especially when you use good, descriptive identifiers.

Anyway, in the Sphinx pages that say "Source code for ",
and that show every line of the particular python module (syntax
highlighted), the tabs are all expanded to 8 columns, and the total
width is 80 columns.  I can scroll around to see everything, but it's
a little like looking at a football field through a microscope.

Is there any good way of making Sphinx use 4 column tabs and 120 column text?

I can imagine recursively applying *ix "expand -4" to the .py files to
get a for-doc-only tree before passing them to Sphinx, but what about
the 80 column limit?  And is there a nicer way of dealing with the tab
situation?

I googled quite a bit, and found some stuff suggesting that the Sphinx
devs would be OK with doing hard tabs, but Sphinx depends on Docutils,
and the Docutils project is perhaps more into PEP8.

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: sphinx (or other means to document python)

2016-10-24 Thread Dan Stromberg
On Sat, Sep 24, 2016 at 6:30 PM, Yann Kaiser  wrote:
> pydoctor may be something you're looking for. I don't know if it supports
> exporting to PDF like Sphinx does.
>
> As you've no doubt figured out by now, Sphinx doesn't revolve around the
> Python files themselves, but rather .rst files in which you can indeed
> instruct Sphinx to just go and document a module.

I just evaluated a bunch of docstring-extracting-for-documentation
tools, including Sphinx and pydoctor.

Sphinx isn't that hard anymore, with autodoc and apidoc.

But pydoctor appears to be Python 2.x only - that's a problem in 2016.
Please correct me if I'm wrong.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sphinx + autodoc + apidoc

2016-10-24 Thread Ned Batchelder
On Monday, October 24, 2016 at 5:00:47 PM UTC-4, Dan Stromberg wrote:
> Hi folks.
> 
> I'm attempting to set up Sphinx to document several API's based on docstrings.
> 
> I've got something browseable for one example API using Sphinx +
> autodoc + apidoc.
> 
> However, we aren't really a PEP8 shop; we use hard tabs expanded to 4
> columns, and we use 120 columns total width (and sometimes a little
> more :).
> 
> I'd love to switch to spaces, but it's not my decision, so...  And
> it's hard for me to imagine going back to 80 columns - it's so
> confining, especially when you use good, descriptive identifiers.
> 
> Anyway, in the Sphinx pages that say "Source code for ",
> and that show every line of the particular python module (syntax
> highlighted), the tabs are all expanded to 8 columns, and the total
> width is 80 columns.  I can scroll around to see everything, but it's
> a little like looking at a football field through a microscope.
> 
> Is there any good way of making Sphinx use 4 column tabs and 120 column text?
> 
> I can imagine recursively applying *ix "expand -4" to the .py files to
> get a for-doc-only tree before passing them to Sphinx, but what about
> the 80 column limit?  And is there a nicer way of dealing with the tab
> situation?
> 
> I googled quite a bit, and found some stuff suggesting that the Sphinx
> devs would be OK with doing hard tabs, but Sphinx depends on Docutils,
> and the Docutils project is perhaps more into PEP8.

Are you sure your tabs are being changed to eight spaces? It's possible they
are still tabs in the browser, and the browser is choosing to display them
as eight spaces. If that's the case, you can change the width using CSS in
the theme.  Likely the page width of 80 characters is also manipulable with
CSS.

--Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


lxml and xpath(?)

2016-10-24 Thread Doug OLeary
Hey;

Reasonably new to python and incredibly new to xml much less trying to parse 
it. I need to identify cluster nodes from a series of weblogic xml 
configuration files. I've figured out how to get 75% of them; now, I'm going 
after the edge case and I'm unsure how to proceed.

Weblogic xml config files start with namespace definitions then a number of 
child elements some of which have children of their own.

The element that I'm interested in is  which will usually have a 
subelement called  containing the hostname that I'm looking for.

Following the paradigm of "we love standards, we got lots of them", this model 
doesn't work everywhere. Where it doesn't work, I need to look for a subelement 
of  called . That element contains an alias which is expanded 
in a different root child, at the same level as .

So, picture worth a 1000 words:


< [[ heinous namespace xml snipped ]] >
   [[text]]
   ...
   
  EDIServices_MS1
  ...
  EDIServices_MC1
  ...
   
   
  EDIServices_MS2
  ...
  EDIServices_MC2
  ...
   
   
 EDIServices_MC1
 
   EDIServices_MC1
   SSL
   host001
   7001
 
   
   
 EDIServices_MC2
 
   EDIServices_MC2
   host002
   7001
 
   


So, running it on 'normal' config, I get:

$ ./lxml configs/EntsvcSoa_Domain_config.xml  
EntsvcSoa_CS=> host003.myco.com
EntsvcSoa_CS   => host004.myco.com

Running it against the abi-normal config, I'm currently getting:

$ ./lxml configs/EDIServices_Domain_config.xml
EDIServices_CS => EDIServices_MC1
EDIServices_CS => EDIServices_MC2

Using the examples above, I would like to translate EDIServices_MC1 and 
EDIServices_MC2 to host001 and host002 respectively.

The primary loop is:

for server in root.findall('ns:server', namespaces):
  cs = server.find('ns:cluster', namespaces)
  if cs is None:
continue
  # cluster_name = server.find('ns:cluster', namespaces).text
  cluster_name = cs.text
  listen_address = server.find('ns:listen-address', namespaces)
  server_name = listen_address.text
  if server_name is None:
machine = server.find('ns:machine', namespaces)
if machine is None:
  continue
else:
  server_name = machine.text

  print("%-15s => %s" % (cluster_name, server_name))

(it's taken me days to write 12 lines of code... good thing I don't do this for 
a living :) )

Rephrased, I need to find the  under the  child who's 
name matches the name under the corresponding  child. From some of the 
examples on the web, I believe xpath might help but I've not been able to get 
even the simple examples working. Go figure, I just figured out what a 
namespace is...

Any hints/tips/suggestions greatly appreciated especially with complete noob 
tutorials for xpath.

Thanks for your time.

Doug O'Leary
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Internet Data Handling ยป mailbox

2016-10-24 Thread Adam Jensen
On 10/22/2016 11:56 PM, Jason Friedman wrote:
>>
>> for message in mailbox.mbox(sys.argv[1]):
>> if message.has_key("From") and message.has_key("To"):
>> addrs = message.get_all("From")
>> addrs.extend(message.get_all("To"))
>> for addr in addrs:
>> addrl = addr.lower()
>> if addrl.find(name) > 0:
>> print message
>> break
>> -
> 
> 
> I usually see
> 
> if addrl.find(name) > 0:
> 
> written as
> 
> if name in addrl:
> 

Yeah, that would be more consistent with the 'for addr in addrs'
construct. But I've never been able to take a serious look at Python, or
develop an understanding and consistent style. The catastrophic
battology[1] present in every book I've encountered is too much of an
obstacle.

[1]: http://grammar.about.com/od/ab/g/battologyterm.htm


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Quick way to calculate lines of code/comments in a collection of Python scripts?

2016-10-24 Thread Tomasz Rola
On Mon, Oct 24, 2016 at 10:03:29AM +0100, Stephen Tucker wrote:
> Tomasz,
> 
> How about using the command prompt command FIND /C  on each of your source
> files as follows:
> 
> FIND/C "#" >NumbersOfLinesContainingPythonComments.dat
> FIND/C /V "#" >NumbersOfLinesNotContainingPythonComments.dat
> 
> You would end up with two files each with a column of line counts;
> 
> Import these lines into an Excel Spreadsheet and calculate whatever you
> like with them.

If this is what you really want to do, then why not. Albeit I would
rather go with sh script for this, with ability to process either a
directory or single file of Python code. Also, I tend to avoid tools
that are "click to work" as much as possible, so for me, this is not
good.

Using "find/c" or "grep|wc" might look like simple and quick and good
solution, but it may soon turn out to be too little, which is why I do
not consider sloccount to be an overkill (which you seem to
suggest). Especially that OP mentioned something about code
complexity, if memory serves. On my system, all it takes is:

(as root)   apt-get install sloccount

and:   sloccount alioth_nbody.lsp (or .py or what you like)

I guess it is similarly easy to install under other OSes, even under
Windows - I would try cygwin installer for this.

On the other hand, using Office (or equivalent) only to count lines
seems like royal excess. And if I want to calculate, I use lisp
interpreter interactively (believe it or not). Spritesheep, like
Excel, has some merits but I consider them poor choice for computing
anything important (I see no formula, I see no errors).

-- 
Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:tomasz_r...@bigfoot.com **
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sphinx + autodoc + apidoc

2016-10-24 Thread Dan Stromberg
On Mon, Oct 24, 2016 at 2:39 PM, Ned Batchelder  wrote:
> On Monday, October 24, 2016 at 5:00:47 PM UTC-4, Dan Stromberg wrote:

>> However, we aren't really a PEP8 shop; we use hard tabs expanded to 4
>> columns, and we use 120 columns total width (and sometimes a little
>> more :).

>> Is there any good way of making Sphinx use 4 column tabs and 120 column text?

> Are you sure your tabs are being changed to eight spaces? It's possible they
> are still tabs in the browser, and the browser is choosing to display them
> as eight spaces. If that's the case, you can change the width using CSS in
> the theme.  Likely the page width of 80 characters is also manipulable with
> CSS.

It turned out CSS was the answer.  I fixed it with:

echo 'pre {tab-size: 4;width: 80em;}' > doc/_build/html/_static/custom.css
echo 'div.document {width: 100em; margin-top: 0px; margin-bottom:
0px; margin-right: 0px; margin-left: 0px;}' >>
doc/_build/html/_static/custom.css

Though it remains to be seen if it'll look as good in other people's
browsers.  It bothers me that 120 columns of text fit so easily into
80em.  I thought 80em would be the width of 80 character cells...  It
seems like a fixed pitch font, but maybe it's really proportionate.
Using 120em was huge.

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: retain dimensions for numpy slice

2016-10-24 Thread duncan smith
On 24/10/16 19:05, Peter Otten wrote:
> duncan smith wrote:
> 
>> Hello,
>>   I have several arrays that I need to combine elementwise in
>> various fashions. They are basically probability tables and there is a
>> mapping of axes to variables. I have code for transposing and reshaping
>> that aligns the variables / axes so the usual broadcasting rules achieve
>> the desired objective. But for a specific application I want to avoid
>> the transposing and reshaping. So I've specified arrays that contain the
>> full dimensionality (dimensions equal to the total number of variables).
>> e.g.
>>
>> Arrays with shape,
>>
>> [1,3,3] and [2,3,1]
>>
>> to represent probability tables with variables
>>
>> [B,C] and [A,B].
>>
>> One operation that I need that is not elementwise is summing over axes,
>> but I can use numpy.sum with keepdims=True to retain the appropriate
>> shape.
>>
>> The problem I have is with slicing. This drops dimensions. Does anyone
>> know of a solution to this so that I can e.g. take an array with shape
>> [2,3,1] and generate a slice with shape [2,1,1]? I'm hoping to avoid
>> having to manually reshape it. Thanks.
> 
> Can you clarify your requirement or give an example of what you want?
> 
> Given an array 
> 
 a.shape
> (2, 3, 1)
> 
> you can get a slice with shape (2,1,1) with (for example)
> 
 a[:,:1,:].shape
> (2, 1, 1)
> 
> or even
> 
 newshape = (2, 1, 1)
 a[tuple(slice(d) for d in newshape)].shape
> (2, 1, 1)
> 
> but that's probably not what you are asking for...
> 

Thanks. I think that's exactly what I wanted.

Duncan
-- 
https://mail.python.org/mailman/listinfo/python-list


System-wide module path

2016-10-24 Thread Rob Gaddi
On a Linux (Ubuntu) system, with no concerns for Python < 3.4, how do I
  a) Add a directory to the system-wide (rather than per-user) module
path? 
  b) Tell pip that I would like to install a given module to there.

What's going on is that we're trying to set up an internal software
distribution system to make sure that internally-written software gets
installed on a bunch of identical machines. The easiest mechanism to
work with in all of this is a single directory on the server that can
simply be rsync'd to all of the target machines.  So if I could do my
installs to /usr/highland/python3.4/site-packages, and put all the
executable stubs that pip creates into /usr/highland/bin, then I can
just rsync all of /usr/highland.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sphinx + autodoc + apidoc

2016-10-24 Thread Ned Batchelder
On Monday, October 24, 2016 at 7:02:11 PM UTC-4, Dan Stromberg wrote:
> On Mon, Oct 24, 2016 at 2:39 PM, Ned Batchelder  
> wrote:
> > On Monday, October 24, 2016 at 5:00:47 PM UTC-4, Dan Stromberg wrote:
> 
> >> However, we aren't really a PEP8 shop; we use hard tabs expanded to 4
> >> columns, and we use 120 columns total width (and sometimes a little
> >> more :).
> 
> >> Is there any good way of making Sphinx use 4 column tabs and 120 column 
> >> text?
> 
> > Are you sure your tabs are being changed to eight spaces? It's possible they
> > are still tabs in the browser, and the browser is choosing to display them
> > as eight spaces. If that's the case, you can change the width using CSS in
> > the theme.  Likely the page width of 80 characters is also manipulable with
> > CSS.
> 
> It turned out CSS was the answer.  I fixed it with:
> 
> echo 'pre {tab-size: 4;width: 80em;}' > doc/_build/html/_static/custom.css
> echo 'div.document {width: 100em; margin-top: 0px; margin-bottom:
> 0px; margin-right: 0px; margin-left: 0px;}' >>
> doc/_build/html/_static/custom.css
> 
> Though it remains to be seen if it'll look as good in other people's
> browsers.  It bothers me that 120 columns of text fit so easily into
> 80em.  I thought 80em would be the width of 80 character cells...  It
> seems like a fixed pitch font, but maybe it's really proportionate.
> Using 120em was huge.

An em is a unit as wide as the font size. So with 12-point text, an em
is 12 points wide. Most characters are much narrower than that.  The unit is
called "em" because it's roughly the width of a capital M in a proportional
font.  Your monospace font would have 80 characters in 80em if the
characters were all square, but they are not.  Much more common is a
character width of about .6em.

Typography has a long history spanning multiple technologies, and close
connections with people and how they read, so it isn't always obvious,
though I personally find it fascinating.

--Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: System-wide module path

2016-10-24 Thread Zachary Ware
On Mon, Oct 24, 2016 at 6:49 PM, Rob Gaddi
 wrote:
> On a Linux (Ubuntu) system, with no concerns for Python < 3.4, how do I
>   a) Add a directory to the system-wide (rather than per-user) module
> path?

This is the trickier part.  There are a couple of ways to do it, but
which is better is a matter of some debate (at least in my head).  The
first option is to stick a `.pth` file in the regular site-packages
directory that points to /usr/highland/lib/python3.4/site-packages.
Another option is to set PYTHONPATH; this is one of the very few
exceptions to the rule that you never want to permanently set
PYTHONPATH.  The main differences between the two options are which
end of sys.path the directory is added to, and whether it's added when
the -S interpreter option is used (say, by system utilities).  The
`.pth` option is cleaner and safer, but `.pth` files just feel icky.

>   b) Tell pip that I would like to install a given module to there.

Use the --prefix option: `pip install --prefix /usr/highland/
alembic`.  This tells pip to install the package(s) as though Python
was installed at /usr/highland/, so libraries go in
/usr/highland/lib/python3.4/site-packages and executable stubs go in
/usr/highland/bin/.

Hope this helps,
-- 
Zach
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't Python include non-blocking keyboard input function?

2016-10-24 Thread Steven D'Aprano
On Tuesday 25 October 2016 05:14, jlada...@itu.edu wrote:

> After reading this rather vague thread...
> 
> https://groups.google.com/forum/#!topic/comp.lang.python/FVnTe2i0UTY
> 
> ... I find myself asking why Python doesn't include a standard, non-blocking
> keyboard input function.  I have often wanted one myself.  The only way that
> I've ever achieved this behavior is:
> 
> 1) by restricting the user to pressing Ctrl-C while the program is running,
> and catching a KeyboardInterrupt; or
> 
> 2) loading a heavyweight GUI like wxPython or PyQt, and using its event loop
> to intercept keyboard events.
> 
> I gather that non-blocking keyboard input functions aren't the easiest thing
> to implement.  They seem to depend on the operating system.  Still, ease of
> use is a primary goal of Python, and the need for this feature must be
> common.


Not really. I think that lots of people think they need it, but once they write 
a little utility, they often realise that it's not that useful. That's just my 
opinion, and I'm one of those guys who wrote one:

http://code.activestate.com/recipes/577977-get-single-keypress/?in=user-4172944

Me and ten thousand others.

If you (generic you, not you specifically) are telling the user "press any key 
to continue", then you probably shouldn't. *Any* key may not do anything. E.g. 
if the user hits the Shift key. A much better interface is to specify a 
specific key, and ignore anything else... in which case, why not specify the 
Enter key?

raw_input('Press the Enter key to continue... ')


If you are doing something more complex, waiting on different keys to do 
different things, then you probably should use an existing text UI like Curses, 
or a GUI like wxPython etc, rather than trying to reinvent the wheel badly.



-- 
Steven
git gets easier once you get the basic idea that branches are homeomorphic 
endofunctors mapping submanifolds of a Hilbert space.

-- 
https://mail.python.org/mailman/listinfo/python-list