[Tutor] Concerning relative import paths

2016-03-14 Thread David Aldrich
Hi My Python project's directory structure looks like this: myproj - gui | |-- python The 'gui' folder contains my main.py. The 'python' folder contains various modules that we have written. My gui/main.py contains this sort of import code: import os, sys sy

Re: [Tutor] Guidance on using custom exceptions please

2015-10-13 Thread David Aldrich
> If you don't want to let the original timeout error bubble up you can create > your own little hierarchy of exceptions: > > class ResponseError(Exception): > pass > > class TimeoutError(ResponseError): > pass > > class BadDataError(ResponseError): > pass > > Then the baseclass of

[Tutor] Guidance on using custom exceptions please

2015-10-12 Thread David Aldrich
Hi Consider a 'send' method that sends a message to another system via a socket. This method will wait for a response before returning. There are two possible error conditions: 1) Timeout - i.e. no response received 2) Illegal response received I need to communicate these errors

Re: [Tutor] How to read all integers from a binary file?

2015-10-12 Thread David Aldrich
> data = array.array("i", inf.read()) Thanks for all the answers to my question. I used the array method in the end. Best regards David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mail

[Tutor] How to read all integers from a binary file?

2015-10-09 Thread David Aldrich
Hi I have a binary file of 32-bit unsigned integers. I want to read all those integers into a list. I have: ulData = [] with open(ulBinFileName, "rb") as inf: ulData.append(struct.unpack('i', inf.read(4))) This obviously reads only one integer from the file. How would I modify

Re: [Tutor] Basic question about docstrings

2015-07-30 Thread David Aldrich
If I have a script called main.py and document a function in it: def get_value(x): """ Some text ... :param x: Some value :returns: Something useful """ What is the most basic way of showing those docstrings at the

Re: [Tutor] Basic question about docstrings

2015-07-30 Thread David Aldrich
>> If I have a script called main.py and document a function in it: >> >> def get_value(x): >> """ >> Some text ... >> :param x: Some value >> :returns: Something useful >> """ >> >> What is the most basic way of showing those docstrings at the Python >> prompt? > > Tr

[Tutor] Basic question about docstrings

2015-07-29 Thread David Aldrich
Hi If I have a script called main.py and document a function in it: def get_value(x): """ Some text ... :param x: Some value :returns: Something useful """ What is the most basic way of showing those docstrings at the Python prompt? For getting started with document

Re: [Tutor] How to return a list in an exception object?

2015-06-18 Thread David Aldrich
Thanks very much for all the answers to my question. I have taken the advice to return a list of differing files, rather than raise an exception. I do have a follow-up question: I have a list of paths that contain files I want to check. paths = [pathA, pathB] then I check the files in each pa

[Tutor] How to return a list in an exception object?

2015-06-17 Thread David Aldrich
Hi I have a function that compares a set of files with a reference set of files. All files are compared and then, if any differences were found, an exception is raised: class Error(Exception): pass def check_results(file_list): if isDifferent: raise Error('One or more resul

Re: [Tutor] How to import a dictionary from another module?

2015-06-15 Thread David Aldrich
Hi I have a solution for this now. Best regards David > -Original Message- > From: Tutor [mailto:tutor-bounces+david.aldrich=eu.nec@python.org] > On Behalf Of David Aldrich > Sent: 15 June 2015 12:03 > To: tutor@python.org > Subject: [Tutor] How to import a dicti

[Tutor] How to import a dictionary from another module?

2015-06-15 Thread David Aldrich
Hi I have defined a dictionary in a module: mydir.py: REG_LOOKUP = { 'REG_1' : some_value1, 'REG_2' : some_value2, } How would I import that dictionary from my main() function (which lives in a different module) please? Best regards David