Newby Python Programming Question

CM cmpython at gmail.com
Fri May 11 17:57:10 EDT 2012


On May 11, 11:25 am, Coyote <sageande... at gmail.com> wrote:
> Folks,
>
> I am migrating to Python after a 20+ year career writing IDL programs exclusively. I have a really simple question that I can't find the answer to in any of the books and tutorials I have been reading to get up to speed.
>
> I have two programs. The first is in a file I named file_utils.py:
>
>    def pwd():
>        import os
>        print os.getcwd()
>
> The second is in a file I named pwd.py:
>
>    import os
>    print os.getcwd()
>
> Here is my question. I am using the Spyder IDE to run these programs. If I type these commands, I get exactly what I want, the name of my current directory:
>
>    >>>from file_utils import pwd
>    >>>pwd()
>    C:\Users\coyote\pyscripts
>
> But, if I "run" the pwd.py script by selecting the "Run" option from the IDE menu, the directory is printed *twice* in the output window. Why is that?

I don't know Spyder IDE, but I don't think this should happen; could
there just be a simple mistake?  Because you first refer to the .py
file as 'file_utils.py' but then you refer to the file as
'pwd.py'...which is also the name of your function. Room for
confusion...so could you test this by saving only your one function
(below), give the .py a new name to avoid confusion (like test_pwd.py)
and then running *that* through Spyder IDE?

def pwd():
    import os
    print os.getcwd()




More information about the Python-list mailing list