Re: [Tutor] Confused "from module import Name" better than "import module"?

2005-07-11 Thread Matt Richardson
Kent Johnson wrote:

> from module import * is problematic and discouraged. It causes namespace 
> pollution and makes it harder to find out where a name is defined.
> 
> Other than that I think it is personal preference.
> 

I have avoided the 'from module import *' style for the reasons you 
mentioned, but I have a question about 'import module' versus 'from 
module import name':  is there a performance hit to consider when 
importing the entire module rather than just getting the specific 
niceFunction()?  Right now,it's more of a curiousity as my programs are 
fairly small and don't do a whole lot.  I would imagine that there would 
be a penalty, but for now I'm happy with keeping my namespaces distinct 
and knowing what came from where at a glance.

Matt


-- 
Matt Richardson
IT Consultant
College Of Arts & Letters
CSU San Bernardino
(909)537-7596
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Confused "from module import Name" better than "import module"?

2005-07-11 Thread Matt Richardson
Kent Johnson wrote:

> 
> This is good stuff to understand, but really, it isn't going to make an 
> appreciable difference in most applications. Where it does matter, for 
> example if func() is called many times in a loop, the best solution will 
> probably be to bind func to a local variable which is the fastest to access.
> 
> Pick the style that you find most practical and readable and don't worry 
> about efficiency.
> 
> Kent


Thanks for the explanation.  It won't make a difference in this really 
short program I'm putting together, but I was curious about it.  Going 
through the library reference I found a bunch of modules that would 
replace some ugly (but working) code I had, then started to wonder if 
importing a bunch of different modules would have much of an effect.  In 
any case, I'm more concerned with readability.

Matt


-- 
Matt Richardson
IT Consultant
College Of Arts & Letters
CSU San Bernardino
(909)537-7596
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] problem with class overloading (maybe it's just me)

2005-10-24 Thread Matt Richardson
Hi all,

I've started the wxPython tutorials and have hit a problem already. 
When run from IDLE or by calling the script from the command line with

[EMAIL PROTECTED]:~/wxpy$ python helloWorld.py

the script works fine, generating a small text editor.  Making the file 
executable and including the shebang, running

[EMAIL PROTECTED]:~/wxpy$ ./helloWorld.py

generates a cross-hair looking mouse pointer.  Clicking the mouse 
generates the following error:

[EMAIL PROTECTED]:~/wxpy$ ./helloWorld.py
./helloWorld.py: line 6: syntax error near unexpected token `('
./helloWorld.py: line 6: `class MainWindow(wx.Frame):'

Which to me looks like it doesn't know what to do with wx.Frame, or some 
problem in extending the class.  In the hello world example previous to 
this, there's no problem with wx.Frame and the program runs when 
executed from the command line.

Here's the details:
python 2.3.5

this one works:

[EMAIL PROTECTED]:~/wxpy$ cat hello.py
#!/usr/bin/python

import wx

app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "Hello World")
frame.Show(1)
app.MainLoop()



this one fails:
[EMAIL PROTECTED]:~/wxpy$ cat helloWorld.py

#!/usr/bin/python

import wx

class MainWindow(wx.Frame):
 """ We simply derive a new class of Frame. """
 def __init__(self, parent, id, title):
 wx.Frame.__init__(self, parent, wx.ID_ANY, title, 
size=(200,100),
 
style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
 self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
 self.Show(True)

app = wx.PySimpleApp()
frame = MainWindow(None, -1, 'Small editor')
app.MainLoop()


I'm sure it's something simple I'm overlooking, so I'll go get a cup of 
coffee and see if someone with better eyes spots my error.

thanks,
Matt


-- 
Matt Richardson
IT Consultant
College of Arts and Letters
CSU San Bernardino
(909)537-7598

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


Re: [Tutor] problem with class overloading (maybe it's just me)

2005-10-24 Thread Matt Richardson
Danny Yoo wrote:

> Hope this helps!

Helped a lot.  Shows that syntax errors aren't always visible (like 
whitespace) and that I should know better than to attempt anything 
before having at least one cup of coffee.

Thanks!
Matt

-- 
Matt Richardson
IT Consultant
College of Arts and Letters
CSU San Bernardino
(909)537-7598

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


[Tutor] sockets

2006-05-03 Thread Matt Richardson
Just verifying what I looked up earlier:  are strings and binary 
(through struct.pack) the only data types that can be sent through a 
socket?  This is my first crack at socket programming, so I'll probably 
have lots of questions to bug you with.

thanks,
Matt


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


Re: [Tutor] sockets

2006-05-04 Thread Matt Richardson
I need to send some data, 2 strings and a list, to a remote computer. 
After thinking about it some last night, it wouldn't be hard to just 
send it all as a string and then parse it on the receiving end.

I'm writing a program for work (and for a class project, so no answers!) 
that will provide some info on the network location of a laptop.  The 
client will gather IP address, MAC address, and a traceroute dump (the 
list mentioned above), then send this off to a super simple server that 
receives the data and puts it in a database.  We've had a few laptops 
'disappear' either through theft or people taking them home to do 'work 
from home' or whatever.  Makes annual inventory a huge pain.

Matt

-- 
Matt Richardson
IT Consultant
College of Arts and Letters
CSU San Bernardino
(909)537-7598

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


Re: [Tutor] sockets

2006-05-04 Thread Matt Richardson
Kent Johnson wrote:

> 
> This would be very easy to do with XML-RPC. On the server side, writ a 
> function that takes three parameters - the IP address, MAC address, and 
> traceroute dump - and saves them to a database. Use SimpleXMLRPCServer 
> to expose the function. On the client side, gather the data and use 
> xmlrpclib to call the remote function. Easy. Since this function will 
> presumably be exposed on the public internet you need to worry about 
> security; you should use some kind of authorization. A really simple 
> solution would be to add username and password arguments to the function 
> you expose.


I thought that might be overkill after quickly glancing at it in 
'Foundations of Python Network Programming', but I think you might have 
just convinced me that it is actually the easier route.  My original 
thought was that it could be just a simple string, sent via UDP, that 
would happen after networking was established but before log in.  I had 
done something simpler before using a bash script and sendmail, but I 
really don't want my inbox plugged up with a bunch of 'phone home' 
messages :)

Matt


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


Re: [Tutor] debug process

2006-06-13 Thread Matt Richardson
Bob Gailer wrote:
> Kent Johnson wrote:
>> [EMAIL PROTECTED] wrote:
>>   
>>> Hello,
>>>
>>> Is there a way to debug (trace) the python code line by
>>> line?
>>> 

I'll put in my $.02 for SPE.  PyChecker and Tab Nanny are built in and 
run as you code, which saved me from making lots of silly mistakes.

-- 
Matt Richardson
IT Consultant
College of Arts and Letters
CSU San Bernardino
work: (909)537-7598
fax: (909)537-5926

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


Re: [Tutor] MySQLdb: cant get '... where field in %s' to work for string sequences

2006-06-23 Thread Matt Richardson
On 6/22/06, Justin Ezequiel <[EMAIL PROTECTED]> wrote:
> how can I get 'select ... from ... where field in %s' to work for
> sequences of strings?
> sequences of integers works just fine
>
> import MySQLdb
>
> DBCRED = {'host': 'localhost', 'user': 'userjustin',
>   'passwd': 'passwdjustin', 'db': 'dbjustin'}
>
> ARTICLES = ('XXX9', 'ABZ2')
> PIDS = (29379, 29380)
>
> FIXEDARTICLENAME = """SELECT * FROM tblForTransfer2Prodsite
> WHERE articleName IN ('XXX9', 'ABZ2')"""
> TESTARTICLENAME = """SELECT * FROM tblForTransfer2Prodsite
> WHERE articleName IN %r""" % (ARTICLES,)
> SQLARTICLENAME = """SELECT * FROM tblForTransfer2Prodsite
> WHERE articleName IN %s"""
>
> FIXEDPID = """SELECT * FROM tblForTransfer2Prodsite
> WHERE pid IN (29379, 29380)"""
> TESTPID = """SELECT * FROM tblForTransfer2Prodsite
> WHERE pid IN %r""" % (PIDS,)
> SQLPID = """SELECT * FROM tblForTransfer2Prodsite
> WHERE pid IN %s"""
>
> if __name__ == '__main__':
> conn = MySQLdb.connect(**DBCRED)
> try:
> cur = conn.cursor()
> print FIXEDARTICLENAME
> print TESTARTICLENAME
> print cur.execute(FIXEDARTICLENAME),
> print cur.execute(TESTARTICLENAME),
> # cannot get this to work
> print cur.execute(SQLARTICLENAME, (ARTICLES,))
> print
> print FIXEDPID
> print TESTPID
> print cur.execute(FIXEDPID),
> print cur.execute(TESTPID),
> # but this does
> print cur.execute(SQLPID, (PIDS,))
> print
> finally: conn.close()
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>

Can you post your error messages?

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


Re: [Tutor] Python Programming Books

2006-07-14 Thread Matt Richardson
On 7/14/06, wesley chun <[EMAIL PROTECTED]> wrote:
> (LONG... you've been warned ;-) )


Heh, that was pretty long.  I bought the first edition of Core Python
and thought that it was well-written, but I didn't quite get it (stay
with me, this gets better).  It wasn't until after I had taken quite a
few courses in C++ that I realized 1) that python was s much nicer
to work with and 2) Wesley's book made a lot more sense.  It's
probably not a good one for someone new to programming, but I find
that I pick it up when I need to see an example of how something is
done in python.

As for an absolute beginner, Alan's tutorial and How To Think Like a
Computer Scientist are both pretty good.  The latter had my daughter
doing a fair bit of programming in a day.

So Wesley's Big Book was a huge help in a project I did for work that
involved socket programming, pickling, and interfacing with MySQL.
Showing how particular things were done in python in clear, concise
examples is it's big strength.  Thanks for not getting sucked in to
using lots of source code :)


-- 
Matt
Waiting for the second edition
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Has anyone tried matplotlib...??

2006-10-22 Thread Matt Richardson
I just used it a couple of weeks ago to produce a histogram of
randomly generated numbers.  Read the documentation, it's well written
and has good examples.

Matt

On 10/22/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote:
>
> Folks,
>
> Has anyone tried matplotlib ..//???
>
> If yes, then is it easy to use...
>
>
>
>
> --
> To HIM you shall return.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>


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