On Saturday 16 July 2011 03:15:12 Richard D. Moores wrote:
> But that makes me wonder if there isn't a simpler way to do it with
> Python -- to delete the contents of a file without deleting the file?
Up to now, knowing no better ;-), I have opened the file in, or copied and
pasted the contents o
On Fri, Jul 15, 2011 at 21:38, Steven D'Aprano wrote:
>
> Richard D. Moores wrote:
>
>> But that makes me wonder if there isn't a simpler way to do it with
>> Python -- to delete the contents of a file without deleting the file?
>
> Opening a file for writing will flush the contents.
>
> open(file
Richard D. Moores wrote:
But that makes me wonder if there isn't a simpler way to do it with
Python -- to delete the contents of a file without deleting the file?
Opening a file for writing will flush the contents.
open(filename, 'w')
will do it, taking advantage of Python's garbage collecto
On Fri, Jul 15, 2011 at 17:16, Dave Angel wrote:
> On 07/15/2011 07:39 PM, Richard D. Moores wrote:
>> with open("C:/test/test.txt", "a") as file_object:
>> print("Hello, world!", file=file_object)
>>
>> Yes, that works for me with Windows Vista. However, if test.txt is
>> empty, it puts in
On 07/15/2011 07:39 PM, Richard D. Moores wrote:
On Fri, Jul 15, 2011 at 16:21, xDog Walker wrote:
I believe on Windows, you can almost always use a forward slash in a path:
C:/somewhere/somewhereelse/
with open("C:/test/test.txt", "a") as file_object:
print("Hello, world!", file=file_o
On Fri, Jul 15, 2011 at 16:21, xDog Walker wrote:
> I believe on Windows, you can almost always use a forward slash in a path:
> C:/somewhere/somewhereelse/
with open("C:/test/test.txt", "a") as file_object:
print("Hello, world!", file=file_object)
Yes, that works for me with Windows Vista
On Friday 2011 July 15 15:58, Richard D. Moores wrote:
> On Fri, Jul 15, 2011 at 14:47, Stefan Behnel wrote:
> > Richard D. Moores, 15.07.2011 23:21:
> >> What do I do to test.txt to make it "an object with a write(string)
> >> method"?
> >
> > Oh, there are countless ways to do that, e.g.
> >
> >
On Fri, Jul 15, 2011 at 14:47, Stefan Behnel wrote:
> Richard D. Moores, 15.07.2011 23:21:
>> What do I do to test.txt to make it "an object with a write(string)
>> method"?
>
> Oh, there are countless ways to do that, e.g.
>
> class Writable(object):
> def __init__(self, something):
>
Richard D. Moores, 15.07.2011 23:21:
On Sun, Jul 10, 2011 at 05:05, Peter Otten wrote:
>>> help(print)
shows
print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-l
On Sun, Jul 10, 2011 at 05:05, Peter Otten <__pete...@web.de> wrote:
> >>> help(print)
>
> shows
>
> print(...)
> print(value, ..., sep=' ', end='\n', file=sys.stdout)
>
> Prints the values to a stream, or to sys.stdout by default.
> Optional keyword arguments:
> file: a file-like obje
On 7/10/2011 4:12 AM Robert H said...
Dear all,
I have Python 3.2 installed on Windows 7. I am a complete beginner
playing around with the basic functions. My problem is the following script:
name="world"
print("Hello", name,"!")
print("Hello", name+"!")
Alan mentioned using concatenation
"Robert H" wrote
name="world"
print("Hello", name,"!")
Hello world !
However, I don't want the space before the exclamation
mark. I want this:
Hello world!
Can anyone out there help me? Thank you.
I see you've already had two answers, a third is
to construct the string before printing it.
Robert H wrote:
> I have Python 3.2 installed on Windows 7. I am a complete beginner playing
> around with the basic functions. My problem is the following script:
>
>
> name="world"
> print("Hello", name,"!")
>
>
> The result is:
> Hello world !
>
>
> However, I don't want the space before
Sending args to the print command always puts spaces between them.
Try:
print("Hello {name}!".format(name=name))
2011/7/10 Robert H
> Dear all,
>
>
> I have Python 3.2 installed on Windows 7. I am a complete beginner playing
> around with the basic functions. My problem is the following sc
Dear all,
I have Python 3.2 installed on Windows 7. I am a complete beginner playing
around with the basic functions. My problem is the following script:
name="world"
print("Hello", name,"!")
The result is:
Hello world !
However, I don't want the space before the exclamation mark. I want
15 matches
Mail list logo