Re: [Tutor] MP3Info class usage

2008-12-15 Thread Gareth at Serif

Okay, I've moved over to eyeD3.py... fif nothing else, the documentation for
it's usage is far superior.

However, I can't get anything to run.  The help gives examples of some
simple tasks, but as soon as I 'import eyeD3', not even calling any
functions within it, I start getting errors such as:

In eyeD3.py, the 'from eyeD3.tag import *;' line (and similar) didn't work
until I removed the 'eyeD3.' part and just imported 'tag'.

Then in tag.py, some of the class defs complained about undefined variables,
for example 'def link(self, f, v = ID3_ANY_VERSION)' needed to have quotes
around 'ID3_ANY_VERSION'.

Now these issues are addressed I have an error in mp3.py, 'class
EyeD3Driver(eyeD3.utils.FileHandler) NameError: name 'eyeD3' is not defined.

I'm baffled that I'm having to jump through so many hoops because I imported
eyeD3... is this typical?  What have I done wrong?

Cheers,
Gareth



Todd Zullinger wrote:
 
 I'd recommend eyeD3¹ and/or mutagen² for tag reading.  Both are pretty
 easy to use.
 
 ¹ http://eyed3.nicfit.net/
 ² http://code.google.com/p/quodlibet/wiki/Development/Mutagen
 
 

-- 
View this message in context: 
http://www.nabble.com/MP3Info-class-usage-tp20934673p20980334.html
Sent from the Python - tutor mailing list archive at Nabble.com.

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


Re: [Tutor] Having Issues with CMD and the 'python' command

2008-12-15 Thread James Mills
cmd has _nothing_ to do with Python.

--JamesMills

--
-- Problems are solved by method



On Mon, Dec 15, 2008 at 10:51 PM, Lamonte Harris pyth0nc0...@gmail.com wrote:
 Every time I start cmd on windows it requires me to set
 path=%path%;C:\python26 why? I'm getting annoyed...

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


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


Re: [Tutor] Having Issues with CMD and the 'python' command

2008-12-15 Thread rdmurray

On Mon, 15 Dec 2008 at 23:01, James Mills wrote:

On Mon, Dec 15, 2008 at 10:51 PM, Lamonte Harris pyth0nc0...@gmail.com wrote:

Every time I start cmd on windows it requires me to set
path=%path%;C:\python26 why? I'm getting annoyed...


cmd has _nothing_ to do with Python.



(Top posting corrected.)

But the answer is that you need to update your PATH string at the system
level.  You do that in Control Panel/System/Advanced/Environment variables
(it's a button on the advanced screen, which is something that confused
me the first time I went looking for it).

ObPython: you know, it occurs to me that Windows follows exactly the
opposite philosophy from Python when it comes to hierarchy.  Python's
Zen is shallow is better than deep, whereas Windows' philosophy
is deep is better than shallow.  Every release of Windows seems
to bury the things one needs to do to administer the system deeper
and deeper inside a nested set of windows...and every time I touch
Windows I am reminded how sensible the Python Zen is :)

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


Re: [Tutor] Python Lib Files

2008-12-15 Thread Kent Johnson
On Sun, Dec 14, 2008 at 9:49 AM,  btk...@email.unc.edu wrote:
 Hello everyone,

 I discovered yesterday that the Python package has a number of built in
 example scripts in the /lib directory. Perhaps this is common knowledge but
 I did not know about it. I can't seem to find any kind of guide to the
 files, though. Is there a readme somewhere that someone can point me to, or
 perhaps documentation for the files online? I cant find anything on the
 python.org site. This is for version 2.5.

Those are not sample scripts, they are the standard library. There is
extensive documentation, for example
http://docs.python.org/library/
or for Python 2.5 see
http://www.python.org/doc/2.5.2/lib/lib.html

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


Re: [Tutor] Python Lib Files

2008-12-15 Thread Alan Gauld

Kent Johnson ken...@tds.net wrote

I discovered yesterday that the Python package has a number of 
built in

example scripts in the /lib directory.


Those are not sample scripts, they are the standard library. There 
is

extensive documentation, for example


However there are some sample scripts in the Tools directory...
For example a regex checker and reindentation tool.

HTH,

Alan G. 



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


Re: [Tutor] Having Issues with CMD and the 'python' command

2008-12-15 Thread Alan Gauld

bob gailer bgai...@gmail.com wrote


Try this:

Start-Settings-Control Panel-System-Advanced-Environment 
Variables

Highlight PATH under System Variables  Click Edit.
Add ;C:\python26


And notice that Bob said ADD - DO NOT REPLACE the existing setting or
you will likely break stuff and its not easy to fix it afterwards 
unless

you have a full backup to hand!!

Alan G. 



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


Re: [Tutor] Ask a class for it's methods

2008-12-15 Thread Kent Johnson
On Fri, Dec 12, 2008 at 6:06 PM, Shrutarshi Basu
technorapt...@gmail.com wrote:
 Is there a way to ask an object for a list of it's
 methods (with argument requirements if possible)?

Take a look at the inspect module. If it does not directly give you
what you need, look at the source - it looks at function attributes
that you can directly access.

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


[Tutor] Having Issues with CMD and the 'python' command

2008-12-15 Thread Lamonte Harris
Every time I start cmd on windows it requires me to set
path=%path%;C:\python26 why? I'm getting annoyed...
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Having Issues with CMD and the 'python' command

2008-12-15 Thread bob gailer




Lamonte Harris wrote:
Every time I start cmd on windows it requires me to "set
path=%path%;C:\python26" why? I'm getting annoyed...


I have never started cmd and have it require anything.

I guess what you are really asking is "how to permanenly set an
environment variable".

In this case so you can launch Python by just typing python at the cmd
prompt?

Are we on the same page so far?

And realize this is not a Python question but rather a Windows question?

Try this:

Start-Settings-Control
Panel-System-Advanced-Environment Variables
Highlight PATH under System Variables  Click Edit.
Add ;C:\python26
-- 
Bob Gailer
Chapel Hill NC 
919-636-4239


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


Re: [Tutor] Having Issues with CMD and the 'python' command

2008-12-15 Thread Benjamin Kaplan
On Mon, Dec 15, 2008 at 8:13 AM, rdmur...@bitdance.com wrote:

 On Mon, 15 Dec 2008 at 23:01, James Mills wrote:

 On Mon, Dec 15, 2008 at 10:51 PM, Lamonte Harris pyth0nc0...@gmail.com
 wrote:

 Every time I start cmd on windows it requires me to set
 path=%path%;C:\python26 why? I'm getting annoyed...


 cmd has _nothing_ to do with Python.


 (Top posting corrected.)

 But the answer is that you need to update your PATH string at the system
 level.  You do that in Control Panel/System/Advanced/Environment variables
 (it's a button on the advanced screen, which is something that confused
 me the first time I went looking for it).

 ObPython: you know, it occurs to me that Windows follows exactly the
 opposite philosophy from Python when it comes to hierarchy.  Python's
 Zen is shallow is better than deep, whereas Windows' philosophy
 is deep is better than shallow.  Every release of Windows seems
 to bury the things one needs to do to administer the system deeper
 and deeper inside a nested set of windows...and every time I touch
 Windows I am reminded how sensible the Python Zen is :)


It's not a question of sensibility. It's a question of purpose. The Zen is
the philosophy of a language that tries to be easy to learn and easy to use.
Python is used by programmers who want to experiment with it, but who
usually know enough not to os.system(rm -r /) or anything similar.
Windows, on the other hand, wants to hide everything that can potentially
ruin the system as deep as possible so that many of the idiots who use that
system don't do stupid things like delete the registry, wipe the environment
settings, turn off the Nag Screen (UAC), and other things of that nature.



 --RDM

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

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


[Tutor] Creating IDLE Shortcut

2008-12-15 Thread Bradford Fisher
Hello,

Does anyone know the proper method for re-creating the Windows XP shortcut for 
IDLE?  I (not thinking clearly) deleted the original and now am not sure how to 
go about fixing the problem.  I've attempted creating a shortcut and linking it 
to pythonw.exe with the target idle.pyw, but when loading IDLE with that 
shortcut all of my settings are lost and the load process is far greater.

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


[Tutor] need to clean a string

2008-12-15 Thread johnf
Hi,
I have a string that I need to extract just the sql  statement. 
The following is the string
\000\000\000\000\000\000\000\000.\000\000\000\\000\000\000
\000$\000\000\000\000\000(\000\000\000\000X\000\000\000\000\000,
\000\000\000\000P\000\000\000\000\000Q\000\000\000\000\000R\000
\000\000\000\000/\000\000\000�\000\000\000\000%\000\000\000
\000'\000\000\000\000+brttyp\000�\000\000\000\000*SELECT 
Brttyp.ctrscode, Brttyp.cdescript, Brttyp.ctrstype, Brttyp.cstatus, 
Brttyp.lreqno, Brttyp.dcreate FROM  brttyp Brttyp WHERE  Brttyp.ctrscode = 
( ?gcKey1 )\000\000\000\000\000 AMCONNECT\000\000\000\000\000)
\000\000\000\000\000\000\000 \000\000\000\000BR Transaction Code 
File\000

How can I get rid of all the junk?
 
I can find the '*' with str.find('*') but I can't use find '\000' to get to 
the end?
-- 
John Fabiani
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need to clean a string

2008-12-15 Thread Andreas Kostyrka
Am Mon, 15 Dec 2008 10:18:28 -0800
schrieb johnf jfabi...@yolo.com:

 Hi,
 I have a string that I need to extract just the sql
 statement. The following is the string
 \000\000\000\000\000\000\000\000.\000\000\000\\000\000\000
 \000$\000\000\000\000\000(\000\000\000\000X\000\000\000\000\000,
 \000\000\000\000P\000\000\000\000\000Q\000\000\000\000\000R\000
 \000\000\000\000/\000\000\000�\000\000\000\000%\000\000\000
 \000'\000\000\000\000+brttyp\000�\000\000\000\000*SELECT 
 Brttyp.ctrscode, Brttyp.cdescript, Brttyp.ctrstype, Brttyp.cstatus, 
 Brttyp.lreqno, Brttyp.dcreate FROM  brttyp Brttyp WHERE
 Brttyp.ctrscode = ( ?gcKey1 )\000\000\000\000\000
 AMCONNECT\000\000\000\000\000) \000\000\000\000\000\000\000
 \000\000\000\000BR Transaction Code File\000
 
 How can I get rid of all the junk?
  
 I can find the '*' with str.find('*') but I can't use find '\000' to
 get to the end?

str.find has an optional second parameter specifying the start where to
search:

Given the above string as str, you can do:

start_pos = str.find('*')
sql = None
if start_pos != -1:
end_pos = str.find('\0', start_pos)
if end_pos == -1:
end_pos = len(str)
sql = str[start_pos:end_pos]

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


[Tutor] what does the @ operator mean?

2008-12-15 Thread Mary Lou Knack
I'm looking at some code from Enthought's ETS examples and ran across the 
following statement:

@mayavi2.standalone

I have no idea what the @ operator means, if anything.  I tried searching for 
it in the documentation (locally and online), but no luck.  Or rather, the 
local (windows) help said it couldn't search for that phrase (@) and the online 
search turned up a bazillion hits and I don't know how to refine the search.

Knowledge isn't necessary for me to proceed, but it sure would be nice.  Thanks.

Mary Lou Knack___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what does the @ operator mean?

2008-12-15 Thread Marc Tompkins
On Mon, Dec 15, 2008 at 12:33 PM, Mary Lou Knack mlkn...@gmail.com wrote:
 I'm looking at some code from Enthought's ETS examples and ran across the
 following statement:

 @mayavi2.standalone

 I have no idea what the @ operator means, if anything.  I tried searching
 for it in the documentation (locally and online), but no luck.  Or rather,
 the local (windows) help said it couldn't search for that phrase (@) and the
 online search turned up a bazillion hits and I don't know how to refine the
 search.

It indicates a decorator.
Try this:
http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Decorators

If you're just starting out in Python, decorators can be hard to get
your head around...
-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need to clean a string

2008-12-15 Thread johnf
On Monday 15 December 2008 11:31:12 am Andreas Kostyrka wrote:
 Am Mon, 15 Dec 2008 10:18:28 -0800

 schrieb johnf jfabi...@yolo.com:
  Hi,
  I have a string that I need to extract just the sql
  statement. The following is the string
  \000\000\000\000\000\000\000\000.\000\000\000\\000\000\000
 
  \000$\000\000\000\000\000(\000\000\000\000X\000\000\000\000\000,
  \000\000\000\000P\000\000\000\000\000Q\000\000\000\000\000R\000
  \000\000\000\000/\000\000\000�\000\000\000\000%\000\000\000
  \000'\000\000\000\000+brttyp\000�\000\000\000\000*SELECT
  Brttyp.ctrscode, Brttyp.cdescript, Brttyp.ctrstype, Brttyp.cstatus,
  Brttyp.lreqno, Brttyp.dcreate FROM  brttyp Brttyp WHERE
  Brttyp.ctrscode = ( ?gcKey1 )\000\000\000\000\000
  AMCONNECT\000\000\000\000\000) \000\000\000\000\000\000\000
  \000\000\000\000BR Transaction Code File\000
 
  How can I get rid of all the junk?
 
  I can find the '*' with str.find('*') but I can't use find '\000' to
  get to the end?

 str.find has an optional second parameter specifying the start where to
 search:

 Given the above string as str, you can do:

 start_pos = str.find('*')
 sql = None
 if start_pos != -1:
 end_pos = str.find('\0', start_pos)
 if end_pos == -1:
 end_pos = len(str)
 sql = str[start_pos:end_pos]

 Andreas

Thanks I got it done just as you explained.  What was interesting was my 
editor showed '\x000'  and not '\000'  so I was always looking for the wrong 
thing.  I thought I was doing it wrong.   Then while re-reading the message I 
sent to this list I noticed the lack of the 'x'.  And sure enough that was 
the problem.  Thanks for your help.



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


Re: [Tutor] need to clean a string

2008-12-15 Thread Andreas Kostyrka
Am Mon, 15 Dec 2008 12:43:46 -0800
schrieb johnf jfabi...@yolo.com:

 On Monday 15 December 2008 11:31:12 am Andreas Kostyrka wrote:
  Am Mon, 15 Dec 2008 10:18:28 -0800
 
  schrieb johnf jfabi...@yolo.com:
   Hi,
   I have a string that I need to extract just the sql
   statement. The following is the string
   \000\000\000\000\000\000\000\000.\000\000\000\\000\000\000
  
   \000$\000\000\000\000\000(\000\000\000\000X\000\000\000\000\000,
   \000\000\000\000P\000\000\000\000\000Q\000\000\000\000\000R\000
   \000\000\000\000/\000\000\000�\000\000\000\000%\000\000\000
   \000'\000\000\000\000+brttyp\000�\000\000\000\000*SELECT
   Brttyp.ctrscode, Brttyp.cdescript, Brttyp.ctrstype,
   Brttyp.cstatus, Brttyp.lreqno, Brttyp.dcreate FROM  brttyp Brttyp
   WHERE Brttyp.ctrscode = ( ?gcKey1 )\000\000\000\000\000
   AMCONNECT\000\000\000\000\000) \000\000\000\000\000\000\000
   \000\000\000\000BR Transaction Code File\000
  
   How can I get rid of all the junk?
  
   I can find the '*' with str.find('*') but I can't use find '\000'
   to get to the end?
 
  str.find has an optional second parameter specifying the start
  where to search:
 
  Given the above string as str, you can do:
 
  start_pos = str.find('*')
  sql = None
  if start_pos != -1:
  end_pos = str.find('\0', start_pos)
  if end_pos == -1:
  end_pos = len(str)
  sql = str[start_pos:end_pos]
 
  Andreas
 
 Thanks I got it done just as you explained.  What was interesting was
 my editor showed '\x000'  and not '\000'  so I was always looking for
 the wrong thing.  I thought I was doing it wrong.   Then while
 re-reading the message I sent to this list I noticed the lack of the
 'x'.  And sure enough that was the problem.  Thanks for your help.

Well \xHH is the hexadecimal notation, while \OOO is the octal
notation. The problem is that \x000 means the 00 byte followed the
character 0.

Andreas

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


[Tutor] Reading module to import from a string

2008-12-15 Thread Shrutarshi Basu
Suppose I have a module that I want to import called ImMod1 that's
saved in a variable like so:

var = ImMod1

Is there some way to import ImMod1 by using var?
Thanks,
Basu
-- 
The ByteBaker :
http://www.bytebaker.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading module to import from a string

2008-12-15 Thread Chris Calloway

On 12/15/2008 5:38 PM, Shrutarshi Basu wrote:

Suppose I have a module that I want to import called ImMod1 that's
saved in a variable like so:

var = ImMod1

Is there some way to import ImMod1 by using var?


http://stackoverflow.com/questions/67631/how-to-import-module-from-file-name

--
Sincerely,

Chris Calloway
http://www.secoora.org
office: 332 Chapman Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599



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


Re: [Tutor] Reading module to import from a string

2008-12-15 Thread Chris Calloway

On 12/15/2008 5:38 PM, Shrutarshi Basu wrote:

Suppose I have a module that I want to import called ImMod1 that's
saved in a variable like so:

var = ImMod1

Is there some way to import ImMod1 by using var?


http://docs.python.org/library/imp.html

--
Sincerely,

Chris Calloway
http://www.secoora.org
office: 332 Chapman Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599



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


[Tutor] numarray issues

2008-12-15 Thread Mr Gerard Kelly
Hello, I am a python beginner, and I have a question about scalars vs
arrays.

I am making a (very simple) code, and part of it is:

from numarray import *
from math import *

def source(x,y):
  f=sin(x)
  return f

a=4.

m=10

dx=a/(m+1.)

x=zeros([m,1], Float)

print x[0]

print func(x[0])

When I run this code, I get:

[ 0.]
0.0

However, if I change the line f=sin(x) to f=2*x, I will get:

[ 0.]
[ 0.]

Why does func(x[0]) return a scalar for sin(x), but returns an array for
2*x?

If I want a scalar returned for f=2*x, I need to put in func(x[0,0]).
Why do x[0] and x[0,0] both work for sin(x), but only x[0,0] will work
for 2*x?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what does the @ operator mean?

2008-12-15 Thread Chris Calloway

On 12/15/2008 3:42 PM, Marc Tompkins wrote:
 If you're just starting out in Python, decorators can be hard to get
 your head around...

This would be a huge help:

http://www.ddj.com/web-development/184406073

--
Sincerely,

Chris Calloway
http://www.secoora.org
office: 332 Chapman Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599

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


Re: [Tutor] Creating IDLE Shortcut

2008-12-15 Thread Alan Gauld


Bradford Fisher fisher@wright.edu wrote 

I've attempted creating a shortcut and linking it to pythonw.exe 


The one the installer created on my PC is a shortcut to:

C:\Python24\Tools\scripts\idle.pyw

with a start-in directory of

C:\Python24\Tools\scripts

HTH,

Alan G.

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


Re: [Tutor] what does the @ operator mean?

2008-12-15 Thread Alan Gauld


Marc Tompkins marc.tompk...@gmail.com wrote


If you're just starting out in Python, decorators can be hard to get
your head around...


I've been using Python for oover 10 years and still find decorators
hard to get my head around! :-)

I confess I'm not a fan, they go against the Python spirit of
explicit is best in my opinion. If I'm calling a function I like to
know I'm calling a function... I know they make the code look
pretty but IMHO they are a pain to debug and I'm never totally
convinced I've got it exactly right.

Alan G 



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


Re: [Tutor] numarray issues

2008-12-15 Thread bob gailer

Mr Gerard Kelly wrote:

Hello, I am a python beginner, and I have a question about scalars vs
arrays.

I am making a (very simple) code, and part of it is:

from numarray import *
from math import *

def source(x,y):
  f=sin(x)
  return f

a=4.

m=10

dx=a/(m+1.)

x=zeros([m,1], Float)

print x[0]

print func(x[0])

When I run this code, I get:

[ 0.]
0.0

However, if I change the line f=sin(x) to f=2*x, I will get:

[ 0.]
[ 0.]

Why does func(x[0]) return a scalar for sin(x), but returns an array for
2*x?

If I want a scalar returned for f=2*x, I need to put in func(x[0,0]).
Why do x[0] and x[0,0] both work for sin(x), but only x[0,0] will work
for 2*x?
  


sin() expects a scalar value.
x[0] is a 1 element array.
numarray magically converts the 1 element array to a scalar.
x[0]*2 multiplies each element of the array by 2 giving an array result.


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

  



--
Bob Gailer
Chapel Hill NC 
919-636-4239


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


Re: [Tutor] numarray issues

2008-12-15 Thread bob gailer




Please always reply-all so a copy goes to the list.

Mr Gerard Kelly wrote:

  is there a quick way to convert a one element array into a scalar value
so that I can use x[0] for all operations?
  


x = x[0]


  
- Original Message -
From: bob gailer bgai...@gmail.com
Date: Tuesday, December 16, 2008 11:19 am
Subject: Re: [Tutor] numarray issues
  
  
Mr Gerard Kelly wrote:


  Hello, I am a python beginner, and I have a question about 
  

scalars vs


  arrays.

I am making a (very simple) code, and part of it is:

from numarray import *
from math import *

def source(x,y):
  f=sin(x)
  return f

a=4.

m=10

dx=a/(m+1.)

x=zeros([m,1], Float)

print x[0]

print func(x[0])

When I run this code, I get:

[ 0.]
0.0

However, if I change the line f=sin(x) to f=2*x, I will get:

[ 0.]
[ 0.]

Why does func(x[0]) return a scalar for sin(x), but returns an 
  

array for


  2*x?

If I want a scalar returned for f=2*x, I need to put in 
  

func(x[0,0]). Why do x[0] and x[0,0] both work for sin(x), but 
only x[0,0] will work


  for 2*x?
  
  

sin() expects a scalar value.
x[0] is a 1 element array.
numarray magically converts the 1 element array to a scalar.
x[0]*2 multiplies each element of the array by 2 giving an array 
result.


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

  
  


-- 
Bob Gailer
Chapel Hill NC 
919-636-4239



  
  
  



-- 
Bob Gailer
Chapel Hill NC 
919-636-4239


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


Re: [Tutor] what does the @ operator mean?

2008-12-15 Thread Mary Lou Knack

Thanks Chris  Marc

I certainly don't need to know about decorators at this stage of my 
development.  Maybe I'll be able to avoid them entirely


Mary Lou

- Original Message - 
From: Chris Calloway c...@unc.edu

To: tutor@python.org
Sent: Monday, December 15, 2008 2:22 PM
Subject: Re: [Tutor] what does the @ operator mean?



On 12/15/2008 3:42 PM, Marc Tompkins wrote:
 If you're just starting out in Python, decorators can be hard to get
 your head around...

This would be a huge help:

http://www.ddj.com/web-development/184406073

--
Sincerely,

Chris Calloway
http://www.secoora.org
office: 332 Chapman Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599

___
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] what does the @ operator mean?

2008-12-15 Thread Marc Tompkins
On Mon, Dec 15, 2008 at 5:03 PM, Alan Gauld alan.ga...@btinternet.com wrote:

 Marc Tompkins marc.tompk...@gmail.com wrote

 If you're just starting out in Python, decorators can be hard to get
 your head around...

 I've been using Python for oover 10 years and still find decorators
 hard to get my head around! :-)

 I confess I'm not a fan, they go against the Python spirit of
 explicit is best in my opinion. If I'm calling a function I like to
 know I'm calling a function... I know they make the code look
 pretty but IMHO they are a pain to debug and I'm never totally
 convinced I've got it exactly right.

 Alan G

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


I'm sorry I left it as flat as I did - that Dr. Dobbs article is a
pretty good explanation, and there's an article somewhere in the
Effbot bookshelf that does a decent job - but I couldn't find either
one at that moment.

I've only been using Python for a couple of years now, but my
experience so far is the same as yours: decorators make my head hurt.
Even in the Dr. Dobbs article, the examples seem horribly contrived.
There must be plenty of programmers who use decorators all the time
and would feel lost without them, but I have yet to see a compelling
use case.  (It's always something like Here's another useless,
made-up situation.  We could handle it in a straightforward way, but
wouldn't it be cooler if we used a decorator instead?)

Actually, I'm being unnecessarily harsh: I can imagine a theoretical
case, where there is some operation you wish to apply to several
functions, and you don't want to write the code more than once.
(Wrapping a timer around functions comes to mind.)  But I've never run
across a situation where a decorator actually seemed like the best way
to do it, and (almost) all of the articles on the subject feel like
they were written to check an action item off the editor's to-do list:
this book won't be complete unless we mention decorators, so better
slop something together.

Does anybody who reads this list use decorators and have a nice word
to say about them?  I'd be interested to hear it.

-- 
www.fsrtechnologies.com

p.s. - Is anybody else as sick of the phrase syntactic sugar as I am?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what does the @ operator mean?

2008-12-15 Thread Steve Willoughby

Marc Tompkins wrote:

On Mon, Dec 15, 2008 at 5:03 PM, Alan Gauld alan.ga...@btinternet.com wrote:

I've been using Python for oover 10 years and still find decorators
hard to get my head around! :-)

I've only been using Python for a couple of years now, but my
experience so far is the same as yours: decorators make my head hurt.


Interesting.  I actually rather like them and find them to be a tool to 
clean up code quite a bit.  Python's ability to have classes offer 
attributes which are really handled by wrapper functions is a similar 
animal (in the sense that they can be very nice but also could be 
horribly abused to make smelly code).


That said, I don't find myself using them too often.  Sort of like a 
special seasoning you add to the occasional dish but exotic enough to 
taste weird if you used it all the time.


For example, creating web apps in TurboGears uses decorators to expose 
methods, apply error handling and output templates without unnecessarily 
cluttering all your method definitions.

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


[Tutor] problems finding position in list and changing it for GO game

2008-12-15 Thread Lee Meredith
Hi
I am looking for some help if you have or worked with pygame or not
I'm sure if you have not you could still help me
I am working on a  *GO game* no AI a analog behavior only
I have the stones going to the board and switching colors between black and
white
but I want to take *stones/pieces* off and count them
and if you don't play go it's okay as well but might help

the MOUSEBUTTONDOWN gives the black0 XandYpositions with the*.append*
how do I reference the address in the list by using XandYpositions
Then replace them or take it out off the list

This code puts out an error when you hit the letter b

Traceback (most recent call last):
  File C:/Users/Lee/Desktop/pyGame01/GO/GO_1_2_3.py, line 46, in module
for stone in len(black0):
TypeError: 'int' object is not iterable

Which I'm not really sure what that means or how to remedy it as well

Thank you everyone

## geting there black and white stones alternate now the issue
## of taking the stones off the board
## Or more precisely to .insert into the list at an address that I detected
by finding the X. and the Y. by using the
## if event.pos == range( black0[stone][0] - (stoneWidth/2),
black0[stone][0] + ((stoneWidth/2)+1)):
import pygame
from pygame.locals import *
from sys import exit
pygame.init()
screen = pygame.display.set_mode((758, 758), 0, 32)
##Color
color0 = (0,255)

b = 0

white0 = [] #white0
black0 = [] #black0

stoneWidth = 20

while True:
pressed_keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == QUIT:
exit()
if event.type == MOUSEBUTTONDOWN:##makes a variable out of the X.
and Y. coordinates
if b==0:
b=1
black0.append(event.pos)##black0.append [X. and Y.]
black1.append(event.pos)
print black points1
print black0
print
else:
b=0
white0.append(event.pos)
white1.append(event.pos)
print white points
print white0
print
if event.type == KEYDOWN:
if event.key == K_b:
print cut black
for stone in len(black0):##I'm not sure here either   is
this the way I would look for detection of mouse in the range
Circleif event.pos == range( black0[stone][0] -
(stoneWidth/2), black0[stone][0] + ((stoneWidth/2)+1)):
## this is where I get confused what should I do

## black0.insert(event.pos,0)
if event.pos == range( black0[stone][1] -
(stoneWidth/2), black0[stone][1] + ((stoneWidth/2)+1)):
## this is where I get confused what should I do

##black0.insert(event.pos,1)

screen.fill((229,181,83))
screen.lock()
for white in white0: #you're drawing
pygame.draw.circle(screen, (color0[1],color0[1],color0[1]), white,
20)
for black in black0:
pygame.draw.circle(screen, (color0[0],color0[0],color0[0]), black,
20)
screen.unlock()
pygame.display.update()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problems finding position in list and changing it for GO game

2008-12-15 Thread W W
On Mon, Dec 15, 2008 at 10:01 PM, Lee Meredith tesujicam...@gmail.comwrote:

 snip
 the MOUSEBUTTONDOWN gives the black0 XandYpositions with the*.append*
 how do I reference the address in the list by using XandYpositions
 Then replace them or take it out off the list

 This code puts out an error when you hit the letter b


This error is pretty verbose, as most python errors are:


 Traceback (most recent call last):
   File C:/Users/Lee/Desktop/pyGame01/GO/GO_1_2_3.py, line 46, in module


This line tells you that the offending statement, the one that broke your
program/contained a bug is on line 46. Usually this is a pretty good place
to start looking.


 for stone in len(black0):


That tells you the statement that broke


 TypeError: 'int' object is not iterable


This line tells you /why/ it broke, which is usually the most important bit,
and this one gives you some good information. First off, it tells you the
type of error, in this case TypeError. AFAIK, this means you tried to do
something with a type that isn't allowed. In this case you tried to iterate
over an integer. This doesn't work.

Would you expect this to work?
for num in 7:

Hopefully your experience with python will tell you that it would be silly
to think of such a thing.However, if you were to say:

for num in range(0, 7): - that would be a little more sane. In this case,
you are performing something similar to the prior example: you're trying to
iterate over a single integer. len() returns the length of the list as an
integer value.

If you look at some of your other statements you have for white in white0:
- a list is iterable, and white0 is a list.

I hope this helps,
Wayne




 Which I'm not really sure what that means or how to remedy it as well

 Thank you everyone

 ## geting there black and white stones alternate now the issue
 ## of taking the stones off the board
 ## Or more precisely to .insert into the list at an address that I detected
 by finding the X. and the Y. by using the
 ## if event.pos == range( black0[stone][0] - (stoneWidth/2),
 black0[stone][0] + ((stoneWidth/2)+1)):
 import pygame
 from pygame.locals import *
 from sys import exit
 pygame.init()
 screen = pygame.display.set_mode((758, 758), 0, 32)
 ##Color
 color0 = (0,255)

 b = 0

 white0 = [] #white0
 black0 = [] #black0

 stoneWidth = 20

 while True:
 pressed_keys = pygame.key.get_pressed()
 for event in pygame.event.get():
 if event.type == QUIT:
 exit()
 if event.type == MOUSEBUTTONDOWN:##makes a variable out of the X.
 and Y. coordinates
 if b==0:
 b=1
 black0.append(event.pos)##black0.append [X. and Y.]
 black1.append(event.pos)
 print black points1
 print black0
 print
 else:
 b=0
 white0.append(event.pos)
 white1.append(event.pos)
 print white points
 print white0
 print
 if event.type == KEYDOWN:
 if event.key == K_b:
 print cut black
 for stone in len(black0):##I'm not sure here either   is
 this the way I would look for detection of mouse in the range
 Circleif event.pos == range( black0[stone][0] -
 (stoneWidth/2), black0[stone][0] + ((stoneWidth/2)+1)):
 ## this is where I get confused what should I do
 
 ## black0.insert(event.pos,0)
 if event.pos == range( black0[stone][1] -
 (stoneWidth/2), black0[stone][1] + ((stoneWidth/2)+1)):
 ## this is where I get confused what should I do
 
 ##black0.insert(event.pos,1)

 screen.fill((229,181,83))
 screen.lock()
 for white in white0: #you're drawing
 pygame.draw.circle(screen, (color0[1],color0[1],color0[1]), white,
 20)
 for black in black0:
 pygame.draw.circle(screen, (color0[0],color0[0],color0[0]), black,
 20)
 screen.unlock()
 pygame.display.update()



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




-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] MP3Info class usage

2008-12-15 Thread Todd Zullinger
Gareth at Serif wrote:
 Okay, I've moved over to eyeD3.py... fif nothing else, the
 documentation for it's usage is far superior.
 
 However, I can't get anything to run.  The help gives examples of
 some simple tasks, but as soon as I 'import eyeD3', not even calling
 any functions within it, I start getting errors such as:
 
 In eyeD3.py, the 'from eyeD3.tag import *;' line (and similar)
 didn't work until I removed the 'eyeD3.' part and just imported
 'tag'.

How have you installed eyeD3?  Perhaps there's something wrong with
the installation.  Certainly, 'import eyeD3' should not create any
errors.

 Then in tag.py, some of the class defs complained about undefined
 variables, for example 'def link(self, f, v = ID3_ANY_VERSION)'
 needed to have quotes around 'ID3_ANY_VERSION'.

That's not what you want to do.  ID3_ANY_VERSION is defined in
eyeD3/__init__.py.  If you quote it, you're breaking it.

 I'm baffled that I'm having to jump through so many hoops because I
 imported eyeD3... is this typical?  What have I done wrong?

That's hard to guess at.  If you can explain what you have done and
how you've installed eyeD3, that would help.

-- 
ToddOpenPGP - KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~
Don't look for me in daylight where robots all assemble.  You'll find
me in my dark world, in my smoke-filled temple.



pgpcUXQkD7v1L.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] listen in on other program's tcp connections

2008-12-15 Thread xbmuncher
On windows XP, I'm running a program that sends TCP connections on port
5039. I'v ran wireshark to determine this. I want to create a simple program
that listens for these connections and intercepts and then turns the data
transferred into a string. From there I'd obviously like my program to act
and manipulate those strings, but for now just spitting out that intercepted
TCP data is good enough.

I was reading up on Twisted. http://twistedmatrix.com/
Can someone get me started on how to do this with twisted framework or
anything else?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor