Critic my module

Dave Angel davea at davea.name
Sat Jul 27 15:35:50 CEST 2013


On 07/27/2013 09:19 AM, Devyn Collier Johnson wrote:
>

     <SNIP>

> About the aliases, I have tried setting pwd() as an alias for
> "os.getcwd()", but I cannot type "pwd()" and get the desired output.
> Instead, I must type "pwd". I tested this in Guake running Python3.3.
>
>  >>> os.getcwd()
> '/home/collier'
>  >>> pwd = os.getcwd()
>  >>> pwd()
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: 'str' object is not callable
>  >>> pwd
> '/home/collier'
>  >>> pwd() = os.getcwd()
>    File "<stdin>", line 1
> SyntaxError: can't assign to function call
>
>
> How could I make pwd() work?

Don't call getcwd() when making the alias.  You want it to be called 
when USING the alias.

pwd = os.getcwd    #creates the alias

pwd()     #runs the alias



-- 
DaveA




More information about the Python-list mailing list