Jim Mooney Py3.4.3winXP | 23 May 07:56 2015

Is there a way to use "with" across suite boundaries?

'''I was using with open...:, but I'm printing a header in one function,
calling a looping
function to print detail lines, then returning to the calling function to
the footer. But that didn't work since the with statement only seems to work
with the lexical suite and the file wasn't open in the detail print
function. Is there
a way around this, other than passing the file as I have here? Also, is it a
good idea to pass a file handle like that or is there a better way?

Using the below csv file  co2-sample.csv  to print a simple HTML table
(header omitted)
Since this is a file there are enclosing single quotes not visible:

"BAHAMAS, THE",1,1,1,1,1

Program follows (py3.4, winxp):'''

htbegin = '''
table, td {border:2px solid black; border-collapse:collapse;}
td {padding:3px; background-color:pink;
(Continue reading)

Albert-Jan Roskam via Tutor | 21 May 14:55 2015

ls *.py[co] >> .hidden


I would like to hide .pyc and .pyo files because they are visually distracting. Is the aforementioned
command the best way? [1]. 

I know Python 3 uses __pycache__ (much better!), but I also need Python 2. And not writing bytecode files
altogether using what's-that-environment-var-called-again is not an option for me. I use Debian Linux
(Jessie, since today, yaaayy!)



[1] http://superuser.com/questions/200730/hiding-files-of-a-certain-extension-pyc-from-nautilus


All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation,
roads, a 

fresh water system, and public health, what have the Romans ever done for us?

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

(Continue reading)

Albert-Jan Roskam via Tutor | 21 May 10:02 2015



Wired.com features trinket.io [1] and I thought it&#39;d be nice to share this here: https://trinket.io.
Not sure whether I like this better than IPython Notebook, though.


[1] http://www.wired.com/2015/05/running-python-browser-awesome-think
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:

Grace Anne St Clair-Bates | 20 May 04:53 2015

Help with writing a bean bag toss game in python

Hello! I am trying to code a bean-bag toss game in python where the program
generates three random dots inside a turtle graphic. Each different hole
means a different score, but I don't know how to write the function to
calculate the total score with all three random points and display the
score on the score board. It is hard to explain, but if anyone has an idea
please let me know! thanks
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:

Jim Mooney Py3.4.3winXP | 20 May 01:45 2015

Getting import to use a variable name

I use python help() a good deal but get tired of paging through the
__object__ stuff to get to what I use at my level, so I wrote the following
to omit it. The problem is, I want to import it then use it as shorthelp.py
for different modules so I could just type shorthelp(modulename). Only the
import mechanism won't let me rename. I can only use the hardcoded imported
module name, shutil in this case. If I try x = anothermodule, then import
x, it doesn't work. import sys.argv[1] also doesn't work. Is there any way
to get around this? I'm mostly interested in doing this from the repl
rather than running from the console.
Py3.4 win32

import shutil  #this works to print non  __xxx  helpstrings for a module,
but I can't substitute it.
useful_helps = []
helps = dir(shutil)
for helper in helps:
    if helper[0] == '_':

for helper in useful_helps:
    print(helper.upper() + ':', helper.__doc__, '\n')



After not doing dishes for a week and washing spoon after spoon, fork after
fork, knife after knife - I suddenly understand the mathematical concept of
infinity, which is just one more damn thing after another.
(Continue reading)

Remco | 19 May 14:20 2015

create a copying tool


I am new here, and new with Python.
I use Python 2.7 on a windows computer in Pyscripter.

I've got the next problem witch I need some help with:

I need to copy several files, from several folders to a new location in the same folder structure as they are now.
And all the files I need to copy are in a text (.txt) file.

The source folder looks like this: (with in some cases even sub-folders or sub-sub-folders)

And the list.txt looks like this: (over 250 entries in the original list file) D:\source\folder1\1.jpg
D:\source\folder1\2.jpg D:\source\folder1\text3.txt D:\source\folder1\FLD\pic.tif
In every source folder there different kind of extensions that I need to copy.
I have written the script below, with the help of google, and the only action I see is the missings.txt that is produced.
With in it all the files that are not copied.
import os
import shutil

target_dir = r'D:\target\'
source_dir = r'D:\source\'
source_file = r'D:\source\list.txt'
missing_files = open("missings.txt","w")

(Continue reading)

bgenest@masonlive.gmu.edu | 19 May 17:58 2015

Myplotlab issue


I am currently working with a simple program in Python (just starting out) and am getting an error message:

Traceback (most recent call last):
  File "/Users/nomargfan661/Desktop/PythonProjects/chapter3/graphics.py", line 3
    from pylab import plot,show
line 1
    from matplotlib.pylab import *
line 269
    from matplotlib.pyplot import *
line 29
    from matplotlib.figure import Figure, figaspect
line 36
    from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
line 4
    from ._subplots import *
line 10
(Continue reading)

cartman6921 | 18 May 20:27 2015

Tkinter help?

*Below is a code made by me in 5 minutes, I am new to Tkinter so am kinda
noobish. as you can see, lemon equals 0 at the start and when you click the
button it adds 1 to the amount lemon equals. After about 15 minutes of
trying and 10 minutes googling i can find nothing to help me. when the code
loops, lemon is set back to 0 again, how do i stop lemon from being set back
to 0.

I need it so if you press the button eg 4 times, lemon=4*

from tkinter import *

root.title("Lemonade Stand")


def BuyLemon():

button = Button(root,text="Buy Lemon x1", command=BuyLemon)


View this message in context: http://python.6.x6.nabble.com/Tkinter-help-tp5095151.html
Sent from the Python - tutor mailing list archive at Nabble.com.
(Continue reading)

Stewart Lawton | 18 May 13:54 2015

Apache cgi Python Sockets classic Linux permissions and SELinux under Fedora19


Thanks to recent help from Alan Gauld and Felix Dietrich I have studied the 'classic Linux ' permissions
to allow an Apache cgi script to connect to a Python Socket.
Though I became convinced that the corrected  permissions were correct the Python cgi script still would
not work when 

called from apache even though all was OK when the cgi script was executed directly by a user.
I have found that SELinux provides further access constraints. The Fedora SELinux graphic tool and
associated 'trouble shooter' parser of the SELinux audit file made suggestions that worked for TCPIP
Sockets but failed for Unix Sockets.
(I only experimented with Unix Sockets since I could not get TCPIP Sockets to work).

Below is the textual response from the trouble shooter for TCPIP and Unix Socket connect failures .
I found that assigning PORT_TYPE to dns_port_t worked for TCPIP sockets.

SELinux is preventing /usr/bin/python2.7 from name_connect access on the tcp_socket .

If you want to allow /usr/bin/python2.7 to connect to network port 1080
you need to modify the port type.
# semanage port -a -t PORT_TYPE -p tcp 1080
where PORT_TYPE is one of the following: dns_port_t, kerberos_port_t, ocsp_port_t.

SELinux is preventing /usr/bin/python2.7 from write access on the sock_file /test/uds_socket.

Plugin: catchall_labels 
you want to allow python2.7 to have write access on the uds_socket sock_fileIf you want to allow python2.7
to have write access on the uds_socket sock_file
You need to change the label on /test/uds_socket
# semanage fcontext -a -t FILE_TYPE '/test/uds_socket'
(Continue reading)

Anubhav Yadav | 18 May 13:59 2015

Implementing a Media Streaming Server in Python

I was looking to implement a media streaming server in python, which can
stream movies to mobile based clients efficiently to multiple clients (over
50 clients )

Should I just use plain sockets to create connection or should I go with a
framework like twisted/flask?

I want to know what would be the best way to design the video/media
streaming server?

Thank you.


Anubhav Yadav
Tutor maillist  -  Tutor <at> python.org
To unsubscribe or change subscription options:

Danny Yoo | 17 May 23:50 2015

Stem and leaf plots

I was reading the "Cartoon Guide to Statistics", and came across a
description on "Stem and plot diagrams".
(http://en.wikipedia.org/wiki/Stem-and-leaf_display.)  It's sorta like
a histogram diagram, but bundles by the ten's digit, and uses the
one's digit as the "point".

Here's my attempt at describing it as a program:

Stem and leaf plotting.

import collections
import sys

def printStemPlot(values):
    """Prints a stem plot of the values."""
    stems = collections.defaultdict(list)
    for v in values:
        stems[v / 10].append(v % 10)

    low, high = min(stems.keys()), max(stems.keys())
    padding = len(str(high))
    for i in range(low, high+1):
        print(str(i).ljust(padding) + ' | ' +
              ' '.join(map(str, stems[i])))def printStemPlot(values):

(Continue reading)