Re: A limit to writing to a file from a loop?

2019-02-13 Thread Peter Otten
Steve wrote: > My program reads from a text file (A), modifies the data, and writes to > another file (B). This works until I reach about 300 writes and no more > lines are written to file (B). > > I had to create a Counter and increment it to 250 when it gets reset. > > Upon reset, I close the

RE: A limit to writing to a file from a loop?

2019-02-12 Thread Steve
ytes) instead of the incoming data, 250+ times? Footnote: Ultrasound Technician Asks Pregnant Woman If She’d Like to Know Baby’s Name... -Original Message- From: DL Neil Sent: Tuesday, February 12, 2019 2:13 PM To: Steve ; python-list@python.org Subject: Re: A limit to writing to a file from a loo

Re: A limit to writing to a file from a loop?

2019-02-12 Thread DL Neil
Steve, On 13/02/19 7:56 AM, Steve wrote: My program reads from a text file (A), modifies the data, and writes to another file (B). This works until I reach about 300 writes and no more lines are written to file (B). I had to create a Counter and increment it to 250 when it gets reset. Upon res

Re: A limit to writing to a file from a loop?

2019-02-12 Thread Chris Angelico
On Wed, Feb 13, 2019 at 5:58 AM Steve wrote: > > My program reads from a text file (A), modifies the data, and writes to > another file (B). > This works until I reach about 300 writes and no more lines are written to > file (B). > > I had to create a Counter and increment it to 250 when it gets

A limit to writing to a file from a loop?

2019-02-12 Thread Steve
My program reads from a text file (A), modifies the data, and writes to another file (B). This works until I reach about 300 writes and no more lines are written to file (B). I had to create a Counter and increment it to 250 when it gets reset. Upon reset, I close the file (B) being written a

Re: python3: why writing to socket require bytes type while writing to a file require str ?

2016-07-22 Thread Steven D'Aprano
a socket requires argument > to be of type 'bytes' Correct. Sockets are low-level endpoint for transmitting bytes between processes. > (otherwise python throw 'str does not support > buffer interface...' exception), while writing to a file requires >

Re: python3: why writing to socket require bytes type while writing to a file require str ?

2016-07-22 Thread Frank Millman
"Yubin Ruan" wrote in message news:47f3acf9-8da2-4aad-a6f0-7a9efbdfe...@googlegroups.com... In my understanding, writing to a file would requires that everything be written byte by byte. So writing objects of type 'bytes' to socket makes sense. But, how could python

Re: python3: why writing to socket require bytes type while writing to a file require str ?

2016-07-22 Thread Chris Angelico
On Fri, Jul 22, 2016 at 6:52 PM, Yubin Ruan wrote: > In my understanding, writing to a file would requires that everything be > written byte by byte. So writing objects of type 'bytes' to socket makes > sense. But, how could python write to file using unicode(type &#x

python3: why writing to socket require bytes type while writing to a file require str ?

2016-07-22 Thread Yubin Ruan
se python throw 'str does not support buffer interface...' exception), while writing to a file requires argument to be of type 'str'. Why is that? In standard UNIX interface, everything is file, which mean that writing to a socket is the same as writing to a normal file. Th

Re: Python : writing to a file

2015-01-11 Thread Peter Otten
Ganesh Pal wrote: > On Sun, Jan 11, 2015 at 2:17 PM, Dave Angel wrote: >> >> >> You chopped off the output there. It probably looked like this: >> >> >> node-1# cat test_2.txt >> Sundaynode-1# >> >> >> Your output is there, right before the prompt. Since you neglected the >> newline in your cod

Re: Python : writing to a file

2015-01-11 Thread Ganesh Pal
On Sun, Jan 11, 2015 at 2:17 PM, Dave Angel wrote: > > > You chopped off the output there. It probably looked like this: > > > node-1# cat test_2.txt > Sundaynode-1# > > > Your output is there, right before the prompt. Since you neglected the > newline in your code, that's what you'd expect, wou

Re: Python : writing to a file

2015-01-11 Thread Dave Angel
You accidentally did a Reply instead of a Reply-List. So the email came to me and not to the list. if your mail program doesn't support reply-list, do a reply-all and remove the personal addresses. The list is what's important here. On 01/11/2015 12:20 AM, Ganesh Pal wrote: On Sat, Jan 10,

Re: Python : writing to a file

2015-01-10 Thread Steven D'Aprano
Ganesh Pal wrote: > Throttling-1# cat test_2.txt Are you running these scripts as root? That could be a bad idea. If you have a bug in your code, as often happens when coding, who knows what it might do. E.g. if you put in the wrong pathname, you could overwrite important files. You should always

Re: Python : writing to a file

2015-01-10 Thread Dave Angel
On 01/10/2015 10:14 AM, Ganesh Pal wrote: Please provide you input on the below questions: For each new thread, you should specify at a minimum your Python version and OS. it frequently matters, and it's better to specify than to have everyone try to guess. I'll assume Python 2.7 and Linux

Python : writing to a file

2015-01-10 Thread Ganesh Pal
Please provide you input on the below questions: (a) I was expecting the string i.e day of week , example Saturday to be written in the file. what Iam I missing in the below program ? Program: #!/usr/bin/python import time f = open ('test_2.txt','w+b') DAY = time.strftime("%A") f.write(DAY)

Re: writing to a file from within nested loops

2012-02-15 Thread Mark Lawrence
On 15/02/2012 20:12, Rituparna Sengupta wrote: Hi, I'm working on this code and I keep getting an error. It might be some very basic thing but I was wondering if someone could help. Its a loop within a loop. The part outside the innermost loop gets printed fine, but the part within the innerm

Re: writing to a file from within nested loops

2012-02-15 Thread Dave Angel
On 02/15/2012 03:12 PM, Rituparna Sengupta wrote: Hi, I'm working on this code and I keep getting an error. It might be some very basic thing but I was wondering if someone could help. Its a loop within a loop. The part outside the innermost loop gets printed fine, but the part within the inn

Re: writing to a file from within nested loops

2012-02-15 Thread Chris Rebert
On Wed, Feb 15, 2012 at 12:12 PM, Rituparna Sengupta wrote: > Hi, > > I'm working on this code and I keep getting an error. It might be some very > basic thing but I was wondering if someone could help. Its a loop within a > loop. The part outside the innermost loop gets printed fine, but the pa

Re: writing to a file from within nested loops

2012-02-15 Thread Ian Kelly
On Wed, Feb 15, 2012 at 1:12 PM, Rituparna Sengupta wrote: > Hi, > > I'm working on this code and I keep getting an error. It might be some very > basic thing but I was wondering if someone could help. Its a loop within a > loop. The part outside the innermost loop gets printed fine, but the par

writing to a file from within nested loops

2012-02-15 Thread Rituparna Sengupta
Hi, I'm working on this code and I keep getting an error. It might be some very basic thing but I was wondering if someone could help. Its a loop within a loop. The part outside the innermost loop gets printed fine, but the part within the innermost loop doesn't get printed. I get an error: 'st

Re: Reading and writing to a file creates null characters

2012-01-13 Thread Denhua
On Jan 12, 6:21 pm, MRAB wrote: > On 12/01/2012 22:26, Denhua wrote: > > > > > > > > > Hi, > > > I've got a file which I'd like to read, modify and write. > > > # file contents > > a > > b > > c > > d > > > My script reads the file contents into a list and rotates the list and > > writes it back t

Re: Reading and writing to a file creates null characters

2012-01-12 Thread MRAB
On 12/01/2012 22:26, Denhua wrote: Hi, I've got a file which I'd like to read, modify and write. # file contents a b c d My script reads the file contents into a list and rotates the list and writes it back to the same file. Problem is that the output contains null characters. I don't know whe

Re: Reading and writing to a file creates null characters

2012-01-12 Thread Roy Smith
In article <4f7d125a-2713-4b57-a108-2a56ae653...@h3g2000yqe.googlegroups.com>, Denhua wrote: > [omitted] > f.write("\n".join(newlist)) > f.close() > > # output > > [root@Inferno html]# python rotate.py > ['b', 'c', 'd', 'a'] > [root@Inferno html]# python rotate.py > ['c', 'd', 'a', '\x00\x00\

Reading and writing to a file creates null characters

2012-01-12 Thread Denhua
Hi, I've got a file which I'd like to read, modify and write. # file contents a b c d My script reads the file contents into a list and rotates the list and writes it back to the same file. Problem is that the output contains null characters. I don't know where they are coming from. #!/usr/bin/

Re: Is it possible to execute Python code from C++ without writing to a file?

2011-04-16 Thread Anssi Saari
Roger House writes: > I tried PyRun_String, but I can't see how it can be used to return a > tuple (the Py_file_input option always returns None). There's an example of this at http://stackoverflow.com/questions/3789881/create-and-call-python-function-from-string-via-c-api The comments say this

Re: Is it possible to execute Python code from C++ without writing to a file?

2011-04-15 Thread Chris Angelico
On Sat, Apr 16, 2011 at 9:46 AM, Roger House wrote: > I'm a Python newbie who's been given a task requiring calls of Python code > from a C++ program.  I've tried various tutorials and dug into The Python/C > API doc and the Extending and Embedding Python doc, but I haven't been able > to answer t

Is it possible to execute Python code from C++ without writing to a file?

2011-04-15 Thread Roger House
I'm a Python newbie who's been given a task requiring calls of Python code from a C++ program. I've tried various tutorials and dug into The Python/C API doc and the Extending and Embedding Python doc, but I haven't been able to answer this question: Is it possible in a C++ program to genera

RE: Writing to a file

2011-03-28 Thread jyoung79
I appreciate you all taking the time to answer my question. These were the types of things I was needing to hear. Sorry for any confusion I may have caused by using a relative file path with the '~'… I was typing from memory and didn't think about it beforehand. Eryksun, thank you for the in

Re: Writing to a file

2011-03-26 Thread Steven D'Aprano
On Sat, 26 Mar 2011 14:49:31 +1300, Gregory Ewing wrote: > jyoun...@kc.rr.com wrote: > >import os >os.system('echo "Testing a... b... c..." > "~/Desktop/test2.txt"') > > This is like going out the back door, getting a ladder out of the shed > and climbing through your bedroom window to g

Re: Writing to a file

2011-03-26 Thread Nobody
On Fri, 25 Mar 2011 19:39:11 -0600, Littlefield, Tyler wrote: > >with open(test_absname, 'w') as test: > what's the difference in that and test = ...? I can see why you mentioned > the os.path for cross-platform, but I don't understand why someone would > use with over =. Using "with" will a

Re: Writing to a file

2011-03-25 Thread eryksun ()
On Friday, March 25, 2011 9:39:11 PM UTC-4, Littlefield, Tyler wrote: > >with open(test_absname, 'w') as test: > what's the difference in that and test = ...? I can see why you > mentioned the os.path for cross-platform, but I don't understand why > someone would use with over =. It avoids h

Re: Writing to a file

2011-03-25 Thread Dan Stromberg
with closes the file for you, when the indented block is exited. ~ isn't cross-platform at all, in fact it's not precisely python, though os.path.expanduser understands it. AFAIK, the jury's still out on whether the /'s in pathnames as directory separators are portable. I know they work on *ix a

Re: Writing to a file

2011-03-25 Thread Gregory Ewing
jyoun...@kc.rr.com wrote: import os os.system('echo "Testing a... b... c..." > "~/Desktop/test2.txt"') This is like going out the back door, getting a ladder out of the shed and climbing through your bedroom window to get into bed at night, instead of just using the stairs. Use open/write/clo

Re: Writing to a file

2011-03-25 Thread Gregory Ewing
John Gordon wrote: The write() way is much better. (However, I'm not sure it will do what you were expecting with the tilde in the file path.) It won't, but the os.path.expanduser() function can be used to fix that. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing to a file

2011-03-25 Thread Littlefield, Tyler
>with open(test_absname, 'w') as test: what's the difference in that and test = ...? I can see why you mentioned the os.path for cross-platform, but I don't understand why someone would use with over =. On 3/25/2011 7:11 PM, eryksun () wrote: On Friday, March 25, 2011 11:07:19 AM UTC-4, jy

Re: Writing to a file

2011-03-25 Thread eryksun ()
On Friday, March 25, 2011 11:07:19 AM UTC-4, jyou...@kc.rr.com wrote: > > >>> f = open('~/Desktop/test.txt', 'w') > >>> f.write('testing 1... 2... 3...') > >>> f.close() Consider using "with" to automatically close the file and os.path for cross-platform compatibility: import os.path use

Re: Writing to a file

2011-03-25 Thread Adam Tauno Williams
On Fri, 2011-03-25 at 15:07 +, jyoun...@kc.rr.com wrote: > Just curious how others view the 2 examples below for creating and > writing to a file in Python (in OS X). Is one way better than the other? > If it was a large amount of text, would the 'os.system' call be a

Re: Writing to a file

2011-03-25 Thread John Gordon
In writes: > Just curious how others view the 2 examples below for creating and > writing to a file in Python (in OS X). Is one way better than the other? > If it was a large amount of text, would the 'os.system' call be a bad > way to do it? The write() way is

Re: Writing to a file

2011-03-25 Thread cassiope
On Mar 25, 8:07 am, wrote: > Just curious how others view the 2 examples below for creating and > writing to a file in Python (in OS X).  Is one way better than the other?   > If it was a large amount of text, would the 'os.system' call be a bad > way to do it? > > T

Writing to a file

2011-03-25 Thread jyoung79
Just curious how others view the 2 examples below for creating and writing to a file in Python (in OS X). Is one way better than the other? If it was a large amount of text, would the 'os.system' call be a bad way to do it? Thanks. Jay >>> f = open('~/Desktop/tes

Re: Unicode in writing to a file

2009-04-23 Thread Carbon Man
Thanks yes that did it. "Peter Otten" <__pete...@web.de> wrote in message news:gspmrf$qlq$0...@news.t-online.com... > Carbon Man wrote: > >> Py 2.5 >> Trying to write a string to a file. >> self.dataUpdate.write(u"\nentry."+node.tagName+ u" = " + cValue) >> cValue contains a unicode character. no

Re: Unicode in writing to a file

2009-04-23 Thread Peter Otten
Carbon Man wrote: > Py 2.5 > Trying to write a string to a file. > self.dataUpdate.write(u"\nentry."+node.tagName+ u" = " + cValue) > cValue contains a unicode character. node.tagName is also a unicode string > though it has no special characters in it. > Getting the error: > UnicodeEncodeError: '

Re: Unicode in writing to a file

2009-04-23 Thread Ulrich Eckhardt
Carbon Man wrote: > self.dataUpdate.write(u"\nentry."+node.tagName+ u" = " + cValue) > cValue contains a unicode character. node.tagName is also a unicode string > though it has no special characters in it. > Getting the error: > UnicodeEncodeError: 'ascii' codec can't encode character u'\x93' in >

Re: Unicode in writing to a file

2009-04-23 Thread Diez B. Roggisch
Carbon Man wrote: > Py 2.5 > Trying to write a string to a file. > self.dataUpdate.write(u"\nentry."+node.tagName+ u" = " + cValue) > cValue contains a unicode character. node.tagName is also a unicode string > though it has no special characters in it. > Getting the error: > UnicodeEncodeError: '

Re: Unicode in writing to a file

2009-04-23 Thread Marco Mariani
Carbon Man wrote: Py 2.5 Trying to write a string to a file. self.dataUpdate.write(u"\nentry."+node.tagName+ u" = " + cValue) cValue contains a unicode character. node.tagName is also a unicode string though it has no special characters in it. So what's the encoding of your file? If you didn

Unicode in writing to a file

2009-04-23 Thread Carbon Man
Py 2.5 Trying to write a string to a file. self.dataUpdate.write(u"\nentry."+node.tagName+ u" = " + cValue) cValue contains a unicode character. node.tagName is also a unicode string though it has no special characters in it. Getting the error: UnicodeEncodeError: 'ascii' codec can't encode charac

Re: [Tutor] list iteration question for writing to a file on disk

2007-09-14 Thread Shawn Milochik
When you use "print," it automatically adds a newline (\n). You can avoid this by following the print line with a comma: print j, Or rstrip() the line before printing. Either way. -- http://mail.python.org/mailman/listinfo/python-list

Re: writing to a file

2007-05-30 Thread sturlamolden
On May 30, 4:53 pm, sturlamolden <[EMAIL PROTECTED]> wrote: > However, numpy has a properly working memory mapped array class, > numpy.memmap. It seems that NumPy's memmap uses a buffer from mmap, which makes both of them defunct for large files. Damn. mmap must be fixed. -- http://mail.p

Re: writing to a file

2007-05-30 Thread sturlamolden
On May 30, 4:53 pm, sturlamolden <[EMAIL PROTECTED]> wrote: > import numpy > > byte = numpy.uint8 > desc = numpy.dtype({'names':['r','g','b'],'formats':[byte,byte,byte]}) > mm = numpy.memmap('myfile.dat', dtype=desc, offset=4096, > shape=(480,640), order='C') > red = mm['r'] > green = mm['g'] > bl

Re: writing to a file

2007-05-30 Thread sturlamolden
On May 30, 1:41 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] schrieb: > > what i want to know is which one is faster (if there is any difference > > in speed) since i'm working with very large files. of course, if there > > is any other way to write data to a file, i'd lov

Re: writing to a file

2007-05-30 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > as i understand there are two ways to write data to a file: using > f.write("foo") and print >>f, "foo". > what i want to know is which one is faster (if there is any difference > in speed) since i'm working with very large files. of course, if there > is any other way

Re: writing to a file

2007-05-30 Thread Szabolcs Nagy
[EMAIL PROTECTED] wrote: > as i understand there are two ways to write data to a file: using > f.write("foo") and print >>f, "foo". well print will add a '\n' or ' ' if you use ',' after it > what i want to know is which one is faster (if there is any difference there shouldn't be any noticable d

writing to a file

2007-05-30 Thread montyphyton
as i understand there are two ways to write data to a file: using f.write("foo") and print >>f, "foo". what i want to know is which one is faster (if there is any difference in speed) since i'm working with very large files. of course, if there is any other way to write data to a file, i'd love to

Re: problem writing to a file each record read

2006-03-15 Thread bruno at modulix
Eduardo Biano wrote: > I am a python newbie and I have a problem with writing > each record read to a file. The expected output is 10 > rows of records, but the actual output of the code > below is only one row with a very long record (10 > records are lump into one record). Thank you in > advance

Re: problem writing to a file each record read

2006-03-14 Thread Peter Otten
Eduardo Biano wrote: > #--- > #  This is the problem code. Ten records > #  is  lump into 1 row and written > #  in the output file. > # > #  My expected output is 10 rows. > #--- > info = string.join([fn, mi, ln, deg, dat] Should pr

problem writing to a file each record read

2006-03-14 Thread Eduardo Biano
I am a python newbie and I have a problem with writing each record read to a file. The expected output is 10 rows of records, but the actual output of the code below is only one row with a very long record (10 records are lump into one record). Thank you in advance for your help. Here is the code: