Thomas Toker | 27 Feb 21:00 2015

Variable data to CSV

Hey all so I'm new to python(like 2 days ago new) I need to find the device address, usb port, and number of
times the error occurs Heres what I have: 
import re import csv
import reimport csvf = open("file.txt", "r") #location of log file
searchlines = f.readlines()                   #create list from filef.close()for element in
searchlines:     usbPres = re.search('(USB)',element)  #pattern to find usb lines     devAddr
= re.search('(address)\s\d+',element)  #parsing pattern for device address     port =
re.search('(port)\s\d',element)  #parsing pattern for port     if usbPres:         This is
where I get lost because I want to assign the correct port to device address and then count number of time it
failed before a new device is inserted into that port. then write it to a CSV

**** SAMPLE TEXT ***
[11883.112089] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11883.224080] usb 1-7: new high speed USB device using ehci_hcd and address 42
[11883.328151] hub 1-0:1.0: unable to enumerate USB device on port 7
[11904.472097] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11907.440096] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11910.408093] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11913.376095] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11913.616090] usb 1-7: new high speed USB device using ehci_hcd and address 47
[11913.716121] hub 1-0:1.0: unable to enumerate USB device on port 7
[11927.340096] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11930.308096] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11933.276124] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11936.244118] hub 1-0:1.0: Cannot enable port 3. Maybe the USB cable is bad?
[11939.212116] hub 1-0:1.0: Cannot enable port 7. Maybe the USB cable is bad?Any help is much appreciated.Tom

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
(Continue reading)

Rishi Ganesh V | 27 Feb 13:21 2015
Picon

Re: Tutor Digest, Vol 132, Issue 57

how to pass the argument in the command line
i have the input file as csv and output file as txt
both input file and output file i am passing the value to an argument

like
inputfile=sys.argv[1] , output file=sys.argv[2]

convert(inputfile,outputfile)

how to pass the value in argument

On Fri, Feb 27, 2015 at 4:30 PM, <tutor-request <at> python.org> wrote:

>  [image: Boxbe] <https://www.boxbe.com/overview> This message is eligible
> for Automatic Cleanup! (tutor-request <at> python.org) Add cleanup rule
> <https://www.boxbe.com/popup?url=https%3A%2F%2Fwww.boxbe.com%2Fcleanup%3Ftoken%3DSsvtCVRkSHyy2ZOz%252BKAD0kZT6ycCZZheON%252Bq6mOmcXydLmTk%252BpDuKzgMM64Vcz6NRClN2E6kXxuIWs3nMDzy0SfYh0gAqhA%252Bhgrj57WnHuIuP1N1AYJGr%252Fm8sqNL7XNsLsrkdC%252BPQusCtgmOPqlf9Q%253D%253D%26key%3Dern%252BAFx0dKIEaMdbdH29X8RHL%252BlM4fGaLKtde%252BH6UDo%253D&tc_serial=20566764364&tc_rand=1876920614&utm_source=stf&utm_medium=email&utm_campaign=ANNO_CLEANUP_ADD&utm_content=001>
> | More info
> <http://blog.boxbe.com/general/boxbe-automatic-cleanup?tc_serial=20566764364&tc_rand=1876920614&utm_source=stf&utm_medium=email&utm_campaign=ANNO_CLEANUP_ADD&utm_content=001>
>
> Send Tutor mailing list submissions to
>         tutor <at> python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>         tutor-request <at> python.org
>
> You can reach the person managing the list at
>         tutor-owner <at> python.org
>
(Continue reading)

shouqiang1989 | 27 Feb 04:19 2015

Remove a blank row of a Table

Hello, everybody,      I came accross a question a few days 
ago. I wrote a Python script to copy something to a table in a word 
file. For some reaons, there are some blank rows. And I want to remove 
the blank rows. I tried many ways, but all didn't work. Below is the 
code. The code in blue is to remove the  blank row.

import codecs
import os
import textwrap
import win32com,string,shutil
from win32com.client import Dispatch,constants
def ReportPackage(reportName, reportApi, package=None):
    desfile='C:\\Daten\\TestCASE5\\Model_hill.doc'
    w = win32com.client.Dispatch('Word.Application')
    w.Visible = 1
    os.path.join(reportApi.GetReportDir(), reportName)
    fd = w.Documents.Open(desfile)              #open the model file    info = reportApi.GetInfo()
    if package is None:
        package = reportApi.GetMainPackage()
        result = info.GetResult()
        execTime = info.GetExecutionTime()
        pkgName =package.GetName()
    else:
        result = package.GetResult()
        execTime = package.GetTime()
    i=1
    s=0
    f=0
    e=0

(Continue reading)

Picon

Help with python in MAC OS 10.6

Dear tutor,
I'd like to ask for help with an issue I have with python. My MAC is with OS 10-6.8, darwin kernel, 64 bits. For
some reason I updated macports and it automatically updated python to 2.7 with a 32 bits library, and it is
giving me lots of trouble. I can't install any new software that uses python, and recently I tried to use
some plot (matplotlib) routines that were working fine before, simply didn't work, the window with the
plot didn't open.Is there a way to force macports to install a 64bits version of python?I downloaded and
installed the 3.4 and 3.1 myself, but still the computer only sees the version macports installed.Thank you!Regards,
Bárbara
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Willie Sims | 26 Feb 21:51 2015

Use python to parse the subject line of emails, listen for and react to commands

Hello I have been trying to figure out a way to parse the subject line of new emails in Gmail, the subject line
will be commands for another python script. I know this isn't the most secure way of doing things but it is
for a Beagle Bone, I'm really new to python and don't know of this is even possible though I don't see why not.
The way I thought it would work would to have py check email subject lines coming from one sender when it sees
a subject  "Command(the command to follow)" it would then start another py script with that command, or
otherwise sees the subject Settings(the item to change(the change)) it would change a settings page.
I haven't found any examples of using py to loop back on itself like this, mostly I'm sure because this is not
secure and easy to hack and clunky for remote access, 
I know py can parse emails,  but I cant figure out how to limit to only the subject and only if its in that certain
format and only if its coming from a recognized email address and since I'm using 3.4 it seems all the other
kind of examples don't work half the time anyway.
can someone point me in the right direction  
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Huijae | 26 Feb 19:04 2015
Picon

Gaussian process regression

Hi, I am trying to use Gaussian process regression for Near Infrared spectra. I have reference
data(spectra), concentrations of reference data and sample data, and I am trying to predict
concentrations of sample data. Here is my code. 
from sklearn.gaussian_process import GaussianProcess gp = GaussianProcess() gp.fit(reference,
concentration) concentration_pred = gp.predict(sample) The results always gave me the same
concentration even though I used different sample data. When I used some parts of reference data as sample
data, it predicted concentration well. But whenever I use different data than reference data, it always
gave me the same concentration. Can I get some help with this problem? What am I doing wrong? I would
appreciate any help. Thanks, Jay  		 	   		  
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

shouqiang1989 | 26 Feb 06:53 2015

Remove a blank row of a Table

Hello, everybody:     I came accross a question a few days 
ago. I wrote a Python script to copy something to a table in a word 
file. For some reaons, there are some blank rows. And I want to remove 
the blank rows. I tried many ways, but all didn't work. Below is the 
code.    desfile='C:\\Daten\\TestCASE5\\Model_hill.doc'
    fd = w.Documents.Open(desfile)    lNam = textwrap.wrap(reportItem.PName)
    maxLines = len(lNam)    for idx in xrange (1,maxLines) :
        if fd.Tables[6].Rows[idx].Cells[1] == None :
              fd.Tables[6].Rows[idx].Remove()
         else :
               pass
Thanks in advance

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Fatimah Taghdi | 26 Feb 12:52 2015
Picon

Don't get it

I have a qestion about understanding my assignment. I was wonerding if it
is possible for someone to expalin. it

this is whar it asks of
This assignment question will give you practice with recursive
backtracking. You are to create a class called AnagramSolver that uses a
word list to find all combinations of words that have the same letters as a
given phrase. You might want to first look at the sample log of execution at
the end of this part of the assignment

and i am unsure of how to work with these guidlines for the constructor of
the class

 A constructor, __init__. Takes a list of words, and constructs an anagram
solver that will use the given list as its dictionary. It is not to modify
the list

--

-- 

*F.T.*
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Ken G. | 26 Feb 13:13 2015
Picon

Rearranging a list

Assuming I have the following list and code how do I best be able 
rearrange the list as stated below:

list = [0, 0, 21, 35, 19, 42]

Using print list[2:6] resulted in the following:

2    21
3    35
4    19
5    42

I would like to rearrange the list as follow:

5    42
3    35
2    21
4    19

I tried using list.reverse() and print list[0,6] and it resulted in:

[42, 19, 35, 21, 0, 0] or as printed:

0    42
1    19
2    35
3    21
4    0
5    0

(Continue reading)

kcberry | 26 Feb 05:30 2015

Don't Understand Problem

So I am new to this, and I have a book call /Hello Python by Anthony Briggs/.
It is a good book but it is using Python 2 I think and I can't get my code
to work. I get an "AttributeError: 'range' object has no attribute
'remove'". I have tried to look it up on the web with no luck. Can someone
help me understand this . 

**********
#Setting up the cave
from random import choice

cave_numbers = range(0,20)
caves = []
for i in cave_numbers:
    caves.append([])

#Setting up cave network
unvisited_caves = range(0,20)
current = 0
visited_caves = [0]
*unvisited_caves.remove(0)*

#Main loop of linking cave network
while unvisited_caves != []:
#Picking a random visited cave
    i = choice(visited_caves)
    if len(caves[i]) >= 3:
        continue

#link to unvisited caves
    next_cave = choice(unvisited_caves)
(Continue reading)

kailash ganesh | 26 Feb 07:54 2015
Picon

How to save telnet output logs to a text file in python

Hi All,

Please someone help on the below request.

I am learning python and trying to connect my satellite decoder using
telnet. When I tried to connect my device through telnet python script, I
could successfully connected to the device.

But i want to capture/save as well as read the output and logs of device
(connected thru telnet) from starting in a text file. Also, i want to send
few commands to get the output of the command and store in the text file.

Please kindly help on how to capture and write the output logs of device
connected thru telnet connection in a local text file.

Note: Once the password is successful, my device prints some set of logs
and it has to capture in the local text file, also the output of commands
should also record in the text file.

   1. HOST = "192.131.244.100"
   2. user = "user"
   3. password = "user"
   4.
   5. tn = Telnet(HOST)
   6. tn.read_until("Login: ")
   7. tn.write(user + "\n")
   8. tn.read_until("Password: ")
   9. tn.write(password + "\n")
   10. time.sleep(5)
   11. tn.write("lr\n") # lr is command to pause logs
(Continue reading)


Gmane