Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > general coding issues - coding style...

Reply
Thread Tools

general coding issues - coding style...

 
 
JW
Guest
Posts: n/a
 
      02-20-2006
About this line:
1585 if sys.path[0][-12:] == "\library.zip": #for py2exe

pl... suggested:
if sys.path[0].endswith( "\\library.zip" ):

and said, "did you really mean one back-slash there?". You responded
"yeah, one backslash", but I still don't believe you. In this case, it
happens to work, but you should be aware that the back-slash is an
escape character, which causes the next character to be interpreted
differently. Try this in your interpreter:

print "\a" # System bell - might cause your speaker to beep
print "\t" # Tab character
print "\n" # Newline character / sequence

See http://www.python.org/doc/2.4.2/ref/strings.html for more details
on the escape sequences that Python recognizes. Here's a summary: if
the backslash + character is a special escape code, then replace it
with that, otherwise assume the programmer meant a real backslash.
That's dangerous, and will break when the name changes from one that
starts with an L to one that starts with an A, B, F, N, etc. The safe
way it to tell Python "Yes, I really want a backslash", which is
indicated with the double backslash:

print "\\library.zip"

If you don't use the double backslash, you'll eventually have a
problem, especially in Windows, which unfortunately uses the backslash
as a directory seperator. You might also want to look at os.sep and
the os.path.* functions, if you are interested in making your code work
on different platforms.

JW

 
Reply With Quote
 
 
 
 
calmar
Guest
Posts: n/a
 
      02-21-2006
On 2006-02-20, JW <(E-Mail Removed)> wrote:

Hi JW,

> About this line:
> 1585 if sys.path[0][-12:] == "\library.zip": #for py2exe
>
> pl... suggested:
> if sys.path[0].endswith( "\\library.zip" ):
>
>
> print "\\library.zip"
>


Yeah, I have two backslashes, but thaks for pointing out.

> If you don't use the double backslash, you'll eventually have a
> problem, especially in Windows, which unfortunately uses the backslash
> as a directory seperator. You might also want to look at os.sep and
> the os.path.* functions, if you are interested in making your code work
> on different platforms.


Yeah, I will use the os.sep variable, that's a good idea

thanks a lot,
calmar


--
calmar

(o_ It rocks: LINUX + Command-Line-Interface
//\
V_/_ http://www.calmar.ws
 
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
General....very general.... no important for u forever hi Python 0 03-18-2009 08:21 AM
Burning issues and general noob questions =?Utf-8?B?SGVuZGxlZmU=?= Windows 64bit 8 05-28-2005 12:25 AM
XML-RPC and SOAP:differences and general issues... RedHat_79 XML 0 05-29-2004 11:21 AM
coding issues with vhdl and ROM vhdl_rookie VHDL 0 05-10-2004 07:39 PM
SNMP Issues in Cisco Routers; Vulnerability Issues in TCP =?iso-8859-1?Q?Frisbee=AE?= MCSE 0 04-21-2004 03:00 PM



Advertisments