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

Best way to create temporary file?

Hi all

I need to generate potentially large reports from a database, and I
want to offer the option of print preview before actually printing
(using wxPython). I figure that the best way to achieve this is to
write the report to a temporary file, or more likely to a temporary
directory with a separate file for each page. I can use that for
previewing and for printing, and then delete the file/directory.

There seems to be a few ways to achieve this, and I am not sure of the
best way.

1. I can call tempfile.TemporaryFile() for each file required.

2. I can call tempfile.mkdtemp() to create a temporary directory, and
create each file manually.

3. I can call os.tmpfile() for each file required.

After creating the files, I need to re-read them, either one at a time
in sequence (if printing), or any one at random (if previewing a
particular page). This makes me lean towards method 2.

With this method, I create the files manually, so I can name them
according to their page numbers, which makes it easy to open and close
them as required. The other two methods return open file objects, so
it seems that I cannot close them, as there would be no means of
accessing their contents subsequently. Therefore I would have to
maintain a list of open file objects, use indexing to retrieve a
particular page, and then perform seek(0) before I could read it. A
slight downside of method 2 is that I have to delete the files and the
directory manually when I have finished.

I have two additional questions regarding method 3.

Firstly, I am not sure how it works. The docs say that the file has no
directory entries associated with it, and it will be automatically
deleted when there are no file descriptors for the file. What does
this mean? Does it create a physical file, or is it stored in memory?
If the latter, could I run into memory problems if I create a report
with hundreds of pages?

Secondly, I can create the file using FC3 (Python 2.4), but if I try
on Windows 2000 (Python 2.4) I get the message 'OSError: Permission
denied', even though I am a member of the Administrators group.

Any advice on the best approach for this will be much appreciated.

Frank Millman
Jul 19 '05 #1
4 6730

"Frank Millman" <fr***@chagford.com> ha scritto nel messaggio
news:24**************************@posting.google.c om...
Hi all

I need to generate potentially large reports from a database, and I
want to offer the option of print preview before actually printing
(using wxPython). I figure that the best way to achieve this is to
write the report to a temporary file, or more likely to a temporary
directory with a separate file for each page. I can use that for
previewing and for printing, and then delete the file/directory.

There seems to be a few ways to achieve this, and I am not sure of the
best way.

1. I can call tempfile.TemporaryFile() for each file required.

2. I can call tempfile.mkdtemp() to create a temporary directory, and
create each file manually.

3. I can call os.tmpfile() for each file required.

After creating the files, I need to re-read them, either one at a time
in sequence (if printing), or any one at random (if previewing a
particular page). This makes me lean towards method 2.

With this method, I create the files manually, so I can name them
according to their page numbers, which makes it easy to open and close
them as required. The other two methods return open file objects, so
it seems that I cannot close them, as there would be no means of
accessing their contents subsequently. Therefore I would have to
maintain a list of open file objects, use indexing to retrieve a
particular page, and then perform seek(0) before I could read it. A
slight downside of method 2 is that I have to delete the files and the
directory manually when I have finished.

I have two additional questions regarding method 3.

Firstly, I am not sure how it works. The docs say that the file has no
directory entries associated with it, and it will be automatically
deleted when there are no file descriptors for the file. What does
this mean? Does it create a physical file, or is it stored in memory?
If the latter, could I run into memory problems if I create a report
with hundreds of pages?

Secondly, I can create the file using FC3 (Python 2.4), but if I try
on Windows 2000 (Python 2.4) I get the message 'OSError: Permission
denied', even though I am a member of the Administrators group.

Any advice on the best approach for this will be much appreciated.

Frank Millman

Why create an intermediate file to preview with wxPython? I would just
preview the data with wx and keep it inside your application. If you want to
print it just print... avoid temp file creation if it's not necessary... :)

F.P.
Jul 19 '05 #2
Frank Millman wrote:
Hi all

I need to generate potentially large reports from a database, and I
want to offer the option of print preview before actually printing
(using wxPython). I figure that the best way to achieve this is to
write the report to a temporary file, or more likely to a temporary
directory with a separate file for each page. I can use that for
previewing and for printing, and then delete the file/directory.

Fabio Pliger wrote: Why create an intermediate file to preview with wxPython? I would just
preview the data with wx and keep it inside your application. If you want to
print it just print... avoid temp file creation if it's not necessary... :)

F.P.


It depends on what you mean, Fabio.

If a report contains sub-totals, page breaks, etc, it is not possible
to preview a particular page at random without generating the entire
report first.

It is certainly possible to store the entire report in memory, using a
two-dimensional list (page/line), but if a report runs into hundreds of
pages, I am concerned at the amount of memory this would require.
Perhaps I am being old-fashioned - with todays memory of at least 64k,
it would probably fit without a problem - but I would prefer to write
the pages away and read them back when needed.

Frank
Jul 19 '05 #3
Frank Millman wrote:
It is certainly possible to store the entire report in memory, using a
two-dimensional list (page/line), but if a report runs into hundreds of
pages, I am concerned at the amount of memory this would require.
Perhaps I am being old-fashioned - with todays memory of at least 64k,
it would probably fit without a problem - but I would prefer to write
the pages away and read them back when needed.


Modern operating systems have a technique for dealing with this. It is
called virtual memory. You are only using up more memory, CPU, and disk
speed by using temporary files unnecessarily.
--
Michael Hoffman
Jul 19 '05 #4
Ok, thanks for the advice.

Frank

Jul 19 '05 #5

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

Similar topics

3
by: James Proctor | last post by:
Hi there, im brand new to ASP. Ive done loads of VB coding and one of my clients is intrested in a web based application, so im trying to play on and learn it a tad. However im comming across lots...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
0
by: Bryan Ax | last post by:
Quick question regarding best practices for using the AspState database for storing session variables in .NET web applications. I know I need to configure the web.config file with a database user...
4
by: Asaf | last post by:
Hi, Is there a way to create a temporary download link and to know when the client has finished downloading the file? Thanks in advanced,
1
by: James Proctor | last post by:
Hi there, im brand new to ASP. Ive done loads of VB coding and one of my clients is intrested in a web based application, so im trying to play on and learn it a tad. However im comming across lots...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
13
by: Daniel Walzenbach | last post by:
Hi, Imagine the following situation: I have an asp.net application which allows uploading files to a SQL Server 2000 database (Files are stored as type "images"). As a next step I would like to...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
4
by: lwoods | last post by:
I need to create a temporary file on a server. How do I do it? I tried using IO.Path but it created a local file; i.e., file://C:...... TIA, lwoods
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.