Hello World-ish

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ludvig.ericson@gmail.com

    #1

    Hello World-ish

    from os import *
    print "Working path: %s" % os.getcwd();

    Just wondering how you would do that .. in theory, if you get what I
    mean?
    I get
    NameError: name 'os' is not defined
    currently, which I don't know how to fix.. anyone?

  • Jorge Godoy

    #2
    Re: Hello World-ish

    "ludvig.ericson @gmail.com" <ludvig.ericson @gmail.com> writes:
    [color=blue]
    > from os import *
    > print "Working path: %s" % os.getcwd();
    >
    > Just wondering how you would do that .. in theory, if you get what I
    > mean?
    > I get
    > NameError: name 'os' is not defined
    > currently, which I don't know how to fix.. anyone?[/color]

    Either:

    import os

    or

    print "Working path: %s" % getcwd();



    Avoid "from <module> import *" always when you can (there are still modules
    designed to work with it). It pollutes namespace and might lead to
    undesirable clobbing of data structures (is it your 'getId' method or the
    module's that is being used? ;-)).



    Be seeing you,
    --
    Jorge Godoy <godoy@ieee.org >

    Comment

    • Jesse Lands

      #3
      Re: Hello World-ish

      On 26 Nov 2005 03:19:55 -0800
      "ludvig.ericson @gmail.com" <ludvig.ericson @gmail.com> wrote:
      [color=blue]
      > from os import *
      > print "Working path: %s" % os.getcwd();
      >
      > Just wondering how you would do that .. in theory, if you get what I
      > mean?
      > I get
      > NameError: name 'os' is not defined
      > currently, which I don't know how to fix.. anyone?
      >[/color]

      your using the getcwd from os. You need to change the 'from os import
      *' to import os


      i.e.

      import os
      print "Working path: %s" % os.getcwd()


      --
      JLands
      Slackware 9.1
      Registered Linux User #290053
      "If you were plowing a field, which would you rather use? Two strong
      oxen or 1024 chickens?"
      - Seymour Cray (1925-1996), father of supercomputing

      Comment

      Working...