Hello Newsgroup,
I have the following problem:
I want to write a python script, that writes text into files. The text is
being "collected" in a for-loop, the code looks like this:
for i in range(len(myLis t)):
id = myList[i]
print "some text"
container.write ToFile(id, printed)
Where writeToFile() creates a new file with the id 'id' and fills it with
'printed'. The problem is, that I have to delete the
content of 'printed' before entering the for-loop again. Else, I'll find
the content of the past for-loops in my file. (The file created in the
second loop would look like this:)
some text
some text
Is there a possibility to do clear the content of 'printed' in python?
Thanks alot!! 4 1760
Christian Otteneuer wrote: Is there a possibility to do clear the content of 'printed' in python?
What is 'printed'? A string, a list, a dictionary, a StringIO instance... -
as long as we do not know what it is we cannot say how/whether it can be
cleared. It is common practice in Python to just forget about an old object
and create a new one, though:
for path in aList:
printed = Printed()
printed.fillWit h("some text")
container.write ToFile(path, printed)
Or was the
print "some text"
statement for real and you are assigning to sys.stdout (generally a bad
idea)?
Please provide the complete source code or at least some more context.
Peter
What is "printed" (and why do you think that 'print "some text"' will
modify it)? What is "container" , that it has a "writeToFil e" method?
You must be using some non-standard module you didn't mention.
If I understand what you're asking for, I might write something like
for i, id in enumerate(myLis t):
f = open(id, "w")
print >>f, "some text"
(Enumerate is a new built-in function in Python 2.3. The "print >>"
syntax has been available since 2.1 or so)
Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBKKlLJd0 1MZaTXX0RAk0ZAJ 9gQP9UwHuYN1ibi jw15KlMoHN27wCf fKEF
ecjN48PxVLS15Jq +wDG7JHw=
=0t/p
-----END PGP SIGNATURE-----
Christian Otteneuer wrote: I have the following problem: I want to write a python script, that writes text into files. The text is being "collected" in a for-loop, the code looks like this:
for i in range(len(myLis t)): id = myList[i] print "some text" container.write ToFile(id, printed)
[...] Is there a possibility to do clear the content of 'printed' in python?
This question properly belongs in one of the Zope lists, since the
regular Python folks have no idea what you're talking about. Thank
goodness I spotted you, or wackiness would ensue ;-)
"printed" is a magic variable implemented by the Script machinery, and
is read-only. You need to drop print and use plain strings:
for i in range(len(myLis t)):
id = myList[i]
txt = "some text"
container.write ToFile(id, txt)
Cheers,
Evan @ 4-am
"Evan Simpson" wrote: "printed" is a magic variable implemented by the Script machinery, and is read-only. You need to drop print and use plain strings:
for i in range(len(myLis t)): id = myList[i] txt = "some text" container.write ToFile(id, txt)
Thanks! That's the way I'll do it... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: la_haine |
last post by:
Hi,
A website I work on has a print stylesheet to strip navigation and things out
of a page, and changes the fonts and various bits and pieces here and there.
What I'd also like is something small (a footer, perhaps) that says something
along the lines of 'you are viewing a printed version of , available
at '. I know I can do this by just adding the content and using display:
none for the screen CSS, but then it becomes visible in text...
|
by: feng |
last post by:
The Combobox1.item.clear doesn't seem to work for me
correctly. I have a Combox with a datasource bind to it.
When I try to clear the Combobox with the following code:
Combobox1.DataSource = Nothing
Combobox1.items.Clear
Even though the items in the dropdown list are gone now, I
still see one line showing in the combo:
System.Data.DataRowView.
|
by: jnm |
last post by:
How can I avoid the content of
<meta name="Microsoft Border" content="b, default">
is printed, when printing by means of
<link rel="stylesheet" href="../print.css" type="text/css" media="print" />
I expect it to be possible with som script in the print.css????
|
by: Raistlin Majere |
last post by:
I have Apache/MySQL/PHP on Windows XP.
I want my PHP files to behave in my computer like in web host.
I open a PHP file with FF and its content is printed!
|
by: laurakr |
last post by:
I am trying to use a clear to get my bottom nav bar below the quote box
on the right, but it isn't working. I would like the bottom edge of the
quote box to "stick" to the footer nav bar but copy to be able to flow
to the left of the quote box. For the bonus round I would like the
right edge of the box to align with the right edge of the footer Could
someone take a look at my code and help a newbie troubleshoot? my email
is lroeder at...
| |
by: Vincent |
last post by:
Dear all,
I have implemented a class to export the content of RichTextBox to
image in WYSISYG mode so that line breaks on the screen are the same as
exported.
C# Code:
public struct STRUCT_RECT
|
by: ffrugone |
last post by:
I am creating a blog and I have a problem which seems fairly common:
Within the content of the posts I sometimes have floated images. The
comments bar that follows each post will not clear the float unless I
use clear:both in the class for the comment bar. HOWEVER, when
clear:both is used for the comment bar, the first post on the blog
shows a huge, (enormous) vertical gap between the content and the
comment bar when viewed using...
|
by: Neo Geshel |
last post by:
Greetings.
BACKGROUND:
My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are
delivered as application/xhtml+xml for all non-MS web clients, and as
text/xml for all MS web clients (Internet Explorer).
My flash content was originally brought in via the “flash satay” method,
but I have since used some server-side magic do deliver one <objecttag
|
by: Jess |
last post by:
Hello,
I tried to clear a vector "v" using "v.clear()". If "v" contains
those objects that are non-built-in (e.g. string), then "clear()" can
indeed remove all contents. However, if "v" contains built-in types
(e.g. int), then "clear()" doesn't remove anything at all. Why does
"clear()" have this behaviour?
Also, when I copy one vector "v1" from another vector "v2", with "v1"
longer than "v2" (e.g. "v1" has 2 elements and "v2" has...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |