Alex Hall | 25 May 20:11 2016

Logging exceptions, but getting stderr output instead

Hello again list,
I didn't expect to be back so soon. :) I'm trying to log my new script, and works fine. However, logger.exception() doesn't; I see the
exception print to stderr, and it never appears in the log. Oddly, info
messages after that appear in the shell and in my log, whereas normally
they are only in the log. Here's my logger setup:

logger = logging.getLogger(appName)
infoLogFormatter = logging.Formatter("%(asctime)s\n%(name)s, %(levelname)s:
%(message)s", datefmt = "%I:%M:%S %p, %B %d, %Y")
infoLogFileName = appName+".log"
infoFileHandler = logging.FileHandler(infoLogFileName, mode="w")
infoFileHandler.level = logging.INFO

Then, I deliberately called a non-existant function:

for rep in reps:
  workbook = xlsxwriter.Workbook(workbookName)
  worksheet = workbook.addWorksheet( #should be add_worksheet, so
this errors out
  logging.exception("Error generating spreadsheet for {name}".format(name=

The string I pass to logging.exception, along with the stack trace, print
to the command line and not to my log file. Other calls also
(Continue reading)

Alan Gauld via Tutor | 25 May 18:19 2016

Re: Fwd: Re: I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.

On 25/05/16 14:11, Angelia Spencer wrote:
> in your code below you're telnet-ing to a website,

No, I'm telnetting to a server with the IP address
(which is obviously fictitious, but could be any valid IP address).
There is nothing that says it's a web site. (And even some web
sites might allow telnet access, that's just an admin thing)

> I am not and when I type, >>> response = I get an error.
> >>>
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: Telnet instance has no attribute 'read'
> >>>

Sorry, I misremembered the method name.
Here is an actual session using a public telnet site:

>>> import telnetlib
>>> tn = telnetlib.Telnet('')
>>> response = tn.read_some()
>>>b'\r\nConnected to TELEH'
b'\r\nConnected to TELEH'
>>> tn.close()

There are a bunch of other read_xxxx() methods, you
need to read the help page to find out how they differ.
-- Alan G Author of the Learn to Program web site
(Continue reading)

Alex Hall | 25 May 18:05 2016

Baffling problem with a list of objects sharing a property

Hello all,
I've used Python off and on for years, and consider myself pretty good with
it. I was on this list quite a while ago and learned a lot, but hadn't used
Python for a while so eventually unsubscribed.

Now I'm using Python for work, and have run into a problem that has me
baffled. It's as though a bunch of class instances in a list are sharing a
single property. Have a look at this script:

class Test(object):
 def __init__(self, name, paths=[]): = name
  self.paths = paths

 def __str__(self):
  return "Name: {name}. Path count: {paths}.".format(,

#end class Test

tests = [

for t in tests:
 print t
 print t
(Continue reading)

Alan Gauld via Tutor | 25 May 02:08 2016

Fwd: Re: I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.

Forwarding to the list.
Please use reply-all to respond to list messages.

Also please use plain text as HTML messages often result in
code listings being corrupted, especially the spacing, which
is very important in Python.

-------- Forwarded Message --------

> I just opened the python IDLE 3.5 on my MAC and I imported telnet.lib.
> On the next line I typed telnet and I got an error. It said
> invalid syntax. I'm trying to telnet to my other MAC here at home, just
> to see if I can connect.

You cannot just type telnet commands into Python you need to use
the telnet API. (Type help(telnetlib) at the >>> prompt or visit the
modules documentation page)

A typical session might look something like:

>>> import telnetlib
>>> tn = telnetlib.Telnet('')
>>> response =
>>> print(response)
..... some stuff here ....
>>> tn.close()

That's assuming you have telnet access to of course, many sites
don't allow it because of the security issues associated with telnet.
ssh is
(Continue reading)

Alan Gauld via Tutor | 25 May 02:10 2016

Fwd: Re: I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.

Forwarding to list...

-------- Forwarded Message --------

The box is my controller with and IP address, I'm doing all this from my
windows 7 PC. 
As I said I can type telnet in the dos cmd prompt and get to
my controller. I wrote a python script with the user_acct dictionary.

I do get the >>> in the python IDLE but within my python script/file can
I telnet to my controller? Keep in mind when I do log into my controller
it's command line driven.

I have python 2.7 and 3.5 installed on my windows 7 pc.

So you're saying open the python IDLE and import the telnet lib and just
type; telnet and I'll be able to get to my controller???

Thank you for helping me :) cannot direct the wind but you can adjust your sails...

*Angelia Spencer (Angie)*

*From:* Alan Gauld via Tutor <tutor <at>>
*To:* tutor <at>
*Sent:* Tuesday, May 24, 2016 2:38 PM
*Subject:* Re: [Tutor] I've subscribed to your service, no confirmation
(Continue reading)

Angelia Spencer via Tutor | 24 May 19:06 2016

I've subscribed to your service, no confirmation yet. I'm looking for a tutor and I need help with some code.

 I'm trying to telnet to my box. When I do this in DOS it's simple, I even have a blinking cursor for me to type
in commands for each response. Not so for python. I have a dictionary "user_acct" which has the username
and password in it. My box is interactive, I must be able to type in commands and I don't know how to do this in
python. Pleasehelp me any way you can.
1st prompt = Username:2nd prompt = Password:

After this my box's output looks like this:Last Login Date      : May 24 2016 09:42:08
Last Login Type      : IP Session(CLI)
Login Failures       : 0 (Since Last Login)
                     : 0 (Total for Account)
TA5000>then I type en and get
TA5000# then I type conf t and getTA5000(config)#
My code is below:

import getpass
import sys
import telnetlibusername = input()
password = input()
tid = 'TA5000'
first_prompt = '>' # type 'en' at this prompt
second_prompt = '#' # type 'conf t' at this prompt
third_prompt = '(config)'
prompt1 = tid + first_prompt
prompt2 = tid + second_prompt
prompt3 = tid + third_prompt + second_prompt
host = ""
#username = "ADMIN" + newline
#password = "PASSWORD" + newline
tn = telnetlib.Telnet(host,"23")
(Continue reading)

Terry--gmail | 24 May 00:08 2016

Learning Regular Expressions

Running Linux Mint
The YouTube Sentdex Video tutor I am following.
He is working in Python3.4 and I am running Python3.4.3

He's demonstrating some Regular Expressions which I wanted to test out. 
On these test scripts, for future referrence, I have been putting my 
notes in Tripple Quotes and naming the scripts descriptively to be able 
to find them again, when I need to review. However, this time, when  I 
copied in a simple script below my RE notes, and ran it from IDLE (and 
from Console) I got the following error:

SyntaxError:  EOF while scanning triple-quoted string literal

Now, there was also a tripple-quoted string I had set a variable to in 
my I thought it was the active part of the script! But 
eventually, through the process of elimination, I discovered the 
scripted worked great without the notes!  I'd like to know what it is in 
the below Tripple-Quoted section that is causing me this problem...if 
anyone recognizes. In IDLE's script file..._it's all colored green_, 
which I thought meant Python was going to ignore everything between the 
tripple-quotes! But if I run just the below portion of the script in 
it's own file, I get the same While Scanning Tripple-Quotes error.

#!/usr/bin/env python3

Regular Expressions - or at least some


(Continue reading)

Crusier | 24 May 05:17 2016

Web Page Scraping

Dear All,

I am trying to scrape a web site using Beautiful Soup. However, BS
doesn't show any of the data. I am just wondering if it is Javascript
or some other feature which hides all the data.

I have the following questions:

1) Please advise how to scrape the following data from the website:


Type, Listing Date (Y-M-D), Call / Put, Last Trading Day (Y-M-D),
Strike Price, Maturity Date (Y-M-D),  Effective Gearing (X),Time to
Maturity (D),
Delta (%), Daily Theta (%),  Board Lot.......

2) I am able to scrape most of the data from the same site


 Please advise what is the difference between these two sites.
Attached is my code

Thank you


from bs4 import BeautifulSoup
(Continue reading)

Palanikumar Gopalakrishnan | 23 May 09:54 2016

which is best python 2 or python3

Hi buddies,
                    I read one article on internet which is said python 2
and python3 is totally different in programming.
As a beginner which i prefer for my learning,  python 2 or python3 ?

Tutor maillist  -  Tutor <at>
To unsubscribe or change subscription options:

Saidov | 21 May 20:34 2016

Python 3: string to decimal conversion

Hello all,

I am working on a piece of python code that's supposed to help me manage a

1. Read a banking statement
2. Categorize expenses and income by month and by type
3. Print out a report comparing the projected expenses/income with actual

*File characteristics:*
Banking statement in a csv file format.
contents: 5 columns, 1st column= date, 4 column=expenses
date format: mm/dd/yyyy, type: string
expenses format: ($0.00), type: string
income format: $0.00, type: string

*Python Version: 3.5 (64 bit)*
IDE:Microsoft Visual Studio Community 2015
Version 14.0.25123.00 Update 2

Python Tools for Visual Studio   2.2.40315.00
Python Tools for Visual Studio provides IntelliSense, projects, templates,
Interactive windows, and other support for Python developers.

 I want to convert expense/income values into a decimal form so I could sum
them into appropriate buckets according to the month in which they occur. I
am getting the following error message when I run my code:

(Continue reading)

Max Jegers | 21 May 03:21 2016

What these Python user-defined functions do?


I started learning Python (v3.5) and was given some code samples to assist
in my studies. There are some things I could not figure out using Python
documentation or other online sources. I have experience with SQL
programming and some procedural programming, but little in terms of OOP.

I try to slice and dice a Python script that exports a shipment from ERP
system to a text file.

Shipment consists of a Header (H, one record) and Details (D, one or more

Script first imports a library with a number of user-defined functions.
Then the script uses functions defined in library to do exporting to a text

Here is the part of the library:

class View:

def __init__(self):

              self.handle = None


def order(self, n):

              return hostviewOrder(handle, self.handle, n)
(Continue reading)