|
From: Oliver S. <oli...@gm...> - 2010-01-18 07:55:57
|
Hi! the r in front of the string literal designates a raw string (bing that), it tells the python interpreter to handle the characters inside the quotes "as is" and to not interpret the backslash \ as escape. Working alternatives would be to write "c:\\yourpath\\yourfile.ini" or "c:/yourpath/yourfile.ini" or """c:\yourpath\yourfile.ini""" Also for all thing involving paths, better get used to the os.path helper functionalities, i.e. import os iniLoc = os.path.join(sys.argv[1],'arm.ini') will give you a well formed path for your environment. Don't concatenate partial paths yourself. Also check the documentation for sys.argv, the first element (sys.argv[0]) contains the name of the script you are interpreting. All the above is easily found in freely available documentation and literature, e.g. http://diveintopython.org/toc/index.html Your email is kind of off-topic for this mailing list; since you did a smart thing with identifying and using ConfigObj, I'm happy to help you anyway. Have a nice week! Best regards, Oliver On 18.01.2010, at 04:45, Alex Hall wrote: > Hello all, > I am new to this list. I am writing a small application (so small it is > really just a single script and an ini file). I am trying to read my ini > file. This was working earlier today, but I put the initial reading in a try > statement and now nothing works!! Does anyone see anything wrong with the > below syntax? Note that indents are one space, not four. > > iniLoc=os.path.dirname(sys.argv[0])+"\\arm.ini" > try: > ini=ConfigObj('c:\arm\arm.ini', interpolation=False, fileerror=True) > except: > print("The ARM.ini file was not found or could not be accessed. Please make > sure no other program is using the file, and that the file "+iniLoc+" > exists, and try running ARM again.") > exitProgram() > #end except > > The program is called ARM, and the ini file is currently at c:\arm\arm.ini. > However, the file cannot be found whether I use the iniLoc variable or > hard-code the location, as I did in the above code. > > Also, I found a tutorial earlier today that got me started, but the syntax > in that tutorial was > > file=ConfigObj(r"c:\...") > > Note the "r" in front of the path. My program did not work right until I put > in the "r", but now it seems to make no difference. I cannot imagine what > this "r" is supposed to do, and I cannot find it in the documentation. Any > light shed on this would be great. Thanks! > > Have a great day, > Alex > Email: me...@gm... > > > ------------------------------------------------------------------------------ > Throughout its 18-year history, RSA Conference consistently attracts the > world's best and brightest in the field, creating opportunities for Conference > attendees to learn about information security's most important issues through > interactions with peers, luminaries and emerging and established companies. > http://p.sf.net/sfu/rsaconf-dev2dev > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop |