Re: Newbie append() question

2006-05-19 Thread Brian Blazer
Thanks guys.  Your solutions worked.

I'm still not sure why it was grabbing the prompt string though.

Thanks again,

Brian
[EMAIL PROTECTED]

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


noob import question

2006-05-19 Thread Brian Blazer
OK, I have a very simple class here:

class Student:
 Defines the student class

 def __init__(self, lName, fName, mi):
 self.lName = lName
 self.fName = fName
 self.mi = mi

Then I have a small script that I am using as a test:

from Student import *

s1 = Student(Brian, Smith, N)

print s1.lName

This works as expected.  However, if I change the import statement to:
import Student

I get an error:
TypeError: 'module' object is not callable

I have tried to look up what is going on, but I have not found  
anything.  Would it be possible for someone to take a minute and give  
an explanation?

Thank you - your time is appreciated.

Brian
[EMAIL PROTECTED]




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


Re: noob import question

2006-05-19 Thread Brian Blazer
Thank you for your responses.  I had a feeling is had something to do  
with a namespace issue but I wasn't sure.

You are right, I do come from a Java background.  If it is poor form  
to name your class file the same as your class, can I ask what the  
standard is?

Thanks again,
Brian

On May 19, 2006, at 8:33 AM, Diez B. Roggisch wrote:

 I have tried to look up what is going on, but I have not found
 anything.  Would it be possible for someone to take a minute and give
 an explanation?

 The

 from module import *|nameslist

 syntax imports some or all names found in module into the current  
 modules
 namespace. Thus you can access your class.

 But if you do

 import module

 you only get module in your current namespace. So you need to access
 anything inside module by prefixing the expression. In your case,  
 it is

 Student.Student

 If you only write Student, that in fact is the MODULE Student, which
 explains the error message.

 Now while this sounds as if the from module import * syntax is  
 the way to
 go, you should refrain from that until you really know what you are  
 doing
 (and you currently _don't_ know), as this can introduce subtle and
 difficult to debug bugs. If you don't want to write long module- 
 names, you
 can alias them:

 import moduel-with-long-name as shortname


 And it seems as if you have some JAVA-background, putting one class  
 in one
 file called the same as the class. Don't do that, it's a stupid  
 restriction
 in JAVA and should be avoided in PYTHON.

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

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


Re: Complex evaluation bug

2006-05-18 Thread Brian Blazer
I am not exactly sure what is going on, but I get the error:

ValueError: complex() arg is a malformed string

I think that it might be because the value of 'j' is not defined.

But I am a newbie so I could very well be wrong.

Brian Blazer
[EMAIL PROTECTED]




On May 18, 2006, at 11:36 AM, of wrote:

 a = 1+3j
 complex(str(a))

 Why does this not work ? It should
 -- 
 http://mail.python.org/mailman/listinfo/python-list

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


Newbie append() question

2006-05-18 Thread Brian Blazer
I promise that this is not homework.  I am trying to self teach here  
and have run into an interesting problem.  I have created a method  
that asks for a class name and then is supposed to add it to classes 
[].  Here is a snippet:

def getCurrentClasses():
 classes = []
 print 'Please enter the class name. When finished enter D.'
 while (c != D):
 c = raw_input(Enter class name)
 if (c != D):
 classes.append(c)

I have been running this in the interactive interpreter and if I  
print the list I get the string Enter class name as the first entry  
in the list and what was supposed to be the first entry as the second  
element like this:

Enter class name: cs1
['Enter class name: cs1']

I guess that I assumed that c would be equal to the value entered by  
the user not the prompt string.  It actually looks like it is taking  
the whole thing as one string.  But then if I enter more classes I  
get this:

Enter class name: cs2
['Enter class name: cs1', 'cs2']

So with the second and successive inputs, it appends the entered string.

Hopefully someone could enlighten me as to what is going on and maybe  
offer a suggestion to help me figure this one out.

Thank you for your time,

Brian
[EMAIL PROTECTED]




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


Re: playing with pyGoogle - strange codec error

2005-04-05 Thread Brian Blazer
On 2005-04-04 10:06:23 -0500, Brian Blazer [EMAIL PROTECTED] said:
snip
You know, I am beginning to think that I MAY have stumbled on a bug 
here.  At first I was thinking that this issue was related to the 
offending character being out of range for the Mac.  Then I tried it on 
A MS machine and a linux box; all with the same error.

This does not happen when I wrote the same script in java.  This is 
making me wonder if there is an issue with the wrapper for the google 
api that was originally done in java.

For the sake of it, here is the full code (minus my google key).  It is 
going to look wierd, but those print statements are there so that I 
dont have to open the file it is writing to every time I want to see 
stuff.  it has my name hard coded into the search query.  The commented 
r.snippet.encode(mac_roman) was there to see if by changing the 
encoding, I could make it work (no luck).  I also tried putting

#-*- coding: utf-8 -*-
right after the shebang (as listed here: 
http://www.python.org/peps/pep-0263.html).  Again, no help.

Anyway, here is the code 
import google
google.LICENSE_KEY = 'insertKeyHere'
#print google.doSpellingSuggestion('helllo')
data = google.doGoogleSearch('Brian Blazer')
print 'Found %d results' % len(data.results)
searchData = open('searchData.txt','w')
for r in data.results:
#r.snippet.encode('mac_roman')
   searchData.write ('Title: ' + r.title + '\n' + '\n')
   searchData.write ('URL: ' + r.URL + '\n' + '\n')
   searchData.write ('Snippet: ' + r.snippet + '\n' + '\n'+'\n')
   print r.URL
   print r.title
   print r.snippet

--
Nail a post to the Spalted Board. Free WW'ing software and forums.  
Regular freebies! http://www.spaltedboard.com

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


Re: playing with pyGoogle - strange codec error

2005-04-05 Thread Brian Blazer
On 2005-04-05 13:55:48 -0500, Erik Max Francis [EMAIL PROTECTED] said:
snip
Thank you, that worked.
Brian
--
Nail a post to the Spalted Board. Free WW'ing software and forums.  
Regular freebies! http://www.spaltedboard.com

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


playing with pyGoogle - strange codec error

2005-04-04 Thread Brian Blazer
Hello,
I am playing around with pyGoogle and encountered an error that I have 
never seen, and I am unsure how to correct for it.  Here is a code 
snippet:

for r in data.results:
   print 'Title: ',r.title
   print 'URL: ',r.URL
   print 'Summary: ',r.snippet
   print
Everything works fine until I get to r.snippet.  Here is the error:
UnicodeEncodeError: 'ascii' codec can't encode character '\ua9' in 
position 119: ordinal not in range(128)

Any help is appreciated.
Thanks,
Brian
--
Nail a post to the Spalted Board. Free WW'ing software and forums.  
Regular freebies! http://www.spaltedboard.com

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