"Denis,\n\nThat works perfectly!\n\nMerci Beaucoup!\n\nPayo" :-)
On Tue, Feb 10, 2009 at 6:48 PM, spir <denis.s...@free.fr> wrote: > Le Tue, 10 Feb 2009 18:08:26 +0100, > pa yo <payo2...@gmail.com> a écrit : > >> Novice programmer here. >> >> I am using urllib.urlencode to post content to a web page: >> >> ... >> >>Title = "First Steps" >> >>Text = "Hello World." >> >>Username = "Payo2000" >> >>Content = Text + "From: " + Username >> >>SubmitText = urllib.urlencode(dict(Action = 'submit', Headline = Title, >> >>Textbox = Content)) >> >>Submit = opener.open('http://www.website.com/index.php?', SubmitText) >> >> This works fine to produce in this: >> >> "Hello World From Payo2000" >> >> ...on the page. >> >> However I can't work out how to add a linefeed (urlencode: %0A) in >> front of Username so that I get: >> >> "Hello World. >> From: Payo2000" >> >> Any hints, tips or suggestions welcome! > > In python (and many other languages) some special characters that are not > easy to represent have a code: > LF : \n > CR : \r > TAB : \t > So just add \n to to first line to add an eol: Text = "Hello World.\n" > [Beware that inside python \n actually both means char #10 and 'newline', > transparently, whatever the os uses as 'newline' code for text files. Very > handy.] > Alternatively, as you seem to be used to web codes, you can have hexa > representation \x0a or even octal \012 > > Denis > ----- > la vida e estranya > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor