You just have to run python -m compileall again. It will overwrite older .pyc files. You can pass it the -f switch to force rebuild even if timestamps are up to date (as per the documentation).
You just have to run python -m compileall again. It will overwrite older .pyc files. You can pass it the -f switch to force rebuild even if timestamps are up to date (as per the documentation).
When the source code has changed, new .pyc files are automatically created when you run the program again. Therefore I wouldn't worry about compiling, but focus your attention on the code itself.. :)
Videos
i don't have any experience with python that is worth anything. got sent a program for a school project, but it was made in Python and set up for linux. i have to compile it and i have no idea about how that works and need help.
in the message i got with the files, the creator writes " it was set up to work only on my specificLinux machine. You will probably have to recompile things to make it work." Having searched on the internet for how to do this, i haven't found anything that gave me a good idea about what i should do.
i would prefer not to send the files in this thread if anyone asks, out of respect to the creator, as i don't know if he would like that.
Edit: people seem to understand me not wanting to share it in this thread as i don't want to share it at all. i have no problem with doing in in dms, i just don't want to do it publicly
You can use the builtin reload function in python to automatically reload your module. What you can do is something like this:
import mymodule
def hook():
reload(mymodule)
mymodule.myfunction()
where hook() is what's called by ArcMap and mymodule is the module you're editing between invocations. You may have to edit sys.path to include the path of the module you're editing so that import mymodule does not fail. Or include the directory in site-packages (maybe using python setup.py develop).
Per @blah238's suggestion, the following script
- closes ArcMap (if open)
- creates Add-in
- installs Add-in silently
- re-opens ArcMap document
Save to directory containing makeaddin.py:
import os
#Location of ESRIRegAddIn.exe
esri = "C:/Program Files (x86)/Common Files/ArcGIS/bin/ESRIRegAddIn.exe"
cwd = os.getcwd()
mapdoc = <path to mxd>
#Close ArcMap if it is open
try: os.system("TASKKILL /F /IM ArcMap.exe")
except: pass
#Create ESRI Add-in file
os.system(os.path.join(cwd, "makeaddin.py"))
#Silently install Add-in file. The name of the file is based on folder it's located in.
os.system('"{0}" {1} /s'.format(esri, os.path.split(cwd)[-1] + ".esriaddin"))
#Open test map document.
os.system(mapdoc)
I've had a lot of experience running a compiled regex 1000s of times versus compiling on-the-fly, and have not noticed any perceivable difference. Obviously, this is anecdotal, and certainly not a great argument against compiling, but I've found the difference to be negligible.
EDIT:
After a quick glance at the actual Python 2.5 library code, I see that Python internally compiles AND CACHES regexes whenever you use them anyway (including calls to re.match()), so you're really only changing WHEN the regex gets compiled, and shouldn't be saving much time at all - only the time it takes to check the cache (a key lookup on an internal dict type).
From module re.py (comments are mine):
def match(pattern, string, flags=0):
return _compile(pattern, flags).match(string)
def _compile(*key):
# Does cache check at top of function
cachekey = (type(key[0]),) + key
p = _cache.get(cachekey)
if p is not None: return p
# ...
# Does actual compilation on cache miss
# ...
# Caches compiled regex
if len(_cache) >= _MAXCACHE:
_cache.clear()
_cache[cachekey] = p
return p
I still often pre-compile regular expressions, but only to bind them to a nice, reusable name, not for any expected performance gain.
For me, the biggest benefit to re.compile is being able to separate definition of the regex from its use.
Even a simple expression such as 0|[1-9][0-9]* (integer in base 10 without leading zeros) can be complex enough that you'd rather not have to retype it, check if you made any typos, and later have to recheck if there are typos when you start debugging. Plus, it's nicer to use a variable name such as num or num_b10 than 0|[1-9][0-9]*.
It's certainly possible to store strings and pass them to re.match; however, that's less readable:
num = "..."
# then, much later:
m = re.match(num, input)
Versus compiling:
num = re.compile("...")
# then, much later:
m = num.match(input)
Though it is fairly close, the last line of the second feels more natural and simpler when used repeatedly.
beginner here, i don't really see a difference just assigning the regex pattern to a variable. are there some cases where it can be helpful?