Re: [Tutor] web intefaces?

2006-05-09 Thread Christian Wyglendowski

> > >>> "Chad Crabtree" <[EMAIL PROTECTED]> 5/8/2006 6:29 PM >>>
> > While everything that Alan Guald said is true, there are a 
> couple of 
> > options for you. Provided you know HTML (you must), you 
> could generate 
> > html pragmatically but, knowledge of html is still mandatory.
> > Your options are, basically
> >
> > _http://www.cherrypy.org _ Which 
> is an app 
> > server that should be fairly easy to package up with, say py2exe.

If you do go with CherryPy, check out this recipe I submitted to the
online Python Cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442481

It was written for CherryPy 2.1 but should still work with the current
2.2 release.

Christian
http://www.dowski.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Renaming computers

2006-03-23 Thread Christian Wyglendowski
Danny Yoo wrote:
> There are examples of programs that people have written to 
> automate some Windows administration tasks.  For example:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347812
> 
> is code to get the MAC address of one's ethernet card

You can also use WMI for this task.  The pywin32 package is required.
Here is an example using the interactive interpreter:

>>> from win32com.client import GetObject
>>> machine = GetObject('winmgmts://some_remote_machine/root/cimv2')
>>> query = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE
IPEnabled = True"
>>> adapters = machine.ExecQuery(query)
>>> macs = [a.MACAddress for a in adapters]
>>> for m in macs: print m
... 
00:0E:0C:82:7A:33
00:14:22:0F:54:3C

Christian
http://www.dowski.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] mod_python and other web frameworks

2006-01-26 Thread Christian Wyglendowski
Some others have already mentioned TurboGears, but since it sounds like
you want more control perhaps, I would recommend going with CherryPy
(http://www.cherrypy.org).  You basically write python code and then
expose it to the web (or intranet or whatever).

# simple example
import cherrypy
import time

class MySection(object):
@cherrypy.expose
def index(self):
yield "Hello, world!"
yield "Check the time"
# if you are using Python 2.3, you do the following to expose a method
#   index.exposed = True

@cherrypy.expose
def time(self):
return "The current time is %s" % self.get_time()

# this method is not exposed and thus not accessible from the web
def get_time(self):
return time.ctime()

# mount the class at the server root
cherrypy.root = MySection()

cherrypy.server.start()
# end of example

You can then run that script and visit http://localhost:8080/.  That
will call the "index" method of the MySection object mounted at the
server root.  You can also visit http://localhost:8080/time.  However,
http://localhost:8080/get_time is _not_ available to the web, because it
is not "exposed".

Anyhow, CherryPy is very pythonic and flexible.  Use whatever DB you
want (or flat files or ...).  Use whatever templating language you want
(or just return html from your methods.

Anyhow, that's probably more info than you wanted.  Good luck!

Christian
http://www.dowski.com

ps And "as a beginner", I would _not_ start with something like
mod_python ;-)


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Intercodes
Sent: Wednesday, January 25, 2006 12:59 PM
To: tutor@python.org
Subject: [Tutor] mod_python and other web frameworks

Hello everyone,

Disclaimer:  Beginner.

I have an idea of coding a web application and decided to do it entirely
with python (reddit style). I started looking for web programming in
python and somehow I saw mod_python first. Iam perusing the help
document now. 

Few minutes of browsing confused my mind entirely , since it seems there
are about 20 different web frameworks available for python. I am left
clueless as to pick which one. I have an soft side towards the one I
picked first. 

Considering yourself as a beginner to python  ,do you prefer mod_python
over all other framework?. Say if you want to create a blog , will
mod_python suffice? And is mod_python and cgi (the python lib)
different?


--
Intercodes


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


Re: [Tutor] Newb ?

2005-11-17 Thread Christian Wyglendowski
Orri said:
> Or you could just do the following:
> 
> >>> print "\n\nWelcome to the Backwards Message Display."
> >>> print
> >>> message = raw_input("\nPlease Enter a Message.")
> >>> print message[::-1]

Interesting.  I forgot about the 'step' option when slicing.
 
> This is the equivalent of print ''.join(reversed(message)), since 
> reversed works on any iterable sequence, including strings.  

Ha!  Good call.  Makes it even clearer.

> In any 
> case, the syntax for this sort of thing in general is: 
> sequence[start:stop:step], with start defaulting to 0, step 
> defaulting 
> to sys.maxint (which, for all intents and purposes, means the 
> end of the 
> string), and step defaulting to 1.  However, when step is negative, 
> start and end switch defaults.  So by doing [::-1], you're telling 
> Python to return the values of the sequence that can be found 
> from the 
> end to the start

Cool.  Thanks for this explanation.

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


Re: [Tutor] compiled images

2005-11-17 Thread Christian Wyglendowski
Fred said:
> 
[snip] 
> I've got another question I think you may have come across before. 
> I'm planning on purchasing a license to use some stock icons in an
> application I'm developing.  The problem is the license requires this:
> 
> "Where an application is to be distributed, the graphical media must
> be compiled into the application binary file or its associated data
> files, documentation files, or components."
> 
> Anyone have any idea as to how I could basically "compile" all my
> artwork into a data file for a python application?  Would this require
> compiling them into a *.dll/*.so?  It seems like there must be any
> easier way--Also, I need my application to work on windows + linux
> (and mac).

Hhhmm...from what I remember, getting at icons in DLLs is pretty easy.
I think that is where windows stores a lot of its icons actually.  If
they are just looking to dissuade the "casual icon theft" maybe they
would be ok if you included the images as base64 encoded strings in your
source code:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52264

You could even take that further by having a resource file or something
that contained pickled base64 encoded image strings.  Maybe that would
be "compiled" enough for them?

> Any suggestions/experience would be greatly appreciated!

Hope some of this helps.  I guess asking them how they have dealt with
interpreted languages in the past might help.

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


Re: [Tutor] Newb ?

2005-11-17 Thread Christian Wyglendowski
Liam said:
> 
> How about -
> print "\n\nWelcome to the Backwards Message Display."
> print
> message = raw_input("\nPlease Enter a Message.")
> msgAsList = [ char for char in message]

You could also do:

msgAsList = list(message)

list() takes any iterable and returns a list object.

> msgAsList.reverse()
> reversedMessage = ''.join(msgAsList)

In Python 2.4, the following is also possible:

reversedMessage = ''.join(reversed(list(message)))

It's amazing how in Python even one-liners can be so pretty :-)

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


Re: [Tutor] lambda in a loop

2005-11-17 Thread Christian Wyglendowski
Fred said:
> >> Obviously, the lambda is using "value" at the end of the loop (4),
> >>rather than what I want, "value" during the loop (0,1,2,3).  

Christian said:
> > Right.  I think the issue is that your lambda calls another funtion.
> > However, the function isn't called until the lambda is called later,
> > when value == 4.

Kent said:
> No, the problem is not when the function is called, but when 
> value is bound into the closure.

I don't think that the value is being bound into the closure, though.
It is using the global 'value', which is why I said "the function isn't
called until the lambda is called later, when value == 4".  I should
have been more clear and said "when global value == 4".  

I think this can be demonstrated by adding a "del value" statement after
the loop.  Here is the traceback I get after adding that statement:

Traceback (most recent call last):
  File
"C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py"
, line 310, in RunScript
exec codeObject in __main__.__dict__
  File "C:\Documents and
Settings\cwyglendowski\Desktop\cp_playground\lambdatest.py", line 12, in
?
c()
  File "C:\Documents and
Settings\cwyglendowski\Desktop\cp_playground\lambdatest.py", line 7, in

commands.append(lambda:doLambda(value))
NameError: global name 'value' is not defined


Christian said:
> > I'd use a closure rather than a lambda. 

Kent said:
> The original solution does use a closure. 

Thanks for pointing that out.  I don't use lambda often and didn't think
about how you can create closures with lambda statements.

Kent said:
> The problem is that 
> variables are not bound into a closure until the scope of the 
> variable exits. That is why using a separate factory function 
> works - the closure is bound when the factory function exits 
> which happens each time through the loop. In the case of 
> closures in a loop the closure is not bound until exiting the 
> scope containing the loop and all the closures are bound to 
> the same value.

I'm not even going to go there ... Danny just wrote an excellent book on
this :-)

Thanks to all for the great discussion.

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


Re: [Tutor] lambda in a loop

2005-11-16 Thread Christian Wyglendowski
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Fred Lionetti
> Sent: Wednesday, November 16, 2005 2:32 PM
> To: tutor@python.org
> Subject: [Tutor] lambda in a loop
> 
> Hi everyone,

Hello,
 
>  If I have this code:
> 
> 
>  def doLambda(val):
>print "value 2:", val
> 
>  commands = []
>  for value in range(5):
>print "value 1:", value
>commands.append(lambda:doLambda(value))
> 
>  for c in commands:
>c()
> --
> 
>  my output is:
>  value 1: 0
>  value 1: 1
>  value 1: 2
>  value 1: 3
>  value 1: 4
>  value 2: 4
>  value 2: 4
>  value 2: 4
>  value 2: 4
>  value 2: 4
> 
>  Obviously, the lambda is using "value" at the end of the loop (4),
> rather than what I want, "value" during the loop (0,1,2,3).  

Right.  I think the issue is that your lambda calls another funtion.
However, the function isn't called until the lambda is called later,
when value == 4.

> Is there
> any *simple* way around this?  I'd prefer not to use a separate array
> with all the values ( i.e.
> commands.append(lambda:doLambda(values[commands.index(c)])) ) if
> possible.

I'd use a closure rather than a lambda. 

def wrapper(val):
def inner():
print "value 2:", val
return inner

commands = []
for value in range(5):
print "value 1:", value
commands.append(wrapper(value))

for c in commands:
c()

That way each item in commands is an "inner" function that has its own
local copy of value.  So it is really a variable scope issue.


>  Thanks,
>  Fred

HTH, sorry it isn't more clear.

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


Re: [Tutor] Help me

2005-11-15 Thread Christian Wyglendowski
 > -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Danny Yoo
> 
> On Tue, 15 Nov 2005, sivapriya pasupathi wrote:
> 
> > I am planning to start my career in computer programming.But i don't
> > have specific resource(websire/book) to improve my basic computer
> > programming skills.If you know any helpful resources,please 
> let me know.
> 
> Hi Priya,
> 
> Welcome aboard!
> 

[SNIP Danny's suggestions]

> 
> Unfortunately, I came to Python with previous programming 
> experience, so I
> might not be the best person to point out what books are friendly to
> people starting from scratch.  *grin*
> 
> Does anyone else have recommendations?

Python was my first programming language (I don't count PHP).  I started
learning about 4 years ago.  

I found the standard tutorial by Guido quite helpful.  I had to read it
a few times though, as it moves quite fast for a tutorial (for a raw
beginner, at least).

I also went through "How to Think Like a Computer Scientist".  It is a
great book that is freely available online.  

Finally, the interactive interpreter is sitting there just waiting for
you to start typing stuff in.  The help() and dir() functions are
particularly helpful when playing around in the interpreter.

Python Tutorial - http://docs.python.org/tut/tut.html
How to Think Like a Computer Scientist -
http://www.ibiblio.org/obp/thinkCSpy/

-also-

The Python Cookbook - http://www.oreilly.com/catalog/pythoncook2/


Good luck and welcome to Python!

Christian

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


Re: [Tutor] Console output

2005-10-05 Thread Christian Wyglendowski
 > -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Oliver Maunder
> Sent: Wednesday, October 05, 2005 1:13 PM
> To: tutor@python.org
> Subject: [Tutor] Console output
> 
> Does anyone know how I can update a line of console output 
> without creating a new line? 

Hi Oliver,

If you are on a *nix system, check out the "curses" package in the
standard library.  I have never used it, but it provides ways to
accomplish what you are after.

HTH,

Christian
http://www.dowski.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting singal strength of the received packet

2005-07-19 Thread Christian Wyglendowski
Signal strength is not stored in an IP packet.  It is more of a
radio-level statistic that would need to be gathered from the wireless
device somehow.

Christian 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of sunny sunny
> Sent: Tuesday, July 19, 2005 12:18 PM
> To: tutor@python.org
> Subject: [Tutor] Getting singal strength of the received packet
> 
> Hi,
> 
> I am sending and receiving for a simple server application 
> over wirless link. 
> Can I get the signal strength of the received packet in Python? 
> 
> One way would be to get the value of the RSSI from /proc/net/wireless.
> However I would like to get the signal strength (in terms of RSSI or
> dBm) of the specific packet. Is it possible to do this in Python.
> 
> I am using hostAP driver, and know that using C, I can get 
> the packet RSSI. 
> 
> Thanks 
> Santosh.
> ___
> 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] Cookies and authorization

2005-06-23 Thread Christian Wyglendowski
 

> -Original Message-
> 
> Christian, 
> 
> > Try subclassing urllib.FancyURLopener and overriding the
> > prompt_user_passwd() method.  That should get you what you need :-)
> 
> Well, I used urllib.FancyURLopener, and can open and look at 
> the url, like this:
> 
> import urllib
> opener2 = urllib.FancyURLopener({})
> f = 
> opener2.open("http://www.pythonchallenge.com/pc/return/romance.html";)
> f.read()
> 
> ..but to get at the cookies, I need to use urllib2.build_opener

Ah ha ... I should have been paying more attention :-)

> instead of urllib.FancyURLopener so that I can have access to
> urllib2.HTTPCookieProcessor, which does not seem to be an option in
> the regular urllib module?  Sorry if this seems like a dense question,
> I have little-to-no experience with cookies (and very little with
> urllib itself), so the examples sometimes leave me hanging!

It looks like the link that Kent suggested uses urllib2 and gives some
good examples of how to do authentication.  
 
> I'd appreciate any clarification you could give, or if you meant
> something else by your message?

I don't have much programming experience with cookies, so I don't have
much more to offer.  Good luck!

Christian
http://www.dowski.com

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


Re: [Tutor] Interesting problem

2005-06-23 Thread Christian Wyglendowski
 

> -Original Message-
> 
> Consider a class with a lt of properties.  I would like a member
> function which generates a dictionary where the keys are the property
> names and the values are the property values?
> 
> Is this clear?

I think so :-)

> How might I go about this?

I think you could simply use the special object attribute __dict__.  It
holds a dictionary of all properties and their values.

>>> class Something:
... def __init__(self, item1, item2, item3, item4, item5):
... self.item1 = item1
... self.item2 = item2
... self.item3 = item3
... self.item4 = item4
... self.item5 = item5
... 
>>> s = Something(42,52,55,1,54)
>>> s.__dict__
{'item2': 52, 'item3': 55, 'item1': 42, 'item4': 1, 'item5': 54}


> Jeff

HTH,

Christian
http://www.dowski.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Cookies and authorization

2005-06-23 Thread Christian Wyglendowski
 

> -Original Message-
> 
> Hello, everyone!

Hi,



> My problem is, when I plug this url into my sample code above, I get
> an error ("HTTP Error 401: Authorization Required"), because normally
> when you go to this url it makes you enter in a username and a
> password.  Does anyone know how to get around this, either with code
> commands I can change to embed the password/username, or a way I can
> reformat the URL to *include* the password/username?  I remember
> seeing something like this but I can't get it formatted right.  Say my
> username is "guido" and my password is "python."

Try subclassing urllib.FancyURLopener and overriding the
prompt_user_passwd() method.  That should get you what you need :-)

> Any help would be much appreciated! Thanks :)
> 
> ~Denise

HTH,

Christian
http://www.dowski.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] database app

2005-06-23 Thread Christian Wyglendowski
> -Original Message-
> 
> Hey there,

Hi,
 
> i have used the cgi module and dig it.
> heres the deal,
> my employer wants me to build a dynamic website that will 
> access a 
> database and display customer
> information on web. ok, easy enough.

Looks like some others have pointed you in the right direction as far as
interfacing with Access.

For the "web" part of your application, I'd recommend CherryPy
(http://www.cherrypy.org).  It lets you write web applications in
python.  Example:

from time import ctime
from cherrypy import cpg


header = """

%s

"""

footer = """


"""

class Site:
def index(self):
yield header % ('Index',)

yield "Here is a header\n"
yield "Here is a paragraph.  It is currently is %s.\n" %
(ctime(),)
yield "Here is a list of items\n"
yield "\n"
for num in range(10):
yield "Item %s\n" % (num,)
yield "\n"

yield footer
index.exposed = True

cpg.root = Site()
cpg.server.start()

---

That starts a webserver listening on port 8080 serving up your "index"
method at:
http://yourhost:8080/
or
http://yourhost:8080/index

Anyhow, CherryPy is very easy to get a hold of.

Good luck with your web application.

Christian
http://www.dowski.com

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


Re: [Tutor] Trying Ruby...

2005-06-07 Thread Christian Wyglendowski
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Terry Carroll
> Sent: Monday, June 06, 2005 8:20 PM
> To: tutor@python.org
> Subject: [Tutor] Trying Ruby...
> 
> This message is not as off-topic as it at first appears.
> 
> I'm a user of Activestate's ActivePython under Windows/XP.  I 
> want to give
> Ruby a spin, just for the heck of it.  I vaguely recall a post a few
> months ago, I don't know if it was in this forum, where someone had a
> problem in Python, and it turns out it was because a Ruby 
> install messed
> with some setting, perhaps in the Windows registry.

Terry,

If I remember correctly, it had to do with Tk getting messed up.  But
that's all I recall :-)

Christian
http://www.dowski.com 

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


Re: [Tutor] CPAN for python

2005-06-06 Thread Christian Wyglendowski
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Danny Yoo
> 
> 
> Yes, there is a system called 'PyPI':
> 
> http://www.python.org/pypi
> 

Also see EasyInstall
(http://peak.telecommunity.com/DevCenter/EasyInstall).  Installs
packages from the command line by searching PyPI.  It's pretty new from
what I gather.  Much more info at the above address.

Christian
http://www.dowski.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wxpython button icons?

2005-05-31 Thread Christian Wyglendowski
Hey Jeff, 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Jeff Peery
> 
> Hello, does anyone know if there is a list of widows icons 
> available? I'm creating an application for windows and I'd 
> like to use standard icons for things like a "print" button 
> or "save" button etc. thanks.

Checkout "images.py" in the wxPython demo directory.  If you put it in
your python path somewhere you can do an "import images" and then write
code like this (grabbed from the wxPython toolbar demo):

tb = self.CreateToolBar( wx.TB_HORIZONTAL
 | wx.NO_BORDER
 | wx.TB_FLAT
 | wx.TB_TEXT
 )

tb.AddSimpleTool(10, images.getNewBitmap(), "New", "Long help
for 'New'")
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=10)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=10)

tb.AddSimpleTool(20, images.getOpenBitmap(), "Open", "Long help
for 'Open'")
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=20)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=20)


There are probably other ways to do this as well, but there's my .02!

Christian
http://www.dowski.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] A Newbie Printing Question

2005-04-01 Thread Christian Wyglendowski
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
> 
> Quoting "Jacob S." <[EMAIL PROTECTED]>:
> 
> > Cool! Does anybody know of... I guess a rather *thorough* 
> tutorial of
> > win32? for the very reason that I don't know that this 
> existed, and there may
> > be other things I can use that I'm missing...
> 
> I don't know of anything online ... It seems a very 
> poorly-documented corner of
> Python.

Since the pywin32 stuff just wraps standard Win32 libraries for the most
part, the resources at MSDN (http://msdn.microsoft.com) are quite
helpful.  While it is not Python-specific, it would probably be
redundant to extensively document the pywin32 stuff with MSDN available.

> Oreilly have a book which may be of help to you if you do a 
> lot of programming
> on Windows: http://www.oreilly.com/catalog/pythonwin32/

I agree.  It is an older book, but I found it helpful.  I think I got it
used for $6 or $8 on Amazon.

Christian
http://www.dowski.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] iterating through large dictionary

2005-03-22 Thread Christian Wyglendowski
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of jeff
> 
> Hi,

Hey Jeff,
 
> I'm trying to print out all the attributes of a user account in active
> directory. I got a script from:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303348
> /index_txt

Hhhmm... I have some code that does basically the same thing, sans the
printing.  Mine looks up the user based on the sAMAccountName instead of
the distinguishedName, though.

> Now I'd like it to print pretty.

[SNIP function]

> user='LDAP://cn=Wardlaw\, Jeff,OU=IS Department,OU=IT
> department,DC=acpdom,DC=acp,DC=edu'
> for k, v in ad_dict(user):
> print "%s=%s" % (k, v)
> 
> I get the following error when I try this:
> 
> D:\Python24>ad-attr.py
> Traceback (most recent call last):
>   File "D:\Python24\ad-attr.py", line 32, in ?
> for k, v in ad_dict(user):
> ValueError: too many values to unpack

Try this instead ... I think it should help:



for k,v in ad_dict(user).items():



HTH,

Christian
http://www.dowski.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] "TypeError: 'int' object is not callable"??

2004-12-17 Thread Christian Wyglendowski
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Jacob S.
> Sent: Friday, December 17, 2004 3:54 PM
> To: Kent Johnson
> Cc: [EMAIL PROTECTED]
> Subject: Re: [Tutor] "TypeError: 'int' object is not callable"??
> 
> Hey, could you give an example?
> Thanks,
> Jacob
> 
> >
> > apply() is deprecated; it has been replaced by 'extended 
> call syntax'.
> Instead of
> >apply(fn, args, kwds)
> > you can now write
> >fn(*args, **kwds)
> >
> > Kent

Here is a quick example I came up with:

>>> def spam(*args, **kwargs):
... print "Here are the args you supplied:"
... for item in args:
... print item
... print
... print "Here are the kwargs you supplied:"
... for key,value in kwargs.items():
... print key, '=', value
... 
>>> spam(1,'a','eggs',s=0, p=1, a=2, m=3)
Here are the args you supplied:
1
a
eggs

Here are the kwargs you supplied:
a = 2
p = 1
s = 0
m = 3

In the case of the spam() function, 1, 'a', and 'eggs' are all put into
the sequence args (not sure if it is a list or tuple).  The key/value
pairs are bundled into the dictionary kwargs.  The arguments have to be
given in the right order though:

>>> spam(t=1, b=1, 'this', 'will', 'fail')
Traceback (SyntaxError: non-keyword arg after keyword arg

HTH!

Christian
http://www.dowski.com


___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor


RE: [Tutor] Socket events and wxPython events?

2004-12-06 Thread Christian Wyglendowski
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Mike Eve
> Sent: Sunday, December 05, 2004 6:21 PM
> To: [EMAIL PROTECTED]
> Subject: [Tutor] Socket events and wxPython events?

Hey Mike,
 

 
> I'm thinking about 3 approaches, but rather than beat my head 
> against the wall, I was hoping to find out if any  of these 
> are workable:

Here are my thoughts.  You might have better luck on the wxPython users
mailing list if this doesn't help point you in the right direction.
  
> 1) use sockets lib. Do socket send/recv generate any kind of 
> event with an event id that can used with the wxPython window 
> events? That is, I want to just sit and receive events such 
> as OnPaint, OnButton, in the same loop as I receive 
> "OnReceiveSocket" (or whatever it might be called).

Python sockets are pretty basic, and do not tie in to wxPython as far as
I know.
  
> 2) create a separate thread which does a select then sends a 
> wxPython compatible event which can be intermixed with 
> OnPaint, etc (similar to option 1)

This sounds doable - maybe combined with option 1 or 3.
  
> 3) use SocketServer. I noticed the  SocketServer class refers 
> to "request handler class" and "handle" functions. Do these 
> generate any events which are wxPython compatible

By default, SocketServer will probably not interface with wxPython as
far as generating events goes.
  
> You probably noticed I'm a little confused about what a 
> wxPython compatible event is. I'm not sure if these events 
> and their event handling are part of Python or something 
> added by  and unique to wxPython.

wxPython provides the event processing framework.  Using any of these
approaches, it sounds like you want to create a custom event and have
your network portion of the code fire that event.  Check out the
PythonEvents demo in the wxPython demo to see some sample code
implementing a custom event.

  
> Thanks, Mike
> 

HTH,

Christian
http://www.dowski.com

___
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor