Crashing and opening problems

2020-10-09 Thread Jamie
   I’ve downloaded python and when I try to launch a application to use with
   python it opens then closes fast but when I double click it it opens the
   installer and not python, so I have to use “Open with”

    

    

   Sent from [1]Mail for Windows 10

    

References

   Visible links
   1. https://go.microsoft.com/fwlink/?LinkId=550986
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Requests for webbrowser module

2016-09-16 Thread Jamie Ansell
Thanks for your help, I realise that what I wanted was chromes default new
tab page, not a blank page. 'about:blank' worked fine but it wasn't what I
wanted sorry. I'll try the CTRL+4 later and see it that works.

On 14 Sep 2016 21:11, "John Gordon"  wrote:

> In  Jamie <
> ja9...@my.bristol.ac.uk> writes:
>
> > I am not sure if this is an intended consequence but when using the
> > webbrowser module to open a new blank browser tab in chrome it opens it
> > in a new browser window instead of using the current window. Providing
>
> There is an internal setting within Chrome that controls whether new pages
> are opened in a new tab or a new window.  Perhaps that is your issue?
>
> --
> John Gordon   A is for Amy, who fell down the stairs
> gor...@panix.com  B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Requests for webbrowser module

2016-09-14 Thread Jamie

Hi,

I am not sure if this is an intended consequence but when using the 
webbrowser module to open a new blank browser tab in chrome it opens it 
in a new browser window instead of using the current window. Providing 
any complete url provides different behaviour, it opening a new tab in 
the current browser window. Below is some code that produces the 
different behaviours.


blank tab code:
import webbrowser

chrome = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
url = "chrome://newtab"
webbrowser.get(chrome).open_new_tab(url)
webbrowser.get(chrome).open_new_tab(url)

normal tab code:
import webbrowser

chrome = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
url = "http://google.com";
webbrowser.get(chrome).open_new_tab(url)
webbrowser.get(chrome).open_new_tab(url)

I would like to be able to open new blank tabs in the current browser 
window if possible. If you know of a way to do this with the webbrowser 
module I would appreciate your help. Also is there any chance that the 
ability to close browser tabs will be added to the webbrowser module soon?


Kind Regards,
James Ansell
--
https://mail.python.org/mailman/listinfo/python-list


Proposal for new minor syntax

2015-03-27 Thread Jamie Willis
I would like to propose a new piece of syntax for the python language; .=

In short, the operator is form of syntactic sugar, for instance consider
the following code:

hello = "hello world  "
hello = hello.strip()

This could be written as:

hello = "hello world  "
hello .= strip()

In this slightly contrived example, the programmer saved (a small amount
of) time when writing the code. With code with longer variable names, or
lots of similar statements all in a row, this helps to keep code more
concise.

The operator would be constricted to one method or field on the right-hand
side, which must belong to the object on the left hand side.

Another example could be when using Linked Lists, instead of writing
something like:

loop_node = loop_node.next

you could write:

loop_node .= next

Does this idea have any chance of acceptance if submitted as a PEP? What
are the potential concerns I could consider with the syntax?

Thanks,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib Contour Plots

2014-08-20 Thread Jamie Mitchell
On Tuesday, August 19, 2014 10:21:48 PM UTC+1, pec...@pascolo.net wrote:
> Jamie Mitchell  writes:
> 
> 
> 
> > You were right Christian I wanted a shape (2,150).
> 
> >
> 
> > Thank you Rustom and Steven your suggestion has worked.
> 
> >
> 
> > Unfortunately the data doesn't plot as I imagined.
> 
> >
> 
> > What I would like is:
> 
> >
> 
> > X-axis - hs_con_sw
> 
> > Y-axis - te_con_sw
> 
> > Z-axis - Frequency
> 
> >
> 
> > What I would like is for the Z-axis to contour the frequency or
> 
> > amount of times that the X-axis data and Y-axis data meet at a
> 
> > particular point or bin.
> 
> >
> 
> > Does anyone know what function or graph could best show this?
> 
> 
> 
> in my understanding, you have 3 arrays of data that describe 3D data
> 
> points, and you want to draw a 2D contour plot...
> 
> 
> 
> in this case you have to interpolate the z-values on a regular grid,
> 
> that's very easy if you already know what to do ;-)
> 
> 
> 
> here I assume that data is in a .csv file
> 
> 
> 
> % cat a.csv
> 
> 0 ≤ x ≤ 10, 0 ≤ y ≤ 10, z = cos(sqrt((x-5)**2_(y-5)**2))
> 
> 1.922065,5.827944,-0.998953
> 
> 7.582322,0.559370,0.411861
> 
> 5.001753,3.279957,-0.148694
> 
> ...
> 
> 
> 
> of course my z's are different from yours, but this shouldn't be a
> 
> real problem --- and here it is my *tested* solution (tested on python
> 
> 2.7, that is), please feel free to adapt to your needs
> 
> 
> 
> hth, ciao
> 
>g
> 
> 
> 
> % cat contour.py
> 
> from numpy import loadtxt, linspace
> 
> from matplotlib.mlab import griddata
> 
> import matplotlib.pyplot as pl
> 
> 
> 
> # open 'a.csv', specify the delimiter, specify how many header rows,
> 
> # slurp the data
> 
> temp_array = loadtxt(open('a.csv'),delimiter=',',skiprows=1)
> 
> 
> 
> # the shape of temp_array is (N,3), we want its transpose
> 
> temp_array = temp_array.transpose()
> 
> 
> 
> # now the shape is (3,N) and we can do "unpack and assignment:
> 
> x, y, z = temp_array
> 
> 
> 
> # now the tricky part, 
> 
> 
> 
> # 1: create two arrays with 101 (arbitrary number) equispaced values
> 
> # between 0 and 10 --- that is the ranges of data x and data y
> 
> xi = linspace(0,10,101)
> 
> yi = linspace(0,10,101)
> 
> 
> 
> # 2: create, by interpolation, the 2D array that contourf so eagerly
> 
> # awaited!
> 
> print griddata.__doc__
> 
> zi = griddata(x,y,z, xi,yi)
> 
> 
> 
> # eventually, lets plot the stuff...
> 
> # see http://matplotlib.org/examples/pylab_examples/griddata_demo.html
> 
> # for further details and ideas
> 
> 
> 
> pl.contour (xi,yi,zi,11,linewidths=1,colors='black')
> 
> pl.contourf(xi,yi,zi); pl.colorbar()
> 
> # optional
> 
> pl.gca().set_aspect('equal', 'box')
> 
> pl.show()
> 
> % python contour.py

This is great and works very well - thank you!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib Contour Plots

2014-08-19 Thread Jamie Mitchell
You were right Christian I wanted a shape (2,150).

Thank you Rustom and Steven your suggestion has worked.

Unfortunately the data doesn't plot as I imagined.

What I would like is:

X-axis - hs_con_sw
Y-axis - te_con_sw
Z-axis - Frequency

What I would like is for the Z-axis to contour the frequency or amount of times 
that the X-axis data and Y-axis data meet at a particular point or bin.

Does anyone know what function or graph could best show this?

Thanks for all your help,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib Contour Plots

2014-08-18 Thread Jamie Mitchell
I forgot to mention that when I try:

a=np.array([[hs_con_sw],[te_con_sw]])

I get a 3D shape for some reason - (2,1,150) which is not what I'm after.

Thanks,

Jamie

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib Contour Plots

2014-08-18 Thread Jamie Mitchell
On Friday, August 15, 2014 4:13:26 PM UTC+1, Steven D'Aprano wrote:
> Jamie Mitchell wrote:
> 
> 
> 
> > I created the 2D array which read as:
> 
> 
> 
> That's not a 2D array.
> 
> 
> 
> When the amount of data you have is too big to clearly see what it
> 
> happening, replace it with something smaller. Instead of 30 items per
> 
> sub-array, try it with 5 items per sub-array. Instead of eight decimal
> 
> places, try it with single-digit integers. Anything to make it small enough
> 
> to see clearly.
> 
> 
> 
> When I do that with your data, instead of this:
> 
> 
> 
> > array([[[ 2.0886,  2.29400015,  2.00400019,  1.8811,  2.0480001 ,
> 
> >   2.16800022,  2.0480001 ,  1.8829,  1.9586,  2.0029,
> 
> >   2.02800012,  1.8124,  1.9505,  1.96200013,  1.95200014,
> 
> >   1.99800014,  2.0717,  1.8829,  1.9849,  2.1346,
> 
> >   2.1148,  1.8945,  2.0519,  2.0198,  2.03400016,
> 
> >   2.16600013,  2.0099,  1.86200011,  2.19800019, 
> 
> >   2.0128]],
> 
> > 
> 
> >[[ 8.515 ,  8.8811,  8.5519,  7.9481,  8.6066,
> 
> >   8.515 ,  8.8019,  8.1311,  8.6858,  8.7254,
> 
> >   8.4754,  8.25  ,  8.4085,  8.4358,  8.3839,
> 
> >   8.3566,  8.6339,  8.5123,  8.3689,  8.6981,
> 
> >   8.5273,  8.1339,  8.3689,  8.4208,  8.5547,
> 
> >   8.7254,  9.0915,  8.1858,  8.7623, 
> 
> >   8.5396]]], dtype=float32)
> 
> 
> 
> 
> 
> I get this:
> 
> 
> 
> 
> 
> array([[[ 2,  2,  2,  1,  2]],
> 
>[[ 8,  8,  8,  7,  8]]], dtype=float32)
> 
> 
> 
> 
> 
> which is much easier to work with. See the difference between that smaller
> 
> example, and my earlier explanation of the difference between a 1D and 2D
> 
> array?
> 
> 
> 
> One dimensional arrays are made from a single list of numbers: [...]
> 
> Two dimensional arrays are made from a list of lists: [ [...], [...] ]
> 
> 
> 
> *Three* dimensional arrays are made from a list of lists of lists: 
> 
> [ [ [...], [...] ] ]
> 
> 
> 
> *Four* dimensional arrays are made from a list of lists of lists of lists:
> 
> [ [ [ [...], [...] ] ] ]
> 
> 
> 
> and so on. You have a 3D array, with dimensions 2 x 1 x 30.
> 
> 
> 
> You can check the dimensions by storing the array into a variable like this:
> 
> 
> 
> py> a = numpy.array([[[ 2,  2,  2,  1,  2]], [[ 8,  8,  8,  7,  8]]])
> 
> py> a.shape
> 
> (2, 1, 5)
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Thanks for your suggestions Steven. Unfortunately I still can't make the plot 
I'm looking for.

Do you mind if I go back to the start? Sorry I'm probably not explaining what I 
need very well.

So I have two 1D arrays:

1st array - ([8, 8.8,8.5,7.9,8.6 ...], dtype=float32)

It has a shape (150,)

2nd array - ([2, 2.2, 2.5, 2.3, ...],dtype=float32)

It has a shape (150,)

What I want to do is create a 2D array which merges the 1st and 2nd array so 
that I would have:

([[8, 8.8,8.5,7.9,8.6 ...],[2,2,2,2,5,2.3, ...]], dtype=float32) that would 
have a shape (150,150)

In this form I could then plot a 2D contour.

Thanks for your patience.

Jamie

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib Contour Plots

2014-08-15 Thread Jamie Mitchell
On Friday, August 15, 2014 2:23:25 PM UTC+1, Steven D'Aprano wrote:
> Jamie Mitchell wrote:
> 
> 
> 
> [...]
> 
> > I just want to get a contour plot of two numpy arrays.
> 
> > When I call plt.contour on my data I get "input must be a 2D array"
> 
> 
> 
> You are providing a 1D array, or possibly a 3D array. So the question you
> 
> really want to ask is not "How do I do contour plots" but "how do I make a
> 
> 2D array?"
> 
> 
> 
> 
> 
> > An example of one of my arrays:
> 
> > 
> 
> > array([ 2.0886,  2.29400015,  2.00400019,  1.8811,  2.0480001 ,
> 
> > 2.16800022,  2.0480001 ,  1.8829,  1.9586,  2.0029,
> 
> > 2.02800012,  1.8124,  1.9505,  1.96200013,  1.95200014,
> 
> > 1.99800014,  2.0717,  1.8829,  1.9849,  2.1346,
> 
> > 2.1148,  1.8945,  2.0519,  2.0198,  2.03400016,
> 
> > 2.16600013,  2.0099,  1.86200011,  2.19800019,  2.0128],
> 
> > dtype=float32)
> 
> > 
> 
> > How do I get the above array in to the right format for a contour plot?
> 
> 
> 
> Here's an example of making a 2D array:
> 
> 
> 
> py> import numpy
> 
> py> a = numpy.array([1.2, 2.5, 3.7, 4.8])  # One dimensional array
> 
> py> a
> 
> array([ 1.2,  2.5,  3.7,  4.8])
> 
> py> b = numpy.array([ [1.2, 2.5, 3.7, 4.8], 
> 
> ...   [9.5, 8.1, 7.0, 6.2] ])  # Two dimensional array
> 
> py> b
> 
> array([[ 1.2,  2.5,  3.7,  4.8],
> 
>[ 9.5,  8.1,  7. ,  6.2]])
> 
> 
> 
> One dimensional arrays are made from a single list of numbers: [...]
> 
> 
> 
> Two dimensional arrays are made from a list of lists: [ [...], [...] ]
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Thank you Steven.

I created the 2D array which read as:

array([[[ 2.0886,  2.29400015,  2.00400019,  1.8811,  2.0480001 ,
  2.16800022,  2.0480001 ,  1.8829,  1.9586,  2.0029,
  2.02800012,  1.8124,  1.9505,  1.96200013,  1.95200014,
  1.99800014,  2.0717,  1.8829,  1.9849,  2.1346,
  2.1148,  1.8945,  2.0519,  2.0198,  2.03400016,
  2.16600013,  2.0099,  1.86200011,  2.19800019,  2.0128]],

   [[ 8.515 ,  8.8811,  8.5519,  7.9481,  8.6066,
  8.515 ,  8.8019,  8.1311,  8.6858,  8.7254,
  8.4754,  8.25  ,  8.4085,  8.4358,  8.3839,
  8.3566,  8.63999939,  8.5123,  8.3689,  8.6981,
  8.5273,  8.1339,  8.3689,  8.4208,  8.5547,
  8.7254,  9.0915,  8.1858,  8.7623,  8.5396]]], 
dtype=float32)

Unfortunately when I called plt.contour on this, it said again "Input must be a 
2D array".

Is there something I have missed?

Thanks,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib Contour Plots

2014-08-15 Thread Jamie Mitchell
On Thursday, August 14, 2014 5:53:09 PM UTC+1, Steven D'Aprano wrote:
> Jamie Mitchell wrote:
> 
> 
> 
> > Hello all,
> 
> > 
> 
> > I want to contour a scatter plot but I don't know how.
> 
> > 
> 
> > Can anyone help me out?
> 
> 
> 
> Certainly. Which way did you come in? 
> 
> 
> 
> :-)
> 
> 
> 
> Sorry, I couldn't resist.
> 
> 
> 
> It took me literally 20 seconds to find this by googling for "matplotlib
> 
> contour plot", and it only took that long because I misspelled "contour"
> 
> the first time.
> 
> 
> 
> http://matplotlib.org/examples/pylab_examples/contour_demo.html
> 
> 
> 
> 
> 
> Does this help? If not, please explain what experience you have with
> 
> matplotlib, what you have tried, what you expected it to do, and what it
> 
> did instead.
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Yep I've seen that thanks but I can't get it to work. I don't have much 
experience with matplotlib or programming in general.

I just want to get a contour plot of two numpy arrays.

When I call plt.contour on my data I get "input must be a 2D array"

An example of one of my arrays:

array([ 2.0886,  2.29400015,  2.00400019,  1.8811,  2.0480001 ,
2.16800022,  2.0480001 ,  1.8829,  1.9586,  2.0029,
2.02800012,  1.8124,  1.9505,  1.96200013,  1.95200014,
1.99800014,  2.0717,  1.8829,  1.9849,  2.1346,
    2.1148,  1.8945,  2.0519,  2.0198,  2.03400016,
2.16600013,  2.0099,  1.86200011,  2.19800019,  2.0128], 
dtype=float32)

How do I get the above array in to the right format for a contour plot?

Thanks,

Jamie

-- 
https://mail.python.org/mailman/listinfo/python-list


Matplotlib Contour Plots

2014-08-14 Thread Jamie Mitchell
Hello all,

I want to contour a scatter plot but I don't know how.

Can anyone help me out?

Cheers,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Contouring a 2D histogram

2014-06-27 Thread Jamie Mitchell
Hi all,

I have plotted a 2D histogram like so:

python2.7
import netCDF4
import iris
import iris.palette
import numpy as np
import matplotlib as mpl
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
from matplotlib.colors import from_levels_and_colors

fig=plt.figure()
nbins=20
nice_cmap=plt.get_cmap('brewer_RdYlBu_11')
colors=nice_cmap([5,6,7,8,9,10])
levels=[1,2,3,4,5]
cmap, norm=from_levels_and_colors(levels, colors, extend='both')

H, xedges, yedges=np.histogram2d(te_Q0_con_sw,hs_Q0_con_sw,bins=nbins)
Hmasked=np.ma.masked_where(H==0,H)
plt.pcolormesh(xedges,yedges,Hmasked,cmap=cmap,norm=norm,label='Q0 control')

# From this I get a 'scattered' 2D histogram.

Does anyone know how I can contour that scatter?

Thanks,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib Colouring outline of histogram

2014-06-20 Thread Jamie Mitchell
On Friday, June 20, 2014 9:10:58 AM UTC+1, Jamie Mitchell wrote:
> Hi folks,
> 
> 
> 
> Instead of colouring the entire bar of a histogram i.e. filling it, I would 
> like to colour just the outline of the histogram. Does anyone know how to do 
> this?
> 
> Version - Python2.7
> 
> 
> 
> Cheers,
> 
> Jamie

Great thanks again Jason.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib Colouring outline of histogram

2014-06-20 Thread Jamie Mitchell
On Friday, June 20, 2014 2:47:03 PM UTC+1, Jason Swails wrote:
> On Fri, Jun 20, 2014 at 4:10 AM, Jamie Mitchell  wrote:
> 
> Hi folks,
> 
> 
> 
> Instead of colouring the entire bar of a histogram i.e. filling it, I would 
> like to colour just the outline of the histogram. Does anyone know how to do 
> this?
> 
> Version - Python2.7
> 
> 
> 
> Look at the matplotlib.pyplot.hist function documentation: 
> http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.hist
> 
> 
> 
> In addition to the listed parameters, you'll see the "Other Parameters" taken 
> are those that can be applied to the created Patch objects (which are the 
> actual rectangles).  For the Patch keywords, see the API documentation on the 
> Patch object 
> (http://matplotlib.org/api/artist_api.html#matplotlib.patches.Patch). So you 
> can do one of two things:
> 
> 
> 
> 1) Pass the necessary Patch keywords to effect what you want
> 
> 
> 
> e.g. (untested):
> import matplotlib.pyplot as plt
> 
> 
> 
> plt.hist(dataset, bins=10, range=(-5, 5), normed=True,
>          edgecolor='b', linewidth=2, facecolor='none', # Patch options
> 
> )
> 
> 
> plt.show()
> 
> 
> 
> 2) Iterate over the Patch instances returned by plt.hist() and set the 
> properties you want.
> 
> 
> 
> e.g. (untested):
> import matplotlib.pyplot as plt
> 
> 
> 
> n, bins, patches = plt.hist(dataset, bins=10, range=(-5, 5), normed=True)
> for patch in patches:
> 
>     patch.set_edgecolor('b') # color of the lines around each bin
>     patch.set_linewidth(2) # Set width of bin edge
> 
>     patch.set_facecolor('none') # set no fill
>     # Anything else you want to do
> 
> 
> 
> plt.show()
> 
> 
> Approach (1) is the "easy" way, and is there to satisfy the majority of use 
> cases.  However, approach (2) is _much_ more flexible.  Suppose you wanted to 
> highlight a particular region of your data with a specific facecolor or 
> edgecolor -- you can apply the features you want to individual patches using 
> approach (2).  Or if you wanted to highlight a specific bin with thicker 
> lines.
> 
> 
> 
> This is a common theme in matplotlib -- you can use keywords to apply the 
> same features to every part of a plot or you can iterate over the drawn 
> objects and customize them individually.  This is a large part of what makes 
> matplotlib nice to me -- it has a "simple" mode as well as a predictable API 
> for customizing a plot in almost any way you could possibly want.
> 
> 
> 
> HTH,
> Jason
> 
> 
> -- 
> 
> Jason M. Swails
> BioMaPS,
> Rutgers University
> Postdoctoral Researcher

That's great Jason thanks for the detailed response, I went with the easier 
option 1!

I am also trying to put hatches on my histograms like so:

plt.hist(dataset,bins=10,hatch=['*'])

When it comes to plt.show() I get the following error message:
File 
"/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/backends/backend_gtk.py",
 line 435, in expose_event
self._render_figure(self._pixmap, w, h)
  File 
"/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/backends/backend_gtkagg.py",
 line 84, in _render_figure
FigureCanvasAgg.draw(self)
  File 
"/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/backends/backend_agg.py",
 line 451, in draw
self.figure.draw(self.renderer)
  File 
"/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/artist.py",
 line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
  File 
"/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/figure.py",
 line 1034, in draw
func(*args)
  File 
"/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/artist.py",
 line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
  File 
"/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/axes.py",
 line 2086, in draw
a.draw(renderer)
  File 
"/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/artist.py",
 line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
  File 
"/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/patches.py",
 line 429, in draw
renderer.draw_path(gc, tpath, affine, rgbFace)
  File 
"/usr/local/sci/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-linux-x

Re: Problem with numpy 2D Histogram

2014-06-20 Thread Jamie Mitchell
On Friday, June 20, 2014 9:46:29 AM UTC+1, Jamie Mitchell wrote:
> Hi folks,
> 
> 
> 
> I'm trying to plot a 2D histogram but I'm having some issues:
> 
> from pylab import *
> 
> import numpy as np
> 
> import netCDF4
> 
> hist,xedges,yedges=np.histogram2d(x,y,bins=10)
> 
> extent=[xedges[0],xedges[-1],yedges[0],yedges[-1]]
> 
> imshow(hist.T,extent=extent,interpolation='nearest')
> 
> colorbar()
> 
> show()
> 
> 
> 
> After the first line of code I get:
> 
> TypeError: Cannot cast array data from dtype('O') to dtype('float64') 
> according to the rule 'safe'
> 
> 
> 
> I'm using python2.7, x and y are type 'numpy.ndarray'
> 
> 
> 
> Cheers,
> 
> Jamie

Thanks for your help Peter.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with numpy 2D Histogram

2014-06-20 Thread Jamie Mitchell
On Friday, June 20, 2014 12:00:15 PM UTC+1, Peter Otten wrote:
> Jamie Mitchell wrote:
> 
> 
> 
> > I have changed my x and y data to float64 types but I am still getting the
> 
> > same error message?
> 
> 
> 
> Please double-check by adding
> 
> 
> 
> assert x.dtype == np.float64
> 
> assert y.dtype == np.float64
> 
> 
> 
> If none of these assertions fail try to make a minimal script including some 
> 
> data that provokes the TypeError and post it here.

OK this is my code:

swh_Q0_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_annavg.nc','r')
hs_Q0_con_sw=swh_Q0_con_sw.variables['hs'][:]
x=hs_Q0_con_sw.astype(float64)
# When I print the dtype of x here it says 'float64'
mwp_Q0_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/mean_wave_period/south_west/controlperiod/mwpcontrol_swest_annavg1D.nc','r')
te_Q0_con_sw=mwp_Q0_con_sw.variables['te'][:]
y=te_Q0_con_sw.astype(float64)
If I try assert x.dtype == np.float64 I get:
AssertionError

hist,xedges,yedges=np.histogram2d(x,y,bins=10)
TypeError: Cannot cast array data from dtype('O') to dtype('float64') according 
to the rule 'safe' 

Thanks,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with numpy 2D Histogram

2014-06-20 Thread Jamie Mitchell
On Friday, June 20, 2014 10:25:44 AM UTC+1, Peter Otten wrote:
> Jamie Mitchell wrote:
> 
> 
> 
> > Hi folks,
> 
> > 
> 
> > I'm trying to plot a 2D histogram but I'm having some issues:
> 
> > from pylab import *
> 
> > import numpy as np
> 
> > import netCDF4
> 
> > hist,xedges,yedges=np.histogram2d(x,y,bins=10)
> 
> > extent=[xedges[0],xedges[-1],yedges[0],yedges[-1]]
> 
> > imshow(hist.T,extent=extent,interpolation='nearest')
> 
> > colorbar()
> 
> > show()
> 
> > 
> 
> > After the first line of code I get:
> 
> > TypeError: Cannot cast array data from dtype('O') to dtype('float64')
> 
> > according to the rule 'safe'
> 
> > 
> 
> > I'm using python2.7, x and y are type 'numpy.ndarray'
> 
> 
> 
> The error message complains about the dtype, i. e. the type of the elements 
> 
> in the array, not the array itself. Make sure the elements are floating 
> 
> point numbers or something compatible, not arbitrary Python objects.
> 
> As a baseline the following works
> 
> 
> 
> from pylab import *
> 
> import numpy as np
> 
> 
> 
> x, y = np.random.randn(2, 100)
> 
> print "x", type(x), x.dtype
> 
> print "y", type(y), y.dtype
> 
> 
> 
> hist, xedges, yedges = np.histogram2d(x, y, bins=10)
> 
> extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
> 
> imshow(hist.T, extent=extent, interpolation='nearest')
> 
> colorbar()
> 
> show()
> 
> 
> 
> while this doesn't:
> 
> 
> 
> #...
> 
> x, y = np.random.randn(2, 100)
> 
> import decimal
> 
> y = np.array([decimal.Decimal.from_float(v) for v in y])
> 
> #...

Thanks Peter.

I have changed my x and y data to float64 types but I am still getting the same 
error message?

Cheers,
Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Problem with numpy 2D Histogram

2014-06-20 Thread Jamie Mitchell
Hi folks,

I'm trying to plot a 2D histogram but I'm having some issues:
from pylab import *
import numpy as np
import netCDF4
hist,xedges,yedges=np.histogram2d(x,y,bins=10)
extent=[xedges[0],xedges[-1],yedges[0],yedges[-1]]
imshow(hist.T,extent=extent,interpolation='nearest')
colorbar()
show()

After the first line of code I get:
TypeError: Cannot cast array data from dtype('O') to dtype('float64') according 
to the rule 'safe'

I'm using python2.7, x and y are type 'numpy.ndarray'

Cheers,
Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Matplotlib Colouring outline of histogram

2014-06-20 Thread Jamie Mitchell
Hi folks,

Instead of colouring the entire bar of a histogram i.e. filling it, I would 
like to colour just the outline of the histogram. Does anyone know how to do 
this?
Version - Python2.7

Cheers,
Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Overlaying a boxplot onto a time series figure

2014-06-06 Thread Jamie Mitchell
Hi there,

I would like to overlay some boxplots onto a time series.

I have tried pylab.hold(True) in between the two plots in my code but this 
hasn't worked.

The problem is that the x-axes of the boxplots and the time series are not the 
same.

Code for time series:

python2.7
import netCDF4
import matplotlib.pyplot as plt
import numpy as np

swh_Q0_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
hs_Q0_con_sw=swh_Q0_con_sw.variables['hs'][:]
year_con=swh_Q0_con_sw.variables['year'][:]
swh_Q3_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
hs_Q3_con_sw=swh_Q3_con_sw.variables['hs'][:]
swh_Q4_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
hs_Q4_con_sw=swh_Q4_con_sw.variables['hs'][:]
swh_Q14_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
hs_Q14_con_sw=swh_Q14_con_sw.variables['hs'][:]
swh_Q16_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
hs_Q16_con_sw=swh_Q16_con_sw.variables['hs'][:]
swh_Q0_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
hs_Q0_fut_sw=swh_Q0_fut_sw.variables['hs'][:]
year_fut=swh_Q0_fut_sw.variables['year'][:]
swh_Q3_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
hs_Q3_fut_sw=swh_Q3_fut_sw.variables['hs'][:]
swh_Q4_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
hs_Q4_fut_sw=swh_Q4_fut_sw.variables['hs'][:]
swh_Q14_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
hs_Q14_fut_sw=swh_Q14_fut_sw.variables['hs'][:]
swh_Q16_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
hs_Q16_fut_sw=swh_Q16_fut_sw.variables['hs'][:]

fit_Q0_con_sw=np.polyfit(year_con,hs_Q0_con_sw,1)
fit_fn_Q0_con_sw=np.poly1d(fit_Q0_con_sw)

plt.plot(year_con,hs_Q0_con_sw,'g.')
plt.plot(year_con,fit_fn_Q0_con_sw(year_con),'g',label='Q0 no pert')

fit_Q3_con_sw=np.polyfit(year_con,hs_Q3_con_sw,1)
fit_fn_Q3_con_sw=np.poly1d(fit_Q3_con_sw)

plt.plot(year_con,hs_Q3_con_sw,'b.')
plt.plot(year_con,fit_fn_Q3_con_sw(year_con),'b',label='Q3 low sens')

fit_Q4_con_sw=np.polyfit(year_con,hs_Q4_con_sw,1)
fit_fn_Q4_con_sw=np.poly1d(fit_Q4_con_sw)

plt.plot(year_con,hs_Q4_con_sw,'y.')
plt.plot(year_con,fit_fn_Q4_con_sw(year_con),'y',label='Q4 low sens')

fit_Q14_con_sw=np.polyfit(year_con,hs_Q14_con_sw,1)
fit_fn_Q14_con_sw=np.poly1d(fit_Q14_con_sw)

plt.plot(year_con,hs_Q14_con_sw,'r.')
plt.plot(year_con,fit_fn_Q14_con_sw(year_con),'r',label='Q14 high sens')

fit_Q16_con_sw=np.polyfit(year_con,hs_Q16_con_sw,1)
fit_fn_Q16_con_sw=np.poly1d(fit_Q16_con_sw)

plt.plot(year_con,hs_Q16_con_sw,'c.')
plt.plot(year_con,fit_fn_Q16_con_sw(year_con),'c',label='Q16 high sens')

fit_Q0_fut_sw=np.polyfit(year_fut,hs_Q0_fut_sw,1)
fit_fn_Q0_fut_sw=np.poly1d(fit_Q0_fut_sw)

plt.plot(year_fut,hs_Q0_fut_sw,'g.')
plt.plot(year_fut,fit_fn_Q0_fut_sw(year_fut),'g')

fit_Q3_fut_sw=np.polyfit(year_fut,hs_Q3_fut_sw,1)
fit_fn_Q3_fut_sw=np.poly1d(fit_Q3_fut_sw)

plt.plot(year_fut,hs_Q3_fut_sw,'b.')
plt.plot(year_fut,fit_fn_Q3_fut_sw(year_fut),'b')

fit_Q4_fut_sw=np.polyfit(year_fut,hs_Q4_fut_sw,1)
fit_fn_Q4_fut_sw=np.poly1d(fit_Q4_fut_sw)

plt.plot(year_fut,hs_Q4_fut_sw,'y.')
plt.plot(year_fut,fit_fn_Q4_fut_sw(year_fut),'y')

fit_Q14_fut_sw=np.polyfit(year_fut,hs_Q14_fut_sw,1)
fit_fn_Q14_fut_sw=np.poly1d(fit_Q14_fut_sw)

plt.plot(year_fut,hs_Q14_fut_sw,'r.')
plt.plot(year_fut,fit_fn_Q14_fut_sw(year_fut),'y')

fit_Q16_fut_sw=np.polyfit(year_fut,hs_Q16_fut_sw,1)
fit_fn_Q16_fut_sw=np.poly1d(fit_Q16_fut_sw)

plt.plot(year_fut,hs_Q16_fut_sw,'c.')
plt.plot(year_fut,fit_fn_Q16_fut_sw(year_fut),'c')

plt.legend(loc='best')
plt.xlabel('Year')
plt.ylabel('Significant Wave Height annual averages SW England')
plt.title('Time series of Significant Wave Height')
plt.show()

Code for boxplots:

python2.7
from pylab import *
import netCDF4

data=(hs_Q0_con_sw,hs_Q3_con_sw,hs_Q4_con_sw,hs_Q14_con_sw,hs_Q16_con_sw)

figure(1)
boxplot(data)
labels=('QO no pert','Q3 low sens','Q4 low sens','Q14 high sens','Q16 high 
sens')
xticks(range(1,6),labels,rotation=15)
xlabel('Ensemble Member')
ylabel('Significant Wave Height Annual Average')
title('Significant Wave Height SW England 1981-2010')
show()



If anybody knows how I could integrate these two plots I would be eternally 
grateful!

Thanks,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib - specifying bin widths

2014-06-06 Thread Jamie Mitchell
On Thursday, June 5, 2014 4:54:16 PM UTC+1, Jamie Mitchell wrote:
> Hello all!
> 
> 
> 
> Instead of setting the number of bins I want to set the bin width.
> 
> 
> 
> I would like my bins to go from 1.7 to 2.4 in steps of 0.05.
> 
> 
> 
> How do I say this in the code?
> 
> 
> 
> Cheers,
> 
> 
> 
> Jamie

That's great thanks Mark.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Adding R squared value to scatter plot

2014-06-05 Thread Jamie Mitchell
On Wednesday, May 21, 2014 1:30:16 PM UTC+1, Jason Swails wrote:
> 
> 
> 
> 
> 
> 
> On Wed, May 21, 2014 at 7:59 AM, Jamie Mitchell  wrote:
> 
> I have made a plot using the following code:
> 
> 
> 
> python2.7
> 
> import netCDF4
> 
> import matplotlib.pyplot as plt
> 
> import numpy as np
> 
> 
> 
> swh_Q0_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
> 
> hs_Q0_con_sw=swh_Q0_con_sw.variables['hs'][:]
> 
> swh_Q3_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
> 
> hs_Q3_con_sw=swh_Q3_con_sw.variables['hs'][:]
> 
> swh_Q4_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
> 
> hs_Q4_con_sw=swh_Q4_con_sw.variables['hs'][:]
> 
> swh_Q14_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
> 
> hs_Q14_con_sw=swh_Q14_con_sw.variables['hs'][:]
> 
> swh_Q16_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
> 
> hs_Q16_con_sw=swh_Q16_con_sw.variables['hs'][:]
> 
> swh_Q0_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
> 
> hs_Q0_fut_sw=swh_Q0_fut_sw.variables['hs'][:]
> 
> swh_Q3_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
> 
> hs_Q3_fut_sw=swh_Q3_fut_sw.variables['hs'][:]
> 
> swh_Q4_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
> 
> hs_Q4_fut_sw=swh_Q4_fut_sw.variables['hs'][:]
> 
> swh_Q14_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
> 
> hs_Q14_fut_sw=swh_Q14_fut_sw.variables['hs'][:]
> 
> swh_Q16_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
> 
> hs_Q16_fut_sw=swh_Q16_fut_sw.variables['hs'][:]
> 
> 
> 
> fit_Q0_sw=np.polyfit(hs_Q0_con_sw,hs_Q0_fut_sw,1)
> 
> fit_fn_Q0_sw=np.poly1d(fit_Q0_sw)
> 
> 
> 
> plt.plot(hs_Q0_con_sw,hs_Q0_fut_sw,'g.')
> 
> plt.plot(hs_Q0_con_sw,fit_fn_Q0_sw(hs_Q0_con_sw),'g',label='Q0 no pert')
> 
> 
> 
> fit_Q3_sw=np.polyfit(hs_Q3_con_sw,hs_Q3_fut_sw,1)
> 
> fit_fn_Q3_sw=np.poly1d(fit_Q3_sw)
> 
> 
> 
> plt.plot(hs_Q3_con_sw,hs_Q3_fut_sw,'b.')
> 
> plt.plot(hs_Q3_con_sw,fit_fn_Q3_sw(hs_Q3_con_sw),'b',label='Q3 low sens')
> 
> 
> 
> fit_Q4_sw=np.polyfit(hs_Q4_con_sw,hs_Q4_fut_sw,1)
> 
> fit_fn_Q4_sw=np.poly1d(fit_Q4_sw)
> 
> 
> 
> plt.plot(hs_Q4_con_sw,hs_Q4_fut_sw,'y.')
> 
> plt.plot(hs_Q4_con_sw,fit_fn_Q4_sw(hs_Q4_con_sw),'y',label='Q4 low sens')
> 
> 
> 
> fit_Q14_sw=np.polyfit(hs_Q14_con_sw,hs_Q14_fut_sw,1)
> 
> fit_fn_Q14_sw=np.poly1d(fit_Q14_sw)
> 
> 
> 
> plt.plot(hs_Q14_con_sw,hs_Q14_fut_sw,'r.')
> 
> plt.plot(hs_Q14_con_sw,fit_fn_Q14_sw(hs_Q14_con_sw),'r',label='Q14 high sens')
> 
> 
> 
> fit_Q16_sw=np.polyfit(hs_Q16_con_sw,hs_Q16_fut_sw,1)
> 
> fit_fn_Q16_sw=np.poly1d(fit_Q16_sw)
> 
> 
> 
> plt.plot(hs_Q16_con_sw,hs_Q16_fut_sw,'c.')
> 
> plt.plot(hs_Q16_con_sw,fit_fn_Q16_sw(hs_Q16_con_sw),'c',label='Q16 high sens')
> 
> 
> 
> plt.legend(loc='best')
> 
> plt.xlabel('Significant Wave Height annual averages NW Scotland 1981-2010')
> 
> plt.ylabel('Significant Wave Height annual averages NW Scotland 2040-2069')
> 
> plt.title('Scatter plot of Significant Wave Height')
> 
> plt.show()
> 
> 
> 
> --
> 
> 
> 
> What I would like to do is display the R squared value next to the line of 
> best fits that I have made.
> 
> 
> 
> Does anyone know how to do this with matplotlib?
> 
> 
> 
> You can add plain text or annotations with arrows using any of the API 
> functions described here: http://matplotlib.org/1.3.1/users/text_intro.html 
> (information specifically regarding the text call is here: 
> http://matplotlib.org/1.3.1/api/pyplot_api.html#matplotlib.pyplot.text)
> 
> 
> 
> You can also use LaTeX typesetting here, so you can make the text something 
> like r'$R^2$' to display R^2 with "nice" typesetting. (I typically use raw 
> strings for matplotlib text strings with LaTeX formulas in them since LaTeX 
> makes extensive use of the \ character.)
> 
> 
> 
> The onus is on you, the programmer, to determine _where_ on the plot you want 
> the text to appear.  Since you know what you are plotting, you can write a 
> quick helper function that will compute the optimal (to you) location for the 
> label to occur based on where things are drawn on the canvas.  There is a 
> _lot_ of flexibility here so you should be able to get your text looking 
> exactly how (and where) you want it.
> 
> 
> 
> Hope this helps,
> Jason
> 
> 
> -- 
> 
> Jason M. Swails
> BioMaPS,
> Rutgers University
> Postdoctoral Researcher

Hi Jason,

Thank you for your swift response - you solved my problem!

Sorry I took a while to get back to you.

Thanks again,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Matplotlib - specifying bin widths

2014-06-05 Thread Jamie Mitchell
Hello all!

Instead of setting the number of bins I want to set the bin width.

I would like my bins to go from 1.7 to 2.4 in steps of 0.05.

How do I say this in the code?

Cheers,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Adding R squared value to scatter plot

2014-05-21 Thread Jamie Mitchell
I have made a plot using the following code:

python2.7
import netCDF4
import matplotlib.pyplot as plt
import numpy as np

swh_Q0_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
hs_Q0_con_sw=swh_Q0_con_sw.variables['hs'][:]
swh_Q3_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
hs_Q3_con_sw=swh_Q3_con_sw.variables['hs'][:]
swh_Q4_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
hs_Q4_con_sw=swh_Q4_con_sw.variables['hs'][:]
swh_Q14_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
hs_Q14_con_sw=swh_Q14_con_sw.variables['hs'][:]
swh_Q16_con_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/controlperiod/south_west/swhcontrol_swest_annavg1D.nc','r')
hs_Q16_con_sw=swh_Q16_con_sw.variables['hs'][:]
swh_Q0_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
hs_Q0_fut_sw=swh_Q0_fut_sw.variables['hs'][:]
swh_Q3_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q3/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
hs_Q3_fut_sw=swh_Q3_fut_sw.variables['hs'][:]
swh_Q4_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q4/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
hs_Q4_fut_sw=swh_Q4_fut_sw.variables['hs'][:]
swh_Q14_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q14/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
hs_Q14_fut_sw=swh_Q14_fut_sw.variables['hs'][:]
swh_Q16_fut_sw=netCDF4.Dataset('/data/cr1/jmitchel/Q16/swh/2050s/south_west/swh2050s_swest_annavg1D.nc','r')
hs_Q16_fut_sw=swh_Q16_fut_sw.variables['hs'][:]

fit_Q0_sw=np.polyfit(hs_Q0_con_sw,hs_Q0_fut_sw,1)
fit_fn_Q0_sw=np.poly1d(fit_Q0_sw)

plt.plot(hs_Q0_con_sw,hs_Q0_fut_sw,'g.')
plt.plot(hs_Q0_con_sw,fit_fn_Q0_sw(hs_Q0_con_sw),'g',label='Q0 no pert')

fit_Q3_sw=np.polyfit(hs_Q3_con_sw,hs_Q3_fut_sw,1)
fit_fn_Q3_sw=np.poly1d(fit_Q3_sw)

plt.plot(hs_Q3_con_sw,hs_Q3_fut_sw,'b.')
plt.plot(hs_Q3_con_sw,fit_fn_Q3_sw(hs_Q3_con_sw),'b',label='Q3 low sens')

fit_Q4_sw=np.polyfit(hs_Q4_con_sw,hs_Q4_fut_sw,1)
fit_fn_Q4_sw=np.poly1d(fit_Q4_sw)

plt.plot(hs_Q4_con_sw,hs_Q4_fut_sw,'y.')
plt.plot(hs_Q4_con_sw,fit_fn_Q4_sw(hs_Q4_con_sw),'y',label='Q4 low sens')

fit_Q14_sw=np.polyfit(hs_Q14_con_sw,hs_Q14_fut_sw,1)
fit_fn_Q14_sw=np.poly1d(fit_Q14_sw)

plt.plot(hs_Q14_con_sw,hs_Q14_fut_sw,'r.')
plt.plot(hs_Q14_con_sw,fit_fn_Q14_sw(hs_Q14_con_sw),'r',label='Q14 high sens')

fit_Q16_sw=np.polyfit(hs_Q16_con_sw,hs_Q16_fut_sw,1)
fit_fn_Q16_sw=np.poly1d(fit_Q16_sw)

plt.plot(hs_Q16_con_sw,hs_Q16_fut_sw,'c.')
plt.plot(hs_Q16_con_sw,fit_fn_Q16_sw(hs_Q16_con_sw),'c',label='Q16 high sens')

plt.legend(loc='best')
plt.xlabel('Significant Wave Height annual averages NW Scotland 1981-2010')
plt.ylabel('Significant Wave Height annual averages NW Scotland 2040-2069')
plt.title('Scatter plot of Significant Wave Height')
plt.show()

--

What I would like to do is display the R squared value next to the line of best 
fits that I have made. 

Does anyone know how to do this with matplotlib?

Thanks,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Saving a file as netCDF4 in Python

2014-05-08 Thread Jamie Mitchell
Dear all,

Apologies as this sounds like a very simple question but I can't find an answer 
anywhere. 

I have loaded a netCDF4 file into python as follows:

swh=netCDF4.Dataset('path/to/netCDFfile,'r')

I then isolate the variables I wish to plot:

hs=swh.variables['hs']
year=swh.variables['year']

I would then like to save these hs and year variables so that I don't have to 
isolate them every time I want to plot them.

Any help would be much appreciated.

Cheers,

Jamie 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: len() of unsized object - ks test

2014-04-25 Thread Jamie Mitchell
On Friday, April 25, 2014 3:07:54 PM UTC+1, Jamie Mitchell wrote:
> Hello all,
> 
> 
> 
> I am trying to perform a Kolmogorov-Smirnov test in Python but I'm having a 
> few difficulties.
> 
> 
> 
> # My files are netCDF so I import them as follows:
> 
> 
> 
> control=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_concatannavg_1D.nc','r')
> 
> 
> 
> # The string is simply a 1D array
> 
> 
> 
> # Then performing the ks test:
> 
> 
> 
> kstest(control,'norm')
> 
> 
> 
> # I then get the following error:
> 
> 
> 
> File "", line 1, in 
> 
>   File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", 
> line 3413, in kstest
> 
> N = len(vals)
> 
> TypeError: len() of unsized object
> 
> 
> 
> Any ideas on why this isn't working would be great.
> 
> 
> 
> Thanks,
> 
> 
> 
> Jamie

Thanks for your help.

Steven your right I wasn't reading in the file on netCDF4.Dataset, I was just 
opening it. I have rectified it now - a silly mistake!

Thanks again,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


len() of unsized object - ks test

2014-04-25 Thread Jamie Mitchell
Hello all,

I am trying to perform a Kolmogorov-Smirnov test in Python but I'm having a few 
difficulties.

# My files are netCDF so I import them as follows:

control=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/south_west/swhcontrol_swest_concatannavg_1D.nc','r')

# The string is simply a 1D array

# Then performing the ks test:

kstest(control,'norm')

# I then get the following error:

File "", line 1, in 
  File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", line 
3413, in kstest
N = len(vals)
TypeError: len() of unsized object

Any ideas on why this isn't working would be great.

Thanks,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Line of best fit

2014-03-31 Thread Jamie Mitchell
I am new to python so apologies for the ignorance with this question.

How would I apply a line of best fit to a plot?

My data are netCDF4 data files and this is essentially what I have done so far:

swh1=netCDF4.Dataset('filename','r')
hs1=swh1.variables['hs']

swh2=netCDF4.Dataset('filename'.'r')
hs2=swh2.variables['hs']

plt.plot(hs1,hs2,'.')

Cheers,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Memory error

2014-03-24 Thread Jamie Mitchell
On Monday, March 24, 2014 11:32:31 AM UTC, Jamie Mitchell wrote:
> Hello all,
> 
> 
> 
> I'm afraid I am new to all this so bear with me...
> 
> 
> 
> I am looking to find the statistical significance between two large netCDF 
> data sets.
> 
> 
> 
> Firstly I've loaded the two files into python:
> 
> 
> 
> swh=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/averages/swh_control_concat.nc',
>  'r')
> 
> 
> 
> swh_2050s=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/averages/swh_2050s_concat.nc',
>  'r')
> 
> 
> 
> I have then isolated the variables I want to perform the pearson correlation 
> on:
> 
> 
> 
> hs=swh.variables['hs']
> 
> 
> 
> hs_2050s=swh_2050s.variables['hs']
> 
> 
> 
> Here is the metadata for those files:
> 
> 
> 
> print hs
> 
> 
> 
> int16 hs(time, latitude, longitude)
> 
> standard_name: significant_height_of_wind_and_swell_waves
> 
> long_name: significant_wave_height
> 
> units: m
> 
> add_offset: 0.0
> 
> scale_factor: 0.002
> 
> _FillValue: -32767
> 
> missing_value: -32767
> 
> unlimited dimensions: time
> 
> current shape = (86400, 350, 227)
> 
> 
> 
> print hs_2050s
> 
> 
> 
> int16 hs(time, latitude, longitude)
> 
> standard_name: significant_height_of_wind_and_swell_waves
> 
> long_name: significant_wave_height
> 
> units: m
> 
> add_offset: 0.0
> 
> scale_factor: 0.002
> 
> _FillValue: -32767
> 
> missing_value: -32767
> 
> unlimited dimensions: time
> 
> current shape = (86400, 350, 227)
> 
> 
> 
> 
> 
> Then to perform the pearsons correlation:
> 
> 
> 
> from scipy.stats.stats import pearsonr
> 
> 
> 
> pearsonr(hs,hs_2050s)
> 
> 
> 
> I then get a memory error:
> 
> 
> 
> Traceback (most recent call last):
> 
>   File "", line 1, in 
> 
>   File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", 
> line 2409, in pearsonr
> 
> x = np.asarray(x)
> 
>   File "/usr/local/sci/lib/python2.7/site-packages/numpy/core/numeric.py", 
> line 321, in asarray
> 
> return array(a, dtype, copy=False, order=order)
> 
> MemoryError
> 
> 
> 
> This also happens when I try to create numpy arrays from the data.
> 
> 
> 
> Does anyone know how I can alleviate theses memory errors?
> 
> 
> 
> Cheers,
> 
> 
> 
> Jamie

Just realised that obviously pearson correlation requires two 1D arrays and 
mine are 3D, silly mistake!
-- 
https://mail.python.org/mailman/listinfo/python-list


Memory error

2014-03-24 Thread Jamie Mitchell
Hello all,

I'm afraid I am new to all this so bear with me...

I am looking to find the statistical significance between two large netCDF data 
sets.

Firstly I've loaded the two files into python:

swh=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/averages/swh_control_concat.nc',
 'r')

swh_2050s=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/2050s/averages/swh_2050s_concat.nc',
 'r')

I have then isolated the variables I want to perform the pearson correlation on:

hs=swh.variables['hs']

hs_2050s=swh_2050s.variables['hs']

Here is the metadata for those files:

print hs

int16 hs(time, latitude, longitude)
standard_name: significant_height_of_wind_and_swell_waves
long_name: significant_wave_height
units: m
add_offset: 0.0
scale_factor: 0.002
_FillValue: -32767
missing_value: -32767
unlimited dimensions: time
current shape = (86400, 350, 227)

print hs_2050s

int16 hs(time, latitude, longitude)
standard_name: significant_height_of_wind_and_swell_waves
long_name: significant_wave_height
units: m
add_offset: 0.0
scale_factor: 0.002
_FillValue: -32767
missing_value: -32767
unlimited dimensions: time
current shape = (86400, 350, 227)


Then to perform the pearsons correlation:

from scipy.stats.stats import pearsonr

pearsonr(hs,hs_2050s)

I then get a memory error:

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", line 
2409, in pearsonr
x = np.asarray(x)
  File "/usr/local/sci/lib/python2.7/site-packages/numpy/core/numeric.py", line 
321, in asarray
return array(a, dtype, copy=False, order=order)
MemoryError

This also happens when I try to create numpy arrays from the data.

Does anyone know how I can alleviate theses memory errors?

Cheers,

Jamie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-30 Thread Jamie Paul Griffin
* Yuvraj Sharma  [2012-12-28 01:37:23 -0800]:

> Use IDLE
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

The OP is already a proficient C, C++, perl, ... hacker using console based 
tools and hardcore UNIX editors like vi(1) - I doubt he'll stay with IDLE for 
very long - once you've got accustomed to the UNIX environment and the 
command-line it's difficult and undesirable, in my experience, to switch to GUI 
stuff. 

Stick with what you've been using for the last couple of decades. These tools 
have stood the test of time for a good reason: they're powerful, efficient and 
made for the task of programming. 

Jamie

-- 
Primary Key: 4096R/1D31DC38 2011-12-03
Key Fingerprint: A4B9 E875 A18C 6E11 F46D  B788 BEE6 1251 1D31 DC38
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to python, do I need an IDE or is vim still good enough?

2012-12-27 Thread Jamie Paul Griffin
* mogul  [2012-12-27 12:01:16 -0800]:

> 'Aloha!
> 
> I'm new to python, got 10-20 years perl and C experience, all gained on unix 
> alike machines hacking happily in vi, and later on in vim.
> 
> Now it's python, and currently mainly on my kubuntu desktop.
> 
> Do I really need a real IDE, as the windows guys around me say I do, or will 
> vim, git, make and other standalone tools make it the next 20 years too for 
> me? 
> 
> Oh, by the way, after 7 days I'm completely in love with this python thing. I 
> should have made the switch much earlier!
> 
> /mogul %-)

If these are the tools you're used to, stick with them. 

I have a tmux session with however many terminals open I need. I use the
traditional vi editor (not vim) and the python shell/interpreter as well
as the UNIX tools I need. A web browser and a separate urxvt window for
my mutt client when I need to mail a list for some help. That's it. 

The benefit of the tmux client (terminal multiplexer) is that I can see
all the screens at the same time and quickly switch between them. I
believe Linux has screen(1) which does the same thing. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Brython - Python in the browser

2012-12-20 Thread Jamie Paul Griffin
* Ian Kelly  [2012-12-19 17:54:44 -0700]:

> On Wed, Dec 19, 2012 at 5:07 PM, Terry Reedy  wrote:
> > That says that my browser, Firefox 17, does not support HTML5. Golly gee. I
> > don't think any browser support5 all of that moving target, and Gecko
> > apparently supports about as large a subset as most.
> > https://en.wikipedia.org/wiki/Comparison_of_layout_engines_%28HTML5%29
> > It is possible the FF still does not support the particular feature needed
> > for the clock, but then the page should say just that. Has the latest FF
> > (17) actually been tested?
> 
> It works for me using FF 17.0.1.

I'm using FF 13 on OpenBSD and it works for me too. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Obnoxious postings from Google Groups

2012-11-04 Thread Jamie Paul Griffin
/ ru...@yahoo.com wrote on Fri  2.Nov'12 at 11:39:10 -0700 /

> (I also hope I haven't just been suckered by a troll
> attempt, windows/unix is better then unix/windows being 
> an age-old means of trolling.)

No, i'm not a "troll". I was just adding my opinion to the thread, I assumed 
that was allowed. I didn't say UNIX is better than Windows, did I; I just feel 
that Windows is not -- for me anyway -- the most suitable plaform for learning 
about the science of computing and coding, etc... being a computer science 
student that's the view i have and share with those I learn with and from. Why 
must people be accused of trolling everytime they make a statement that conveys 
a preference over one platform or language, for example, than the other. 
Provoking someone by labeling them a troll or implying they might be is a bit 
childish really. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime issue

2012-11-02 Thread Jamie Paul Griffin
/ ru...@yahoo.com wrote on Thu  1.Nov'12 at 15:00:48 -0700 /

> 
> * In Search dialog clicked on the Search in folder dropdown after
>   an earlier search and TB crashed (disappeared along with the
>   new message I was editing.) [3.0.1]
> 
> * Search for japanese text in body no longer works (never finds
>   text even when it exists). [3.0.1] Used to work.
> 
> * Each mail message displays useless header info that uses 25%
>   of the available vertical space.  
> 
> * When editing a reply message, typing a return at eol results in
>   two blank lines inserted.
> 
> * When editing message, siometimes edit cursor disappears
>   tho editing still seems to work normally.
> 
> * Requires voodoo to create hmtl new message when default is
>   plain text or visa versa.  Have to hold shift key while clicking
>   "write" button.  Shift while choosing "new", "reply", etc in
>   menu doesn't work.  
> 
> * Frequently, clinking on a usenet newsgroup results in TB freeze.
>   Only solution is to remove group and re-add later.  (Problem 
>   since 2.x days.)
> 
> * Frequently after an apparently normal shutdown, attempt to restart
>   results in "TB is already running" error.
> 
> * Some folders in the folder tree view are greyed out and not 
>   selectable even though they have no visible different properties
>   than selectable ones.  Don't know how they got that way.
> 
> * Clicking on a folder in the folder tree pane results in a pop-
>   up dialog "this folder is not selectable" that has to be dismissed,
>   even though one is trying to get it's properties, or is selecting
>   it to create a subfolder.
> 
> * Messages change from "read" to "unread" in folders at random when
>   folder is accessed, or even when it is not accessed. [gone in 3.0.3?]
> 
> * Interminttently, when I click a usenet message to view it,
>   the contents pane remains blank.  Contents of that message
>   remain blank foreever. [new with 3.0.1].
> 
> * When TB main window closed while editing an email, can no longer
>   save the email, even if the TB main window is reopened.
> 
> * Counts of new messages in usenet groups are often wildly high.
> 
> * When opening up a usenet server, status bar reports "no new
>   messages on server" even though TB then updates the groups 
>   with the new messages that *are* on the server.  [new in 3.0.1]
> 
> * After upgrade to TB-3.0, opening a usenet server results not
>   only in the group being scanned for new messages in each group
>   (as before) but also the headers for all those new messages
>   being downloaded (slow on a dialup connection and a waste of
>   time if I don't intend to read anything in that group).
>   No obvious way to revert to original behaviour.
> 
> * Even tho the number of unread messages listed beside a usenet
>   group in the folder pane is less than the download limit, I
>   sometimes get pop-up asking how many messages to download,
>   when I access the group. (side effect of above problem I think.)
> 
> * Sometimes TB downloads two copies of each header.
> 
> * When I compress folders, get a series of several dozen pop-
>   up messages (each requiring a click on "OK") telling me
>   that foplder "xx" is not selectable.
> 
> * Copy-paste from TB to other app fails if TB is closed
>   before the paste -- the paste buffer appears empty [TB-3.0b4]
> 
> * Copy paste fails by removing text (forgot if it is just the
>   copied text or other text) in the TB message when pasted
>   somewhere else. [TB-2?]
> 
> * After upgrade to TB-3.0x, i no longer see a way to create a 
>   new imap subfolder.  Had to create it using MSOE.
> 
> * After upgrade to TB-3.0x double clicking on attached .jpg image
>   no longer opens it -- only option is to save and open outside
>   of TB.  phfft.
> 
> * HTF do you change the font size for plain text message composition?
>   Prefs has a setting for html but...
> 
> * search of body for multiple "anded" text never ends if one of
>   the search boxes is empty.  
> 
> * Search "stop" button doesn't stop search.
> 
> * One group frequently, without any action on my part, read thousands 
>   of old articles, showing them as unread, and when I choose one, responds
>   with "article expired" message.  (tb-3.0.4)
 
[ ... ]

With a list of problems like that maybe the time spent on learning how to use a 
Usenet client or mua that is properly written would be worthwhile. Personally I 
haven't used the Google Groups interface, and most likely never will so I can't 
really comment on how it performs or how nice it is to use but if you're happy 
with it that's the main thing. But you can't deny that it does cause irritating 
problems for other people trying to read information sent from it. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Obnoxious postings from Google Groups

2012-11-02 Thread Jamie Paul Griffin
/ ru...@yahoo.com wrote on Thu  1.Nov'12 at 15:08:26 -0700 /

> On 11/01/2012 03:55 AM, Jamie Paul Griffin wrote:
> > Anybody serious about programming should be using a form of
> > UNIX/Linux if you ask me. It's inconceivable that these systems
> > should be avoided if you're serious about Software Engineering and
> > Computer Science, etc. For UNIX there are loads of decent news
> > reading software and mail user agents to learn and use. slrn is a
> > good one and point it at gmane.org as someone else pointed out. I
> > can't even imagine using a browser or Google Groups, etc. now.
 
> Are you saying that this group is only for "serious" programmers?
 
I don't see where my comments suggested that this group is only for serious 
programmers. I simply believe that the UNIX platform, in whatever form, is 
better placed and designed for all sorts of computing and engineering projects. 
The history of UNIX speaks for itself. Many Universities that offer respected 
and credible science based degree programmes, namely engineering and computing 
programmes, strongly encourage students to become competent with UNIX systems. 
Windows in my opinion is really for those who use the internet on a casual 
basis or in a commercial environment where its staff are not necessarily 
computer literate and therefore need a platform that they can use which doesn't 
require them to learn more complex techniques and protocols. But, having said 
that, I'm not against Windows at all. I use it frequently and enjoy using it 
most of the time. 

> "serious" is also a matter of opinion.  I have some serious
> programmer friends who maintain, in complete sincerity, that
> serious programmers should not waste time on slow, script-kiddie
> languages like Python, but should be developing their skills 
> with serious professional languages like Java, C#, etc.

That is a narrow minded approach. different languages serve different purposes 
and it's down to the developer to use which language she needs to achieve what 
it is they've set out to do. Sometimes, basic shell scripts can be extremely 
powerful for certain tasks; other needs will require something different. I 
certainly wouldn't describe Python as a "script-kiddie" language. It's 
extremely powerful and modern. So there ;-P lol
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Obnoxious postings from Google Groups

2012-11-01 Thread Jamie Paul Griffin
/ Steven D'Aprano wrote on Wed 31.Oct'12 at 22:33:16 + /

> On Wed, 31 Oct 2012 12:32:57 -0700, rurpy wrote:
 
> I don't killfile merely for posting from Gmail or Google Groups, but 
> regarding your second point, it has seemed to me for some years now that 
> Gmail is the new Hotmail, which was the new AOL. Whenever there is an 
> inane, lazy, mind-numbingly stupid question or post, chances are 
> extremely high that the sender has a Gmail address.

That's a bit harsh but then, sadly there's some truth in it. I subscribe to a 
number of technical mailing lists, like that of my OS OpenBSD and the problem 
doesn't exist there whether they use Gmail or Hotmail, etc, or not. This and 
the tutor python list are the two I have the most problems with formatting. 
Some people just don't seem to give a shit about sending horrid html and other 
irritating formatted mail in spite of being asked not to do so.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Obnoxious postings from Google Groups

2012-11-01 Thread Jamie Paul Griffin
/ Robert Miles wrote on Wed 31.Oct'12 at  0:39:02 -0500 /

> For those of you running Linux:  You may want to look into whether
> NoCeM is compatible with your newsreader and your version of Linux.
> It checks newsgroups news.lists.filters and alt.nocem.misc for lists
> of spam posts, and will automatically hide them for you.  Not available
> for other operating systems, though, except possibly Unix.

Anybody serious about programming should be using a form of UNIX/Linux if you 
ask me. It's inconceivable that these systems should be avoided if you're 
serious about Software Engineering and Computer Science, etc. For UNIX there 
are loads of decent news reading software and mail user agents to learn and 
use. slrn is a good one and point it at gmane.org as someone else pointed out. 
I can't even imagine using a browser or Google Groups, etc. now. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Functional way to compare things inside a list

2012-09-22 Thread Jamie Paul Griffin
[ Ian Kelly wrote on Sat 22.Sep'12 at  0:22:43 -0600 ]

> On Fri, Sep 21, 2012 at 7:25 PM, Steven D'Aprano
>  wrote:
> > On Fri, 21 Sep 2012 14:49:55 -0600, Ian Kelly wrote:
> >
> >> On Fri, Sep 21, 2012 at 1:54 PM, 8 Dihedral
> >>  wrote:
> >>> I don't think functional aspects are only marked as lazy programming.
> >>
> >> He wrote "lazy evaluation", not "lazy programming".  Two entirely
> >> different things.
> >
> >
> > For the record, the consensus here is that 8 Dihedral is probably a
> > bot. It appears to be a pretty good bot, I haven't spotted it making any
> > egregious or obvious grammatical mistakes, but the semantics of its posts
> > don't seem quite human.
> 
> I'm aware of that, although sometimes the posts seem coherent enough
> that I think maybe it's not.  Especially the ones where it posts
> almost-working code snippets, complete with obvious typos.
> 
> Then it posts a complete non sequitur like the reply to my reply in
> this thread, and the illusion is shattered.

I find this intriguing, I had no idea bots existed to post to mailing
lists in this way. What's the point of them?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Obnoxious postings from Google Groups (was: datetime issue)

2012-09-17 Thread Jamie Paul Griffin
[ Joel Goldstick wrote on Sun 16.Sep'12 at 11:57:56 -0400 ]
 
> email client to python-list@python.org

If using Windows I would certainly use Thunderbird or even slrn news reader - I 
believe there is a version for Windows. Or you could install Interix subsystem 
which provides UNIX tools for Windows 7 Ultimate or Professional. You'd then 
have some more choice of MUA client or newsreader client in that environment. 
Cygwin is another alternative. 

UNIX systems just use whatever email client you like and subscribe to the list 
as explained several times by others. Fortunately for me I've got procmail 
deleting double posts because they are annoying. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which Version of Python?

2012-09-12 Thread Jamie Paul Griffin
[ Ramchandra Apte wrote on Tue 11.Sep'12 at 19:58:29 -0700 ]

> On Tuesday, 11 September 2012 22:19:08 UTC+5:30, Charles Hottel  wrote:
> > I have a lot of programming experience in many different languages and now 
> > 
> > I want to learn Python.  Which version do you suggest I download, Python 
> > 2.x 
> > 
> > or Python 3.x ?  Also why should I prefer one over the other?
> > 
> > 
> > 
> > Right now I am thinkng Python 3.x as it has been out since 2008, but I have 
> > 
> > some concerns about backward compatibility with older packages that I might 
> > 
> > want to use.
> > 
> > 
> > 
> > Thanks for your ideas and help.
> 
> Use Python 3 because most packages support Python 3. Python 2.7 has many 
> features that Python 3 has so it will require minimal effort to write Python 
> 2.x code.

When I first started to learn Python - about a year ago - I got myself a book 
which focuses on version 3 but is does also include Version 2. The author wrote 
that because a number of supporting libraries have not been updated to work in 
Python 3, and where "it is felt that the theory still needs to be expounded 
upon" Python 2.x will be used in lieu of Python 3. I personally, as a beginner, 
have found this approach helpful. Although, when this book was published Python 
3.1 was the latest release, so of course since then said libraries most 
probably have been updated. So, as a fellow beginner i'd go for version 3.x.

Jamie.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Books?

2012-08-23 Thread Jamie Paul Griffin
[ Virgil Stokes wrote on Wed 22.Aug'12 at 16:34:40 +0200 ]

> On 22-Aug-2012 16:04, Steven D'Aprano wrote:
> > On Tue, 21 Aug 2012 18:36:50 -0700, Anonymous Group wrote:
> >
> >> What books do you recomend for learning python? Preferably free and/or
> >> online.
> > Completely by coincidence, I have just discovered, and I mean *literally*
> > just a few minutes ago, this book:
> >
> > http://www.springer.com/mathematics/computational+science+%26+engineering/book/978-3-642-30292-3
> >
> > http://codingcat.com/knjige/python/A%20Primer%20on%20Scientific%20Programming%20with%20Python.pdf
> >
> >
> > I wish it had existed when I was a beginner! I haven't read the whole
> > thing, but dammit it looks like exactly the sort of book I would have
> > adored as a newbie. (Your mileage may vary.)
> >
> >
> >
> I second this --- this is a very good book IMHO. I have the first edition 
> (2009) 
> and have found it very useful.
> 
> Good tip!

absolutely. I've been reading it most of last night, certainly a great learning 
resource. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Books?

2012-08-22 Thread Jamie Paul Griffin
[ Mark Lawrence wrote on Wed 22.Aug'12 at  8:43:58 +0100 ]

> On 22/08/2012 02:36, Anonymous Group wrote:
> > What books do you recomend for learning python? Preferably free and/or
> > online.
> >
> 
> Search for the Alan Gauld tutorial.  I've never used it myself, but OTOH 
> I've never heard anybody complain about it!!!
> 
> As someone else has already mentioned it, I'd highly recommend Dive Into 
> Python

I bought "Beginning Python - Using Python 2.6 and 3.1" by James Payne, 
published by Wrox www.wrox.com. I've found it quite good so far, it's pretty 
comprehensive.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANNC] pybotwar-0.8

2012-08-21 Thread Jamie Paul Griffin
[ Ramchandra Apte wrote on Sat 18.Aug'12 at 19:21:03 +0530 ]

> I'll be using Google Groups (hopefully it won't top-post by default) to
> post stuff.

You are encouraged to get used to it i'm afraid as any mailing list you use, 
its users will prefer you to use the correct formatting of responses. 

You can change the settings in Gmail web interface or use an MUA and configure 
that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Remote uptime with win32pdh

2009-09-29 Thread Jamie
On Sep 29, 1:19 pm, Jamie  wrote:
> On Sep 29, 1:08 pm, Jamie  wrote:
>
>
>
>
>
> > I'm new to python and I'm trying to write a script which takes the
> > computer name from the variable 'name' and gets the uptime.
>
> > What I have so far:
> >     query = win32pdh.OpenQuery()
> >     counter = win32pdh.AddCounter(query, r'\System\System Up Time')
> >     win32pdh.CollectQueryData(query)
> >     var1, val = win32pdh.GetFormattedCounterValue(counter,
> > win32pdh.PDH_FMT_LONG)
> >     uptime = val / 3600
>
> >     print "--> Uptime: %s hours" % uptime
>
> > That works just fine for the local system, but I'm at a loss figuring
> > out how to make it gater that data from a remote system. Any help
> > would be much appreciated!
>
> Oh, and I can't use WMI because WMI doesn't seem to work in Portable
> Python (long story)- Hide quoted text -
>
> - Show quoted text -

path = win32pdh.MakeCounterPath((name, r'System', None, None, 0,
"System Up Time"))
query = win32pdh.OpenQuery()
handle = win32pdh.AddCounter(query, path)
win32pdh.CollectQueryData(query)
seconds = win32pdh.GetFormattedCounterValue(handle,
win32pdh.PDH_FMT_LONG | win32pdh.PDH_FMT_NOSCALE )[ 1 ]

uptime = seconds / 3600


that works! ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Remote uptime with win32pdh

2009-09-29 Thread Jamie
On Sep 29, 1:08 pm, Jamie  wrote:
> I'm new to python and I'm trying to write a script which takes the
> computer name from the variable 'name' and gets the uptime.
>
> What I have so far:
>     query = win32pdh.OpenQuery()
>     counter = win32pdh.AddCounter(query, r'\System\System Up Time')
>     win32pdh.CollectQueryData(query)
>     var1, val = win32pdh.GetFormattedCounterValue(counter,
> win32pdh.PDH_FMT_LONG)
>     uptime = val / 3600
>
>     print "--> Uptime: %s hours" % uptime
>
> That works just fine for the local system, but I'm at a loss figuring
> out how to make it gater that data from a remote system. Any help
> would be much appreciated!

Oh, and I can't use WMI because WMI doesn't seem to work in Portable
Python (long story)
-- 
http://mail.python.org/mailman/listinfo/python-list


Remote uptime with win32pdh

2009-09-29 Thread Jamie
I'm new to python and I'm trying to write a script which takes the
computer name from the variable 'name' and gets the uptime.

What I have so far:
query = win32pdh.OpenQuery()
counter = win32pdh.AddCounter(query, r'\System\System Up Time')
win32pdh.CollectQueryData(query)
var1, val = win32pdh.GetFormattedCounterValue(counter,
win32pdh.PDH_FMT_LONG)
uptime = val / 3600

print "--> Uptime: %s hours" % uptime

That works just fine for the local system, but I'm at a loss figuring
out how to make it gater that data from a remote system. Any help
would be much appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: detmining name during an assignment

2009-09-18 Thread Jamie Riotto
On Fri, Sep 18, 2009 at 1:10 PM, Gabriel Genellina
 wrote:
> En Fri, 18 Sep 2009 14:38:08 -0300, Christian Heimes 
> escribió:
>>
>> Jamie Riotto schrieb:
>
>>> I have an app that uses Python scripting. When a user creates a new
>>> object:
>>>
>>> objName = newObject()
>>>
>>> I'd like the newObject be able to use objName as its internal name.
>>
>> As the others already explained to you there is no way to archive your
>> goal with an assignment to a local or global variable. But you can
>> follow a different approach:
>>
>> class Scene(object):
>>    def __setattr__(self, name, value):
>>        super(Scene, self).__setattr__(name value)
>>        if isinstance(value, SceneObject):
>>            value.name = name
>>            value.scene = self
>>
>> class SceneObject(object):
>>    pass
>>
>> class Cube(SceneObject):
>>    pass
>>
>> scene = Scene()
>> scene.cube1 = Cube()
>
> As the OP said it's being used for scripting some application, presumably
> the application can control the environment on which the script is run. One
> may use the Scene class above as the globlal scope when executing the
> script:
>
> scene = Scene()
> code = "cube1 = Cube(); print cube1.name"
> exec code in Scene
>
> (well, not exactly, Scene should inherit from dict and override __setitem__
> instead, but you get the idea)
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Thanks for the detailed clarifications and suggestions. I understand
the problem a lot better now.
However, I'll have to keep looking for a more elegant solution.
Telling a user that typing:
cube1 = Cube(name = cube1) is a good thing because its pythonic is
somehow unsatisfying.

Also, in the last suggestion about execution the script in the Scene
Handler global scope, well thats
exactly what I do, and yes, cube1=Cube, print cube1.name works great.
The issue is say perhaps that
cube then collides with something called sphere1. How does cube1 know
that it hit "sphere1" and not
just a sphere object. Since I can execute the scripts one line at a
time, I suppose I could search dictionaries
for new names pointing to the same object after every execution, but Yuck.

Perhaps the best approach is a preprossesor that looks for lines of
the form "name = class()" and adds in the
class(name = name) behind the scenes. Thanks again - jamie
-- 
http://mail.python.org/mailman/listinfo/python-list


detmining name during an assignment

2009-09-18 Thread Jamie Riotto
I have an app that uses Python scripting. When a user creates a new object:

objName = newObject()

I'd like the newObject be able to use objName as its internal name.
So, if a user says:

cube1 = Cube()

 A "cube1" object should apear in the scene list. I believe this means I need
to determine that a namespace assignment is going on from inside the
object's init code
or by using properties.

I've searched the web but can't find a simple answer. Is there some
way to use the inspect
module get source code functoins? How would I get the code for "the
current interpreter line"
causing the init code to execute?

Thanks very much in advance,
Jamie Riotto
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem with winreg - The object is not a PyHKEY object

2009-08-21 Thread Jamie
My goal is to remotely remove the registry keys for McAfee. I don't
know how winreg handles an exception if a key doesn't exist, but I
setup my script to skip the exception. But it doesn't seem to work
right.. I think the script should be self explanitory, please help!
Please forgive me, but I'm a python newbie.

## SCRIPT ##

import _winreg

print "Removing McAfee registry entries"
hkey = _winreg.ConnectRegistry(r'\
\00439140PC',_winreg.HKEY_LOCAL_MACHINE)
try:
_winreg.DeleteKey('SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEAPFK')
except:
pass

#try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEAVFK')
#except:
# pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEBOPK')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEHIDK')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEHIDK01')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFERKDK')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFETDIK')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_NAIAVFILTER1')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_NAIAVFILTER101')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MCSHIELD')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','MCTASKMANAGER')
except:
pass

try:
_winreg.DeleteKey('\SOFTWARE','McAfee')
except:
pass

try:
_winreg.DeleteKey('\SOFTWARE','Network Associates')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','AlertManager')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet
\Services','McAfeeFramework')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','McShield')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet
\Services','McTaskManager')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfeapfk')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfeavfk')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfebopk')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfehidk')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfehidk01')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mferkdk')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','mfetdik')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Services','NaiAvFilter1')
except:
pass

try:
_winreg.DeleteKey('\SYSTEM\CurrentControlSet
\Services','NaiAvFilter101')
except:
pass

## END SCRIPT ##

## OUTPUT ##
Removing McAfee registry entries
Traceback (most recent call last):
File "uninstallMcafee.py", line 11, in 
_winreg.DeleteKey('\SYSTEM\CurrentControlSet\Enum
\Root','LEGACY_MFEAVFK')
TypeError: The object is not a PyHKEY object
## END OUTPUT ##
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython BoxSizer

2008-11-19 Thread Jamie McQuay

>
> > FYI: There's a great wxPython mailing list too. Check it out 
> > here:http://wxpython.org/maillist.php
>
> thanks, i will take a look.

Here is the answer i got from the mailing list (and it works)

Try adding a spacer on both sides of text.

i.e)
box.AddStretchSpacer()
box.Add(myText, 0, wx.ALIGN_CENTER)
box.AddStretchSpacer()

jamie

--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython BoxSizer

2008-11-19 Thread Jamie McQuay

>
> Try the style=wx.CENTER like this:
>
> box.Add(myText,0,wx.CENTER)

tried but i still get the same result.  The text is either at the top
of the panel (centered) or in the middle (on the left side).  If i
manually call CenterOnParent when the panel is resized it goes to the
center but i want to get the sizers to work correctly for this.

>
> FYI: There's a great wxPython mailing list too. Check it out 
> here:http://wxpython.org/maillist.php

thanks, i will take a look.

Jamie

--
http://mail.python.org/mailman/listinfo/python-list


wxPython BoxSizer

2008-11-19 Thread Jamie McQuay
Simple question, i just can't make it work.

I need to center a StaticText component in its parent (Panel).  I want
to do this with BoxSizer(s).

if i use:
box = wx.BoxSizer(wx.VERTICAL)   #or wx.HORIZONTAL
box.Add(myText,0,wx.ALIGN_CENTER)
parentPanel.Sizer = box

i can get it to center either vertically or horizontally, but not both
(i.e. the center).  I've tried myText.CenterOnParent but i need to
handle to Size event to move the text when the panel is resized and i
don't want to have to do this.

thanks,
Jamie
--
http://mail.python.org/mailman/listinfo/python-list


Re: I am giving up perl because of assholes on clpm -- switching to Python

2007-08-02 Thread Jamie
In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] mentions:
>Python is a better language, with php support, anyway, but I am fed up
>with attitudes of comp.lang.perl.misc. Assholes in this newsgroup ruin
>Perl experience for everyone. Instead of being helpful, snide remarks,
>back-biting, scare tactings, and so on proliferate and self
>reinforce. All honest people have left this sad newsgroup. Buy bye,
>assholes, I am not going to miss you!!!
>
>Martha

I've heard people tell the same story, that perl folks are... rude.

Actually, I've pretty much heard (and noticed) that about linux, too.

Yet, linux is still a good operating environment, so is perl.

You'll find rude people everywhere you look. While it may be true that
there is a higher percentage of hard-core tech folks who might lack
social skills, at least they don't err.. well, maybe they do.. byte. :-)

Seriously, it is one of the problems facing perl (and linux) people ARE
turned away by the attitude. It is rather embarassing/unflattering when
someone is critical of your work.

I see a lot of ideas about things should be "made easier" but I think 
thats the wrong course. We really just need to be nicer to new folks.

Jamie
-- 
http://www.geniegate.comCustom web programming
Perl * Java * UNIXUser Management Solutions
-- 
http://mail.python.org/mailman/listinfo/python-list


PIL problems

2007-02-15 Thread Jamie Bohr

I am trying to allow JPEG's to be used for portraits inside of Plone.  I
have Googled and found I need to install the Pytphon Imaging Library (PIL);
after that all should be good.  I did that, but I an error that tells me
there is a missing library.  The below is a log of what I did.  From what I
can tell Python sees the library but .. (I'm used to Perl so I have no
idea).  I am working on a RHEL v4 x64 system.

Thank you in advance for your time.

Error Value decoder jpeg not availableHere is the log of me installing PIL:

$ sudo /opt/python/bin/python setup.py install
running install
running build
running build_py
running build_ext

PIL 1.1.6 BUILD SUMMARY

version   1.1.6
platform  linux2 2.4.3 (#1, Jan 30 2007, 15:38:40)
 [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]

*** TKINTER support not available
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not available

*** Warning: zlib 1.2.1.2 may contain a security vulnerability.
*** Consider upgrading to zlib 1.2.3 or newer.
*** See: http://www.kb.cert.org/vuls/id/238678
http://www.kb.cert.org/vuls/id/680620
http://www.gzip.org/zlib/advisory-2002-03-11.txt


To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

To check the build, run the selftest.py script.
running build_scripts
running install_lib
running install_scripts
changing mode of /opt/python/bin/pilprint.py to 755
changing mode of /opt/python/bin/pilconvert.py to 755
changing mode of /opt/python/bin/pilfont.py to 755
changing mode of /opt/python/bin/pildriver.py to 755
changing mode of /opt/python/bin/pilfile.py to 755
creating /opt/python/lib/python2.4/site-packages/PIL.pth
$
$ sudo /opt/python/bin/python selftest.py
*
Failure in example: _info(Image.open("Images/lena.jpg"))
from line #24 of selftest.testimage
Exception raised:
Traceback (most recent call last):
 File "./doctest.py", line 499, in _run_examples_inner
   exec compile(source, "", "single") in globs
 File "", line 1, in ?
 File "./selftest.py", line 22, in _info
   im.load()
 File "PIL/ImageFile.py", line 180, in load
   d = Image._getdecoder( self.mode, d, a, self.decoderconfig)
 File "PIL/Image.py", line 375, in _getdecoder
   raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
1 items had failures:
  1 of  57 in selftest.testimage
***Test Failed*** 1 failures.
*** 1 tests of 57 failed.
$
$  /opt/python/bin/python -vv -c "import PIL._imaging" 2>&1 | less

# PIL/__init__.pyc matches PIL/__init__.py
import PIL # precompiled from PIL/__init__.pyc
# trying PIL/_imaging.so
dlopen("PIL/_imaging.so", 2);
import PIL._imaging # dynamically loaded from PIL/_imaging.so
# clear __builtin__._
# clear sys.path



--
Jamie Bohr
-- 
http://mail.python.org/mailman/listinfo/python-list

How would I create an class with a "Person.Address.City" property?

2006-12-18 Thread Jamie J. Begin
I'm very new to the world of Python and am trying to wrap my head around
it's OOP model. Much of my OOP experience comes from VB.Net, which is
very different.

Let's say I wanted to create an object that simply outputted something
like this:

>>> import employees
>>> person = employee("joe") # Get Joe's employment file
>>> print employee.Title # What does Joe do?
Developer
>>> print person.Address.City # Which city does Joe live in?
Detroit
>>> print person.Address.State # Which state?
Michigan

To do this would I create nested "Address" class within the "employee"
class? Would it make more sense to just use "print
person.Address('City')" instead?

Thanks for your help!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pythot doc problem: lambda keyword...

2005-10-13 Thread Jamie Border
"Pisin Bootvong" <[EMAIL PROTECTED]> wrote:
Xah Lee ?:
[...]
> Fuck the Python liers and ignorant fuckheads. Motherfucking don't know
> shit and yet lying thru their teeth with fanfare.
[...]
>  Xah
>  [EMAIL PROTECTED]
> ? http://xahlee.org/

[elided]

PB> BTW, you post to the wrong group.

No, I think c.l.l is exactly the place to discuss how to play many trumpets 
through one set of teeth.

In fact, I have a box of trumpets lying around somewhere...

Open wide, Xah!

Jamie 


-- 
http://mail.python.org/mailman/listinfo/python-list


Injecting a C side object into the local dict

2005-02-11 Thread Jamie R. Parent
Hello,

How do you go about taking a variable which was declared in C and pass
that through to a Python script? I have tried doing this by adding a
simple string which is a PyObject from C into the local dictionary and
retrieving it from script via a locals()["myCvar"] print statement.
This however does not seem to work. It would seem that when the scripts
are ran the local dictionary with the added item is wiped clean and a
new local dictionary is instead used. Any direction or help would be
appreciated.

Cheers,
Jamie.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket.makefile & AF_UNIX

2004-12-10 Thread Jamie Saker
>If you're trying to create a Unix socket then mknod() isn't what
>you need.  You probably want to create a socket and bind() it to
>the log file:

>filename = 'snort_alert'
> s = socket(AF_UNIX, SOCK_DGRAM)
> s.bind(filename)

Interesting - I tried this with a local test_log and it worked, creating:

srwxr-xr-x  1 field users   0 Dec 10 19:26 test_log=

which looks like my /dev/log device.

>The call to bind() will probably fail if the socket file already
>exists,

Indeed it does.

> If it's binary then you might need to use s.recv().

Makes sense. Thanks Michael. I'd expect socket.makefile is probably less 
encountered than most aspects of socket (according to google, it sure seemed 
so!).

Jamie
--
http://mail.python.org/mailman/listinfo/python-list


socket.makefile & AF_UNIX

2004-12-10 Thread Jamie Saker
I think I'm overlooking something assumed in socket's makefile method. 
Googling several hours and digging thru the python reference didn't help - I 
think I'm overlooking an assumption between Python and UNIX socket objects 
neither is explicitely discussing. I think my mknod 

In the makefile operation on socket (pydoc socket.socket.makefile... using 
AF_UNIX, allowing you to create a file object to correspond to a socket) I've 
got an sample program (goal: open up unix file socket object for snort's 
alert_unixsock output mode to dump to. later, take data written into file 
object and process) as follows:

###3
#!/usr/bin/python
## socketfile.py
## for socket file object to collect snort data via alert_unixsock output
"""makes file interface to socket. demo application takes data written to file 
and prints it."""

from socket import *
import os

FILE = 'snort_alert'
#FILE = '/dev/log'

if not os.path.exists(FILE):
print "Creating file..."
os.mknod(FILE)

s = socket(AF_UNIX, SOCK_DGRAM)
# SOCK_DGRAM for UDP compatibility with /dev/log - errors
# on SOCK_STREAM reference for /dev/log

s.connect(FILE)

f = s.makefile('rw')

while 1:
print "Data: %s" % f.readline(1024)
f.flush()
###3

If I guess correctly, socket.makefile might be wanting to use a block or 
character file, which I may not be setting up properly. pydoc on os.mknod 
refers to os.makedev which is even sparser on explanation. Part of the reason 
for my guess is that:

- permissions on my snort_alert file don't look right:
-rw---  1 sysadmin users 0 Dec 10 02:58 snort_alert

compared to:
srw-rw-rw-  1 root root 0 Dec 10 01:14 /dev/log=

And when I use /dev/log instead (which exists), it connects to the file object 
and runs (though snort does not want to dump to /dev/log and the limitations 
of the alert_unixsock output method limit it to /var/log/snort/snort_alert 
only).  Any thoughts from the socket savvy would be *greatly* appreciated!

Jamie

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 14, Issue 377

2004-11-29 Thread Jamie Saker
On Mon, 29 Nov 2004 16:05:14 -0500, "Eric S. Johansson" <[EMAIL PROTECTED]> 
wrote:
> If I could simply do: py-get twisted

And I forgot to mention, the Gentoo 'emerge' tool is actually written in 
Python, so in a sense, your py-get is already there in Gentoo.

From the header of /usr/bin/python:

#!/usr/bin/python -O
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-src/portage/bin/emerge,v 1.347 2004/10/21 
20:54:38 carpaski Exp $

Gentoo is a rather enjoyable distro for Python work. Most Python packages are 
an emerge away: twisted, zope (including zope3), bsddb, mysql & postgresql 
interfaces, python-ldap, pyparsing and many others. 

A few to make Gentoo more enjoyable:

1. standardize on a kernel (e.g. I use hardened-dev-sources for servers and 
gentoo-dev-sources for workstations - all 2.6 kernels,) This simplifies 
maintenance and opens up distcc for you (which will be handy if you have a 
few systems that will be running Gentoo and want to speed up source builds). 
You'll need a common kernel and gcc version in order to not have distcc 
issues.

2. read up on USE= flags. It simplifies dependencies significantly, but you 
want to make sure you're using it to its fullest, not leaving out important 
options or including everything and the kitchen sink. For instance, if you're 
not using ipv6, don't bother - including this in your USE= statement will 
slow down source builds significantly for no benefit (not to mention some 
bloat and potentially some security issues for unmonitored capabilities e.g. 
enabling samba USE without discretion).

3. set your ACCEPT_KEYWORDS = 'x86' (assuming intel/x86) to back off minor 
version builds. of course, if you need bleeding edge packages, you may have 
to use ~x86. x86 is the "stable" setting. 

4. for help, forums.gentoo.org is useful (though the search engine is rather 
lacking imho)

Having started with two 5.25's in 1993, I've been a die-hard user of SLS, 
Slackware, Redhat, Debian and now Gentoo. You'll hear plenty of distro war 
stuff and certainly every tool has its pros/cons. For python, if you haven't 
given Gentoo a look, check it out...

Jamie
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 14, Issue 377

2004-11-29 Thread Jamie Saker
On Mon, 29 Nov 2004 16:05:14 -0500, "Eric S. Johansson" <[EMAIL PROTECTED]> 
wrote:
> If I could simply do: py-get twisted

or how about 'emerge twisted'

works fine for me! When twisted2 comes out, emerge world will catch it for me 
too. Check out Gentoo at http://www.gentoo.org for more info, or on IRC at 
#gentoo 

Jamie Saker
"Gentoo bumper sticker: I'd rather be compiling!"
-- 
http://mail.python.org/mailman/listinfo/python-list