Thank you both for the quick replies! So I understand now dir is just used to 
assist in finding relevant strings. wapcaseAndCenter('hello', 10) I don't 
understand how from your example you get an output from 
: SwapcaseAndCenter('hello', 10) I get the below error:

Traceback (most recent call last):
  File "<pyshell#24>", line 1, in <module>
    SwapcaseAndCenter('hello', 10)
NameError: name 'SwapcaseAndCenter' is not defined

So i started thinking the string used is "swapcase" and "center" although I 
still get an error with that input:

>>> swapcase.center('hello',10)

Traceback (most recent call last):
  File "<pyshell#28>", line 1, in <module>
    swapcase.center('hello',10)
TypeError: an integer is required









________________________________
From: Wayne Werner <waynejwer...@gmail.com>
To: Alex Smith <alexsmith24...@yahoo.com>
Cc: "tutor@python.org" <tutor@python.org>
Sent: Thursday, 12 May 2011, 5:05
Subject: Re: [Tutor] Just Joined!


On Thu, May 12, 2011 at 6:34 AM, Alex Smith <alexsmith24...@yahoo.com> wrote:

Hi All, 
 
I just joined this list and am really new to python. 

Hi! Welcome to the Python tutor list, and Python!
 
I have an assignment to create a function with (a_string, width) which returns 
the a_string with all the lower case characters changed to upper case 
characters and vice versa and centered; was wondering if someone could point me 
in the right direction. I am not just asking for the answer but just need a few 
tips to get started.

That's good, because that's our policy here ;)
 
So far I do know I should use the dir(str)

I think you might be a little confused as to what dir actually does, or maybe 
what your assignment is really asking! 
 
and do not quite understand what the "width" option is used for....

Since you said the text is supposed to be centered, I suspect it means the 
final width of the string...
 
>>> help(dir)
><snip> 
   Return an alphabetized list of names comprising (some of) the attributes
>    of the given object, and of attributes reachable from it:<snip>

So dir gives you the attributes of an object. In this case since you're playing 
with a string you want to take a look at string objects. What happens when you 
run dir(str)? What happens when you run dir('this is a string')?
 

>
>def SwapcaseAndCenter(dir,??)

The best way to understand what an assignment is asking is usually to have an 
example - and if you don't have an example, make one up!

So I suspect your teacher might want something like this: (I'm replacing spaces 
with 'x' so you can see them. It's a good thing to do while you're testing)

>>> SwapcaseAndCenter('a', 3)
'xAx'
>>> SwapcaseAndCenter('hello', 10)
'xxHELLOxxx'
>>> SwapcaseAndCenter('WeIrD', 12)
'xxxwEiRdxxxx'

I suspect if you look carefully at the output of the `dir` commands that I 
mentioned above, you will find some help.

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

Reply via email to