[Tutor] drag-and-drop argument passing

alan.gauld@bt.com alan.gauld@bt.com
Mon, 1 Jul 2002 18:09:41 +0100


------_=_NextPart_001_01C22122.16EA8C70
Content-type: text/plain; charset="iso-8859-1"

 > Now, there is only one thing left in my way, but it is very vexing.  
 
>  I don't know how to generate raw strings on the fly.  
>  For example: this path would choke my script,  
>  because "\f" is a token: 
>  >>> "c:\ftp\test.txt" 
 
So use forward slashes Unix style.
 
If reading from a user raw_input will correctly escape 
the backslashes for you:
 
C:\\ftp\\test.txt
 
 >   But how do I turn a string in a list, like sys.argv[], into a raw
string?  
 >  for path in sys.argv[1:]:
 >       make_raw(path) 
 
Aha! Good example. Tricky that one, I don't know!
 
I look forward to seeing an answer.
 
Alan G

------_=_NextPart_001_01C22122.16EA8C70
Content-type: text/html; charset="iso-8859-1"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;&gt; </FONT></SPAN>Now, there is only one thing left in my way, but 
it is very vexing.&nbsp;<SPAN class=970570117-01072002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>I don't know how to generate raw strings on the 
fly.&nbsp;<SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>For example: this path would choke my 
script,&nbsp;<SPAN class=970570117-01072002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>because "\f" is a token:<SPAN 
class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>&gt; </FONT>&nbsp;</SPAN>&gt;&gt;&gt; "c:\ftp\test.txt"<SPAN 
class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>So use forward slashes Unix style.</FONT></SPAN></DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>If reading from a user raw_input will correctly escape 
</FONT></SPAN></DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>the backslashes for you:</FONT></SPAN></DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>C:\\ftp\\test.txt</FONT></SPAN></DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;</FONT></SPAN></DIV>
<DIV><SPAN class=970570117-01072002><FONT face="Courier New" color=#0000ff 
size=2>&nbsp;&gt; </FONT>&nbsp; </SPAN>But how do I turn a string in a list, 
like sys.argv[], into a raw string?&nbsp;<SPAN class=970570117-01072002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV dir=ltr><SPAN class=970570117-01072002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;&gt; &nbsp;</FONT></SPAN>for path in 
sys.argv[1:]:</DIV>
<DIV dir=ltr><SPAN class=970570117-01072002><FONT face="Courier New" 
color=#0000ff size=2>&nbsp;&gt;&nbsp;</FONT></SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN 
class=970570117-01072002><FONT face="Courier New" color=#0000ff size=2>&nbsp; 
</FONT></SPAN>make_raw(path)<SPAN class=970570117-01072002><FONT 
face="Courier New" color=#0000ff size=2>&nbsp;</FONT></SPAN></DIV>
<DIV dir=ltr><SPAN class=970570117-01072002><FONT face="Courier New" 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr><SPAN class=970570117-01072002><FONT face="Courier New" 
color=#0000ff size=2>Aha! </FONT></SPAN><SPAN class=970570117-01072002><FONT 
face="Courier New" color=#0000ff size=2>Good example. Tricky that one, I don't 
know!</FONT></SPAN></DIV>
<DIV dir=ltr><SPAN class=970570117-01072002></SPAN><FONT face="Courier New" 
color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face="Courier New"><FONT color=#0000ff size=2><SPAN 
class=970570117-01072002>I look forward to seeing an 
answer.</SPAN></FONT></FONT></DIV>
<DIV dir=ltr><FONT face="Courier New"><FONT color=#0000ff size=2><SPAN 
class=970570117-01072002></SPAN></FONT></FONT>&nbsp;</DIV>
<DIV dir=ltr><FONT face="Courier New"><FONT color=#0000ff size=2><SPAN 
class=970570117-01072002>Alan G</SPAN></FONT></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C22122.16EA8C70--