473,387 Members | 1,650 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,387 software developers and data experts.

File management

I am writing a program in which i open up a file and read the contents
then do some calculations and update the information but in a new
file. So my question is how do i go about declaring the new file so
that the program will know that the new information goes into the new
file and not the original? if it helps here is the code that i have
so far:
def startUp():
# Purpose: opens files and print report headings
global empName, previousYTD, payRate, hoursWorked, recordCount,
eof, payFile, \
payFileUpdated, newYTD, currentPay
payFile=open("payroll.txt", "r")
payFile.readline()
def readRecord():
# Purpose: reads a record
global empName, previousYTD, payRate, hoursWorked, recordCount,
eof, payFile, \
payFileUpdated, newYTD, currentPay

employeeRec = payFile.readline()
if employeeRec == "":
eof = True
else:
# parse file line for record fields and format/convert for
final output
empName = employeeRec[0:25].strip()
previousYTD = float(employeeRec[25:40])
payRate = float(employeeRec[40:55])
hoursWorked = float(employeeRec[55:70])
recordCount += 1
eof = False

def writeRecord():
# Purpose: writes the updated record to the output file
#Parameter
global empName, previousYTD, payRate, hoursWorked, recordCount,
eof, payFile, \
payFileUpdated, newYTD, currentPay

def processRecords():
# Purpose: loops through input file and processes each record
global empName, previousYTD, payRate, hoursWorked, recordCount,
eof, payFile, \
payFileUpdated, newYTD, currentPay

while not eof:
calculatePay()
printReportLine()
writeRecord()
readRecord()

def calculatePay():
# Purpose: calculates pay and updated YTD
# Return values: float - calculated pay, float - updated YTD amount
global empName, previousYTD, payRate, hoursWorked, recordCount,
eof, payFile, \
payFileUpdated, newYTD, currentPay

def printReportLine():
# Purpose: prints employee pay information
# Parameters passed: float - calculated pay, float - updated YTD
amount
global empName, previousYTD, payRate, hoursWorked, recordCount,
eof, payFile, \
payFileUpdated, newYTD, currentPay

def closeUp():
# Purpose: end of program housekeeping
global empName, previousYTD, payRate, hoursWorked, recordCount,
eof, payFile, \
payFileUpdated, newYTD, currentPay

payFile.close()
payFileUpdated.close()
print "\nNumber of records in the file was",recordCount

any and all help is appreciated.

Oct 15 '08 #1
1 1278
erict1689 schrieb:
def closeUp():
# Purpose: end of program housekeeping
global empName, previousYTD, payRate, hoursWorked, recordCount,
eof, payFile, \
payFileUpdated, newYTD, currentPay

payFile.close()
payFileUpdated.close()
print "\nNumber of records in the file was",recordCount

any and all help is appreciated.
don't use global, here ist no need for.

if you need a output file so open one and use it.
def writeFile(fileName, content):
hd = open(fileName, 'wb');
hd.write(content)
hd.close

Oct 16 '08 #2

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

Similar topics

2
by: Tom | last post by:
OK I'm trying to go to the end of a file and delete the contents upwards until I meet a certain character. How can I do this? (NOTE: I'm using text files)
6
by: Codemonkey | last post by:
Hi, I have a few questions about best practices when it comes to the management of temporary files. Any thoughts anyone can give would be much appreciated. Basically, I'm writing a document...
4
by: TempEcho | last post by:
Is there any place where I can find some library / commands to use for file management (e.g. renaming files , copying , deleting?). Thanks in advance! T.E.
4
by: Daven Thrice | last post by:
I have a project I'm working on that is in part a file manager. I would like to be able to drag either a file, a shortcut, or an Internet shortcut over any kind of control in Access, and read the...
8
by: Ritesh | last post by:
Hi!!!!!!!!!!! I am a final year engineering student. I am making a final year project on reed-solomon codec in C using VC++ 6.0. The input to the program can be any file that the user wants to...
0
by: Carlos | last post by:
Does anyone know a good "file management" ASP.NET program out there, so I can get it and learn how to do it ? Thanks
1
by: s | last post by:
I need to coordinate file management between three computers. Users need to enter all file names and would like to store file names,date changed,person changed etc. into a database. User...
5
by: yazwas | last post by:
Hi, I'm looking for a file management library in C++, i.e library that has createfile, readfile, movefile, ...etc I need it for linux espically, it no general one is available does anyone have...
1
by: systemonkey | last post by:
I have a lot of huge files on a server and I can't risk getting deleted by anyone. What I have been doing is I create a ftp account for users and create a hardlinks to the original file in case...
0
by: lgwapnitsky | last post by:
I am writing an Outlook add-in that needs to fire when a PST is added/removed. I have successfully fired the event using the AddStore and RemoveStore functions, as well as when I use the "Open ->...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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...

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.