The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
files over the web
Discuss files over the web in the Python Programming forum on Dev Shed. files over the web Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 21st, 2004, 11:38 AM
|
|
Contributing User
|
|
Join Date: Oct 2003
Location: Canada
Posts: 185
Time spent in forums: 20 h 44 m 50 sec
Reputation Power: 0
|
|
|
files over the web
I have a python script that saves info to a .csv file. If two or more ppl are trying to access it the same time will the file lock and prevent one from opening and submitting to it or does it not matter beacuse of the client/server architecture of the webbrowser?
is there a way to circumvent this in python perhaps catching the exception?
do i HAVE TO use a relational database to circumvent this problem? Please say no.
__________________
"In theory, there is no difference between theory and practice.
But, in practice, there is."
|

April 22nd, 2004, 09:39 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
I can't really test this right now but in theory the file should be locked - two file streams can't write to the file at the same time, or if they do your file gets wiped.
Your earlier post might be relivant here too - http://forums.devshed.com/t140081/s.html
You could always try locking the file manually just to be sure.
Another way to do this would be to check if the file is accessable using os.access() although i havn't used this at all:
http://www.python.org/doc/2.3.3/lib/os-file-dir.html
You should also be able to use a try-except block to check if a file is writeable or not.
All options to consider, hope this helps.
Mark.
__________________
programming language development: www.netytan.com – Hula
|

April 22nd, 2004, 10:21 PM
|
|
Contributing User
|
|
Join Date: Oct 2003
Location: Canada
Posts: 185
Time spent in forums: 20 h 44 m 50 sec
Reputation Power: 0
|
|
|
Thanks for the reply. Sorry about the double post. I didn't receive an email telling me anyone had responded. I think i might just have to use a rdms. Thanks.
|

April 23rd, 2004, 01:31 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
Thats ok, not a problem at all. You might want to look at Py SQLite for small projects where you really dont need to use MySQL although MySQL is ideal for web applications IMO.
Even if the current DBI is a little long winded for my tastes; again just an oppinion  .
Mark.
|

April 23rd, 2004, 10:02 AM
|
|
Contributing User
|
|
Join Date: Oct 2003
Location: Canada
Posts: 185
Time spent in forums: 20 h 44 m 50 sec
Reputation Power: 0
|
|
|
actaully was thinking about using sqlite. i had just read up on it and it said there was some things that still were not implemented. i'll check it out again. by the way sql lite can hold up to 2 terabytes of info. That is pretty significant. unless other databases hold more. never used a db before.
|

April 23rd, 2004, 04:16 PM
|
|
Contributing User
|
|
Join Date: Oct 2003
Location: Canada
Posts: 185
Time spent in forums: 20 h 44 m 50 sec
Reputation Power: 0
|
|
|
okay, i had the txt file opened and then i went online and wrote in the form to see if i would get an error when i submitted to the same file. however the infomation was submitted to the file still. does that mean that the file isn't locked and two or more ppl can submit at the same time. I'm really not expecting a lot of traffic on the site. or did i test it wrong.?
|

April 23rd, 2004, 06:02 PM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
Just because you open a file to read or write does not mean you have a lock on it. There are OS specific ways to get a file lock at the system level.
Doing a search for python file lock threw up this:
http://aspn.activestate.com/ASPN/Co...on/Recipe/65203
From what you say - it's not going to be a problem in practice. Just write the logging code in some function. That way if you ever have to upgrade your logging you just change the core of the function.
Grim 
|

April 24th, 2004, 11:12 AM
|
|
Contributing User
|
|
Join Date: Oct 2003
Location: Canada
Posts: 185
Time spent in forums: 20 h 44 m 50 sec
Reputation Power: 0
|
|
|
for now i just want multiple users to write to the files so i'll just save it as .txt and have it comma delimited then i look at it, i'll save it as a csv file. that'll be easier for me - for now. later i'll look into implementing a database. Still weird how a csv file will lock and a text file won't.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|