Re: [Tutor] Variable data to CSV

2015-02-28 Thread Cameron Simpson

On 27Feb2015 23:16, alan.ga...@btinternet.com  wrote:

On 27/02/15 20:00, Thomas Toker wrote:

I need to find the device address, usb port, and number of times the error 
occurs


OK, Assume we don;t know anything about USB
Explain how that relates tom your sample data below.
Which columns do you want to extract/process?
Your data is not consistent in structure so using csv is
probably more trouble than its worth.


The OP wanted to write the results of his scan as CSV. The input isn't CSV; it 
looks like Linux kernal demsg output with time-since-boot timestamp prefixes.



Look at using split() based on both spaces and colons.


I'd be:
 - using split on space as suggested
 - discarding/skipping (possibly noting) the timestamp column
 - grabbing column 2 and checking for "hub" or "usb", ignoring other lines
 - grabbing column 3 as the device designator; looks like 1+2 is a useful 
device key
 - keeping some state for the counting, and resetting the counter when you see 
a new device
 - for extra points, later, keeping multiple state in case thiese processes 
ever overlap

I would suggest using "in" to check for strings and because they are very fixed 
in kernel messages, checking for long strings:


 # split line into words
 words = line.split()
 if "new high speed USB device using ehci_hcd and address" in line:
   # get port number from last field
   port = int(words[-1])

and so forth. Must simpler.

Regarding counters:

 # at start of script:
 counts = {}   # dict of counter based on port (or better, (device, port))

 # when new device seen (nb: possibly print out accumulated prior count value)
 count[port] = 0

 # when new error seen
 count[port] += 1

Chase CSV as a totally separat thing later; just use print() for now.

Cheers,
Cameron Simpson 

I am of course experienced in teaching and have read the writings of Socrates.
   - egnil...@phoenix.princeton.edu
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] BinaryTrees

2015-02-28 Thread Fatimah Taghdi
So i am doing this assignment and we have  make a function that changes a
binary tree represenation list of lists to nodes and I was wondering if
somone can help on where to start and If there is a possiblity of keeping
track of the indexdes.

-- 

*F.T.*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] BinaryTrees

2015-02-28 Thread Ben Finney
Fatimah Taghdi  writes:

> So i am doing this assignment and we have make a function that changes
> a binary tree represenation list of lists to nodes and I was wondering
> if somone can help on where to start

Your course material (if it's any good) will have given you good places
to start. You will already have gained knowledge of the fundamental
pieces to use, and the ability to put them together.

Start by experimenting! Use the parts you've already learned about, read
the assignment and relate the concepts there to the concepts you've
already learned.

Then show us the code you've come up with.

Honestly, it's much more valuable to fit this into the course you're
doing, than to have someone tell you “where to start”. Start with the
preceding lessons :-)

-- 
 \  “I put instant coffee in a microwave oven and almost went back |
  `\  in time.” —Steven Wright |
_o__)  |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor