943,901 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 670
  • Python RSS
Nov 16th, 2008
0

Pay system

Expand Post »
Its about the pay system of a shop.
The user enters a product ID,the interpreter gets the details from the file and appends it to a list and continues till the products are over.

If the user can't enter the ID he can add the product name directly which will get the details from the file and append to list again.

From the list the total price will be displayed and the product names which will be in the file.

There must also be a fucntion to delete a product from the list and make new sum accordingly.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Feenix45 is offline Offline
14 posts
since Sep 2008
Nov 16th, 2008
0

Re: Pay system

python Syntax (Toggle Plain Text)
  1. def ID_search(prod_id):
  2.  
  3. infile=open("tab.txt","r")
  4.  
  5. line=infile.readline()
  6.  
  7. while line!="":
  8. x=string.split((line),",")
  9. if prod_id==float(x[0]):
  10. print "Product is", x[1]
  11. line=infile.readline()
  12.  
  13. infile.close()
This is the function i've used for search the ID from the file and display result..Please need help from here on.

Editor's note:
Please use code tags with your code to preserve the indentations. Otherwise the code is very difficult to read and not too many folks will help.

[code=python]
your Python code here
[/code]
Last edited by vegaseat; Nov 17th, 2008 at 6:29 pm. Reason: added code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Feenix45 is offline Offline
14 posts
since Sep 2008
Nov 16th, 2008
0

Re: Pay system

Dear Feenix45,
The best way is to enclose the code in bracket to maintain the
Indentation which is vita important. Just wrap your code tags


Is this what you originally wrote??
Is your application GUI or Console?

python Syntax (Toggle Plain Text)
  1. def ID_search(prod_id):
  2. infile=open("tab.txt","r")
  3. line=infile.readline()
  4. while line!="":
  5. x=string.split((line),",")
  6. if prod_id==float(x[0]):
  7. print "Product is", x[1]
  8. line=infile.readline()
  9. infile.close()
Last edited by evstevemd; Nov 16th, 2008 at 3:33 pm.
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007
Nov 16th, 2008
0

Re: Pay system

Also, you open the file and read the entire file for each ID entered. This is time consuming (in computer time) and so you should consider reading the file once and placing the records in a dictionary, indexed on ID, and using the dictionary to look up the info as it is entered.
Reputation Points: 741
Solved Threads: 692
Nearly a Posting Maven
woooee is online now Online
2,306 posts
since Dec 2006
Nov 17th, 2008
0

Re: Pay system

hmm its GUI but about dictionary never did this can u help me with the indexes and dictionary plz.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Feenix45 is offline Offline
14 posts
since Sep 2008
Nov 18th, 2008
0

Re: Pay system

Click to Expand / Collapse  Quote originally posted by woooee ...
Also, you open the file and read the entire file for each ID entered. This is time consuming (in computer time) and so you should consider reading the file once and placing the records in a dictionary, indexed on ID, and using the dictionary to look up the info as it is entered.
Can u guide me with this please?

Or just tell me how to start please
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Feenix45 is offline Offline
14 posts
since Sep 2008
Nov 18th, 2008
0

Re: Pay system

Here's an example of reading the file into a dictionary:
python Syntax (Toggle Plain Text)
  1. def load_IDs():
  2. infile=open("tab.txt","r")
  3. lines=infile.readlines()
  4. infile.close()
  5. my_IDs = {}
  6. for line in lines:
  7. data=line.strip().split(",")
  8. my_IDs[ data[ 0 ] ] = data[ 1 ]
  9. return my_IDs
Reputation Points: 355
Solved Threads: 292
Veteran Poster
jlm699 is offline Offline
1,102 posts
since Jul 2008
Nov 18th, 2008
0

Re: Pay system

Click to Expand / Collapse  Quote originally posted by jlm699 ...
Here's an example of reading the file into a dictionary:
python Syntax (Toggle Plain Text)
  1. def load_IDs():
  2. infile=open("tab.txt","r")
  3. lines=infile.readlines()
  4. infile.close()
  5. my_IDs = {}
  6. for line in lines:
  7. data=line.strip().split(",")
  8. my_IDs[ data[ 0 ] ] = data[ 1 ]
  9. return my_IDs
Thanx but this means i copy the file on a list.

Can i work directly from the file?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Feenix45 is offline Offline
14 posts
since Sep 2008
Nov 18th, 2008
0

Re: Pay system

You're reading the contents of the file into a dictionary, not a list.

What do you mean work directly from the file?
Reputation Points: 355
Solved Threads: 292
Veteran Poster
jlm699 is offline Offline
1,102 posts
since Jul 2008
Nov 18th, 2008
0

Re: Pay system

Click to Expand / Collapse  Quote originally posted by jlm699 ...
You're reading the contents of the file into a dictionary, not a list.

What do you mean work directly from the file?
No i dont know how to work with dictionary.

all the data are stored on a text file which im using though its a bit more time consuming.

Is there a way that i can do product search?i.e i enter the product name and it displays the price.
The program must search the price in the file.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Feenix45 is offline Offline
14 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Why doesnt my calculator script work! <----newb alert
Next Thread in Python Forum Timeline: Approximation of Pi (Python)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC