problem while going through a tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Schuster

    #1

    problem while going through a tutorial

    I'm new to python, and almost new to programming in general. I'm at
    http://www.pasteur.fr/formation/info...thon/ch04.html in that
    tutorial, and my 'count' function (if it's called a function?) isn't
    working suddenly.
    >>x = "fljshfjh"
    >>x
    'fljshfjh'
    >>count(x, 'h')
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    NameError: name 'count' is not defined

    I'm not sure what changed, because it used to work. anyhow thanks a lot!

    chris
  • John Machin

    #2
    Re: problem while going through a tutorial


    Simon Schuster wrote:
    I'm new to python, and almost new to programming in general. I'm at
    http://www.pasteur.fr/formation/info...thon/ch04.html in that
    tutorial, and my 'count' function (if it's called a function?) isn't
    working suddenly.
    >
    >x = "fljshfjh"
    >x
    'fljshfjh'
    >count(x, 'h')
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    NameError: name 'count' is not defined
    >
    I'm not sure what changed, because it used to work. anyhow thanks a lot!
    >
    Probably because you omiitted the line

    from string import *

    However IMHO your use of a tutorial which:

    (1) introduces "from some_module import *" as though it is the normal
    way of doing things

    From chapter 1: """
    Some magical stuff, that will be explained later:
    >>from string import *
    """

    That's *bad* magic


    (2) is still using (outdated) functions in the string module instead of
    teaching string methods

    should be discontinued immediately.

    You may wish to have a look at some of the /other/ tutorials mentioned
    on this page:



    HTH,
    John

    Comment

    • Ralf Schönian

      #3
      Re: problem while going through a tutorial

      Simon Schuster schrieb:
      [..]
      >>>x = "fljshfjh"
      >>>x
      'fljshfjh'
      >>>count(x, 'h')
      Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      NameError: name 'count' is not defined
      >
      I'm not sure what changed, because it used to work. anyhow thanks a lot!
      You forgot to import the string module:
      from string import *

      Regards,
      Ralf Schoenian

      Comment

      Working...