Re: [Tutor] Disable keyboard/mouse input on windows?

2007-10-01 Thread Tim Golden
Trey Keown wrote:
> Hey everybody,
> I was wondering, how could I disable all keyboard/mouse input for the
> whole windows system while I have a video playing? So the user can't
> press, for example, the super key [one with windows logo on it], and have
> the windows menu pop up?
> Could this be accomplished somehow through system hooks?

In the final analysis, I imagine you *could* do this by
digging hard enough. But (a) it won't be easy to do it
in a robust way which takes account of all possibilities,
and (b) I think any program which acted in this way (locking
out all others) would be *very* ill-considered.

If you're really set on this, it's probably worth looking
for kiosk-mode / internet cafe setups as they presumably
do things like this, so maybe Googling for those terms
might throw up a solution.

TJG
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to Practice Python?(Linpeiheng)

2007-10-01 Thread Alan Gauld

"???" <[EMAIL PROTECTED]> wrote

> I am learning Python. Do you know somewhere I can practice Python?
> I means some sites where have exercises I can try solving.

The Useless Python website has some exercises and other small 
projects.
Some have solutions some don't.

Also the Python Challenge web site offers a "Game" where you
navigate through the lasyers by solving Python puzzles, each
using a new feature of Python.

> And there should be standard answer or other people's
> answer that can be refered.

This is harder. There are solutions around for spome of them
but not "standard solutions" - I'm not sure what such a thing would
look like in a programming context. There are no such things
as standard solutions to programming problems, its not like
doing math!

Some solutions are nicer than othes but each usually has some merit.

HTH,

Alan G 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Really basic web templating

2007-10-01 Thread Alan Gauld

"wormwood_3" <[EMAIL PROTECTED]> wrote

> ...nearly every tutorial I have seen regarding Python and CGI only
> have to do with form submissions,

Thats the most common use of CGI but really a form submission is just
a standard HTTP GET/POST request with some predefined variables.
In reality the user requests your python script and whatever the 
script
sends to stdout goes to the browser

So all you have to do is read in your header, body and footer and
stitch them together then send them to stdout.

If you want richer functionality you can use templating engines
from the frameworks without the framework being present.
For example the kid system used in TurboGears can be used
standalone to give sophistoicated templating without anything
special being done to the web server. Indeed it can even be
used outside a web server context.

But from your description simple CGI and Python may be all
you need.

HTH,

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


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Disable keyboard/mouse input on windows?

2007-10-01 Thread Alan Gauld

"Trey Keown" <[EMAIL PROTECTED]> wrote

> I was wondering, how could I disable all keyboard/mouse input for 
> the
> whole windows system while I have a video playing? So the user can't
> press, for example, the super key [one with windows logo on it], and 
> have
> the windows menu pop up?
> Could this be accomplished somehow through system hooks?

Yes it can be done using the low level Windows API calls. You could
do that from Python using ctypes.

But you really shouldn't! It's very easy to lock up a PC completely if
you do that and many users get very cross whem they run a program
which completely locks their machine and prevents them using it
for other things. After all they paid for a multi-tasking OS why 
should
applications prevent them from using it?!

>From a video playing perspective consider too how you might get rid
of a warning dialog that Windows (or your anti-virus scanner etc)
decides to pop onto the screen while watching the video?
You are stuck with a dialog blocking the view which you can't
get rid of till the video ends!

Alan G 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] creating image from a given data in wxpython

2007-10-01 Thread Alan Gauld

"Ian Witham" <[EMAIL PROTECTED]> wrote

>> I basically wanna create a bitmap image in python. This will be
>> basically in pixels. X and y coordinates will be specified in the 
>> program
>> and python should create an image by matching the colours.

> I found it to be a very slow way to do things (both in programming 
> and in
> execution speed) and I ended up using the Python Image Library (PIL)
> instead.
>
> If you don't really need the GUI capabilities of WX for this project 
> then
> PIL is probably a better tool for the job.

Avtually I'd recommend PIL even if you do need the wxPython GUI
capabilities. wxPython will happily display bitmapps created in PIL.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] printing bitmap image dynamically reading data inwxpython

2007-10-01 Thread Alan Gauld
"Varsha Purohit" <[EMAIL PROTECTED]> wrote

> I want to create a wxpython program where i am reading a list 
> having
> integer values like [1,2,3,4]. and i need to display the output 
> value as
> bitmap image which shd be coloured after reading the values. Like 
> 1=red,
> 2=yellow, 3=orange etc and it displays the output in colours at 
> proper
> coordinates by matching values of the array.

Sounds like a fun project.
Have you any plans on how to go about it?
Are you having problems? Or are you just sharing your excitement
at the challenge?

> I need to make a script file for arcgis tool which converts the
> ascii data to a coloured bitmap image at given coordinates.

I dunno much about arcgis but again it sounds like a reasonable
thing to do.

Let us know how you get on. If you run into problems ask
questions we might be able to help. However since it seems
to be a homework type exercise we can't solve it for you.

HTH,

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


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionary - count values where values are stored as a list

2007-10-01 Thread Alan Gauld

"GTXY20" <[EMAIL PROTECTED]> wrote

> Any way to display the count of the values in a dictionary where the 
> values
> are stored as a list? here is my dictionary:
>
> {'1': ['a', 'b', 'c'], '3': ['a', 'b', 'c'], '2': ['a', 'b', 'c'], 
> '4':
> ['a', 'c']}
>
> I would like to display count as follows and I would not know all 
> the value
> types in the values list:
>
> Value QTY
> a   4
> b   3
> c   4

Try a list comprehension:

data = [(key, len(D[key]) for key in D]

Printing that out becomes a simple loop:

print "Value\tQTY"
for tup in data:
print "%s\t%s" % tup

> Also is there anyway to display the count of the values list 
> combinations so
> here again is my dictionary:
> {'1': ['a', 'b', 'c'], '3': ['a', 'b', 'c'], '2': ['a', 'b', 'c'], 
> '4':
> ['a', 'c']}
>

The same approach should work except you change the tuple values:

data = [(len(D[key]), D[key]) for key in D]

HTH,


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


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Really basic web templating

2007-10-01 Thread Martin Walsh
wormwood_3 wrote:
> Well yes and no:-) This sort of application would fall under the
> sprawling category of CGI, yes, and I can use Python scripts on my web
> server, so it is supported. But nearly every tutorial I have seen
> regarding Python and CGI only have to do with form submissions, doing
> calculations and other things with data sent from webpages to Python
> scripts. But that is not really what I want to do. I am wondering what a
> script would need to do to take requests for pages on my site, and
> generate them from templates. I am not sure if I can do this without
> having access to Apache rewrite rules, etc.

I am going to assume from your description that you are looking for a
way to use a *single* cgi script to handle all page requests to your
site, and respond with the appropriate template based on the requested
url. If I have assumed incorrectly then you can safely ignore the rest
of this message. :)

Some mod_rewrite directives are available to .htaccess, IIRC -- so that
may be a valid option, only if your webhost has enabled mod_rewrite of
course, and they allow overrides with htaccess.

Otherwise, this is a fairly simple task if you are content with "ugly"
urls. For example, given a url something like
http://mysite.com/mycgi.py?page=index.html, a very basic cgi
implementation might look like this:

#!/usr/bin/env python
import cgi

form = cgi.FieldStorage()

print "Content-type: text/html\n"
try:
page = form["page"]
except KeyError:
print file('custom404error.html').read()
else:
content = file(page.value).read()
# ... do something with content ...
print content

---

If your webhost has enabled mod_actions (I suppose this is unlikely),
you can also do the following in .htaccess (again, only if they allow
override):

AddHandler my-python-handler .html
Action my-python-handler /cgi-bin/handler.py

which should force apache to set an environment variable named
'PATH_TRANSLATED' with the value of the requested url, and call
'handler.py' for any requested file with an .html extension (that
exists) in that directory -- honestly, I've never attempted this myself
-- and there is probably a better way, but it's all I can think of ATM.
If the file doesn't exist apache returns a 404, which is only desirable
if you plan to store your templates on the filesystem. And you can use
the os module to access the cgi environment variables:

#!/usr/bin/env python
import os

print "Content-type: text/plain\n"

try:
path = os.environ["PATH_TRANSLATED"]
except:
path = 'PATH_TRANSLATED is not defined.'

print "The requested url is:", path

---

Perhaps you could convince your webhost to install mod_python, if they
haven't already. It's fairly trivial to write a simple mod_python
handler to accomplish exactly what you are trying to do.

HTH,
Marty
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating the equivalent of string.strip()

2007-10-01 Thread Andrew James
I've gone ahead and created a script that does this, however it also 
strips punctuation. I was originally just comparing each character to a 
string containing a single space ' ' but even using s[-1].isspace() I 
lose punctuation marks. Any idea why that's happening?

(Not the OP, I just thought this would be interesting to do)

Bob Nienhuis wrote:
> BTW, GMail brings up some interesting sponsored links when the subject 
> line
> has string.strip in it ( :-0)
>
> On 9/30/07, *Alan Gauld* < [EMAIL PROTECTED] 
> > wrote:
>
>
> "wesley chun" < [EMAIL PROTECTED] > wrote
> in message
> news:[EMAIL PROTECTED]
> >> > I'm not sure how to proceed.  My biggest stumbling
> >> > block is how to detect the leading and trailing
> >> > whitespace.
> >>
> >> Use indexing.
> >> Try using a while loop.
> >> Or maybe two?
> >>
> >> And strings have an isspace method...
> >
> > unfortunately, the isspace() string method only returns True if all
> > chars in the string are whitespace chars and False otherwise, so
> > that's a bummer.
>
> But the string can be one character long:
>
> s = 'fred\n'
> print s[-1].isspace()  # --> True
>
> :-)
>
> Alan G
>
>
> ___
> Tutor maillist  -  Tutor@python.org 
> http://mail.python.org/mailman/listinfo/tutor
>
>
> 
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   
> 
>
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.488 / Virus Database: 269.13.35 - Release Date: 29/09/2007 12:00 
> AM
>   
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Really basic web templating

2007-10-01 Thread Kent Johnson
wormwood_3 wrote:
>  I want
> to do this because my site is on a shared hosting account, so I cannot
> install a web framework like Django

Another option is to switch to a hosting account that supports Python. I 
have been working with WebFaction and I'm very happy with them; an 
account with Django support is available for less than $10/month.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionary - count values where values are stored as a list

2007-10-01 Thread Kent Johnson
GTXY20 wrote:
> Hello,
> 
> Any way to display the count of the values in a dictionary where the 
> values are stored as a list? here is my dictionary:
> 
> {'1': ['a', 'b', 'c'], '3': ['a', 'b', 'c'], '2': ['a', 'b', 'c'], '4': 
> ['a', 'c']}
> 
> I would like to display count as follows and I would not know all the 
> value types in the values list:
> 
> Value QTY
> a   4
> b   3
> c   4

You need two nested loops - one to loop over the dictionary values and 
one to loop over the individual lists. collections.defaultdict is handy 
for accumulating the counts but you could use a regular dict also:

In [4]: d={'1': ['a', 'b', 'c'], '3': ['a', 'b', 'c'], '2': ['a', 'b', 
'c'], '4': ['a', 'c']}
In [5]: from collections import defaultdict
In [6]: counts=defaultdict(int)
In [7]: for lst in d.values():
...: for item in lst:
...: counts[item] += 1
...:
In [8]: counts
Out[8]: defaultdict(, {'a': 4, 'c': 4, 'b': 3})

In [10]: for k, v in sorted(counts.items()):
: print k,v
:
:
a 4
b 3
c 4


> Also is there anyway to display the count of the values list 
> combinations so here again is my dictionary:
> 
> {'1': ['a', 'b', 'c'], '3': ['a', 'b', 'c'], '2': ['a', 'b', 'c'], '4': 
> ['a', 'c']}
> 
> 
> And I would like to display as follows
> 
> QTY Value List Combination
> 3  a,b,c
> 1  a,c

Again you can use a defaultdict to accumulate counts. You can't use a 
mutable object (such as a list) as a dict key so you have to convert it 
to a tuple:

In [11]: c2=defaultdict(int)
In [13]: for v in d.values():
: c2[tuple(v)] += 1
:
In [14]: c2
Out[14]: defaultdict(, {('a', 'b', 'c'): 3, ('a', 'c'): 1})

Printing in order of count requires switching the order of the (key, 
value) pairs:

In [15]: for count, items in sorted( ((v, k) for k, v in c2.items()), 
reverse=True):
: print count, ', '.join(items)
:
3 a, b, c
1 a, c

or using a sort key:
In [16]: from operator import itemgetter
In [17]: for items, count in sorted(c2.items(), key=itemgetter(1), 
reverse=True):
: print count, ', '.join(items)
:
3 a, b, c
1 a, c

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating the equivalent of string.strip()

2007-10-01 Thread Alan Gauld

"Andrew James" <[EMAIL PROTECTED]> wrote

> string containing a single space ' ' but even using s[-1].isspace() 
> I
> lose punctuation marks. Any idea why that's happening?

care to show us what you are doing?

>>> ';'.isspace()
False

So puntuation should not show up as true...

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating the equivalent of string.strip()

2007-10-01 Thread Kent Johnson
Andrew James wrote:
> I've gone ahead and created a script that does this, however it also 
> strips punctuation. I was originally just comparing each character to a 
> string containing a single space ' ' but even using s[-1].isspace() I 
> lose punctuation marks. Any idea why that's happening?

Hmmm, I seem to have misplaced my glasses of distant screen reading +3 
Australia is a bit far for me to look over you shoulder. Maybe you 
should just post your code here so we can take a look.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Really basic web templating

2007-10-01 Thread wormwood_3
My host actually does support Python. But I don't have access to Apache rules 
nor the level of access to install apps like Django, so I am limited to just 
scripts I write.

But for that price, i will definitely check out WebFaction!

-Sam

- Original Message 
From: Kent Johnson <[EMAIL PROTECTED]>
To: wormwood_3 <[EMAIL PROTECTED]>
Cc: Python Tutorlist 
Sent: Monday, October 1, 2007 6:44:45 AM
Subject: Re: [Tutor] Really basic web templating

wormwood_3 wrote:
>  I want
> to do this because my site is on a shared hosting account, so I cannot
> install a web framework like Django

Another option is to switch to a hosting account that supports Python. I 
have been working with WebFaction and I'm very happy with them; an 
account with Django support is available for less than $10/month.

Kent



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Really basic web templating

2007-10-01 Thread Kent Johnson
wormwood_3 wrote:
> My host actually does support Python. But I don't have access to
> Apache rules nor the level of access to install apps like Django, so
> I am limited to just scripts I write.

Webfaction gives you both - you can install anything you like as long as 
it doesn't require superuser privileges and you have your own Apache 
instance that you can tweak any way you like.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] using **kwargs in __init__() as attributes

2007-10-01 Thread János Juhász
Dear Tutors,

I would like to make a new class instance, where
the intance attributes coming from the kwargs hash.

class ADUser:
def __init__(self, **kwargs):
for key in kwargs.keys():
self.key = kwargs[k]

a = ADUser(name='papa')


It isn't working :(



Yours sincerely,
__
Janos Juhasz

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using **kwargs in __init__() as attributes

2007-10-01 Thread Kent Johnson
János Juhász wrote:
> Dear Tutors,
> 
> I would like to make a new class instance, where
> the intance attributes coming from the kwargs hash.
> 
> class ADUser:
> def __init__(self, **kwargs):
> for key in kwargs.keys():
> self.key = kwargs[k]

This sets the 'key' attribute of self to the value of the keyword. You 
want to use the value of of key as the attribute name. You can do this 
with setattr():

   setattr(self, key, kwargs[k])

You can also update all the kwargs at once with
   self.__dict__.update(kwargs)

> It isn't working :(

A more specific description of the problem is often helpful; for best 
results copy and paste the exact error message, including the traceback, 
into your email.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using **kwargs in __init__() as attributes

2007-10-01 Thread Dave Kuhlman
On Mon, Oct 01, 2007 at 04:51:53PM +0200, J?nos Juh?sz wrote:
> Dear Tutors,
> 
> I would like to make a new class instance, where
> the intance attributes coming from the kwargs hash.
> 
> class ADUser:
> def __init__(self, **kwargs):
> for key in kwargs.keys():
> self.key = kwargs[k]
> 

You are asking a more sophisticated form of a question that has
been asked on this list several times before: 

"How do I create names in a namespace from string values?"

It's likely that you do not really want (or need) to do this.  Try
the following instead:

def __init__(self, **kwargs):
self.values = kwargs

Then access the values with:

x = self.values['name']

or, safer:

x = self.values.get('name', '')

If you are determined to create names in a namespace, on the fly,
look at the "exec" command (http://docs.python.org/ref/exec.html).
But, that's a dangerous way to code.

Dave



-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using **kwargs in __init__() as attributes

2007-10-01 Thread Tim Golden
Dave Kuhlman wrote:
> On Mon, Oct 01, 2007 at 04:51:53PM +0200, J?nos Juh?sz wrote:
>> Dear Tutors,
>>
>> I would like to make a new class instance, where
>> the intance attributes coming from the kwargs hash.
>>
>> class ADUser:
>> def __init__(self, **kwargs):
>> for key in kwargs.keys():
>> self.key = kwargs[k]
>>
> 
> You are asking a more sophisticated form of a question that has
> been asked on this list several times before: 
> 
> "How do I create names in a namespace from string values?"
> 
> It's likely that you do not really want (or need) to do this.

Also, on the off-chance (from the name of the class) that you're
implementing a wrapper around Active Directory, have a look at:

   http://tgolden.sc.sabren.com/python/active_directory.html

to see if it meets your needs already or is at least a
starting point.

TJG
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using **kwargs in __init__() as attributes

2007-10-01 Thread Kent Johnson
Dave Kuhlman wrote:
> On Mon, Oct 01, 2007 at 04:51:53PM +0200, J?nos Juh?sz wrote:
>> Dear Tutors,
>>
>> I would like to make a new class instance, where
>> the intance attributes coming from the kwargs hash.
>>
>> class ADUser:
>> def __init__(self, **kwargs):
>> for key in kwargs.keys():
>> self.key = kwargs[k]
>>
> 
> You are asking a more sophisticated form of a question that has
> been asked on this list several times before: 
> 
> "How do I create names in a namespace from string values?"
> 
> It's likely that you do not really want (or need) to do this.

Getting and setting attribute values by name is easy and well supported 
using getattr() and setattr(). IMO this is not in the same category as 
setting a variable name in the local or global namespace.

The self.__dict__.update(kwargs) method is from a recipe by none other 
than Alex Martelli:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308

> If you are determined to create names in a namespace, on the fly,
> look at the "exec" command (http://docs.python.org/ref/exec.html).
> But, that's a dangerous way to code.

In this case setattr() is all that is needed and it is safe.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Location of modules in Mac OS X

2007-10-01 Thread Roy Chen
Hello all,

I'm using MacPython 2.5 on OS X 10.4.

I was just wondering if all the Python modules are contained in this  
directory:
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/

Also, I've installed the Python Image Library (PIL), and it seems to  
be installed in this folder:
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site- 
packages/PIL/

Are all external Python modules installed guaranteed to be in this  
folder?

Thanks :)

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to Practice Python?(Linpeiheng)

2007-10-01 Thread Andy
While not Python specific you could to the Ruby quizzes
(http://www.rubyquiz.com/).  Just look at the problems and write a
solution in Python.

On 10/1/07, Alan Gauld <[EMAIL PROTECTED]> wrote:
>
> "???" <[EMAIL PROTECTED]> wrote
>
> > I am learning Python. Do you know somewhere I can practice Python?
> > I means some sites where have exercises I can try solving.
>
> The Useless Python website has some exercises and other small
> projects.
> Some have solutions some don't.
>
> Also the Python Challenge web site offers a "Game" where you
> navigate through the lasyers by solving Python puzzles, each
> using a new feature of Python.
>
> > And there should be standard answer or other people's
> > answer that can be refered.
>
> This is harder. There are solutions around for spome of them
> but not "standard solutions" - I'm not sure what such a thing would
> look like in a programming context. There are no such things
> as standard solutions to programming problems, its not like
> doing math!
>
> Some solutions are nicer than othes but each usually has some merit.
>
> HTH,
>
> Alan G
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
-Andy
"I have a great faith in fools; self-confidence my friends call it." –
Edgar Allen Poe
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionary - count values where values are stored as a list

2007-10-01 Thread GTXY20
This works perfectly.

However I will be dealing with an import of a very large dictionary - if I
call the commands at command line this seems to be very taxing on the CPU
and memory and will take a long time.

I was thinking of creating each as a fucntion whereby python would just to
write to a file instead of calling within a python shell do you think that
this would speed up the process?

All in total I will probably be looking at about 2 million dictionary keys
with assorted value quantities.

M.


On 10/1/07, Kent Johnson <[EMAIL PROTECTED]> wrote:
>
> GTXY20 wrote:
> > Hello,
> >
> > Any way to display the count of the values in a dictionary where the
> > values are stored as a list? here is my dictionary:
> >
> > {'1': ['a', 'b', 'c'], '3': ['a', 'b', 'c'], '2': ['a', 'b', 'c'], '4':
> > ['a', 'c']}
> >
> > I would like to display count as follows and I would not know all the
> > value types in the values list:
> >
> > Value QTY
> > a   4
> > b   3
> > c   4
>
> You need two nested loops - one to loop over the dictionary values and
> one to loop over the individual lists. collections.defaultdict is handy
> for accumulating the counts but you could use a regular dict also:
>
> In [4]: d={'1': ['a', 'b', 'c'], '3': ['a', 'b', 'c'], '2': ['a', 'b',
> 'c'], '4': ['a', 'c']}
> In [5]: from collections import defaultdict
> In [6]: counts=defaultdict(int)
> In [7]: for lst in d.values():
>...: for item in lst:
>...: counts[item] += 1
>...:
> In [8]: counts
> Out[8]: defaultdict(, {'a': 4, 'c': 4, 'b': 3})
>
> In [10]: for k, v in sorted(counts.items()):
>: print k,v
>:
>:
> a 4
> b 3
> c 4
>
>
> > Also is there anyway to display the count of the values list
> > combinations so here again is my dictionary:
> >
> > {'1': ['a', 'b', 'c'], '3': ['a', 'b', 'c'], '2': ['a', 'b', 'c'], '4':
> > ['a', 'c']}
> >
> >
> > And I would like to display as follows
> >
> > QTY Value List Combination
> > 3  a,b,c
> > 1  a,c
>
> Again you can use a defaultdict to accumulate counts. You can't use a
> mutable object (such as a list) as a dict key so you have to convert it
> to a tuple:
>
> In [11]: c2=defaultdict(int)
> In [13]: for v in d.values():
>: c2[tuple(v)] += 1
>:
> In [14]: c2
> Out[14]: defaultdict(, {('a', 'b', 'c'): 3, ('a', 'c'): 1})
>
> Printing in order of count requires switching the order of the (key,
> value) pairs:
>
> In [15]: for count, items in sorted( ((v, k) for k, v in c2.items()),
> reverse=True):
>: print count, ', '.join(items)
>:
> 3 a, b, c
> 1 a, c
>
> or using a sort key:
> In [16]: from operator import itemgetter
> In [17]: for items, count in sorted(c2.items(), key=itemgetter(1),
> reverse=True):
>: print count, ', '.join(items)
>:
> 3 a, b, c
> 1 a, c
>
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionary - count values where values are stored as a list

2007-10-01 Thread Kent Johnson
GTXY20 wrote:
>  
> This works perfectly.
>  
> However I will be dealing with an import of a very large dictionary - if 
> I call the commands at command line this seems to be very taxing on the 
> CPU and memory and will take a long time.
>  
> I was thinking of creating each as a fucntion whereby python would just 
> to write to a file instead of calling within a python shell do you think 
> that this would speed up the process?

I don't understand what you are suggesting.

Both of your requirements just need the values of the dict. If the dict 
is being created from a file, you could probably build the count dicts 
on the fly as you read the values without ever creating the dict with 
all the items in it.

Kent

>  
> All in total I will probably be looking at about 2 million dictionary 
> keys with assorted value quantities.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] function for removing all white spaces from a string

2007-10-01 Thread Tim
Hello,
after reading the responses to athread in 2004 [1] I am wondering why there is
no easy function in python to remove all white spaces from a string.

Like:

" i am very fine "
to
"iamveryfine"

In IDL there's just one simple function which does this: STRCOMPRESS [2].

Is there really not yet such a function in Python?

If not I created it:

a = " i am very fine "


def strcompress(mystring):
... mystring_compressed = ''.join(mystring.split())
... return mystring_compressed

 strcompress(a)
'iamveryfine'

Thanks for your input,
Timmie

[1] Re: how to strip whitespaces from a string.
http://article.gmane.org/gmane.comp.python.tutor/18622

[2] STRCOMPRESS http://idlastro.gsfc.nasa.gov/idl_html_help/STRCOMPRESS.html

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [tutor] printing bitmap image dynamically reading data inwxpython

2007-10-01 Thread Varsha Purohit
Hi Alan,

  Thanks for the response. Its not a home work problem its actually a task i
need to complete as i am tryin to make some tool which will be helpful to
use as a script in arcgis. i kinda got some clue will surely ask help if i
get stuck somewhere coz i know its difficult to put down in words of what i
wanna do :(

thanks,
Varsha


On 10/1/07, Alan Gauld <[EMAIL PROTECTED]> wrote:
>
> "Varsha Purohit" <[EMAIL PROTECTED]> wrote
>
> > I want to create a wxpython program where i am reading a list
> > having
> > integer values like [1,2,3,4]. and i need to display the output
> > value as
> > bitmap image which shd be coloured after reading the values. Like
> > 1=red,
> > 2=yellow, 3=orange etc and it displays the output in colours at
> > proper
> > coordinates by matching values of the array.
>
> Sounds like a fun project.
> Have you any plans on how to go about it?
> Are you having problems? Or are you just sharing your excitement
> at the challenge?
>
> > I need to make a script file for arcgis tool which converts the
> > ascii data to a coloured bitmap image at given coordinates.
>
> I dunno much about arcgis but again it sounds like a reasonable
> thing to do.
>
> Let us know how you get on. If you run into problems ask
> questions we might be able to help. However since it seems
> to be a homework type exercise we can't solve it for you.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Location of modules in Mac OS X

2007-10-01 Thread Alan Gauld

"Roy Chen" <[EMAIL PROTECTED]> wrote

> I'm using MacPython 2.5 on OS X 10.4.
>
> I was just wondering if all the Python modules are contained in this
> directory:
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/

The standard library modules are. Any custom moidules could
be almost anywhere!

> Also, I've installed the Python Image Library (PIL), and it seems to
> be installed in this folder:
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-
> packages/PIL/
>
> Are all external Python modules installed guaranteed to be in this
> folder?

site-packages is the usual place but some authors don't provide
an install script so they could be anywhere that you unpack them.
A few others write unconventional scripts and put them someplace
else (maybe inside their own applications area). Welcome to the
world of Opensource where rules are "flexible" But mostly they
are followed OK. :-)

BTW ISTR that a few Mac specific packages found thir way
someplace else, but I can't recall which ones. Sherlock found
them for me...

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] function for removing all white spaces from a string

2007-10-01 Thread Alan Gauld

"Tim" <[EMAIL PROTECTED]> wrote

> after reading the responses to athread in 2004 [1] I am wondering 
> why there is
> no easy function in python to remove all white spaces from a string.
>
> " i am very fine "
> to
> "iamveryfine"

You can use string.replace.

>>> 'I am very fine'.replace(' ','')
'Iamveryfine'
>>>

But you need to apply several times if you want more than simple 
spaces removed.

Or you can use regexs. (Or the translate function might work too, but 
i haven't
tried it for this)

HTH,

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


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using **kwargs in __init__() as attributes

2007-10-01 Thread Alan Gauld

"János Juhász" <[EMAIL PROTECTED]> wrote

> class ADUser:
>def __init__(self, **kwargs):
>for key in kwargs.keys():
>self.key = kwargs[k]
>
> a = ADUser(name='papa')
>
>
> It isn't working :(

Try using setattr instead of self.key assignment.

HTH,


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


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using **kwargs in __init__() as attributes

2007-10-01 Thread Noufal Ibrahim
János Juhász wrote:
> Dear Tutors,
> 
> I would like to make a new class instance, where
> the intance attributes coming from the kwargs hash.
> 
> class ADUser:
> def __init__(self, **kwargs):
> for key in kwargs.keys():
> self.key = kwargs[k]
> 
> a = ADUser(name='papa')
> 


Your snippet above will set the attribute "key" to kwargs[k] (it will 
overwrite the values for the previous keys so you won't get anywhere).

You need to use setattr to do this since the names of the attributes are 
available as strings. Here's an example.

 >>> class Foo(object):
...   def __init__(self,**d):
...for i in d:
... setattr(self,i,d[i])
...
 >>>
 >>>
 >>> x= Foo(name="Papa")
 >>> x.name
'Papa'
 >>>



-- 
~noufal
http://nibrahim.net.in/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Location of modules in Mac OS X

2007-10-01 Thread Kent Johnson
Roy Chen wrote:
> Hello all,
> 
> I'm using MacPython 2.5 on OS X 10.4.
> 
> I was just wondering if all the Python modules are contained in this  
> directory:
> /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/

Try

import sys
sys.path

That will give you a list of all the places Python will search for 
modules. There are several ways this list can be customized, including
PYTHONPATH environment variables
.pth files
site-customize.py
modifying sys.path in a program

so you shouldn't treat this as a final definitive list, rather it is a 
snapshot of current usage.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Really basic web templating

2007-10-01 Thread wormwood_3
There was another host that I wanted to mention along these lines (for Python 
sites) that I think is even better: VPSLink (http://www.vpslink.com). They 
allow root SSH access, and can install your choice of OS (lots of linux 
flavors, ubuntu, SUSE, CentOS, etc) from a control panel. Aside from that they 
are similar to WebFaction, but having that much flexibility, with the base plan 
only ~$8/month, is pretty awesome.

-Sam

- Original Message 
From: Kent Johnson <[EMAIL PROTECTED]>
To: wormwood_3 <[EMAIL PROTECTED]>
Cc: Python Tutorlist 
Sent: Monday, October 1, 2007 8:36:03 AM
Subject: Re: [Tutor] Really basic web templating

wormwood_3 wrote:
> My host actually does support Python. But I don't have access to
> Apache rules nor the level of access to install apps like Django, so
> I am limited to just scripts I write.

Webfaction gives you both - you can install anything you like as long as 
it doesn't require superuser privileges and you have your own Apache 
instance that you can tweak any way you like.

Kent



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Really basic web templating

2007-10-01 Thread Michael Langford
Check to see if mod_python is installed/installable. It would quite
easily give you a very simple interface to do what you're looking for.

   --Michael

-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.TierOneDesign.com/


On 9/30/07, wormwood_3 <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I am trying to think of a way to make this happen, but it may not be at all 
> possible:-) I would like to use Python to generate pages on demand for my 
> website. By this I mean, when someone hits www.mysite.com/pagex.html, I want 
> to generate the page pagex.html via a Python script.
>
> I have a script setup that can generate a page from a template file and a 
> file with the body and title of the page in particular I want to generate. 
> Now from this, I need to somehow be able to respond to requests, and then 
> generate the page based on the page requested. I want to do this because my 
> site is on a shared hosting account, so I cannot install a web framework like 
> Django, and the site's pages will be rather simple. At the same time, I would 
> like to use templating, so I do not have repeated identical code between the 
> pages.
>
> Any ideas on this?
>
> Thanks,
> Sam
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to Practice Python?(Linpeiheng)

2007-10-01 Thread Rolando Pereira
Alan Gauld wrote:
> There are no such things
> as standard solutions to programming problems, its not like
> doing math!

But usually there is "The Right Way".

I think...

-- 
   _
ASCII ribbon campaign ( )
 - against HTML email  X
 & vCards / \
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] function for removing all white spaces from a string

2007-10-01 Thread Bill Campbell
On Mon, Oct 01, 2007, Alan Gauld wrote:
>
>"Tim" <[EMAIL PROTECTED]> wrote
>
>> after reading the responses to athread in 2004 [1] I am wondering 
>> why there is
>> no easy function in python to remove all white spaces from a string.
>>
>> " i am very fine "
>> to
>> "iamveryfine"
>
>You can use string.replace.
>
 'I am very fine'.replace(' ','')
>'Iamveryfine'

>
>But you need to apply several times if you want more than simple 
>spaces removed.
>
>Or you can use regexs. (Or the translate function might work too, but 
>i haven't
>tried it for this)

import re
whitespace = re.compile(r'\s+')
cleanstring = whitespace.sub('', dirtystring)

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

Marijuana will be legal some day, because the many law students
who now smoke pot will someday become congressmen and legalize
it in order to protect themselves.
-- Lenny Bruce
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionary - count values where values are stored as a list

2007-10-01 Thread Ricardo Aráoz
GTXY20 wrote:
> Hello,
> 
> Any way to display the count of the values in a dictionary where the
> values are stored as a list? here is my dictionary:
> 
> {'1': ['a', 'b', 'c'], '3': ['a', 'b', 'c'], '2': ['a', 'b', 'c'], '4':
> ['a', 'c']}
> 
> I would like to display count as follows and I would not know all the
> value types in the values list:
> 
> Value QTY
> a   4
> b   3
> c   4
> 
> Also is there anyway to display the count of the values list
> combinations so here again is my dictionary:
> 
> {'1': ['a', 'b', 'c'], '3': ['a', 'b', 'c'], '2': ['a', 'b', 'c'], '4':
> ['a', 'c']}
> 
> 
> And I would like to display as follows
> 
> QTY Value List Combination
> 3  a,b,c
> 1  a,c
> 
> Once again all help is much appreciated.
> 
> M.
> 

>>> D = {'1':['a', 'b', 'c'],
 '3':['a', 'b', 'c'],
 '2':['a', 'b', 'c'],
 '4':['a', 'c']
 }
>>> d = {}
>>> for v in reduce(lambda x, y: x+y, [b for a,b in D.iteritems()]):
... d[v] = d.setdefault(v, 0) + 1
...
>>> for k, v in d.iteritems():
... print k, v
...
a 4
c 4
b 3

>>> ld = {}
>>> for v in [''.join(b) for a,b in D.iteritems()]:
... d[v] = d.setdefault(v, 0) + 1
...
>>> for k, v in d.iteritems():
... print v, list(k)
...
1 ['a', 'c']
3 ['a', 'b', 'c']


HTH

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionary - count values where values are stored as a list

2007-10-01 Thread GTXY20
Thanks again I have worked that issue out.

However I have the following function and it is throwing this error:

FEXpython_v2.py", line 32, in UnitHolderDistributionqty
count[item]+=1
KeyError: 3

This is the function:

def Distributionqty(dictionary):
holder=list()
held=list()
distqtydic={}
count={}
for key in sorted(dictionary.keys()):
holder.append(key)
held.append(len(dictionary[key]))
for (key, value) in map(None, holder, held):
distqtydic[key]=value
for item in distqtydic.values():
count[item]+=1
for k,v in sorted(count.items()):
fdist=k
qty=v
print fdist,qty

Not sure...

M.



On 10/1/07, Kent Johnson <[EMAIL PROTECTED]> wrote:
>
> GTXY20 wrote:
> >
> > This works perfectly.
> >
> > However I will be dealing with an import of a very large dictionary - if
>
> > I call the commands at command line this seems to be very taxing on the
> > CPU and memory and will take a long time.
> >
> > I was thinking of creating each as a fucntion whereby python would just
> > to write to a file instead of calling within a python shell do you think
> > that this would speed up the process?
>
> I don't understand what you are suggesting.
>
> Both of your requirements just need the values of the dict. If the dict
> is being created from a file, you could probably build the count dicts
> on the fly as you read the values without ever creating the dict with
> all the items in it.
>
> Kent
>
> >
> > All in total I will probably be looking at about 2 million dictionary
> > keys with assorted value quantities.
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] function for removing all white spaces from a string

2007-10-01 Thread Ricardo Aráoz
Tim wrote:
> Hello,
> after reading the responses to athread in 2004 [1] I am wondering why there is
> no easy function in python to remove all white spaces from a string.
> 
> Like:
> 
> " i am very fine "
> to
> "iamveryfine"
> 
> In IDL there's just one simple function which does this: STRCOMPRESS [2].
> 
> Is there really not yet such a function in Python?
> 
> If not I created it:
> 
> a = " i am very fine "
> 
> 
> def strcompress(mystring):
> ... mystring_compressed = ''.join(mystring.split())
> ... return mystring_compressed
> 
>  strcompress(a)
> 'iamveryfine'
> 
> Thanks for your input,
> Timmie
> 
> [1] Re: how to strip whitespaces from a string.
> http://article.gmane.org/gmane.comp.python.tutor/18622
> 
> [2] STRCOMPRESS http://idlastro.gsfc.nasa.gov/idl_html_help/STRCOMPRESS.html

 ''.join(c for c in a if not c.isspace())



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionary - count values where values are stored as a list

2007-10-01 Thread Kent Johnson
GTXY20 wrote:
>  
> Thanks again I have worked that issue out.
>  
> However I have the following function and it is throwing this error:
>  
> FEXpython_v2.py", line 32, in UnitHolderDistributionqty
> count[item]+=1
> KeyError: 3
>  
> This is the function:
>  
> def Distributionqty(dictionary):
> holder=list()
> held=list()
> distqtydic={}
> for key in sorted(dictionary.keys()):
> holder.append(key)
> held.append(len(dictionary[key]))
> for (key, value) in map(None, holder, held):
> distqtydic[key]=value

Unless you need holder and held for something else, all of the above can 
be replaced with
   distqtydic = dict( (key, len(value)) for key, value in 
sorted(dictionary.items())

> count={}
> for item in distqtydic.values():
> count[item]+=1

The problem is that you are trying to add 1 to a value that is not 
defined yet. You can either make
   count=defaultdict(int)
or write
   count[item] = count.get(item, 0) + 1

If this is the only use of distqtydic then even the shortened code above 
is more than you need, you could just write

   for item in dictionary.values():
 count[len(item)] += 1  # assuming defaultdict

Kent

> for k,v in sorted(count.items()):
> fdist=k
> qty=v
> print fdist,qty

   for fdist,qty in sorted(count.items()):
 print fdist, qty

No need for the intermediate k, v; just use the names you like.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Dictionary - count values where values are stored as a list

2007-10-01 Thread GTXY20
Thanks so much I changed to the following and this worked:

def HolderDistributionqty(dictionary):
from collections import defaultdict
count=defaultdict(int)
for item in dictionary.values():
count[len(item)]+=1
for k,v in sorted(count.items()):
fdist=k
qty=v
print fdist,qty

M.

On 10/1/07, GTXY20 <[EMAIL PROTECTED]> wrote:
>
>
> Thanks again I have worked that issue out.
>
> However I have the following function and it is throwing this error:
>
> FEXpython_v2.py", line 32, in UnitHolderDistributionqty
> count[item]+=1
> KeyError: 3
>
> This is the function:
>
> def Distributionqty(dictionary):
> holder=list()
> held=list()
> distqtydic={}
> count={}
> for key in sorted(dictionary.keys()):
> holder.append(key)
> held.append(len(dictionary[key]))
> for (key, value) in map(None, holder, held):
> distqtydic[key]=value
> for item in distqtydic.values():
> count[item]+=1
> for k,v in sorted(count.items()):
> fdist=k
> qty=v
> print fdist,qty
>
> Not sure...
>
> M.
>
>
>
> On 10/1/07, Kent Johnson <[EMAIL PROTECTED]> wrote:
> >
> > GTXY20 wrote:
> > >
> > > This works perfectly.
> > >
> > > However I will be dealing with an import of a very large dictionary -
> > if
> > > I call the commands at command line this seems to be very taxing on
> > the
> > > CPU and memory and will take a long time.
> > >
> > > I was thinking of creating each as a fucntion whereby python would
> > just
> > > to write to a file instead of calling within a python shell do you
> > think
> > > that this would speed up the process?
> >
> > I don't understand what you are suggesting.
> >
> > Both of your requirements just need the values of the dict. If the dict
> > is being created from a file, you could probably build the count dicts
> > on the fly as you read the values without ever creating the dict with
> > all the items in it.
> >
> > Kent
> >
> > >
> > > All in total I will probably be looking at about 2 million dictionary
> > > keys with assorted value quantities.
> >
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A simple Question...

2007-10-01 Thread Suzanne Peel

Hi,

I have a very simple question that I cannot find the answer to ... if I 
knew the correct question to ask it would be simple.

I am trying to find the name of the file I am currently running (please 
don't laugh at me I know it's simple but I cannot figure it out).

I want to know where my errors are occurring so if I print out the name of 
the file (or script) when it starts that should help me 

I have tried os.listpath os.path and get lists of files and directories 
but no matter how much searching (through Python help and Dive into 
python) I cannot figure out how to find the current file name.

Any help will be more than welcome!!!

Suzanne


This e-mail may contain confidential or privileged information.   If you have 
received it in error, please notify the sender immediately via return e-mail 
and then delete the original e-mail. EnergyAustralia has collected your 
business contact details for dealing with you in your business capacity. More 
information about how we handle your personal information, including your right 
of access is contained at http://www.energy.com.au.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A simple Question...

2007-10-01 Thread John Fouhy
On 02/10/2007, Suzanne Peel <[EMAIL PROTECTED]> wrote:
>  I am trying to find the name of the file I am currently running (please 
> don't laugh at me I know it's simple but I cannot figure it out).

Have a look at sys.argv[0] :-)

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A simple Question...

2007-10-01 Thread Kent Johnson
Suzanne Peel wrote:
> 
> Hi,
> 
> I have a very simple question that I cannot find the answer to ... if I 
> knew the correct question to ask it would be simple.
> 
> I am trying to find the name of the file I am currently running (please 
> don't laugh at me I know it's simple but I cannot figure it out).

__file__ is the name of the current module.
> 
> I want to know where my errors are occurring so if I print out the name 
> of the file (or script) when it starts that should help me

What kind of errors are you getting? If they are exceptions you should 
be able to get a traceback easily with traceback.print_exc(). You can 
also print out a full stack trace at any time with traceback.print_stack().

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] creating the equivalent of string.strip()

2007-10-01 Thread Christopher Spears
I was looking for the source code for the strip
functions at python.org.  I didn't find anything.  Do
you or someone else know where the source code is
posted?  I tried to find python on my workstation, but
I'm not sure where the sys admin installed it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] OT: webhosting

2007-10-01 Thread Martin Walsh
wormwood_3 wrote:
> There was another host that I wanted to mention along these lines (for Python 
> sites) that I think is even better: VPSLink (http://www.vpslink.com). They 
> allow root SSH access, and can install your choice of OS (lots of linux 
> flavors, ubuntu, SUSE, CentOS, etc) from a control panel. Aside from that 
> they are similar to WebFaction, but having that much flexibility, with the 
> base plan only ~$8/month, is pretty awesome.
> 
> -Sam

Running the risk of taking this tread in an inappropriate direction, I
feel compelled to mention http://openhosting.com, founded by Gregory
Trubetskoy the author of mod_python. Aside from the pleasant opportunity
 to name-drop :) I have found their service, up-time, and support to be
phenomenal -- while not the cheapest vps on the block. I think their
service plans start at around $20 US a month.

> 
> - Original Message 
> From: Kent Johnson <[EMAIL PROTECTED]>
> 
> Webfaction gives you both - you can install anything you like as long as 
> it doesn't require superuser privileges and you have your own Apache 
> instance that you can tweak any way you like.
> 
> Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Update values stored as a list in a dictionary with values from another dictionary

2007-10-01 Thread GTXY20
Hello all,

Let's say I have the following dictionary:

{1:(a,b,c), 2:(a,c), 3:(b,c), 4:(a,d)}

I also have another dictionary for new value association:

{a:1, b:2, c:3}

How should I approach if I want to modify the first dictionary to read:

{1:(1,2,3), 2:(1,3), 3:(2,3), 4:(1,d)}

There is the potential to have a value in the first dictionary that will not
have an update key in the second dictionary hence in the above dictionary
for key=4 I still have d listed as a value.

As always all help is appreciated.

M.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Update values stored as a list in a dictionary with values from another dictionary

2007-10-01 Thread John Fouhy
On 02/10/2007, GTXY20 <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> Let's say I have the following dictionary:
>
> {1:(a,b,c), 2:(a,c), 3:(b,c), 4:(a,d)}
>
> I also have another dictionary for new value association:
>
> {a:1, b:2, c:3}
>
> How should I approach if I want to modify the first dictionary to read:
>
>  {1:(1,2,3), 2:(1,3), 3:(2,3), 4:(1,d)}
>
> There is the potential to have a value in the first dictionary that will not
> have an update key in the second dictionary hence in the above dictionary
> for key=4 I still have d listed as a value.

You could use the map function...

Let's say we have something like:

transDict = { 'a':1, 'b':2, 'c':3 }

We could define a function that mirrors this:

def transFn(c):
try:
return transDict[c]
except KeyError:
return c

Then if you have your data:

data = { 1:('a','b','c'), 2:('a','c'), 3:('b','c'), 4:('a','d')}

You can translate it as:

for key in data.keys():
data[key] = map(transFn, data[key])

HTH!

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A simple Question...

2007-10-01 Thread Suzanne Peel

Thankyou for your help,

However both suggestions will only give me that name of the 1st file 
executed eg  when I use  execfile('EA_Owner.py') the name returned when 
the __file__ or sys.argv[0] is executed always EA_Owner.py .

The Traceback feature is an excellent resource however the errors I am 
trying to follow are not python errors but come from the data I am 
manipulating - I cannot remember off-the-top-of-my-head what order each 
file is called so I resort to opening the main file to figure it out - it 
would be nice if I could write out the name whenever the script runs the I 
just look for the name... I do realise I could hardcode the names I was 
just looking for a more elegant solution that I can put in all my scripts 
identifying which one is executing.

The trace-back feature provides this - can I force an error of sorts that 
will not suspend programming but will report the file/module/script that 
it is running ??? (Probably a bit dramatic but I am at a loss..)

Regards, 
Suzanne Peel
Engineer - Subtransmission Planning, Sydney
EnergyAustralia 


Level 3, 570 George St, Sydney NSW 2000

T. 612 9269 4659  (Extn 34659)
F. 612 9269 4690  (Extn 34690)
[EMAIL PROTECTED] 
 


This e-mail may contain confidential or privileged information.   If you have 
received it in error, please notify the sender immediately via return e-mail 
and then delete the original e-mail. EnergyAustralia has collected your 
business contact details for dealing with you in your business capacity. More 
information about how we handle your personal information, including your right 
of access is contained at http://www.energy.com.au.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor