Simple formatting problem in Python pathnames

Joined
Nov 2, 2009
Messages
670
I think I have made a formatting mistake in Python, probably missing out a quotation mark or a slash. But I don't know what I'm doing, so I've included some context.

(Backstory: I am trying to make the EusebiusWorldReligions-Revival mod work on Civ 4 Complete-Warlords. Python fails to initialize, due to a problem in CvPath.py. This turns out to be a piece of Python designed to work out the path automatically, but the Civ 4 Complete installation gives it some problems....)

The original file has some functions for working out the correct path, then a list of paths beginning:

Code:
userDir = _getUserDir()

userAssetsDir = os.path.join(userDir, "CustomAssets")

userModsDir = os.path.join(userDir, "Mods")

userActiveModDir = None

An error here stopped Python initializing, so I thought I'd just type in the correct values thus:

Code:
userDir = C:\Documents and Settings\Matt\My Documents\My Games\Warlords

userAssetsDir = C:\Documents and Settings\Matt\My Documents\My Games\Warlords\CustomAssets

userModsDir = C:\Documents and Settings\Matt\My Documents\My Games\Warlords\Mods

userActiveModDir = C:\Documents and Settings\Matt\My Documents\My Games\Warlords\Mods\EusebiusWorldReligion-Revival

PythonErr2.log reports

Code:
load_module CvPath
Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "<string>", line 52, in load_module
  File "CvEventInterface", line 9, in ?
  File "<string>", line 52, in load_module
  File "CvUtil", line 410, in ?
  File "<string>", line 52, in load_module
  File "CvConfigParser", line 26, in ?
  File "<string>", line 35, in load_module
  File "<string>", line 13, in _get_code
  File "CvPath", line 77
    userDir = C:\Documents and Settings\Matt\My Documents\My Games\Warlords
               ^
SyntaxError: invalid syntax
load_module CvAppInterface

Should I be adding single/double quotation marks, or some other formatting mark?

I have attached my edited file (CvPath.py) and the original file in the mod (CvPath.py.bak)
 

Attachments

Any quotation (single or double) would do, as long as you're consistent - opening and closing the same string with the same quote type.
Specifically regarding back-slashes ('\') - some of them are 'escape characters' for special characters you can't really type. For example - \n is new line (same as Enter).

Specifically in the paths you've typed I don't think there are any special characters like that (so '\D' will actually be interpreted as \D), but it's a good habit to double your back slashes, since '\\' is interpreted as a single backslash.

So;
Code:
userDir = 'C:\\Documents and Settings\\Matt\\My Documents\\My Games\\Warlords'

userAssetsDir = "C:\\Documents and Settings\\Matt\\My Documents\\My Games\\Warlords\\CustomAssets"

userModsDir = "C:\\Documents and Settings\\Matt\\My Documents\\My Games\\Warlords\\Mods"

userActiveModDir = 'C:\\Documents and Settings\\Matt\\My Documents\\My Games\\Warlords\\Mods\\EusebiusWorldReligion-Revival'
 
Thank you for helpful advice, Asaf and The_J.

One of the later paths includes:

Code:
\Sid Meier's Civilization 4 Complete\

So would that mean I'm obliged to use double quotes? Do I need do anything clever so that Python knows the apostrophe is part of the pathname, not the end of it?
 
You can either use double quotes or add a backslash (which is an escape character in this case), so:
Code:
print 'Sid Meier\'s Civilization 4 Complete'

will print
Code:
Sid Meier's Civilization 4 Complete
 
Back
Top Bottom