Re: [Tutor] Hello World in Python without space

2011-07-17 Thread Lisi
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

Re: [Tutor] Hello World in Python without space

2011-07-15 Thread Richard D. Moores
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

Re: [Tutor] Hello World in Python without space

2011-07-15 Thread Steven D'Aprano
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

Re: [Tutor] Hello World in Python without space

2011-07-15 Thread Richard D. Moores
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

Re: [Tutor] Hello World in Python without space

2011-07-15 Thread Dave Angel
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

Re: [Tutor] Hello World in Python without space

2011-07-15 Thread Richard D. Moores
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

Re: [Tutor] Hello World in Python without space

2011-07-15 Thread xDog Walker
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. > > > >

Re: [Tutor] Hello World in Python without space

2011-07-15 Thread Richard D. Moores
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): >    

Re: [Tutor] Hello World in Python without space

2011-07-15 Thread Stefan Behnel
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

Re: [Tutor] Hello World in Python without space

2011-07-15 Thread Richard D. Moores
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

Re: [Tutor] Hello World in Python without space

2011-07-11 Thread Emile van Sebille
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

Re: [Tutor] Hello World in Python without space

2011-07-10 Thread Alan Gauld
"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.

Re: [Tutor] Hello World in Python without space

2011-07-10 Thread Peter Otten
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

Re: [Tutor] Hello World in Python without space

2011-07-10 Thread Izz ad-Din Ruhulessin
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

[Tutor] Hello World in Python without space

2011-07-10 Thread 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 script: name="world" print("Hello", name,"!") The result is: Hello world ! However, I don't want the space before the exclamation mark. I want