Exposing all methods of a class

2017-02-26 Thread Pete Dowdell
I use Python, mainly with Django, for work. I was wondering if anyone 
has encountered an editor that could display a class with all inherited 
methods included in the editor's view of the class code. I am kind of 
envisaging the inherited code would be displayed differently (say, grey 
vs black), and labelled with the name of the parent class so that it 
would provide a one-stop view of the entire class structure.


I edit using vim, and use ctags to explore up the inheritance chain 
which is useful enough, but I feel it should be quite possible for the 
editor to search through the imports and grab the parent classes to 
insert into the editor view. Any suggestions? Maybe there are better 
ways of navigating inheritance but it does seem logical to expose the 
whole class code in one place, suitably annotated. I feel a plugin 
coming on.


Ta, Pete
--
https://mail.python.org/mailman/listinfo/python-list


Re: Calculating longitudinal acceleration, lateral acceleration and normal acceleration

2016-01-24 Thread Pete Dowdell

On 24/01/16 07:27, Robert James Liguori wrote:

Is there a python library to calculate longitudinal acceleration, lateral 
acceleration and normal acceleration?


Might be rocket science...

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


Re: Extracting and summing student scores from a JSON file using Python 2.7.10

2015-11-10 Thread Pete Dowdell

On 10/11/15 08:12, Bernie Lazlo wrote:

> > import json
> >import urllib
> >url ="http://www.wickson.net/geography_assignment.json;
> >response = urllib.urlopen(url)
> >data = json.loads(response.read())


All good up to data. Now:
# make a list of scores
scores = [d['score'] for d in data['comments']  if 
isinstance(d['score'], int) ]

# analysis
total_scores = sum(scores)
average_score= total_scores/float(len(scores))
min_score, max_score = min(scores), max(scores)

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


Re: Converting a string into a float that includes the negative

2015-11-08 Thread Pete Dowdell

On 08/11/15 09:11, phamton...@gmail.com wrote:

I am having issue with converting the string into a float because there is a negative, so 
only end up with "ValueError: invalid literal for float(): 81.4]"81.4]


The error is right there in the exception: you are trying to cast 
'81.4]' - that's a square bracket in the string.
You are also  removing the negative sign from your number before casting 
with your slice


this will fix it - change line:
long1 = long[1:]
to:
long1 = long[:-1]

test:
>>> TXT="[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league 
world series!"

>>> float( TXT.split('\t')[0].split(', ')[1][:-1] )
-81.4

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


Re: Problem working with subprocess.check_call

2015-10-29 Thread Pete Dowdell

On 29/10/15 16:52, David Aldrich wrote:


Hi

I am working on Linux with Python 3.4.

I want to do a bash diff on two text files and show just the first 20 
lines of diff’s output.  So I tried:


>>> cmd = 'head -20 <(diff ' + file1 + ' ' + file2 + ')'

>>> subprocess.check_call(cmd, shell=True)



You could use a shell pipe in your command - and use str.format() too 
for better readability, perhaps:


> cmd = 'diff  {} {} | head -20'.format( file1, file2 )
> subprocess.check_call(cmd, shell=True)

Although this approach would not be recommended if file1 or file2 are 
not sanitised


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


Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run

2015-08-26 Thread Pete Dowdell

On 26/08/15 04:19, RAH wrote:

  UnicodeEncodeError: 'ascii' codec can't encode character '\\xc7' in position 
15: ordinal not in range(128)


(Hi all, this is my first post to the list)

This can be a frustrating issue to resolve, but your issue might be 
solved with this environment variable:

PYTHONIOENCODING=UTF-8

Regards, pd
--
https://mail.python.org/mailman/listinfo/python-list