write whitespace/tab to a text file
Hi,
I would l like to write some data to a text file. I want to write the
data with whitespace or tabs in between so that I create tabular
columns like in a spreadsheet. How can I do this in python.
(btw, I'm new to python)
names = ['John','Steve','asimov','fred','jim']
## output I would like in txt file : John Steve
asimov fred jim
f=open('/User/home/Documents/programming/python/test.txt','w')
for x in range(len(names)):
f.write(tags[x])
f.close()
--
http://mail.python.org/mailman/listinfo/python-list
write whitespace/tab to a text file
Hi,
I would l like to write some data to a text file. I want to write the
data with whitespace or tabs in between so that I create tabular
columns like in a spreadsheet. How can I do this in python.
(btw, I'm new to python)
names = ['John','Steve','asimov','fred','jim']
## output I would like in txt file : John Steve
asimov fred jim
f=open('/User/home/Documents/programming/python/test.txt','w')
for x in range(len(names)):
f.write(tags[x])
f.close()
--
http://mail.python.org/mailman/listinfo/python-list
write whitespace/tab to a text file
Hi,
I would l like to write some data to a text file. I want to write the
data with whitespace or tabs in between so that I create tabular
columns like in a spreadsheet. How can I do this in python.
(btw, I'm new to python)
names = ['John','Steve','asimov','fred','jim']
## output I would like in txt file : John Steve
asimov fred jim
f=open('/User/home/Documents/programming/python/test.txt','w')
for x in range(len(names)):
f.write(tags[x])
f.close()
--
http://mail.python.org/mailman/listinfo/python-list
python 2.5 - f=open('a_file.txt','w') gives [Errno 2]
Hi,
I upgraded my system from tiger to leopard. With leopard came a new
version of python 2.5
Now I trying to run some python code that previously worked on tiger
(which included an older version of python).
This is the error I'm receiving :
Traceback (most recent call last):
File "test.py", line 18, in print_total
f=open('a_file.txt','w')
IOError: [Errno 2] No such file or directory: 'a_file.txt'
Is this a bug in python? This code worked on my old system
--
http://mail.python.org/mailman/listinfo/python-list
Re: python 2.5 - f=open('a_file.txt','w') gives [Errno 2]
On 3 dec, 14:54, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> dirkheld wrote:
> > Hi,
>
> > I upgraded my system from tiger to leopard. With leopard came a new
> > version of python 2.5
>
> > Now I trying to run some python code that previously worked on tiger
> > (which included an older version of python).
>
> > This is the error I'm receiving :
>
> > Traceback (most recent call last):
> > File "test.py", line 18, in print_total
> > f=open('a_file.txt','w')
> > IOError: [Errno 2] No such file or directory: 'a_file.txt'
>
> > Is this a bug in python? This code worked on my old system
>
> The obvious question is: do you have 'a_file.txt' on your new system? There
> are many happy python programmers on leopard, and this is one heck of a
> basic functionality - I really doubt it's broken in such obvious way (if
> any at all).
>
> Diez
I don't have a file called 'a_file.txt'
I want to create that file and write some data to it. (http://
docs.python.org/tut/node9.html#SECTION00920)
The strange thing is that it worked under tiger with an older vesion
of python without any problem
--
http://mail.python.org/mailman/listinfo/python-list
Re: python 2.5 - f=open('a_file.txt','w') gives [Errno 2]
> How exactly are you starting the Python interpreter? "No such file or > directory" on file creation can happen when you try to create a file > in a directory that has ceased to exist: Damn...now it's time to be ashamed. Because of my new installation of leopard I used another computername. So the path were I wanted to write to didn't exist any more. Previous : /users/dirkheld/programming/python/ Now : /users/dirk/programming/python/... Sorry for keeping you guys busy with such a mistake ;) -- http://mail.python.org/mailman/listinfo/python-list
XML expat error
Hi,
I have written a piece of code that reads all xml files in a directory
in onder to retrieve one element in each of these files. All files
have the same XML structure. After file 123 I receive the following
error :
xml.parsers.expat.ExpatError: not well-formed (invalid token): line
554, column 20
I guess that the element I try to read or the XML(which would be
strange since they have been created with the same code) can't ben
retrieved.
Is there a way to :
1. fix this problems so that I can retrieve it
2. is there a way that after such an error the invalid file is being
skipped and the program continues with reading the subsequent files;
Some sort of error handling?
Here is the code I use :
from xml.dom import minidom
import os
path = "/Documents/programming/data/xml/"
dirList = os.listdir(path)
url_file=open('/Documents/programming/data/xml/test.txt','w')
for file in dirList:
xmldoc = minidom.parse('/Documents/programming/data/xml/'+file)
xml_elem = xmldoc.getElementsByTagName('webpage')
web_elem = xml_elem[0]
url = web_elem.attributes['uri']
url_file.write(url.value + '\n')
url_file.close()
--
http://mail.python.org/mailman/listinfo/python-list
Re: XML expat error
On 27 feb, 17:18, "Richard Brodie" <[EMAIL PROTECTED]> wrote:
> "dirkheld" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> > xml.parsers.expat.ExpatError: not well-formed (invalid token): line
> > 554, column 20
>
> > I guess that the element I try to read or the XML(which would be
> > strange since they have been created with the same code) can't ben
> > retrieved.
>
> It's fairly easy to write non-robust XML generating code, and also
> quick to test if one file is always bad. Drop it into a text editor or
> Firefox, and take a quick look at line 554. Most likely some random
> control character has sneaked in; it only takes (for example) one NUL
> to make the document ill-formed.
Something strange here. The xml file causing the problem has only 361
lines. Isn't there a way to catch this error, ignore it and continu
with the rest of the other files?
This is the full error report :
Traceback (most recent call last):
File "xmltest.py", line 10, in
xmldoc = minidom.parse('/Documents/programming/data/xml/'+file)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/xml/dom/minidom.py", line 1913, in parse
return expatbuilder.parse(file)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/xml/dom/expatbuilder.py", line 924, in parse
result = builder.parseFile(fp)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/xml/dom/expatbuilder.py", line 207, in parseFile
parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line
554, column 20
--
http://mail.python.org/mailman/listinfo/python-list
rstrip error python2.4.3 not in 2.5.1?
Hi, I wrote some python code that retrieves urls from a txt file. In this code I use .rstrip() for removing the '\n' at the end of every url. While this code works on my mac (leopard) with python 2.5.1, this same code fails to work on an ubuntu server with python 2.4.3 I was wondering if there is a problem with .rstrip() in that python version? error : Traceback (most recent call last): File "delgraph.py", line 62, in ? url_metadata = d.get_url(site.rstrip()) -- http://mail.python.org/mailman/listinfo/python-list
Re: XML expat error
On 28 feb, 08:18, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Wed, 27 Feb 2008 14:02:25 -0800, dirkheld wrote: > > Something strange here. The xml file causing the problem has only 361 > > lines. Isn't there a way to catch this error, ignore it and continu > > with the rest of the other files? > > Yes of course: handle the exception instead of letting it propagate to the > top level and ending the program. > > Ciao, > Marc 'BlackJack' Rintsch Ehm, maybe a stupid question... how. I'm rather new to python and I never user error handling. -- http://mail.python.org/mailman/listinfo/python-list
Re: rstrip error python2.4.3 not in 2.5.1?
> > What is the actual error message [SyntaxError, NameError? etc] that you > clipped? Here it is : I tought that I didn't matter because the deliciousapi worked fine on my mac. Traceback (most recent call last): File "delgraph.py", line 62, in ? url_metadata = d.get_url(site.rstrip()) File "deliciousapi.py", line 269, in get_url document.bookmarks = self._extract_bookmarks_from_url_history(data) File "deliciousapi.py", line 297, in _extract_bookmarks_from_url_history timestamp = datetime.datetime.strptime(month_string, '%b ‘ %y') AttributeError: type object 'datetime.datetime' has no attribute 'strptime' -- http://mail.python.org/mailman/listinfo/python-list
