473,513 Members | 3,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Dec 12 '06 #1
2 911

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:

http://wiki.python.org/moin/Beginner...NonProgrammers

HTH,
John

Dec 12 '06 #2
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
Dec 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4772
by: millertimebjm | last post by:
I have a login that uses header information to authenticate users. header('WWW-Authenticate: Basic realm="my site", FALSE'); These values go into the php_auth_user and PHP_AUTH_PW in $_SERVER work just fine. But when I try to unset($_SERVER) or PW and go to a different page they are just reset to the way they were before. If you need...
4
6747
by: lebo | last post by:
So I'm new to this python stuff - and this has me stumped # server import SocketServer PORT = 8037 class myRequestHandler(SocketServer.StreamRequestHandler): def handle(self): self.input = self.rfile.read(1024)
6
3718
by: Fao | last post by:
Hi, I am in my first year of C++ in college and my professor wants me to Write a Program with multiple functions,to input two sets of user-defined data types: One type named 'Sign' declared by "typedef" to contain only either +10 or -10 and the other type named Color declared by "enum" to contain only black, blue, purple, red, white, and...
16
2424
by: Harry Putnam | last post by:
I keep stumbling around with varius alignment tags, even using STYLE tag with absolute positioning but not getting a simple job done. I have an arrangment like this: ____________________________________________ | | | Large headline that is really an image | | of Elaborate text created in...
25
7719
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30 minutes with Python 3 times a week since, have 14 years of computing experience, 8 years in mathematical computing and 4 years in unix admin and perl, i...
1
4732
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem I have run into I am not sure how to fix, and really not sure what is causing it. Here's what is going on (test server - Windows 2003 Server): I...
11
2744
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. This works great and opens all images in the database when I open the url mywebsite/gallery.php, or I can choose certain images (by category) by...
2
6532
by: David | last post by:
Sent this to alt.php a couple of days back, but doesn't look like I'll get an answer, so trying here. I'm trying to convert a script to use friendly URLs, I've done this before, but my PHP skills are quite basic so far, far from proficient at this. ..htaccess file- DirectoryIndex default.php index.asp index.html index.htm index.php
19
3647
by: Jim | last post by:
Hi, I have two questions/problems pertaining to CSS horizontal dropdown menus and am hoping that someone here can help me out. (1) I'm having a problem centering the menu. I picked up the code for this from a tutorial but that menu was flush-left justified. Not what I want. Subsequent searches on google on how to center yielded a
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7125
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5703
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3252
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3239
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.