Kent Johnson | 1 Feb 04:22 2008
Picon

Re: creating a nested dictionary

Ricardo Aráoz wrote:
> These solutions sometimes may have unexpected behavior.

> class recursivedefaultdict(defaultdict):
>     def __init__(self):
>         self.default_factory = type(self)
> d = recursivedefaultdict()
> d['pepe']['jose']['juan'] = 25
> d['pepe']['jose'] = 25

Presumably you mean
d['pepe']['martin'] = 25

> [i for i in d['pepe']]
> it prints : ['jose', 'pedro', 'martin']
> expected  : [defaultdict(<class '__main__.hash'>, {'jose':
> defaultdict(<class '__main__.hash'>, {'juan': 25}), 'pedro': 25,
> 'martin': 33})]

I think your expectations are off. Iterating a dict gives the keys:

In [14]: d=dict(juan=25, pedro=25, martin=33)
In [15]: d
Out[15]: {'juan': 25, 'martin': 33, 'pedro': 25}
In [16]: [ i for i in d]
Out[16]: ['juan', 'pedro', 'martin']

Kent
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
(Continue reading)

Varsha Purohit | 1 Feb 07:37 2008
Picon

[tutor] Scrollbars around the image

Hi All,
    I have made a simple panel where i am loading an image from the folder. I have a button named zoomin. When i press this button a pair of horizontal and vertical scrollbars should appear on the image panel nearby image. so that we can see the zoomed image properly. I am trying to use wx.Scrollbar but i am not able to fix the scrollbars properly around the image. I have not added the scrollbar portion to the button handler in the code below.. i have just commented out as its not actually working.

import wx

class ComboBox(wx.Dialog):
    def __init__(self, parent, id, title):
        wx.Dialog.__init__(self, parent, id, title, size=(450, 470))

        panel = wx.Panel(self, -1, (75, 20), (100, 127), style=wx.SUNKEN_BORDER)
        self.picture = wx.StaticBitmap(panel)
        self.picture.SetBitmap(wx.Bitmap('srk.jpg'))
        panel.SetBackgroundColour(wx.WHITE)
       


        wx.Button(self, 1, 'Close', (80, 220))
        wx.Button(self, 2, 'Zoomin', (80, 280))
        self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
        self.Bind(wx.EVT_BUTTON, self.OnZoom, id=2)


        self.Centre()
        self.ShowModal()
        self.Destroy()

    def OnClose(self, event):
        self.Close()

    def OnZoom(self, event):
##        sw = wx.ScrolledWindow(panel)
##        sw.SetScrollbars(20, 20, 155, 40)
##        sw.Scroll(50,10)
         self.Close()

app = wx.App()
ComboBox(None, -1, 'picture box')
app.MainLoop()


But can please anybody suggest me how should i go ahead and solve this problem ??


--
Varsha Purohit,
Graduate Student

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Dinesh B Vadhia | 1 Feb 23:13 2008
Picon

matrix-vector multiplication errors

I've posted this on the Scipy forum but maybe there are answers on Tutor too.  I'm performing a standard Scipy matrix* vector multiplication, b=Ax , (but not using the sparse module) with different sizes of A as follows: 

Assuming 8 bytes per float, then:
1. matrix A with M=10,000 and N=15,000 is of approximate size: 1.2Gb
2. matrix A with M=10,000 and N=5,000 is of approximate size: 390Mb
3. matrix A with M=10,000 and N=1,000 is of approximate size: 78Mb
 
The Python/Scipy matrix initialization statements are:
> A = scipy.asmatrix(scipy.empty((I,J), dtype=int))
> x = scipy.asmatrix(scipy.empty((J,1), dtype=float))
> b = scipy.asmatrix(scipy.empty((I,1), dtype=float))
I'm using a Windows XP SP2 PC with 2Gb RAM.
 
Both matrices 1. and 2. fail with INDeterminate values in b.  Matrix 3. works perfectly.  As I have 2Gb of RAM why are matrices 1. and 2. failing?
 
The odd thing is that Python doesn't return any error messages with 1. and 2. but we know the results are garbage (literally!)
 
Cheers!
 
Dinesh
 
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
William Kilmartin | 2 Feb 05:52 2008
Picon

Where to start?

Here's what I'm trying to accomplish;

I track statistics at work.  E.g. calls out, $ collected etc..

The graph has a rough guess of highest possible at the top and the 
lowest number in the past 3 months at the bottom.

It's a simple line graph, week after week.

I need to be able to add names of various statistics.  I.e. calls out, 
money collected, proposals sent etc..

It then needs to create the graph, store the names, be able to take the 
week's numbers and store them along with being able to print.  The 
highest and lowest points also need to also be inputed and changed if 
needed.

Ideally this would be a GUI driven app for the sake of simplicity.

What I'm looking for is advice on where to start, a middle ground and an 
end.  I'm new to Python and programming and took this as the 1st thing 
I'd to create. 

I've been studying for a bit now and knowing where I'm going would be 
very helpful.

--

-- 

"Microsoft isn't evil, they just make really crappy operating systems." 
-Linus Torvalds

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Alan Gauld | 2 Feb 08:25 2008

Re: Where to start?


"William Kilmartin" <williamakilmartin <at> yahoo.com> wrote

> It then needs to create the graph, store the names, be able to take 
> the
> week's numbers and store them along with being able to print.  The
> highest and lowest points also need to also be inputed and changed 
> if
> needed.
>
> Ideally this would be a GUI driven app for the sake of simplicity.
>
> What I'm looking for is advice on where to start, a middle ground 
> and an
> end.  I'm new to Python and programming and took this as the 1st 
> thing
> I'd to create.

I'd start off with a non gui version to check that the logic and math 
work.
The simplest non GUI approach will be a week by week horizontal
bar chart:

wk5    *****************        $5K
wk4    ********                    $2K
wk3    ************                $3K
wk2    **************            $4K
wk1    *****                        $7K
Calls        10    20    30    Total

This is fairly easy to do using string formatting and print 
statements.

Then work on saving the data to a file - a simple text file would do,
or you could use pickle or even shelve. Shelve would be my
bet since it will allow you to add the ability to easily retrieve
data over a limited period or from archive etc

Finally convert the text form of the graph to a GUI version using
your favourite toolkit. This wouldn't be hard to do from scratch
using a bare Canvas widget but there are plotting libraries
available that make it easier still.

HTH,

--

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Kent Johnson | 2 Feb 13:54 2008
Picon

[Fwd: PyWeek 6 is coming!]

For all of the budding game authors on the list...maybe there is 
interest in a python-tutor team? (No, I am not volunteering to lead it 
though of course the list is available for help.)

Kent

-------- Original Message --------
Subject: PyWeek 6 is coming!
Date: Fri, 1 Feb 2008 08:11:34 +1100
From: richard <at> pyweek.org
Reply-To: python-list <at> python.org
To: pygame-users <at> seul.org
CC: python-announce-list <at> python.org, pyglet-users <at> googlegroups.com, 
python-list <at> python.org

PyWeek 6 will run from 00:00 UTC on March 30th through to 00:00 UTC on 
April
6th.

Registration is NOT OPEN YET. It will open on Friday 2008/02/29.

If you're new (or even coming back again) please have a look at the 
rules and
help pages at http://www.pyweek.org/

The PyWeek challenge:

    1. Invites entrants to write a game in one week from scratch either 
as an
       individual or in a team,
    2. Is intended to be challenging and fun,
    3. Will hopefully increase the public body of game tools, code and
       expertise,
    4. Will let a lot of people actually finish a game, and
    5. May inspire new projects (with ready made teams!)

Entries must be developed in Python during the challenge, and must 
incorporate
some theme decided at the start of the challenge.

--

-- 
Visit the PyWeek website:
   http://www.pyweek.org/

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Seon Kang | 2 Feb 05:59 2008
Picon

Background

How does set the background to change on the press of a chosen key?

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Seon Kang | 2 Feb 05:41 2008
Picon

Livewires

Python will not recognize the keyboard class of livewires. what is my problem? (i have imported the modules and everything)

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Kent Johnson | 2 Feb 14:37 2008
Picon

Re: Background

Seon Kang wrote:
> How does set the background to change on the press of a chosen key?

The background of what? The desktop? An application?

What platform? Are you using a GUI toolkit?

Kent
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

bhaaluu | 2 Feb 16:48 2008
Picon

Re: [Fwd: PyWeek 6 is coming!]

Would you consider a python-Tutor team member who:

1. Is new to Python?
2. Never worked with a programming team before?
3. Doesn't have much gaming experience?
4. Doesn't have a recent version of MS-Windows (has Mac OS X or GNU/Linux)?
5. May not be running the latest and greatest version of Python?
6. Is willing to learn!

If so, in what ways could such a team member contribute to the challenge?
(Hoping to start a discussion here!)

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
"You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance.  Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul." [Mahatma Gandhi]

On Feb 2, 2008 7:54 AM, Kent Johnson <kent37 <at> tds.net> wrote:
> For all of the budding game authors on the list...maybe there is
> interest in a python-tutor team? (No, I am not volunteering to lead it
> though of course the list is available for help.)
>
> Kent
>
> -------- Original Message --------
> Subject: PyWeek 6 is coming!
> Date: Fri, 1 Feb 2008 08:11:34 +1100
> From: richard <at> pyweek.org
> Reply-To: python-list <at> python.org
> To: pygame-users <at> seul.org
> CC: python-announce-list <at> python.org, pyglet-users <at> googlegroups.com,
> python-list <at> python.org
>
> PyWeek 6 will run from 00:00 UTC on March 30th through to 00:00 UTC on
> April
> 6th.
>
> Registration is NOT OPEN YET. It will open on Friday 2008/02/29.
>
> If you're new (or even coming back again) please have a look at the
> rules and
> help pages at http://www.pyweek.org/
>
> The PyWeek challenge:
>
>     1. Invites entrants to write a game in one week from scratch either
> as an
>        individual or in a team,
>     2. Is intended to be challenging and fun,
>     3. Will hopefully increase the public body of game tools, code and
>        expertise,
>     4. Will let a lot of people actually finish a game, and
>     5. May inspire new projects (with ready made teams!)
>
> Entries must be developed in Python during the challenge, and must
> incorporate
> some theme decided at the start of the challenge.
>
>
> --
> Visit the PyWeek website:
>    http://www.pyweek.org/
>
> _______________________________________________
> Tutor maillist  -  Tutor <at> python.org
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


Gmane