Re: Understanding other people's code

2013-07-15 Thread Azureaus
On Friday, 12 July 2013 15:22:59 UTC+1, Azureaus  wrote:
> Hi all,
> 
> I've been asked to take over a project from someone else and to extend the 
> functionality of this. The project is written in Python which I haven't had 
> any real experience with (although I do really like it) so I've spent the 
> last week or two settling in, trying to get my head around Python and the way 
> in which this code works.
> 
> 
> 
> The problem is the code was clearly written by someone who is exceptionally 
> good and seems to inherit everything from everywhere else. It all seems very 
> dynamic, nothing is written statically except in some configuration files. 
> 
> Basically the problem is I am new to the language and this was clearly 
> written by someone who at the moment is far better at it than I am!
> 
> 
> 
> I'm starting to get pretty worried about my lack of overall progress and so I 
> wondered if anyone out there had some tips and techniques for understanding 
> other peoples code. There has to be 10/15 different scripts with at least 10 
> functions in each file I would say.
> 
> 
> 
> Literally any idea will help, pen and paper, printing off all the code and 
> doing some sort of highlighting session - anything! I keep reading bits of 
> code and thinking "well where the hell has that been defined and what does it 
> mean" to find it was inherited from 3 modules up the chain. I really need to 
> get a handle on how exactly all this slots together! Any techniques,tricks or 
> methodologies that people find useful would be much appreciated.

Thanks for all the suggestions, I'm afraid I didn't get a chance to view them 
over the weekend but I will get started with them this morning. I'm currently 
using sublime 2 for my text editor and tried to create a UML diagram using 
Pylint to try and get a map overview of what's going on. Unfortunately it 
seemed to map the classes into groups such as StringIO, ThreadPool, GrabOut 
etc.. rather than into the modules they belong go and how they fit together. 
Maybe this is just my inexperience showing through or I'm using the program 
wrong. If anyone has any 'mapping' programs they use to help them visualise 
program flow that would be a great bonus.

To be fair to who programmed it, most functions are commented and I can't 
complain about the messiness of the code, It's actually very tidy. (I suppose 
Python forcing it's formatting is another reason it's an easily readable 
language!) Luckily not blanked import * were used otherwise I really would be 
up the creek without a paddle. 
Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding other people's code

2013-07-25 Thread Azureaus
On Friday, July 12, 2013 3:22:59 PM UTC+1, Azureaus wrote:
> Hi all,
> 
> I've been asked to take over a project from someone else and to extend the 
> functionality of this. The project is written in Python which I haven't had 
> any real experience with (although I do really like it) so I've spent the 
> last week or two settling in, trying to get my head around Python and the way 
> in which this code works.
> 
> 
> 
> The problem is the code was clearly written by someone who is exceptionally 
> good and seems to inherit everything from everywhere else. It all seems very 
> dynamic, nothing is written statically except in some configuration files. 
> 
> Basically the problem is I am new to the language and this was clearly 
> written by someone who at the moment is far better at it than I am!
> 
> 
> 
> I'm starting to get pretty worried about my lack of overall progress and so I 
> wondered if anyone out there had some tips and techniques for understanding 
> other peoples code. There has to be 10/15 different scripts with at least 10 
> functions in each file I would say.
> 
> 
> 
> Literally any idea will help, pen and paper, printing off all the code and 
> doing some sort of highlighting session - anything! I keep reading bits of 
> code and thinking "well where the hell has that been defined and what does it 
> mean" to find it was inherited from 3 modules up the chain. I really need to 
> get a handle on how exactly all this slots together! Any techniques,tricks or 
> methodologies that people find useful would be much appreciated.

Thank you to everyone who replied constructively, the various suggestions all 
helped a lot. I'd like to suggest to anyone who reads this in the future who is 
in a similar situation to do as David Chess suggested and install eclipse with 
pydev. Although I prefer to use Sublime to actually write code, Eclipse turned 
out to be invaluable in helping me jump around and understand the code 
especially how things were passed around) and for debugging things over the 
last few days. Success!
Cheers everyone.
-- 
http://mail.python.org/mailman/listinfo/python-list


Find out where a class is used throughout a program.

2013-09-04 Thread Azureaus
Hi All,
I'm fairly new to Python so please forgive me If I sound confused or include 
anything a bit irrelevant. I've had some great responses from this group 
already though so thanks.

I have a source file that is laid out roughly like

class:
class methods
methods 
init statement
class:
method

It doesn't seem to have a run method unlike other similar source files I have 
so it seems to be that this is being referenced from other files and is almost 
a 'utility file'.

To try and make this question as general as possible - is there a way of 
finding out / visualising where a particular class is called/used throughout a 
program? I need to find out the way in which these classes are being used and 
their typical input (and where the output from these are going) so I can have a 
play around and really figure out how it works. Without a run method to call, 
or an idea of expected input/output it's difficult. Also without some sort of 
trace it's difficult.

I spoke to colleague and was told to look into dir() method in a Python shell 
which I will do this evening but if anyone has any suggestions that would be 
great. Even better if you think this is what I'm after a quick example/use case 
would be even better. Or maybe I'm looking at this the wrong way and you can 
point me towards some docs?
Thanks for your help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Importing Definitions

2013-09-05 Thread Azureaus
Hi all,
Thank you all for your help so far in the group.

Lets say I have some definitions in a module1.py e.g.

import sys
A,B,C,D,E = range(5)
def method1():
more code
end

Then a second module module2.py where I wish to use these definitions
import module1.py
print A

This will throw an error saying "global name 'A' is not defined."

Now I know if there was a method I wanted to reference I could do something 
like this in module2.
from module1 import method1

which would mean from that point on I could just reference it as method1 rather 
than module1.method1, is there such a way I could do this with definitions??

Thanks!

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


Re: Find out where a class is used throughout a program.

2013-09-05 Thread Azureaus
On Wednesday, 4 September 2013 17:32:28 UTC+1, Azureaus  wrote:
> Hi All,
> 
> I'm fairly new to Python so please forgive me If I sound confused or include 
> anything a bit irrelevant. I've had some great responses from this group 
> already though so thanks.
> 
> 
> 
> I have a source file that is laid out roughly like
> 
> 
> 
> class:
> 
> class methods
> 
> methods 
> 
> init statement
> 
> class:
> 
> method
> 
> 
> 
> It doesn't seem to have a run method unlike other similar source files I have 
> so it seems to be that this is being referenced from other files and is 
> almost a 'utility file'.
> 
> 
> 
> To try and make this question as general as possible - is there a way of 
> finding out / visualising where a particular class is called/used throughout 
> a program? I need to find out the way in which these classes are being used 
> and their typical input (and where the output from these are going) so I can 
> have a play around and really figure out how it works. Without a run method 
> to call, or an idea of expected input/output it's difficult. Also without 
> some sort of trace it's difficult.
> 
> 
> 
> I spoke to colleague and was told to look into dir() method in a Python shell 
> which I will do this evening but if anyone has any suggestions that would be 
> great. Even better if you think this is what I'm after a quick example/use 
> case would be even better. Or maybe I'm looking at this the wrong way and you 
> can point me towards some docs?
> 
> Thanks for your help.

Thanks you all for your time and responses they have been a great help. The 
practical examples were especially helpful. I'm going to go through the 
suggestions and try them out to find which one is most suited but overall I 
feel like my understanding/knowledge of Python has increased which is really 
the whole point. I think I'm going to be a regular here :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Importing Definitions

2013-09-06 Thread Azureaus
Thanks for the advice, much appreciated - I didn't realise you could also 
import definitions. I do always read the documentation before posting but 
sometimes I don't know how it's necessarily applicable to my own case sometimes 
- hence the post. I'll avoid using '*' at all costs, I've had the pleasure of 
going through lots of Python code recently not written by myself and I can see 
how that would make it a total nightmare to figure out what was going on.

I think Python is awesome and look forward to actually getting good with it.
Cheers!

On Thursday, 5 September 2013 13:39:37 UTC+1, Azureaus  wrote:
> Hi all,
> 
> Thank you all for your help so far in the group.
> 
> 
> 
> Lets say I have some definitions in a module1.py e.g.
> 
> 
> 
> import sys
> 
> A,B,C,D,E = range(5)
> 
> def method1():
> 
> more code
> 
> end
> 
> 
> 
> Then a second module module2.py where I wish to use these definitions
> 
> import module1.py
> 
> print A
> 
> 
> 
> This will throw an error saying "global name 'A' is not defined."
> 
> 
> 
> Now I know if there was a method I wanted to reference I could do something 
> like this in module2.
> 
> from module1 import method1
> 
> 
> 
> which would mean from that point on I could just reference it as method1 
> rather than module1.method1, is there such a way I could do this with 
> definitions??
> 
> 
> 
> Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Phone Tree

2015-09-13 Thread Azureaus
Hi,
I'm helping out some teenagers (14yo ish) who have just started programming and 
are working on a 'call tree' program as part of some after school coding 
classes and I wanted to talk about potential solutions. 

The first task is to implement a 'troubleshooting program' similar to what a 
phone operator would have when you phone up with a problem. We all know the 
type when you phone up your ISP, 'have you turned it off and on again?', "have 
you changed your telephone filter' etc..

It states there should be at least 10 questions and that the user should reach 
a solution, e.g. 'replace your power cable'. There and my initial reaction was 
that this could be achieved by lots of if/else statements with each question 
running onto another one, ugly but it would certainly work. One of them pointed 
out how inefficient this was and asked if there was another way, they hated 
writing out tons of if/elif/else statements.

Does anyone have any ideas for a more elegant solution? My thoughts are that I 
could use a tree data structure and hence make traversing the tree recursive 
based on yes or no answers. I'm happy to put the time in to explain these more 
complex ideas, I'm just hoping those with more expertise than myself could 
either help verify the idea or suggest alternatives.

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