I've noticed an oddity when running a program, using the csv module,
within IDLE. I'm new to Python so am confused by what is happening.
Here is what I'm doing:
1) Open the IDLE Shell.
2) Select File | Open...
3) Choose my file, foo.py, opening it in a window.
4) From that window, I hit F5 to run the module.
Within the program, the snippet where I use the csv module is below:
=============== ===============
csvfile = open('foo.csv', 'w')
writer = csv.writer(csvf ile)
for row in rows:
writer.writerow (row[0:3])
csvfile.close
=============== ===============
The rows object is returned from a database query and is a list of
tuples. Now here is the strange thing. If I run this program
directly from the command line, i.e.,
D:\testD:\pytho n25\python foo.py
It runs fine, foo.csv is created and all is well. However, when I run
it through the IDLE shell as described above, the foo.csv file is
created but remains empty at 0 bytes. When I try to delete the file,
Windows says it is in use. The only way I can break out of this is by
restarting the IDLE shell. In other words, it appears that the shell
is hanging.
This will run through Task Scheduler, so shouldn't be a problem, but
I'm worried that I'm coding this wrong for it to be acting this way
under IDLE. Any help or explanation would be appreciated.
Best Regards,
Tom 3 1512
On Fri, 28 Dec 2007 18:12:58 -0800, t_rectenwald wrote:
Within the program, the snippet where I use the csv module is below:
=============== ===============
csvfile = open('foo.csv', 'w')
writer = csv.writer(csvf ile)
for row in rows:
writer.writerow (row[0:3])
csvfile.close
=============== ===============
The rows object is returned from a database query and is a list of
tuples. Now here is the strange thing. If I run this program
directly from the command line, i.e.,
D:\testD:\pytho n25\python foo.py
It runs fine, foo.csv is created and all is well. However, when I run
it through the IDLE shell as described above, the foo.csv file is
created but remains empty at 0 bytes. When I try to delete the file,
Windows says it is in use. The only way I can break out of this is by
restarting the IDLE shell. In other words, it appears that the shell
is hanging.
This will run through Task Scheduler, so shouldn't be a problem, but
I'm worried that I'm coding this wrong for it to be acting this way
under IDLE. Any help or explanation would be appreciated.
You are not closing the file so the buffered data is not written to disk.
To call a function you need the parenthesis, otherwise you are just
referencing it without any effect.
Ciao,
Marc 'BlackJack' Rintsch
On Dec 29, 1:12 pm, t_rectenwald <t.rectenw...@g mail.comwrote:
I've noticed an oddity when running a program, using the csv module,
within IDLE. I'm new to Python so am confused by what is happening.
Here is what I'm doing:
1) Open the IDLE Shell.
2) Select File | Open...
3) Choose my file, foo.py, opening it in a window.
4) From that window, I hit F5 to run the module.
Within the program, the snippet where I use the csv module is below:
Forget snippet, show us a *whole* "program". Cut out the database
stuff; just use some simple made-up value for "rows".
=============== ===============
csvfile = open('foo.csv', 'w')
Always use 'wb' -- not the cause of the current problem but it will
bite you later.
writer = csv.writer(csvf ile)
for row in rows:
writer.writerow (row[0:3])
Adding
del writer
may help
csvfile.close
The above statement does nothing. You meant csvfile.close() , I
presume.
=============== ===============
The rows object is returned from a database query and is a list of
tuples. Now here is the strange thing. If I run this program
directly from the command line, i.e.,
D:\testD:\pytho n25\python foo.py
It runs fine, foo.csv is created and all is well. However, when I run
it through the IDLE shell as described above, the foo.csv file is
created but remains empty at 0 bytes. When I try to delete the file,
Windows says it is in use. The only way I can break out of this is by
restarting the IDLE shell. In other words, it appears that the shell
is hanging.
No it's not hanging, it's just that the file is still open; you
haven't closed it. It won't be closed until you exit IDLE.
>
This will run through Task Scheduler, so shouldn't be a problem, but
I'm worried that I'm coding this wrong for it to be acting this way
under IDLE. Any help or explanation would be appreciated.
Do these things inside a function, so that the objects get garbage-
collected on exit.
On Dec 28, 9:43*pm, John Machin <sjmac...@lexic on.netwrote:
On Dec 29, 1:12 pm, t_rectenwald <t.rectenw...@g mail.comwrote:
I've noticed an oddity when running a program, using the csv module,
within IDLE. *I'm new to Python so am confused by what is happening.
Here is what I'm doing:
1) Open the IDLE Shell.
2) Select File | Open...
3) Choose my file, foo.py, opening it in a window.
4) From that window, I hit F5 to run the module.
Within the program, the snippet where I use the csv module is below:
Forget snippet, show us a *whole* "program". Cut out the database
stuff; just use some simple made-up value for "rows".
=============== ===============
csvfile = open('foo.csv', 'w')
Always use 'wb' -- not the cause of the current problem but it will
bite you later.
writer = csv.writer(csvf ile)
for row in rows:
* * writer.writerow (row[0:3])
Adding
del writer
may help
csvfile.close
The above statement does nothing. You meant csvfile.close() , I
presume.
=============== ===============
The rows object is returned from a database query and is a list of
tuples. *Now here is the strange thing. *If I run this program
directly from the command line, i.e.,
D:\testD:\pytho n25\python foo.py
It runs fine, foo.csv is created and all is well. *However, when I run
it through the IDLE shell as described above, the foo.csv file is
created but remains empty at 0 bytes. *When I try to delete the file,
Windows says it is in use. *The only way I can break out of this is by
restarting the IDLE shell. *In other words, it appears that the shell
is hanging.
No it's not hanging, it's just that the file is still open; you
haven't closed it. It won't be closed until you exit IDLE.
This will run through Task Scheduler, so shouldn't be a problem, but
I'm worried that I'm coding this wrong for it to be acting this way
under IDLE. *Any help or explanation would be appreciated.
Do these things inside a function, so that the objects get garbage-
collected on exit.
Thanks for all of the help. I'm still learning Python so dorked up
here and didn't add the empty parenthesis around csvfile.close as I
should have. So, it never called the close() function, but just
referenced it as was noted in your responses. After doing that,
everything works fine and the file is closed properly. I do have this
in a function in the actual script I'm writing, just sort of made a
dummy, foo.py, to do some testing and didn't have it in a function
there.
I'll research "wb" now to figure out what that does. Thanks again for
the help!
Tom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marcus Schneider |
last post by:
I use PythonWin on WinXP. Every time I change a module, I have to
leave PythonWin and re enter to make it notice I have made changes. I
guess this is not the normal way to do that.. do I have to store the
module at a specific place? Is there a kind of "reset" command to make
the main module update specific data?
|
by: Anders Eriksson |
last post by:
Hello!
I'm using ActivePython 2.3.2 build 232 on Windows 2000 and I have noticed a
strange behavior in PythonWin IDE (win32all build 163)
I'm from Sweden and we have a couple of letters in our alphabet that isn't
part of ASCII and the strangeness is about one of them
When I use the letter å (å) then the next character is eaten!...
|
by: Bill Davy |
last post by:
I am working with MSVC6 on Windows XP.
I have created an MSVC project called SHIP
I have a file SHIP.i with "%module SHIP" as the first line (file is below).
I run SHIP.i through SWIG 1.3.24 to obtain SHIP_wrap.cpp and SHIP.py; the
latter contains the line "import _SHIP".
I compile SHIP_wrap.cpp and a bunch of files into a DLL which I...
|
by: Gopal |
last post by:
Hi,
I've a module report.py having a set of funtions to open/close/write
data to a log file. I invoke these functions from another module
script.py.
Whenever I'm changing something in report.py, I'm running the file
(however, it has not effect). After that I'm running script.py again.
However, the output is not taking effect.
|
by: Jeremy Moles |
last post by:
Hey guys. I have an extension module written in C that abstracts and
simplifies a lot of what we do here. I'm observing some strange behavior
and wanted to know if anyone had any advice as to how I should start
tracking this down. More specific suggestions are obviously appreciated,
but I really don't have a lot of information to provide so...
| |
by: robert |
last post by:
I get python crashes and (in better cases) strange Python exceptions when (in most cases) importing and using cookielib lazy on demand in a thread.
It is mainly with cookielib, but remember the problem also with other imports (e.g. urllib2 etc.).
And again very often in all these cases where I get weired Python exceptions, the problem is around...
|
by: rconradharris |
last post by:
A co-worker of mine came across some interesting behavior in the
Python interpreter today and I'm hoping someone more knowledgeable in
Python internals can explain this to me.
First, we create an instance of an Old-Style class without defining a
__contains__ but instead define a __getitem__ method in which we raise
KeyError. Next we...
|
by: darkyng |
last post by:
hi there,...my name s roberto,from italy...ehm....please...be patient for my english....however i have a question....im trying to know...why this strange thing appens....what?well look at this:
import ftplib
def main():
server = 'www.mysite.org'
user = 'mynick'
...
|
by: dg.google.groups |
last post by:
Hi all,
Is there any standard way to tell if the user is running from a module
or from an interactive shell like IDLE or IPython? The best I've come
up with so far is for a function to look at
getouterframes(currentframe()) (the filename in the frame record
of the frame that called the function), and check if it exists or not
with...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |