Re: [Tutor] error message

2019-03-21 Thread Alan Gauld via Tutor

On 21/03/19 05:13, Glenn Dickerson wrote:

Thank you for all of your responses to:

class Student():
 def__init__(self, name, major, gpa, is_on_probation):
 self.name = name
 self.major = major
 self.gpa = gpa
 self.is_on_probation = is_on_probation



Presumably the lines above ar in a separate file called Student.py?

And the lines below are in another file  called app.py?

If so thats a good start.
Steve (and others have already pointed out the need for a space after 
def (otherwise python looks for a function called def__init__() and 
wonderswhy yu have a colon after its  invocation)


But that will only lead you to the next error.


import Student
student1 = Student('Jim', 'Business', 3.1, False)


When accessing an object in an imported module you must precede
the object's name with the module:

student1 = Student.Student() # Student class in the Student module

Alternatively you can explicitly import the Student class (and nothing 
else!) from Student with:


from Student import Student

I which case you can use it as you do in your code.
In your case it doesn't really matter which of the two styles
you choose. In more complex programs explicit module naming
might make your code clearer (eg. if you have many modules).
Alternatively, pulling in the specific object might save
you some typing if you reference the object several times.
You need to choose which is most appropriate based on your code.

HTH

Alan G.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] error message

2019-03-21 Thread Steven D'Aprano
> I don't understand this error message. Thank you so much, Glenn Dickerson
> 
> Traceback (most recent call last):
>   File "/home/glen/app.py", line 1, in 
> import Student
>   File "/home/glen/Student.py", line 2
> def__init__(self, name, major, gpa, is_on_probation):
> ^
> SyntaxError: invalid syntax


Syntax errors are sometimes the hardest to decipher, because the message 
is usually pretty generic and uninformative, and the caret ^ will appear 
where the interpreter *notices* the problem, not where the problem 
*starts*.

In this case, the problem is you are missing a space between the "def" 
keyword and the "__init__" method name.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message

2014-08-11 Thread Danny Yoo
Hi Richard,

I would recommend asking the PyGame folks on this one.  What you're
running into is specific to that external library, and folks who work
with PyGame have encountered the problem before: they'll know how to
diagnose and correct it.  For example:


http://stackoverflow.com/questions/7775948/no-matching-architecture-in-universal-wrapper-when-importing-pygame


http://stackoverflow.com/questions/8275808/installing-pygame-for-mac-os-x-10-6-8

What appears to be happening is a 32-bit vs 64-bit issue: you may have
installed a version of PyGame for one architecture, but should have
chosen the other.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message

2014-08-10 Thread Steven D'Aprano
On Sun, Aug 10, 2014 at 10:32:52AM +0100, RICHARD KENTISH wrote:
 Hi!
 
 Ive installed Python 2.7.8 and pygame 1.9.1 onto a macbook pro 10.9.4 
 Mavericks.
 
 The code is taken direct from the 'making games' book. Here it is pasted from 
 idle:

Whenever you have a mysterious error in Python that doesn't appear to be 
an error on your part -- and I admit that as a beginner, it's hard to 
tell which errors are yours and which aren't -- it's always worth trying 
again running Python directly. IDEs like IDLE sometimes do funny things 
to the environment in order to provide an Integrated Development 
Environment, and occasionally they can interfere with the clean running 
of Python code. So, just to be sure, I suggest you try running your code 
again outside of IDLE:

* Save your code to a file (which I see you've already done).

* Open up a terminal so you have a command line.

* Change into the directory where your file is saved. Type this command:

  cd /Users/richardkentish/Desktop/Python resources

  then press ENTER.

* Run the file directly using Python by typing this command:

  python blankgame.py

  then press ENTER.

If the error goes away, and you either get no error at all, or a 
different error, then it may be a problem with IDLE. Copy and paste the 
error here, and we can advise further.

Having said all that, looking at the exception you get:

 Traceback (most recent call last):
   File /Users/richardkentish/Desktop/Python resources/blankgame.py, line 1, 
 in module
     import pygame, sys
   File 
 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py,
  line 95, in module
     from pygame.base import *
 ImportError: 
 dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so,
  
 2): no suitable image found.  Did find: 
 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so:
  
 no matching architecture in universal wrapper

it looks to me like perhaps you have a version of Pygame which is not 
compatible with the Mac. How did you install it? I'm not a Mac expert 
(it's been about, oh, 17 years since I've used a Mac) but somebody else 
may be able to advise.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message

2014-08-10 Thread RICHARD KENTISH
Hi All,

I have found a work around - not entirely sure what I did but followed this 
website 
http://www.reddit.com/r/pygame/comments/21tp7n/how_to_install_pygame_on_osx_mavericks/

Still can't run through idle but dragging the saved .py file to the python 
launcher works!

Thanks for your help.

Best wishes,

Richard



 From: RICHARD KENTISH r.kent...@btinternet.com
To: tutor@python.org tutor@python.org 
Sent: Sunday, 10 August 2014, 10:32
Subject: [Tutor] Error message
 


Hi!

Ive installed Python 2.7.8 and pygame 1.9.1 onto a macbook pro 10.9.4 Mavericks.

The code is taken direct from the 'making games' book. Here it is pasted from 
idle:

import pygame, sys
from pygame.locals import *

pygame.init()
displaysurf = pygame.dispaly.set_mode((400, 300))
pygame.display.set_caption('Hello World!')

while True: # main game loop
    for event in pygame.event.get():
        if event.type == quit:
            pygame.quit()
            sys.exit()
    pygame.display.update()

Here is the error I am getting.

Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type copyright, credits or license() for more information.
  RESTART 
 

Traceback (most recent call last):
  File /Users/richardkentish/Desktop/Python resources/blankgame.py, line 1, 
in module
    import pygame, sys
  File 
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py,
 line 95, in module
    from pygame.base import *
ImportError: 
dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so,
 2): no suitable image found.  Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so:
 no matching architecture in universal wrapper


Thanks for your help.

Best wishes,

Richard
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message

2014-08-10 Thread RICHARD KENTISH
Thanks for your response. I have tried your suggestion and get the same error.  
Here's the text from terminal.

Richards-MacBook-Pro:Python resources richardkentish$ pwd
/Users/richardkentish/desktop/Python resources
Richards-MacBook-Pro:Python resources richardkentish$ python blankgame.py
Traceback (most recent call last):
  File blankgame.py, line 1, in module
    import pygame, sys
  File 
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py,
 line 95, in module
    from pygame.base import *
ImportError: 
dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so,
 2): no suitable image found.  Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so:
 no matching architecture in universal wrapper
Richards-MacBook-Pro:Python resources richardkentish$ 

I installed the python files from the python site, latest version for mac.

Best wishes,

Richard



 From: Steven D'Aprano st...@pearwood.info
To: tutor@python.org 
Sent: Sunday, 10 August 2014, 12:30
Subject: Re: [Tutor] Error message
 

On Sun, Aug 10, 2014 at 10:32:52AM +0100, RICHARD KENTISH wrote:
 Hi!
 
 Ive installed Python 2.7.8 and pygame 1.9.1 onto a macbook pro 10.9.4 
 Mavericks.
 
 The code is taken direct from the 'making games' book. Here it is pasted from 
 idle:

Whenever you have a mysterious error in Python that doesn't appear to be 
an error on your part -- and I admit that as a beginner, it's hard to 
tell which errors are yours and which aren't -- it's always worth trying 
again running Python directly. IDEs like IDLE sometimes do funny things 
to the environment in order to provide an Integrated Development 
Environment, and occasionally they can interfere with the clean running 
of Python code. So, just to be sure, I suggest you try running your code 
again outside of IDLE:

* Save your code to a file (which I see you've already done).

* Open up a terminal so you have a command line.

* Change into the directory where your file is saved. Type this command:

  cd /Users/richardkentish/Desktop/Python resources

  then press ENTER.

* Run the file directly using Python by typing this command:

  python blankgame.py

  then press ENTER.

If the error goes away, and you either get no error at all, or a 
different error, then it may be a problem with IDLE. Copy and paste the 
error here, and we can advise further.

Having said all that, looking at the exception you get:


 Traceback (most recent call last):
   File /Users/richardkentish/Desktop/Python resources/blankgame.py, line 1, 
 in module
     import pygame, sys
   File 
 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py,
  line 95, in module
     from pygame.base import *
 ImportError: 
 dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so,
  
 2): no suitable image found.  Did find: 
 /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so:
  
 no matching architecture in universal wrapper

it looks to me like perhaps you have a version of Pygame which is not 
compatible with the Mac. How did you install it? I'm not a Mac expert 
(it's been about, oh, 17 years since I've used a Mac) but somebody else 
may be able to advise.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message received when running “from scipy import interpolate”

2014-06-05 Thread Alan Gauld

On 05/06/14 23:36, Colin Ross wrote:

I am attempting to run the following in python:

|from  scipyimport  interpolate|


This list is for those learning the core Python language and its 
standard library.


Support for scipy is probably best gained from the scipy forum
The MacPython list may also be able to help with MacOS specific queries.

But there are some Mac/Scipy users here so I'll leave it to them to 
chime in if they can help.



I receive this error message:

|Traceback  (most recent call last):
   File  stdin,  line1,  in  module
   File  
/Library/Python/2.7/site-packages/scipy-0.11.0.dev_0496569_20111005-py2.7-macosx-10.7-x86_64.egg/scipy/interpolate/__init__.py,
  line156,  in  module
 from  ndgriddataimport  *
   File  
/Library/Python/2.7/site-packages/scipy-0.11.0.dev_0496569_20111005-py2.7-macosx-10.7-x86_64.egg/scipy/interpolate/ndgriddata.py,
  line9,  in  module
 from  interpndimport  LinearNDInterpolator,  NDInterpolatorBase,  \
   File  numpy.pxd,  line172,  in  init 
interpnd(scipy/interpolate/interpnd.c:7696)
ValueError:  numpy.ndarray has the wrong size,  try  recompiling|

I am currently running Mac OS X Lion 10.7.5 and Python 2.7.1. with
MacPorts installed.

I am attempting to run the code on a different computer than it was
created on. After doing some reading my understanding is that this error
may be a result of the ABI not being forward compatible. To try and
solve the issue I updated my MacPorts and then ran ($ sudo port upgrade
outdated) to upgrade the installed ports. However, the same error
continues to appear when I try and run the code.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-25 Thread Matthew Ngaha
Hi Victoria. im a total beginner aswell but i noticed something. shouldnt this 
line:

else: return s(0) == s(-1) and isPalindrome (s[1:-1])

be

 else: return s[0] == s[-1] and isPalindrome (s[1:-1])


it looks like you have the string s as a function which you are trying
to call. what you wanted was an index position right? which should be
s[] instead of s().

thanks for the help David. Sorry about the sent mail. Gmail is pretty
confusing for me:( ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-25 Thread Victoria Homsy
Thank you everyone for your help with my question - I understand what I was 
doing wrong now. I know I'm posting wrongly so I'm going to go and figure out 
how to do it properly for the future. Have a great day.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-24 Thread David
On 24/08/2012, Victoria Homsy victoriaho...@yahoo.com wrote:

 However, this does not work - I get another error message.
 Could somebody advise what I'm doing wrong here? Thank you.

1) You are not carefully reading the entire error message.
2) You are not allowing us to do it either.

Some other things too, probably, but we need to start with those two :)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-23 Thread Peter Otten
Victoria Homsy wrote:

 Sorry to bother you with a beginner's problem again...

This is the place for beginners.
 
 I have tried to write a program that can check if a string is a
 palindrome. My code is as follows:
 
 
 def isPalindrome(s):
 if len(s) = 1: return True
 else: return s(0) == s(-1) and isPalindrome (s[1:-1])
 isPalindrome('aba')
 
 
 However, when I try to run it in terminal I get the following error
 message:
 
 Traceback (most recent call last):
 File recursion.py, line 5, in module
 isPalindrome('aba')
 File recursion.py, line 3, in isPalindrome
 else: return s(0) == s(-1) and isPalindrome (s[1:-1])
 TypeError: 'str' object is not callable
 
 
 I don't see why this wouldn't work...

If you want to get the nth charactor you have to put the index in brackets, 
not parens:

 s = foo
 s(0) # wrong, python tries to treat s as a function
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: 'str' object is not callable
 s[0] # correct
'f'


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-23 Thread Rob Day
On 23 August 2012 15:17, Victoria Homsy victoriaho...@yahoo.com wrote:


 def isPalindrome(s):
  if len(s) = 1: return True
 else: return s(0) == s(-1) and isPalindrome (s[1:-1])

 I don't see why this wouldn't work...

 Many thanks in advance.

 Kind regards,

 Victoria


Parentheses are used for function arguments in Python, whereas square
brackets are used for slices - so the first character of s is not s(0) but
s[0].

When you say s(0) and s(-1), Python thinks you're calling s as a function
with 0 or -1 as the argument - hence, str object is not callable.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-23 Thread Mark Lawrence

On 23/08/2012 15:17, Victoria Homsy wrote:

Dear all,

Sorry to bother you with a beginner's problem again...


You're welcome as that's what we're here for.



I have tried to write a program that can check if a string is a palindrome. My 
code is as follows:


def isPalindrome(s):
if len(s) = 1: return True
else: return s(0) == s(-1) and isPalindrome (s[1:-1])
isPalindrome('aba')


However, when I try to run it in terminal I get the following error message:

Traceback (most recent call last):
   File recursion.py, line 5, in module
 isPalindrome('aba')
   File recursion.py, line 3, in isPalindrome
 else: return s(0) == s(-1) and isPalindrome (s[1:-1])
TypeError: 'str' object is not callable


I don't see why this wouldn't work...


Always easier for another pair of eyes.  The TypeError tells you exactly 
what the problem is.  Just look very carefully at the return after the 
else and compare your use of the function parameter s.  Then kick 
yourself and have another go :)




Many thanks in advance.

Kind regards,

Victoria



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



--
Cheers.

Mark Lawrence.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-23 Thread Victoria Homsy
Excellent - thank you so much everyone. All is clear now!! 



 From: Mark Lawrence breamore...@yahoo.co.uk
To: tutor@python.org 
Sent: Thursday, 23 August 2012, 15:29
Subject: Re: [Tutor] Error message...
 
On 23/08/2012 15:17, Victoria Homsy wrote:
 Dear all,

 Sorry to bother you with a beginner's problem again...

You're welcome as that's what we're here for.


 I have tried to write a program that can check if a string is a palindrome. 
 My code is as follows:


 def isPalindrome(s):
 if len(s) = 1: return True
 else: return s(0) == s(-1) and isPalindrome (s[1:-1])
 isPalindrome('aba')


 However, when I try to run it in terminal I get the following error message:

 Traceback (most recent call last):
    File recursion.py, line 5, in module
      isPalindrome('aba')
    File recursion.py, line 3, in isPalindrome
      else: return s(0) == s(-1) and isPalindrome (s[1:-1])
 TypeError: 'str' object is not callable


 I don't see why this wouldn't work...

Always easier for another pair of eyes.  The TypeError tells you exactly 
what the problem is.  Just look very carefully at the return after the 
else and compare your use of the function parameter s.  Then kick 
yourself and have another go :)


 Many thanks in advance.

 Kind regards,

 Victoria



 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


-- 
Cheers.

Mark Lawrence.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-23 Thread Steven D'Aprano

On 24/08/12 01:33, Victoria Homsy wrote:


Dear All - sorry to bother you. I just tried to run this program:


def isPalindrome(s):
if len(s)= 1: return True
else: return s[0] == s[-1] and isPalindrome (s[1:-1])
isPalindrome('aba')


However when I run it in terminal it doesn't give me any answer -
True or False. (I want the program to tell me whether the input
string is True or False). In order to get an answer, I assume I
would need to tell the program to print something. However I'm
not sure where in the program I would do this. I tried this:

def isPalindrome(s):
if len(s)= 1: return True and print True
else: return s[0] == s[-1] and isPalindrome (s[1:-1])
isPalindrome('aba')

However, this does not work - I get another error message.


Would you like to tell us what error message you get, or should we
try to guess? I love guessing games!

Ah, who am I fooling? I hate guessing games. It's always best if
you copy and paste the full traceback you get, starting with the
line

Traceback (most recent call last)

all the way to the end of the error message.


In this case, I can guess that you are getting a SyntaxError. Am I
close? If I'm right, you can read the SyntaxError and it will give
you a hint as to where to look for the error:

py if len(s) = 1: return True and print True
  File stdin, line 1
if len(s) = 1: return True and print True
^
SyntaxError: invalid syntax


See the caret ^ printed just below the offending line of source
code and just above the message that it is a syntax error? In the
terminal window, that will point to the first part of the line
which Python doesn't understand.

In this case, you're giving Python instructions in English, and it's
not that smart. A human being might understand what you mean by
return True and print True, but that's invalid Python code. You
need to separate that into two separate operations:

1) The isPalindrome function you write is responsible for returning
the True or False flag, nothing more.

2) The piece of code that calls the function is responsible for
printing the flag.


So in this case, your isPalindrome function must return a flag:


def isPalindrome(s):
if len(s) = 1: return True
else: return s[0] == s[-1] and isPalindrome (s[1:-1])


And the caller is responsible for printing the result:

result = isPalindrome('aba')
print result


Those two lines can be simplified to one line:

print isPalindrome('aba')


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-23 Thread Mark Lawrence

On 23/08/2012 16:33, Victoria Homsy wrote:





Dear All - sorry to bother you. I just tried to run this program:


def isPalindrome(s):
if len(s) = 1: return True
else: return s[0] == s[-1] and isPalindrome (s[1:-1])
isPalindrome('aba')


However when I run it in terminal it doesn't give me any answer - True or 
False. (I want the program to tell me whether the input string is True or 
False). In order to get an answer, I assume I would need to tell the program to 
print something. However I'm not sure where in the program I would do this. I 
tried this:

def isPalindrome(s):
if len(s) = 1: return True and print True
else: return s[0] == s[-1] and isPalindrome (s[1:-1])
isPalindrome('aba')

However, this does not work - I get another error message.

Could somebody advise what I'm doing wrong here? Thank you.


You're not spending enough time thinking, seriously.  In your original 
attempt you've got isPalindrome which returns True or False.  You call 
the function but don't do anything with the return value, so it's simply 
discarded.  Then you mess around with a perfectly good function instead 
of fixing the real problem.  You've two options.  The simplest is :-


print 'isPalindrome returned', isPalindrome('aba')

The alternative which is used when you want to keep using a return value 
is :-


status = isPalindrome('aba')
print 'isPalindrome returned', status





___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



Whoops might have helped if I'd hit Send.

--
Cheers.

Mark Lawrence.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error message...

2012-08-23 Thread Dave Angel
On 08/23/2012 11:33 AM, Victoria Homsy wrote:

 Dear All - sorry to bother you. I just tried to run this program:


 def isPalindrome(s):
 if len(s) = 1: return True 
 else: return s[0] == s[-1] and isPalindrome (s[1:-1])
 isPalindrome('aba')


 However when I run it in terminal it doesn't give me any answer - True or 
 False. (I want the program to tell me whether the input string is True or 
 False). In order to get an answer, I assume I would need to tell the program 
 to print something. However I'm not sure where in the program I would do 
 this. I tried this:

 def isPalindrome(s):
 if len(s) = 1: return True and print True
 else: return s[0] == s[-1] and isPalindrome (s[1:-1])
 isPalindrome('aba')

 However, this does not work - I get another error message. 

 Could somebody advise what I'm doing wrong here? Thank you.



Could we trouble you for two obvious details?

What version of Python are you running?   What exactly is your error
message?  There are at least two possibilities, since two different
versions of Python will give two different error messages.  Or you could
finesse the error by reverting the function to the version that worked,
and printing in the calling code.  The function shouldn't be printing in
any case.

While i've got your attention, could I talk you out of posting html
messages to a text forum?  All the indentation of those code fragments
is lost, for me and probably most people.  And don't top-post.  Put your
comments AFTER the part you quote from earlier messages.



-- 

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] error message

2009-07-08 Thread Emile van Sebille

On 7/8/2009 9:13 AM Steven Buck said...
I'm running a for loop which returns an error message after the third 
iteration (see out[4] at the bottom as evidence).  I don't understand 
the error message.  Although I'll continue to do my own digging to 
debug, I thought I'd give you all a shot.  Thanks, -steve
 

snips

age[(i)] = psid.psid[i][20]

Here you're getting the 20th field from the 4th record.  So, assuming 
the tools you're using are OK...



-- 150 d = unpack(self._header['byteorder']+fmt, byt)[0]



error: unpack requires a string argument of length 1


... you get an unpack error.  So my money's on a source data problem.

you might try...

for ii in range(40):
print psid.psid[3][ii]

...and see what you get.  It's likely a bad record of some sort.  You 
might need to allow for those...



HTH,

Emile


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


Re: [Tutor] error message

2009-07-08 Thread bob gailer




Steven Buck wrote:

  I'm running a for loop which returns an error message after the
third iteration(see out[4] at the bottom as evidence). I don't
understand the error message. Although I'll continue to do my own
digging to debug, I thought I'd give you all a shot. Thanks, -steve
  
  Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32
bit (Intel)]
Type "copyright", "credits" or "license" for more information.
  IPython 0.9.1 -- An enhanced Interactive Python.
? - Introduction and overview of IPython's features.
%quickref - Quick reference.
help - Python's own help system.
object? - Details about 'object'. ?object also works, ?? prints
more.
  In [1]: import psid
  In [2]: age = {}
  In [3]: for i in range(len(psid.psid)):
 ...: age[(i)] = psid.psid[i][20]
 ...:
 ...:
---
error Traceback (most recent call
last)
  C:\Documents and Settings\Steve\ipython console in
module()
  C:\Python26\lib\site-packages\StataTools.pyc in
__getitem__(self, k)
 85 if self._file.tell() != loc:
 86 self._file.seek(loc)
--- 87 return self._next()
 88
 89 ### PyDTA private methods
  
C:\Python26\lib\site-packages\StataTools.pyc in _next(self)
 167 else:
 168 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
 169 return data
 170 else:
-- 171 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
  C:\Python26\lib\site-packages\StataTools.pyc in lambda(i)
 167 else:
 168 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
 169 return data
 170 else:
-- 171 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
  C:\Python26\lib\site-packages\StataTools.pyc in _unpack(self,
fmt, byt)
 148
 149 def _unpack(self, fmt, byt):
  


Add here (temporarily) print self._header['byteorder'], fmt, byt
make sure it is indented the same as 150.
Let's examine the 4th printed line.


  -- 150 d = unpack(self._header['byteorder']+fmt,
byt)[0]
 151 if fmt[-1] in self.MISSING_VALUES:
 152 nmin, nmax = self.MISSING_VALUES[fmt[-1]]
  error: unpack requires a string argument of length 1
  In [4]: age
Out[4]: {0: 22, 1: 51, 2: 42}
  In [5]:
  

___
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] error message

2009-07-08 Thread Steven Buck
As Bob prescribed, I added (and made sure to indent):

print self._header['byteorder'], fmt, byt

The fourth printed line appears to be the same:
Out[4]: {0: 22, 1: 51, 2: 42}

This is consistent with what I observe as the first three age observations
in the Stata data editor.

I include the rest of the error message I received ( could capture) below.
Any more thoughts?
Thanks
Steve

 b ▬
 b §
 b ☺
 b ☺
 b ☺
 b ☻
 b ☺
 f  PCF
 b ♣
 f ∞Qê@
 b ☺
 f   `A
 b ☺
 b ♣
 f
 f
 b
 b
 b ♣
 h ╥
 f   ßC
 b e
 b ♣
 b
 b
 b
 b ☺
 b ♥
 b ♥
 b ☺
 h ñ
 h
 f 5î─D
 b ☺
 b
 b
 b
 b
 b
 b ☺
 b ☺
 h Σ☺
 b ☺
 b ☺
 f   ÉB
 f ÜÖôB
 f ÜÖêB
 f   âB
 f ═╠ƒB
 f ÜÖàB
 f ÜÖúB
 f ffzB
 f ═╠ùB
 f fféB
 f ffrB
 f 33æB
 f ∞Q8?
 f ü↓ⁿ@
 f «1¿╛
 f b♥2A
 f �...@a
 f ♠·OA
 f ╟▌QA
 f   Ç?
 h ⌠←
 b
 h ║
 h ☻
 f  áîF
 f
 h (♣
 f   èE
 h
 h ╝
 h
 f  α½F
 f
 f  α½F
 f   ╥E
 f  hαF
 f   }E
 b 
 b ☺
 b ☻
 b 3
 b 1
 b ☺
 b ☻
 b ☺
 b ☺
 b ☺
 f  α½F
 b e
 f Å┬1A
 b
 f   ,B
 b ♣
 b ♣
 f
 f
 b
 b ☺
 b ♣
 h
 f
 b e
 b ☺
 b ☺
 b
 b
 b ☻
 b ☺
 b ☺
 b ☻
 h ç
 h
 f 8↑sE
 b
 b ☺
 b
 b
 b ☺
 b
 b
 b
 h )
 b ☺
 b
 f   ÉB
 f ÜÖôB
 f ÜÖêB
 f   âB
 f ═╠ƒB
 f ÜÖàB
 f ÜÖúB
 f ffzB
 f ═╠ùB
 f fféB
 f ffrB
 f 33æB
 f ∞Q8?
 f ≥Ä♂A
 f «1¿╛
 f ░₧CA
 f _iXA
 f ↑├`A
 f ♫»iA
 f   Ç@
 h àD
 b ☺
 h ║
 h Ñ♥
 f
 f  Ç╨D
 h
 f   ☻E
 h
 h ╚♠
 h
 f  @£E
 f
 f  @£E
 f
 f  @£E
 f
 b
 b ☻
 b ☻
 b *
 b )
 b ☺
 b
 b ☺
 b ☺
 b ☺
 f  @£E
 b ☺
 f ∞Q8@
 b
 f   Ç?
 b ☺
 b ♣
 f
 f
 b
 b
 b ♣
 h
 f
 b e
 b ♣
 b
 b
 b
 b ☻
 b ☻
 b ☻
 b ♥
 h É
 h
 f ^ë↑D
 b
 b
 b ☺
 b
 b
 b ☺
 b
 b
 h Σ♠
 b ☺
 b
 f   ÉB
 f ÜÖôB
 f ÜÖêB
 f   âB
 f ═╠ƒB
 f ÜÖàB
 f ÜÖúB
 f ffzB
 f ═╠ùB
 f fféB
 f ffrB
 f 33æB
 f ∞Q8?
 f ■■■@
 f «1¿╛
 f ä▐3A
 f :─CA
 f ¡♫RA
 f bVUA
 f   @@
 h ▐►
 b
 h ║
 h ►►
 f
 f   aD
 h X☻
 f  ÇE
 h
 h ÷
 h ≡
 f  ╝TF
 f   HD
 f  αvF
 f
 f  αvF
 f   »D
 b ↑
 b ♣
 b ♣
 b
---
error Traceback (most recent call last)
C:\Documents and Settings\Steve\ipython console in module()
C:\Python26\lib\site-packages\StataTools.py in __getitem__(self, k)
 85 if self._file.tell() != loc:
 86 self._file.seek(loc)
--- 87 return self._next()
 88
 89 ### PyDTA private methods

C:\Python26\lib\site-packages\StataTools.py in _next(self)
168 else:
169 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
170 return data
171 else:
-- 172 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
C:\Python26\lib\site-packages\StataTools.py in lambda(i)
168 else:
169 data[i] = self._unpack(typlist[i],
self._file.read(s
elf._col_size(i)))
170 return data
171 else:
-- 172 return map(lambda i: self._unpack(typlist[i],
self._file.rea
d(self._col_size(i))), range(self._header['nvar']))
C:\Python26\lib\site-packages\StataTools.py in _unpack(self, fmt, byt)
149 def _unpack(self, fmt, byt):
150 print self._header['byteorder'], fmt, byt
-- 151 d = unpack(self._header['byteorder']+fmt, byt)[0]
152 if fmt[-1] in self.MISSING_VALUES:
153 nmin, nmax = self.MISSING_VALUES[fmt[-1]]
error: unpack requires a string argument of length 1
In [4]: age
Out[4]: {0: 22, 1: 51, 2: 42}
In [5]:


On Wed, Jul 8, 2009 at 1:12 PM, bob gailer bgai...@gmail.com wrote:

   Steven Buck wrote:

 I'm running a for loop which returns an error message after the third
 iteration (see out[4] at the bottom as evidence).  I don't understand the
 error message.  Although I'll continue to do my own digging to debug, I
 thought I'd give you all a shot.  Thanks, -steve

 Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
 (Intel)]
 Type copyright, credits or license for more information.
 IPython 0.9.1 -- An enhanced Interactive Python.
 ? - Introduction and overview of IPython's features.
 %quickref - Quick reference.
 help  - Python's own help system.
 object?   - Details about 'object'. ?object also works, ?? prints more.
 In [1]: import psid
 In [2]: age = {}
 In [3]: for i in range(len(psid.psid)):
...: age[(i)] = psid.psid[i][20]
...:
...:
 ---
 error Traceback (most recent call last)
 C:\Documents and Settings\Steve\ipython console in module()
 C:\Python26\lib\site-packages\StataTools.pyc in __getitem__(self, k)
  85 if self._file.tell() != loc:
  86 self._file.seek(loc)
 --- 87 return self._next()
  88
  89 ### PyDTA private methods

 C:\Python26\lib\site-packages\StataTools.pyc in _next(self)
 167 else:
 168 data[i] = self._unpack(typlist[i],
 self._file.read(s
 

Re: [Tutor] error message with multiple inheritance

2008-06-11 Thread simone

Christopher Spears ha scritto:


I've been working out of Core Python Programming (2nd Edition).  Here is an 
example demonstrating multiple inheritance.


class A(object):

... pass
...

class B(A):

... pass
...

class C(B):

... pass
...

class D(A, B):

... pass
...
Traceback (most recent call last):
  File stdin, line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases B, A

What does this error message mean?  The example worked in the book.  I checked 
in the docs and could not find anything.


http://www.python.org/download/releases/2.3/mro/
Chiacchiera con i tuoi amici in tempo reale! 
http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 


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


Re: [Tutor] error message with multiple inheritance

2008-06-11 Thread Kent Johnson
On Wed, Jun 11, 2008 at 2:25 AM, simone [EMAIL PROTECTED] wrote:
 Christopher Spears ha scritto:

 Traceback (most recent call last):
  File stdin, line 1, in ?
 TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
 order (MRO) for bases B, A

 What does this error message mean?  The example worked in the book.  I
 checked in the docs and could not find anything.

 http://www.python.org/download/releases/2.3/mro/

In layman's terms:
For class C, the method resolution order is C, B, A, object. Note that
B is before A. For class D, A would come before B because of the order
of declaration of base classes. This conflict causes the TypeError.

One way to fix it is to define D as
  class D(B, A):
pass

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


Re: [Tutor] error message questions

2007-05-27 Thread Rikard Bosnjakovic
On 5/27/07, adam urbas [EMAIL PROTECTED] wrote:

 It says:

 can't multiply sequence by non-int of type 'str'

The reason is that raw_input() returns a string. What you are trying
to do is multiply a string with a string, which - in Python - is an
illegal operation.

What you want to do is to convert the read value from raw_input() to
an integer, and then multiply. You convert with the function int(). So
if you change the two upper lines of your code test.py to

height = int(raw_input(enter height:))
width = int(raw_input(enter width:))

then the multiplication will work. It will - however - not work if you
don't enter a numerical value, because int() will fail for everything
else than numericals.

HTH.


-- 
- Rikard - http://bos.hack.org/cv/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] error message questions

2007-05-27 Thread Alan Gauld
adam urbas [EMAIL PROTECTED] wrote in

 Hello all,I was wondering if there would be someone who
 would be able to give me a list of error messages and
 their meanings.

The errors are actually self explanatory - no really! - once
you undestandd the basic concepts. But to understand
those you will need to go back to basics.

I suggested in an earlier post that you read my Raw Materials topic
which discusses data and types. Did you do that?

Also the Talking to the User illustrates the use of raw_input,
you could usefully read that too. it discusses using the Python
conversion functions to get the right input values from raw_input..

 It says:can't multiply sequence by non-int of type 'str'

Which means Python cannot multiply the two types of data
you are giving it. You need to convert those values to the compatible
types.

 can't multiply sequence by non-int of type 'float'

Same thing, you have a sequence type on one side
(probably a string but could be a list or tuple?) and a float
on the other. You need to turn the sequence into something
that a float can multiply - either another float or an int (or
a complex or decimal if you feel really picky).

-- 
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] error message

2006-10-01 Thread Kent Johnson
mike viceano wrote:
 hello i wrote a litle program ware you pick a number and the computer
 guesses it and i recently decided to make it so it dosint reguess
 numbers but now i get a error message
 
 here is the program
 
 def number(number):
from random import randrange
guess=randrange(number*2)
print guess
guessed.append(guess)
guesses=1
guessed=[]
while guess !=number:
guess=randrage(number*2)
if guess not in guessed:
guessed.append(guess) #here is ware the problem is
guesses=guesses+1
printi got the number,number,number,in,guesses,guesses
 
 and here is the error
 
 Traceback (most recent call last):
 File pyshell#17, line 1, in -toplevel-
guess.number(10)
 File 
 /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/guess.py,
 line 5, in number
guessed.append(guess)
 UnboundLocalError: local variable 'guessed' referenced before assignment

It pays to read the traceback carefully, this one is giving you a lot of 
good clues.

First, the error is at line 5. This is the *first* line with 
guessed.append(guess), not the one you have commented.

Second, the error message is that 'guessed' is referenced before 
assignment. Where is 'guessed' assigned? Two lines later, on line 7 with 
guessed=[]

Do you know how to fix it now?

Kent

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


Re: [Tutor] Error message with testing Tkinter

2005-11-07 Thread Danny Yoo


On Mon, 7 Nov 2005, Double Six wrote:

 I'm learning Tkinter with the following code on Mac OS X 10.4:

 from Tkinter import *
 from sys import stdout, exit
 widget = Button(None, text = 'Hello?', command=(lambda:
 stdout.write('Hello?\n') or exit()))
 widget.pack()
 widget.mainloop()

 I do successfully get a GUI with a button, but the problem is if I click
 the button, the GUI window hangs there with the following message
 message in the console:

Hello,

sys.exit() will raise a SystemExit exception when it's called, so the
program is doing what you think it's doing.  However, it looks like the
mainloop() code from Tkinter doesn't expect to see that SystemExit.


You probably want to call the quit() method of the graphical widgets
instead: that'll get us out of the mainloop().

http://www.pythonware.com/library/tkinter/introduction/x9374-event-processing.htm


Best of wishes!

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


Re: [Tutor] error message

2005-02-14 Thread Alan Gauld
 The biggest problem that nobody has mentioned yet is the fact that
group()
 will not have anything unless you explicitly tell it to group it.

Nope, group will work OK even with a normal string regex.

Alan G.

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


Re: [Tutor] error message

2005-02-13 Thread Liam Clarke
OK, so it looks like you're not matching. 
Remember match only matches at the start of a line, so try re.search instead.


On Sun, 13 Feb 2005 17:16:24 -0800 (PST), Ron Nixon [EMAIL PROTECTED] wrote:
 
 
 Got the same error message after trying:
 
 x =re.match(patt,string)
 x.group()
 
 Traceback (most recent call last):
   File C:/Python24/testphone.py, line 5, in
 -toplevel-
 x.group()
 AttributeError: 'NoneType' object has no attribute
 'group'
 
 --- Liam Clarke [EMAIL PROTECTED] wrote:
 
  Try breaking it down to
 
   import re
   string = 'My phone is 410-995-1155'
   pattern = r'\d{3}-\d{3}-\d{4}'
 
  x = re.match(pattern, string)
  x.group()
 
  See if that offers any improvement.
 
 
  On Sun, 13 Feb 2005 17:01:33 -0800 (PST), Ron Nixon
  [EMAIL PROTECTED] wrote:
   I'm dping something very simple in RE.
  
   Lets say I'm trying to match an American Phone
  number
  
   I write the code this way and try to match it:
   import re
   string = 'My phone is 410-995-1155'
   pattern = r'\d{3}-\d{3}-\d{4}'
   re.match(pattern,string).group()
  
   but I get this error message
   Traceback (most recent call last):
 File C:/Python24/findphone, line 4, in
  -toplevel-
   re.match(pattern,string).group()
   AttributeError: 'NoneType' object has no attribute
  'group'
  
  
   __
   Do you Yahoo!?
   Take Yahoo! Mail with you! Get it on your mobile
  phone.
   http://mobile.yahoo.com/maildemo
   ___
   Tutor maillist  -  Tutor@python.org
   http://mail.python.org/mailman/listinfo/tutor
  
 
 
  --
  'There is only one basic human right, and that is to
  do as you damn well please.
  And with it comes the only basic human duty, to take
  the consequences.
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
 
 
 __
 Do you Yahoo!?
 Take Yahoo! Mail with you! Get it on your mobile phone.
 http://mobile.yahoo.com/maildemo
 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] error message

2005-02-13 Thread Alan Gauld
 string = 'My phone is 410-995-1155'
 pattern = r'\d{3}-\d{3}-\d{4}'
 re.match(pattern,string).group()

 AttributeError: 'NoneType' object has no attribute 'group'

When match doesn't find anything it returns None, which has no 
group() method.

Why does it not find the regex?
Because you used match() which looks for a match starting 
at the beginning of the line. You need to use search() 
instead...

I discuss this in my tutorial topic on regex...

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] error message

2005-02-13 Thread Jacob S.
Dive into Python, an excellent tutorial has a case study on this very same 
topic.

The biggest problem that nobody has mentioned yet is the fact that group() 
will not have anything unless you explicitly tell it to group it.
I.E.

pattern = r'(\d{3})-(\d{3})-(\d{4})'
You need the parenthesis to capture the groups.
BTW, dive into python can be found here:
http://www.diveintopython.org/
HTH,
Jacob

I'm dping something very simple in RE.
Lets say I'm trying to match an American Phone number
I write the code this way and try to match it:
import re
string = 'My phone is 410-995-1155'
pattern = r'\d{3}-\d{3}-\d{4}'
re.match(pattern,string).group()
but I get this error message
Traceback (most recent call last):
 File C:/Python24/findphone, line 4, in -toplevel-
   re.match(pattern,string).group()
AttributeError: 'NoneType' object has no attribute 'group'

__
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo
___
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] error message

2005-02-13 Thread Liam Clarke
I was wondering about that also, I've only ever used .group() when
I've got named groups using (?Pfoo)

On Sun, 13 Feb 2005 21:04:22 -0500, Jacob S. [EMAIL PROTECTED] wrote:
 Dive into Python, an excellent tutorial has a case study on this very same
 topic.
 
 The biggest problem that nobody has mentioned yet is the fact that group()
 will not have anything unless you explicitly tell it to group it.
 I.E.
 
 pattern = r'(\d{3})-(\d{3})-(\d{4})'
 
 You need the parenthesis to capture the groups.
 
 BTW, dive into python can be found here:
 http://www.diveintopython.org/
 
 HTH,
 Jacob
 
 
  I'm dping something very simple in RE.
 
  Lets say I'm trying to match an American Phone number
 
  I write the code this way and try to match it:
  import re
  string = 'My phone is 410-995-1155'
  pattern = r'\d{3}-\d{3}-\d{4}'
  re.match(pattern,string).group()
 
  but I get this error message
  Traceback (most recent call last):
   File C:/Python24/findphone, line 4, in -toplevel-
 re.match(pattern,string).group()
  AttributeError: 'NoneType' object has no attribute 'group'
 
 
 
  __
  Do you Yahoo!?
  Take Yahoo! Mail with you! Get it on your mobile phone.
  http://mobile.yahoo.com/maildemo
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
 
 
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] error message

2005-02-13 Thread Kent Johnson
Jacob S. wrote:
Dive into Python, an excellent tutorial has a case study on this very 
same topic.

The biggest problem that nobody has mentioned yet is the fact that 
group() will not have anything unless you explicitly tell it to group it.
group() defaults to returning group 0 which is the whole match.
  import re
  string = 'My phone is 410-995-1155'
  pattern = r'\d{3}-\d{3}-\d{4}'
  re.search(pattern,string).group()
'410-995-1155'
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] error message

2005-02-13 Thread Jacob S.
Okay...
Cool.
Jacob

group() defaults to returning group 0 which is the whole match.
  import re
  string = 'My phone is 410-995-1155'
  pattern = r'\d{3}-\d{3}-\d{4}'
  re.search(pattern,string).group()
'410-995-1155'
Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

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