Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > raw_input can't handle pound sign?

Reply
Thread Tools

raw_input can't handle pound sign?

 
 
Jugdish
Guest
Posts: n/a
 
      12-27-2008
Hi, I'm having problems getting a pound sign to go through as input
sent to the raw_input() command. I'm running Python 2.5.1 on Windows
XP. Here's my simple little script:

while True:
response = raw_input("Please enter a file name: ")
if os.path.exists(response):
break

Problem is if the filename has a "#" in it, the script interprets that
as the beginning of a comment (not sure why -- isn't raw_input
supposed to treat the user's input as raw text and not do any sort of
evals?)

Any ideas how to get a # to go through? Thanks!
 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      12-27-2008
On Fri, 26 Dec 2008 20:20:16 -0800, Jugdish wrote:

> Hi, I'm having problems getting a pound sign to go through as input sent
> to the raw_input() command. I'm running Python 2.5.1 on Windows XP.
> Here's my simple little script:
>
> while True:
> response = raw_input("Please enter a file name: ") if
> os.path.exists(response):
> break
>
> Problem is if the filename has a "#" in it, the script interprets that
> as the beginning of a comment (not sure why -- isn't raw_input supposed
> to treat the user's input as raw text and not do any sort of evals?)


Yes it is. What makes you think it is being interpreted as a comment?
What results are you getting?


> Any ideas how to get a # to go through? Thanks!


Works for me (although I'm not using Windows XP).

Can you execute this line at the interactive interpreter?

print raw_input("Type something with a hash sign: ")


At the prompt, type "test # string" (without the quotes) and show us what
result you get. When I do this, I get the following:


>>> print raw_input("Type something with a hash sign: ")

Type something with a hash sign: test # string
test # string



--
Steven
 
Reply With Quote
 
 
 
 
Jugdish
Guest
Posts: n/a
 
      12-27-2008
Ahh ok, tried out your example and it works just fine. Turns out the
actual problem is what I was doing with the input. Elsewhere, I call
urlparse.urlparse() on the filename past in, which splits up the
filename where the # sign is, so that's why it looked to me like the
characters after the # were getting stripped away.

Thanks for your help, in the future I'll try to do a bit more
debugging of my own scripts before bringing my problems here!

On Dec 26, 9:00*pm, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote:
> On Fri, 26 Dec 2008 20:20:16 -0800, Jugdish wrote:
> > Hi, I'm having problems getting a pound sign to go through as input sent
> > to the raw_input() command. I'm running Python 2.5.1 on Windows XP.
> > Here's my simple little script:

>
> > while True:
> > * * response = raw_input("Please enter a file name: ") if
> > * * os.path.exists(response):
> > * * * * break

>
> > Problem is if the filename has a "#" in it, the script interprets that
> > as the beginning of a comment (not sure why -- isn't raw_input supposed
> > to treat the user's input as raw text and not do any sort of evals?)

>
> Yes it is. What makes you think it is being interpreted as a comment?
> What results are you getting?
>
> > Any ideas how to get a # to go through? Thanks!

>
> Works for me (although I'm not using Windows XP).
>
> Can you execute this line at the interactive interpreter?
>
> print raw_input("Type something with a hash sign: ")
>
> At the prompt, type "test # string" (without the quotes) and show us what
> result you get. When I do this, I get the following:
>
> >>> print raw_input("Type something with a hash sign: ")

>
> Type something with a hash sign: test # string
> test # string
>
> --
> Steven


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I want the # pound in the URL QueryString, not a bookmark =?Utf-8?B?TGFycnk=?= ASP .Net 2 01-02-2006 12:36 PM
streamreader will not read UK pound sign!!! =?Utf-8?B?bTAwbm0wbmtleQ==?= ASP .Net 6 11-22-2005 12:55 PM
Server.HTMLEncode and the # (pound) symbol Chris ASP .Net 2 07-15-2004 01:03 AM
Re: Pound Sign in text emails Jerry III ASP .Net 0 10-15-2003 07:41 AM
Global pound define? Andrew ASP .Net 1 07-15-2003 12:57 AM



Advertisments