473,804 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

clear content of 'printed'

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!!
Jul 18 '05 #1
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

Jul 18 '05 #2
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-----

Jul 18 '05 #3
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

Jul 18 '05 #4
"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...
Jul 18 '05 #5

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

Similar topics

8
3944
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...
1
1891
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.
3
1914
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????
6
1500
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!
1
2044
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...
0
11162
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
3
5952
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...
8
5916
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
9
3762
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...
0
9571
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,...
0
10561
Oralloy
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...
0
10318
jinu1996
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...
0
10069
tracyyun
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...
0
9132
agi2029
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...
1
7608
isladogs
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...
0
5505
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...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
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 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.