473,394 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

2 line Function doesn't work

30
I am trying to go through words in a list of words and take out all the '.'s. I made the function ...

Expand|Select|Wrap|Line Numbers
  1. def clearup(tor): 
  2.  
  3.    tor = tor.replace('.', '')
Expand|Select|Wrap|Line Numbers
  1. words = fcheck.read().split()
  2.  
  3.  for word in words:
  4.       clearup(word)
  5.       if word in dictionary: # dictionary is a tuple of words
  6.          pass
  7.       else:
  8.          print word
why doesn't this work? it prints the words but the periods have not been replaced.
Nov 1 '08 #1
2 1238
Smygis
126 100+
What happens is that you got a function that modify a copy of a string and then don't do anything with it.

This is one way of how you can do it instead.
Expand|Select|Wrap|Line Numbers
  1. def clearup(tor): 
  2.    return tor.replace('.', '')
  3.  
  4. words = fcheck.read().split()
  5.  
  6.  for word in words:
  7.       word = clearup(word)
  8.       if word in dictionary: # dictionary is a tuple of words
  9.          pass
  10.       else:
  11.          print word
But wont it be simpler to just put is as:
Expand|Select|Wrap|Line Numbers
  1. word.replace('.', '')
  2.  
Nov 1 '08 #2
Bouzy
30
Thanks, with your help and some other things I did I got it fixed, but the reason I didn't use your second example is because I was going to reuse the function because it's replacing not just ','s but every punctuation mark in the English language.

Problem solved.
Nov 2 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Steve M | last post by:
I'm trying to invoke a Java command-line program from my Python program on Windows XP. I cannot get the paths in one of the arguments to work right. The instructions for the program describe the...
1
by: Koen | last post by:
Hi all, I created a little database to manage my e-books. The program will synchronize a table with the contents of a directory. Works great. Because I keep additional info (like keywords) to...
40
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
23
by: FrancisC | last post by:
#include <stdio.h> int file_copy( char *oldname, char *newname ); int main() { char source, destination; printf("\nEnter source file: ");
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
11
by: Ken Varn | last post by:
I want to be able to determine my current line, file, and function in my C# application. I know that C++ has the __LINE__, __FUNCTION__, and __FILE___ macros for getting this, but I cannot find a...
6
by: Raul Rodriguez | last post by:
I posted this question already but nobody could answer me. Please forgive for doing it again, but it's very important for my company. We have been searching for this error with different engines...
1
by: Hari Sekhon | last post by:
Hi, I'm wondering if anyone can please help me on figuring out a better way of doing an excepthook. I have a script which is using an excepthook to catch any uncaught exceptions - there usually...
7
by: Jwe | last post by:
Hi, I've written a program which has both a command line interface and Windows form interface, however it isn't quite working correctly. When run from command line with no arguments it should...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.